-
Notifications
You must be signed in to change notification settings - Fork 19
/
filesPlugin.js
104 lines (98 loc) · 2.91 KB
/
filesPlugin.js
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
/*
* Copyright (c) 2023 Sagar Gurung <sagar@jankaritech.com>
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
import '../bootstrap.js'
import { registerFileAction, FileAction, Permission } from '@nextcloud/files'
import OpenProjectIcon from '../../img/app-dark.svg'
import LinkMultipleFilesModal from '../views/LinkMultipleFilesModal.vue'
import Vue from 'vue'
if (!OCA.OpenProject) {
/**
* @namespace
*/
OCA.OpenProject = {
requestOnFileChange: false,
actionIgnoreLists: [
'trashbin',
],
}
}
const compare = (files) => {
// store all the file-id in an array and set the file ids
const fileInfos = []
for (const file of files) {
const fileInfo = {
id: file.fileid,
name: file.basename,
}
fileInfos.push(fileInfo)
}
OCA.OpenProject.LinkMultipleFilesModalVue.$children[0].setFileInfos(fileInfos)
OCA.OpenProject.LinkMultipleFilesModalVue.$children[0].showModal()
}
// registering file action for single file selection
const singleFileAction = new FileAction({
id: 'open-project-single',
displayName: () => t('integration_openproject', 'OpenProject'),
order: 0,
enabled(nodes, view) {
// we don't want 'files.public' or any other view
return view.id === 'files'
&& nodes.length === 1
&& !nodes.some(({ permissions }) => (permissions & Permission.READ) === 0)
},
iconSvgInline: () => OpenProjectIcon,
async exec(node, view, dir) {
window.OCA.Files.Sidebar.setActiveTab('open-project')
await window.OCA.Files.Sidebar.open(node.path)
return null
},
})
registerFileAction(singleFileAction)
// registering file action for multiple file selection
const multipleFileAction = new FileAction({
id: 'open-project-multiple',
displayName: () => t('integration_openproject', 'Link to work package'),
order: 0,
enabled(nodes, view) {
// we don't want 'files.public' or any other view
return view.id === 'files'
&& nodes.length >= 1
&& !nodes.some(({ permissions }) => (permissions & Permission.READ) === 0)
},
iconSvgInline: () => OpenProjectIcon,
async exec(node, view, dir) {
console.debug('in the single action handler')
OCA.OpenProject.LinkMultipleFilesModalVue.$children[0].setFileInfos([{
id: node.fileid,
name: node.basename,
}])
OCA.OpenProject.LinkMultipleFilesModalVue.$children[0].showModal()
// to avoid the toast message
return null
},
async execBatch(nodes, view, dir) {
console.debug('in the multi action handler')
compare(nodes)
// to avoid the toast message
return nodes.map(n => null)
},
})
registerFileAction(multipleFileAction)
OC.Plugins.register('OCA.Files.FileList', OCA.OpenProject.FilesPlugin)
const modalId = 'multipleFileLinkModal'
const modalElement = document.createElement('div')
modalElement.id = modalId
document.body.append(modalElement)
OCA.OpenProject.LinkMultipleFilesModalVue = new Vue({
el: modalElement,
render: h => {
return h(LinkMultipleFilesModal)
},
})