forked from owncloud/web
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapps.js
More file actions
151 lines (141 loc) · 3.73 KB
/
apps.js
File metadata and controls
151 lines (141 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const state = {
file: {
path: '',
edit: false
},
fileEditors: [],
newFileHandlers: [],
fileSideBars: [],
customFilesListIndicators: [],
meta: {}
}
const actions = {
// TODO move to app scope!
/**
* Open a file via webdav
* @param {object} payload - filePath & client reference
*/
openFile(context, payload) {
return new Promise((resolve, reject) => {
// TODO fix js-owncloud-client & change payload to filePath
const filePath = payload.filePath
context.commit('FETCH_FILE', filePath)
// TODO fix js-owncloud-client & use global client
const client = payload.client || false
if (client) {
client.files.getFileContents(filePath).then(resolve).catch(reject)
} else {
// if no client is given, implicit resolve without fetching the file...
// useful for images
resolve()
}
})
},
registerApp({ commit }, app) {
commit('REGISTER_APP', app)
},
addFileAction({ commit }, action) {
commit('ADD_FILE_ACTION', action)
}
}
const mutations = {
REGISTER_EXTENSION(state, extensionBundle) {
const { app, extension } = extensionBundle
const editor = {
app,
icon: extension.icon,
img: extension.img,
newTab: extension.newTab || false,
routeName: extension.routeName,
routes: extension.routes || [],
extension: extension.extension,
handler: extension.handler,
canBeDefault: extension.canBeDefault === true
}
state.fileEditors.push(editor)
if (extension.newFileMenu) {
extension.newFileMenu.ext = extension.extension
extension.newFileMenu.action = editor
state.newFileHandlers.push(extension.newFileMenu)
}
},
REGISTER_APP(state, appInfo) {
if (appInfo.extensions) {
appInfo.extensions.forEach((extension) => {
this.commit('REGISTER_EXTENSION', {
app: appInfo.id,
extension
})
})
}
if (appInfo.fileSideBars) {
// Merge in file side bars into global list
// Reassign object in whole so that it updates the state properly
const list = state.fileSideBars
appInfo.fileSideBars.forEach((sideBar) => {
list.push(sideBar)
})
state.fileSideBars = list
}
if (appInfo.filesListIndicators) {
const indicators = state.customFilesListIndicators
appInfo.filesListIndicators.forEach((indicator) => {
indicators.push(indicator)
})
state.customFilesListIndicators = indicators
}
if (!appInfo.id) return
// name: use id as fallback display name
// icon: use empty box as fallback icon
const app = {
name: appInfo.name || appInfo.id,
id: appInfo.id,
icon: appInfo.icon || 'check_box_outline_blank',
img: appInfo.img || null
}
state.meta[app.id] = app
},
FETCH_FILE(state, filePath) {
state.file.path = filePath
},
LOAD_EXTENSION_CONFIG(state, { id, config }) {
// make available in editors
const editors = [...state.fileEditors]
for (const editor of editors) {
if (editor.app === id) {
editor.config = config
}
}
state.fileEditors = editors
// make available in meta
if (state.meta[id]) {
const meta = { ...state.meta }
meta[id].config = config
state.meta = meta
}
}
}
const getters = {
appIds: (state) => {
return Object.keys(state.meta)
},
apps: (state) => {
return state.meta
},
activeFile: (state) => {
return state.file
},
newFileHandlers: (state) => {
return state.newFileHandlers
},
fileSideBars: (state) => {
return state.fileSideBars
},
customFilesListIndicators: (state) => state.customFilesListIndicators
}
export default {
state,
actions,
mutations,
getters
}