1
|
|
|
/** |
2
|
|
|
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]> |
3
|
|
|
* |
4
|
|
|
* @author John Molakvoæ <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program 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 License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
import Vue from 'vue' |
23
|
|
|
|
24
|
|
|
const state = { |
25
|
|
|
files: {} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
const mutations = { |
29
|
|
|
/** |
30
|
|
|
* Increment the number of contacts accepted |
31
|
|
|
* |
32
|
|
|
* @param {Object} state the store mutations |
33
|
|
|
* @param {Array} files the store mutations |
34
|
|
|
*/ |
35
|
|
|
updateFiles(state, files) { |
36
|
|
|
files.forEach(file => { |
37
|
|
|
Vue.set(state.files, file.id, file) |
38
|
|
|
}) |
39
|
|
|
}, |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Set a folder subfolders |
43
|
|
|
* |
44
|
|
|
* @param {Object} state the store mutations |
45
|
|
|
* @param {Object} data destructuring object |
46
|
|
|
* @param {number} data.id current folder id |
47
|
|
|
* @param {Array} data.folders list of folders |
48
|
|
|
*/ |
49
|
|
|
setSubFolders(state, { id, folders }) { |
50
|
|
|
if (state.files[id]) { |
51
|
|
|
Vue.set(state.files[id], 'folders', [...folders.map(folder => folder.id)]) |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
const getters = { |
57
|
|
|
files: state => state.files |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
const actions = { |
61
|
|
|
/** |
62
|
|
|
* Increment the number of contacts accepted |
63
|
|
|
* |
64
|
|
|
* @param {Object} context the store mutations |
65
|
|
|
* @param {Object} data destructuring object |
66
|
|
|
* @param {Object} data.folder current folder fileinfo |
67
|
|
|
* @param {Array} data.files list of files |
68
|
|
|
* @param {Array} data.folders list of folders within current folder |
69
|
|
|
*/ |
70
|
|
|
updateFiles(context, { folder, files, folders }) { |
71
|
|
|
const t0 = performance.now() |
|
|
|
|
72
|
|
|
// we want all the FileInfo! Folders included! |
73
|
|
|
context.commit('updateFiles', [folder, ...files, ...folders]) |
74
|
|
|
context.commit('setSubFolders', { id: folder.id, folders }) |
75
|
|
|
const t1 = performance.now() |
76
|
|
|
console.debug('perf: updateFiles', `${t1 - t0}ms`) |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
export default { state, mutations, getters, actions } |
81
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.