These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | /** |
||
2 | * Nextcloud - Tasks |
||
3 | * |
||
4 | * @author Raimund Schlüßler |
||
5 | * @copyright 2018 Raimund Schlüßler <[email protected]> |
||
6 | * @copyright 2018 Vadim Nicolai <[email protected]> |
||
7 | * |
||
8 | * This library is free software; you can redistribute it and/or |
||
9 | * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
||
10 | * License as published by the Free Software Foundation; either |
||
11 | * version 3 of the License, or any later version. |
||
12 | * |
||
13 | * This library is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public |
||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
||
20 | * |
||
21 | */ |
||
22 | 'use strict' |
||
23 | |||
24 | import Vue from 'vue' |
||
25 | import Vuex from 'vuex' |
||
26 | import Requests from '../services/requests' |
||
27 | |||
28 | Vue.use(Vuex) |
||
29 | |||
30 | const state = { |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
Loading history...
|
|||
31 | settings: {} |
||
32 | } |
||
33 | |||
34 | const getters = { |
||
0 ignored issues
–
show
|
|||
35 | /** |
||
36 | * Returns the sort order how to sort tasks |
||
37 | * |
||
38 | * @param {Object} state The store data |
||
39 | * @returns {String} The sort order |
||
40 | */ |
||
41 | sortOrder: (state) => state.settings.sortOrder, |
||
42 | |||
43 | /** |
||
44 | * Returns the sort direction how to sort tasks |
||
45 | * |
||
46 | * @param {Object} state The store data |
||
47 | * @returns {String} The sort direction |
||
48 | */ |
||
49 | sortDirection: (state) => state.settings.sortDirection, |
||
50 | } |
||
51 | |||
52 | const mutations = { |
||
0 ignored issues
–
show
|
|||
53 | /** |
||
54 | * Sets all settings |
||
55 | * |
||
56 | * @param {Object} state Default state |
||
57 | * @param {Object} payload The settings object |
||
58 | */ |
||
59 | setSettings(state, payload) { |
||
0 ignored issues
–
show
|
|||
60 | state.settings = payload.settings |
||
61 | }, |
||
62 | |||
63 | /** |
||
64 | * Sets a setting value |
||
65 | * |
||
66 | * @param {Object} state Default state |
||
67 | * @param {Object} payload The setting object |
||
68 | */ |
||
69 | setSetting(state, payload) { |
||
0 ignored issues
–
show
|
|||
70 | state.settings[payload.type] = payload.value |
||
71 | } |
||
72 | } |
||
73 | |||
74 | const actions = { |
||
0 ignored issues
–
show
|
|||
75 | /** |
||
76 | * Writes a setting to the server |
||
77 | * |
||
78 | * @param {Object} context The store context |
||
79 | * @param {Object} payload The setting to save |
||
80 | * @returns {Promise} |
||
81 | */ |
||
82 | setSetting(context, payload) { |
||
0 ignored issues
–
show
|
|||
83 | context.commit('setSetting', payload) |
||
84 | return new Promise(function() { |
||
85 | Requests.post(OC.generateUrl('apps/tasks/settings/{type}/{value}', payload), {}) |
||
86 | }) |
||
87 | }, |
||
88 | |||
89 | /** |
||
90 | * Requests all app settings from the server |
||
91 | * |
||
92 | * @param {Object} commit The store mutations |
||
93 | * @returns {Promise} |
||
94 | */ |
||
95 | loadSettings({ commit }) { |
||
0 ignored issues
–
show
|
|||
96 | return new Promise(function(resolve) { |
||
97 | Requests.get(OC.generateUrl('apps/tasks/settings')) |
||
98 | .then(response => { |
||
99 | commit('setSettings', { |
||
100 | settings: response.data.data.settings |
||
101 | }) |
||
102 | resolve() |
||
103 | }) |
||
104 | }) |
||
105 | } |
||
106 | } |
||
107 | |||
108 | export default { state, getters, mutations, actions } |
||
0 ignored issues
–
show
|
|||
109 |