Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-08-31 09:16:45 +0300
committerdartcafe <github@dartcafe.de>2020-08-31 09:16:45 +0300
commitcc56251f43c1c2c925e8d54c2b153c3eb138a3d2 (patch)
tree08c99cdd2254edff0e9be872fd17cca46d4801c0
parentb0c49ec853c04688b762acb33a393352d00fc6ee (diff)
Added user preferences backend and UI
-rw-r--r--appinfo/routes.php4
-rw-r--r--lib/Controller/PreferencesController.php145
-rw-r--r--lib/Db/Preferences.php61
-rw-r--r--lib/Db/PreferencesMapper.php74
-rw-r--r--lib/Migration/Version0105Date20200523142076.php89
-rw-r--r--src/js/App.vue90
-rw-r--r--src/js/components/Navigation/Navigation.vue10
-rw-r--r--src/js/components/Navigation/NavigationSettings.vue105
-rw-r--r--src/js/store/modules/settings.js81
9 files changed, 619 insertions, 40 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index a2082adf..f4da43f2 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -114,5 +114,9 @@ return [
['name' => 'comment_api#add', 'url' => '/api/v1.0/comment', 'verb' => 'POST'],
['name' => 'comment_api#delete', 'url' => '/api/v1.0/comment/{commentId}', 'verb' => 'DELETE'],
+ ['name' => 'preferences#write', 'url' => '/preferences/write/', 'verb' => 'POST'],
+ ['name' => 'preferences#get', 'url' => '/preferences/get/', 'verb' => 'GET'],
+ ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get/', 'verb' => 'POST'],
+ ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST']
]
];
diff --git a/lib/Controller/PreferencesController.php b/lib/Controller/PreferencesController.php
new file mode 100644
index 00000000..904e1a19
--- /dev/null
+++ b/lib/Controller/PreferencesController.php
@@ -0,0 +1,145 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Controller;
+
+use Exception;
+use OCP\AppFramework\Db\DoesNotExistException;
+
+
+use OCP\IRequest;
+use OCP\ILogger;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+
+use OCP\IGroupManager;
+
+use OCA\Polls\Db\Preferences;
+use OCA\Polls\Db\PreferencesMapper;
+
+class PreferencesController extends Controller {
+
+ private $userId;
+ private $preferencesMapper;
+ private $logger;
+
+ private $groupManager;
+ private $pollMapper;
+ private $anonymizer;
+ private $acl;
+
+ /**
+ * PreferencesController constructor.
+ * @param string $appName
+ * @param $UserId
+ * @param PreferencesMapper $preferencesMapper
+ */
+
+ public function __construct(
+ string $appName,
+ $userId,
+ IRequest $request,
+ ILogger $logger,
+ PreferencesMapper $preferencesMapper
+ ) {
+ parent::__construct($appName, $request);
+ $this->userId = $userId;
+ $this->preferencesMapper = $preferencesMapper;
+ }
+
+
+ /**
+ * get
+ * Read all preferences
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param integer $pollId
+ * @return DataResponse
+ */
+ public function get() {
+
+ try {
+ return new DataResponse($this->preferencesMapper->find($this->userId), Http::STATUS_OK);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($e, Http::STATUS_NOT_FOUND);
+ }
+
+ }
+
+ /**
+ * write
+ * Write a new comment to the db and returns the new comment as array
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param int $pollId
+ * @param string $userId
+ * @param string $message
+ * @return DataResponse
+ */
+ public function write($settings) {
+ if (!\OC::$server->getUserSession()->isLoggedIn()) {
+ return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
+ }
+
+ try {
+ $preferences = $this->preferencesMapper->find($this->userId);
+ $preferences->setPreferences(json_encode($settings));
+ $preferences->setTimestamp(time());
+ $preferences = $this->preferencesMapper->update($preferences);
+ } catch (\Exception $e) {
+ $preferences = new Preferences();
+ $preferences->setUserId($this->userId);
+ $preferences->setPreferences(json_encode($settings));
+ $preferences->setTimestamp(time());
+ $preferences = $this->preferencesMapper->insert($preferences);
+ }
+
+ return new DataResponse($preferences, Http::STATUS_OK);
+
+ }
+
+ // /**
+ // * delete
+ // * Delete Preferences
+ // * @NoAdminRequired
+ // * @param int $pollId
+ // * @param string $message
+ // * @return DataResponse
+ // */
+ // public function delete($userId) {
+ // if (!\OC::$server->getUserSession()->isLoggedIn()) {
+ // return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
+ // }
+ //
+ // try {
+ // $this->preferencesMapper->delete($userId);
+ // } catch (\Exception $e) {
+ // return new DataResponse($e, Http::STATUS_CONFLICT);
+ // }
+ //
+ // return new DataResponse(['deleted' => $userId], Http::STATUS_OK);
+ //
+ // }
+
+}
diff --git a/lib/Db/Preferences.php b/lib/Db/Preferences.php
new file mode 100644
index 00000000..db15d529
--- /dev/null
+++ b/lib/Db/Preferences.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Db;
+
+use JsonSerializable;
+
+use OCP\IUser;
+use OCP\AppFramework\Db\Entity;
+
+/**
+ * @method integer getId()
+ * @method void setId(integer $value)
+ * @method string getUserId()
+ * @method void setUserId(string $value)
+ * @method string getTimestamp()
+ * @method void setTimestamp(integer $value)
+ * @method string getPreferences()
+ * @method void setPreferences(string $value)
+ */
+class Preferences extends Entity implements JsonSerializable {
+
+ /** @var string $userId */
+ protected $userId;
+
+ /** @var integer $timestamp */
+ protected $timestamp;
+
+ /** @var string $preferences */
+ protected $preferences;
+
+ public function jsonSerialize() {
+
+ return [
+ 'id' => intval($this->id),
+ 'userId' => $this->userId,
+ 'timestamp' => intval($this->timestamp),
+ 'preferences' => $this->preferences,
+ ];
+ }
+}
diff --git a/lib/Db/PreferencesMapper.php b/lib/Db/PreferencesMapper.php
new file mode 100644
index 00000000..b4d81a98
--- /dev/null
+++ b/lib/Db/PreferencesMapper.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Db;
+
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\QBMapper;
+
+class PreferencesMapper extends QBMapper {
+
+ /**
+ * PreferencesMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_preferences', '\OCA\Polls\Db\Preferences');
+ }
+
+ /**
+ * @param int $id
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Preferences
+ */
+
+ public function find($userId) {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_INT))
+ );
+
+ return $this->findEntity($qb);
+ }
+
+ // /**
+ // * @param int $userId
+ // */
+ // public function delete($userId) {
+ // $qb = $this->db->getQueryBuilder();
+ //
+ // $qb->delete($this->getTableName())
+ // ->where(
+ // $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_INT))
+ // );
+ //
+ // $qb->execute();
+ // }
+
+}
diff --git a/lib/Migration/Version0105Date20200523142076.php b/lib/Migration/Version0105Date20200523142076.php
new file mode 100644
index 00000000..87da0be3
--- /dev/null
+++ b/lib/Migration/Version0105Date20200523142076.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Migration;
+
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+/**
+ * Installation class for the polls app.
+ * Initial db creation
+ */
+class Version0105Date20200523142076 extends SimpleMigrationStep {
+
+ /** @var IDBConnection */
+ protected $connection;
+
+ /** @var IConfig */
+ protected $config;
+
+ /**
+ * @param IDBConnection $connection
+ * @param IConfig $config
+ */
+ public function __construct(IDBConnection $connection, IConfig $config) {
+ $this->connection = $connection;
+ $this->config = $config;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ * @since 13.0.0
+ */
+ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+ if (!$schema->hasTable('polls_preferences')) {
+ $table = $schema->createTable('polls_preferences');
+
+ $table->addColumn('id', Type::INTEGER, [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ ]);
+ $table->addColumn('user_id', Type::STRING, [
+ 'notnull' => true,
+ 'length' => 64,
+ ]);
+ $table->addColumn('timestamp', Type::INTEGER, [
+ 'length' => 11,
+ 'notnull' => true,
+ 'default' => 0
+ ]);
+ $table->addColumn('preferences', Type::TEXT, [
+ 'notnull' => true,
+ 'default' => '',
+ ]);
+ $table->setPrimaryKey(['id']);
+ }
+ return $schema;
+ }
+}
diff --git a/src/js/App.vue b/src/js/App.vue
index bc9eb3a2..280021e0 100644
--- a/src/js/App.vue
+++ b/src/js/App.vue
@@ -21,10 +21,12 @@
-->
<template>
- <Content app-name="polls" :class="transitionClass">
- <Navigation v-if="getCurrentUser()" />
+ <Content app-name="polls" :class="[transitionClass, { 'experimental': settings.experimental, 'bgimage': settings.useImage, 'bgcolored': settings.experimental }]">
+ <Navigation v-if="getCurrentUser()" :class="{ 'glassy': settings.glassyNavigation }" />
<router-view />
- <SideBar v-if="sideBarOpen && $store.state.poll.id" :active="activeTab" />
+ <SideBar v-if="sideBarOpen && $store.state.poll.id"
+ :active="activeTab"
+ :class="{ 'glassy': settings.glassySidebar }" />
</Content>
</template>
@@ -35,6 +37,7 @@ import { getCurrentUser } from '@nextcloud/auth'
import { showError } from '@nextcloud/dialogs'
import { Content } from '@nextcloud/vue'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
+import { mapState } from 'vuex'
import '@nextcloud/dialogs/styles/toast.scss'
export default {
@@ -53,6 +56,13 @@ export default {
}
},
+ computed: {
+ ...mapState({
+ settings: state => state.settings.user,
+ }),
+
+ },
+
created() {
subscribe('transitions-off', (delay) => {
this.transitionClass = ''
@@ -83,6 +93,7 @@ export default {
})
+ this.$store.dispatch('getSettings')
if (getCurrentUser()) {
this.updatePolls()
subscribe('update-polls', () => {
@@ -303,42 +314,6 @@ input {
}
// experimental colored background in the main area
-.app-polls.bgcolored {
- .app-navigation {
- border-right: 0px;
- box-shadow: 2px 0 6px var(--color-box-shadow);
- }
- .app-content {
- background-color: var(--color-primary-light);
- [class*='area__'] {
- box-shadow: 2px 2px 6px var(--color-box-shadow);
- margin: 12px;
- }
- }
-}
-
-// experimental background image
-.app-polls.bgimage {
- background: url('https://images.unsplash.com/photo-1589967698280-1e86b3d8c1ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80)');
- background-size: cover;
- .app-navigation {
- backdrop-filter: blur(10px);
- background-color: rgba(255, 255, 255, 0.5);
- border-right: 0px;
- box-shadow: 2px 0 6px var(--color-box-shadow);
- }
- .app-content {
- background-color: transparent;
- }
- .app-sidebar {
- backdrop-filter: blur(10px);
- background-color: rgba(255, 255, 255, 0.5);
- }
- [class*='area__'] {
- box-shadow: 2px 2px 6px var(--color-box-shadow);
- margin: 12px;
- }
-}
[class*='area__'] {
padding: 8px;
@@ -348,4 +323,41 @@ input {
min-width: 320px;
}
+.experimental {
+ &.app-polls.bgcolored {
+ .app-navigation {
+ border-right: 0px;
+ box-shadow: 2px 0 6px var(--color-box-shadow);
+ }
+ .app-content {
+ background-color: var(--color-primary-light);
+ [class*='area__'] {
+ box-shadow: 2px 2px 6px var(--color-box-shadow);
+ margin: 12px;
+ }
+ }
+ }
+
+ // experimental background image
+ &.app-polls.bgimage {
+ background: url('https://images.unsplash.com/photo-1589967698280-1e86b3d8c1ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80)');
+ background-size: cover;
+ .glassy {
+ backdrop-filter: blur(10px);
+ background-color: rgba(255, 255, 255, 0.5);
+ }
+ .app-navigation {
+ border-right: 0px;
+ box-shadow: 2px 0 6px var(--color-box-shadow);
+ }
+ .app-content {
+ background-color: transparent;
+ }
+ [class*='area__'] {
+ box-shadow: 2px 2px 6px var(--color-box-shadow);
+ margin: 12px;
+ }
+ }
+}
+
</style>
diff --git a/src/js/components/Navigation/Navigation.vue b/src/js/components/Navigation/Navigation.vue
index d64751f1..cbd59175 100644
--- a/src/js/components/Navigation/Navigation.vue
+++ b/src/js/components/Navigation/Navigation.vue
@@ -38,14 +38,20 @@
</ul>
</AppNavigationItem>
</template>
+ <AppNavigationSettings :title="t('core', 'Settings')">
+ <NavigationSettings />
+ </AppNavigationSettings>
</AppNavigation>
</template>
<script>
+import { AppNavigation, AppNavigationNew, AppNavigationItem, AppNavigationSettings } from '@nextcloud/vue'
+import { showError } from '@nextcloud/dialogs'
+import { mapGetters } from 'vuex'
import CreateDlg from '../Create/CreateDlg'
import PollNavigationItems from './PollNavigationItems'
-import { showError } from '@nextcloud/dialogs'
+import NavigationSettings from './NavigationSettings'
import { emit } from '@nextcloud/event-bus'
import { AppNavigation, AppNavigationNew, AppNavigationItem } from '@nextcloud/vue'
import { mapGetters } from 'vuex'
@@ -56,6 +62,8 @@ export default {
AppNavigation,
AppNavigationNew,
AppNavigationItem,
+ AppNavigationSettings,
+ NavigationSettings,
CreateDlg,
PollNavigationItems,
},
diff --git a/src/js/components/Navigation/NavigationSettings.vue b/src/js/components/Navigation/NavigationSettings.vue
new file mode 100644
index 00000000..df869895
--- /dev/null
+++ b/src/js/components/Navigation/NavigationSettings.vue
@@ -0,0 +1,105 @@
+<!--
+ - @copyright Copyright (c) 2018 René Gieling <github@dartcafe.de>
+ -
+ - @author René Gieling <github@dartcafe.de>
+ -
+ - @license GNU AGPL version 3 or any later version
+ -
+ - This program is free software: you can redistribute it and/or modify
+ - it under the terms of the GNU Affero General Public License as
+ - published by the Free Software Foundation, either version 3 of the
+ - License, or (at your option) any later version.
+ -
+ - This program is distributed in the hope that it will be useful,
+ - but WITHOUT ANY WARRANTY; without even the implied warranty of
+ - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ - GNU Affero General Public License for more details.
+ -
+ - You should have received a copy of the GNU Affero General Public License
+ - along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -
+ -->
+
+<template>
+ <div>
+ <input id="experimental" v-model="experimental"
+ type="checkbox" class="checkbox">
+ <label for="experimental">{{ t('polls', 'Activate experimental settings.') }}</label>
+
+ <div v-if="experimental">
+ <input id="useimage" v-model="useImage"
+ type="checkbox" class="checkbox">
+ <label for="useimage">{{ t('polls', 'Use background image.') }}</label>
+
+ <!-- <input v-if="bgImage" v-model="imageurl" type="text"> -->
+ <input id="glassyNavigation" v-model="glassyNavigation"
+ type="checkbox" class="checkbox">
+ <label for="glassyNavigation">{{ t('polls', 'Glassy navigation.') }}</label>
+ <input id="glassySidebar" v-model="glassySidebar"
+ type="checkbox" class="checkbox">
+ <label for="glassySidebar">{{ t('polls', 'Glassy sidebar.') }}</label>
+ </div>
+ </div>
+</template>
+
+<script>
+
+import { mapState } from 'vuex'
+export default {
+ name: 'NavigationSettings',
+
+ computed: {
+ ...mapState({
+ settings: state => state.settings.user,
+ }),
+ // Add bindings
+ experimental: {
+ get() {
+ return this.settings.experimental
+ },
+ set(value) {
+ this.writeValue({ experimental: value })
+ },
+ },
+ useImage: {
+ get() {
+ return this.settings.useImage
+ },
+ set(value) {
+ this.writeValue({ useImage: value })
+ },
+ },
+ imageUrl: {
+ get() {
+ return this.settings.imageUrl
+ },
+ set(value) {
+ this.writeValue({ imageUrl: value })
+ },
+ },
+ glassyNavigation: {
+ get() {
+ return this.settings.glassyNavigation
+ },
+ set(value) {
+ this.writeValue({ glassyNavigation: value })
+ },
+ },
+ glassySidebar: {
+ get() {
+ return this.settings.glassySidebar
+ },
+ set(value) {
+ this.writeValue({ glassySidebar: value })
+ },
+ },
+ },
+
+ methods: {
+ writeValue(value) {
+ this.$store.commit('setUserSetting', value)
+ this.$store.dispatch('writeSetting')
+ },
+ },
+}
+</script>
diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js
new file mode 100644
index 00000000..43a4b6fd
--- /dev/null
+++ b/src/js/store/modules/settings.js
@@ -0,0 +1,81 @@
+/*
+ * @copyright Copyright (c) 2019 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import axios from '@nextcloud/axios'
+import { generateUrl } from '@nextcloud/router'
+
+const defaultSettings = () => {
+ return {
+ user: {
+ experimental: false,
+ useImage: false,
+ imageUrl: '',
+ glassyNavigation: false,
+ glassySidebar: false,
+ },
+ }
+}
+
+const state = defaultSettings()
+
+const mutations = {
+ reset(state) {
+ Object.assign(state, defaultSettings())
+ },
+
+ setUserSetting(state, payload) {
+ Object.assign(state.user, payload)
+ },
+}
+
+const getters = {
+}
+
+const actions = {
+ getSettings(context) {
+ const endPoint = 'apps/polls/preferences/get'
+
+ return axios.get(generateUrl(endPoint))
+ .then((response) => {
+ context.commit('setUserSetting', JSON.parse(response.data.preferences))
+ })
+ .catch(() => {
+ context.commit('reset')
+ })
+ },
+ writeSetting(context) {
+ const endPoint = 'apps/polls/preferences/write'
+ // context.commit('setUserSetting', { settings: payload })
+
+ return axios.post(generateUrl(endPoint), { settings: context.state.user })
+ .then((response) => {
+ context.commit('setUserSetting', JSON.parse(response.data.preferences))
+ })
+ .catch((error) => {
+ console.error('Error writing preferences', { error: error.response }, { preferences: state.user })
+ throw error
+ })
+ },
+
+}
+
+export default { state, mutations, getters, actions }