From 8330431ae790d8ede3064ed55d507313f9a2ac76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Sun, 2 Sep 2018 15:44:29 +0200 Subject: [PATCH] Save and load settings --- appinfo/routes.php | 2 +- lib/Controller/SettingsController.php | 6 +- lib/Service/SettingsService.php | 17 ++--- src/components/TheSettings.vue | 99 +++++++++++++++++++++++---- src/main.js | 1 + src/services/requests.js | 5 ++ src/store.js | 24 +++++++ 7 files changed, 125 insertions(+), 29 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 3f9c4fe9..a13b2c12 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -40,5 +40,5 @@ $application->registerRoutes($this, array('routes' => array( // settings array('name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'), - array('name' => 'settings#set', 'url' => '/settings/{type}/{setting}/{value}', 'verb' => 'POST'), + array('name' => 'settings#set', 'url' => '/settings/{setting}/{value}', 'verb' => 'POST'), ))); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index fe4edbd0..7ff8a228 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -49,9 +49,9 @@ class SettingsController extends Controller { /** * @NoAdminRequired */ - public function set($setting, $type, $value){ - return $this->generateResponse(function () use ($setting, $type, $value) { - return $this->settingsService->set($setting, $type, $value); + public function set($setting, $value){ + return $this->generateResponse(function () use ($setting, $value) { + return $this->settingsService->set($setting, $value); }); } } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 979e3d78..1440cf8d 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -43,14 +43,11 @@ class SettingsService { */ public function get() { $settings = array( - array( - 'id' => 'various', - 'showHidden' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_showHidden'), - 'startOfWeek' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_startOfWeek'), - 'sortOrder' => (string)$this->settings->getUserValue($this->userId, $this->appName,'various_sortOrder'), - 'sortDirection' => (bool)$this->settings->getUserValue($this->userId, $this->appName,'various_sortDirection'), - 'userID' => $this->userId - ) + 'showHidden' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_showHidden'), + 'startOfWeek' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_startOfWeek'), + 'sortOrder' => (string)$this->settings->getUserValue($this->userId, $this->appName,'various_sortOrder'), + 'sortDirection' => (bool)$this->settings->getUserValue($this->userId, $this->appName,'various_sortDirection'), + 'userID' => $this->userId ); return $settings; } @@ -63,8 +60,8 @@ class SettingsService { * @param $value * @return bool */ - public function set($setting, $type, $value) { - $this->settings->setUserValue($this->userId, $this->appName, $type.'_'.$setting, $value); + public function set($setting, $value) { + $this->settings->setUserValue($this->userId, $this->appName, 'various_'.$setting, $value); return true; } } diff --git a/src/components/TheSettings.vue b/src/components/TheSettings.vue index 3c68ce06..d8bc39c8 100644 --- a/src/components/TheSettings.vue +++ b/src/components/TheSettings.vue @@ -30,10 +30,13 @@ License along with this library. If not, see . @@ -62,12 +70,73 @@ import { mapState } from 'vuex' export default { components: { }, - computed: Object.assign({}, - mapState({ - collections: state => state.collections, - calendars: state => state.calendars, - dayOfMonth: state => state.dayOfMonth - }) - ) + data: function() { + return { + collectionOptions: [ + { + id: 0, + name: t('tasks', 'Hidden') + }, + { + id: 1, + name: t('tasks', 'Visible') + }, + { + id: 2, + name: t('tasks', 'Automatic') + } + ], + startOfWeekOptions: [ + { + id: 0, + name: t('tasks', 'Sunday') + }, + { + id: 1, + name: t('tasks', 'Monday') + }, + { + id: 2, + name: t('tasks', 'Tuesday') + }, + { + id: 3, + name: t('tasks', 'Wednesday') + }, + { + id: 4, + name: t('tasks', 'Thursday') + }, + { + id: 5, + name: t('tasks', 'Friday') + }, + { + id: 6, + name: t('tasks', 'Saturday') + } + ] + } + }, + computed: Object.assign({ + startOfWeek: { + get() { + return this.$store.state.settings.startOfWeek + }, + set(value) { + this.$store.dispatch('setSetting', { type: 'startOfWeek', value: value }) + } + } + }, + mapState({ + collections: state => state.collections, + calendars: state => state.calendars, + dayOfMonth: state => state.dayOfMonth + }) + ), + methods: { + setVisibility: function(collection) { + } + } } diff --git a/src/main.js b/src/main.js index e56cac5e..8a7a53ed 100644 --- a/src/main.js +++ b/src/main.js @@ -65,6 +65,7 @@ OCA.Tasks.App = new Vue({ }, beforeMount() { this.$store.dispatch('loadCollections') + this.$store.dispatch('loadSettings') }, methods: { filter(query) { diff --git a/src/services/requests.js b/src/services/requests.js index d498c1d4..cd8e0fea 100644 --- a/src/services/requests.js +++ b/src/services/requests.js @@ -28,5 +28,10 @@ export default { return Axios.get(url) .then((response) => Promise.resolve(response)) .catch((error) => Promise.reject(error)) + }, + post(url, data) { + return Axios.post(url, data) + .then((response) => Promise.resolve(response)) + .catch((error) => Promise.reject(error)) } } diff --git a/src/store.js b/src/store.js index b931b750..0f3f9227 100644 --- a/src/store.js +++ b/src/store.js @@ -51,11 +51,18 @@ export default new Vuex.Store({ writable: true } ], + settings: {}, dayOfMonth: 23 }, mutations: { setCollections(state, payload) { state.collections = payload.collections + }, + setSettings(state, payload) { + state.settings = payload.settings + }, + setSetting(state, payload) { + state.settings[payload.type] = payload.value } }, actions: { @@ -69,6 +76,23 @@ export default new Vuex.Store({ resolve() }) }) + }, + setSetting(context, payload) { + context.commit('setSetting', payload) + return new Promise(function() { + Requests.post(OC.generateUrl('apps/tasks/settings/' + payload.type + '/' + payload.value), {}) + }) + }, + loadSettings({ commit }) { + return new Promise(function(resolve) { + Requests.get(OC.generateUrl('apps/tasks/settings')) + .then(response => { + commit('setSettings', { + settings: response.data.data.settings + }) + resolve() + }) + }) } } })