Newer
Older
piotr.kupczyk@id.ethz.ch
committed
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
import openbis from '@src/js/services/openbis.js'
import actions from '@src/js/store/actions/actions.js'
import pages from '@src/js/common/consts/pages.js'
import objectType from '@src/js/common/consts/objectType.js'
import objectOperation from '@src/js/common/consts/objectOperation.js'
import BrowserController from '@src/js/components/common/browser/BrowserController.js'
export default class ToolBrowserController extends BrowserController {
doGetPage() {
return pages.TOOLS
}
async doLoadNodes() {
return Promise.all([
openbis.searchPlugins(
new openbis.PluginSearchCriteria(),
new openbis.PluginFetchOptions()
)
]).then(([plugins]) => {
const dynamicPropertyPluginNodes = plugins
.getObjects()
.filter(
plugin => plugin.pluginType === openbis.PluginType.DYNAMIC_PROPERTY
)
.map(plugin => {
return {
id: `dynamicPropertyPlugin/${plugin.name}`,
text: plugin.name,
object: {
type: objectType.DYNAMIC_PROPERTY_PLUGIN,
id: plugin.name
},
canMatchFilter: true,
canRemove: true
}
})
const entityValidationPluginNodes = plugins
.getObjects()
.filter(
plugin => plugin.pluginType === openbis.PluginType.ENTITY_VALIDATION
)
.map(plugin => {
return {
id: `entityValidationPlugin/${plugin.name}`,
text: plugin.name,
object: {
type: objectType.ENTITY_VALIDATION_PLUGIN,
id: plugin.name
},
canMatchFilter: true,
canRemove: true
}
})
let nodes = [
{
id: 'dynamicPropertyPlugins',
text: 'Dynamic Property Plugins',
children: dynamicPropertyPluginNodes,
childrenType: objectType.NEW_DYNAMIC_PROPERTY_PLUGIN,
canAdd: true
},
{
id: 'entityValidationPlugins',
text: 'Entity Validation Plugins',
children: entityValidationPluginNodes,
childrenType: objectType.NEW_ENTITY_VALIDATION_PLUGIN,
canAdd: true
}
]
return nodes
})
}
doNodeAdd(node) {
if (node && node.childrenType) {
this.context.dispatch(
actions.objectNew(this.getPage(), node.childrenType)
)
}
}
doNodeRemove(node) {
if (!node.object) {
return Promise.resolve()
}
const { type, id } = node.object
const reason = 'deleted via ng_ui'
return this._prepareRemoveOperations(type, id, reason)
.then(operations => {
const options = new openbis.SynchronousOperationExecutionOptions()
options.setExecuteInOrder(true)
return openbis.executeOperations(operations, options)
})
.then(() => {
this.context.dispatch(actions.objectDelete(this.getPage(), type, id))
})
.catch(error => {
this.context.dispatch(actions.errorChange(error))
})
}
_prepareRemoveOperations(type, id, reason) {
if (
type === objectType.DYNAMIC_PROPERTY_PLUGIN ||
type === objectType.ENTITY_VALIDATION_PLUGIN
) {
return this._prepareRemovePluginOperations(id, reason)
} else {
throw new Error('Unsupported type: ' + type)
}
}
_prepareRemovePluginOperations(id, reason) {
const options = new openbis.PluginDeletionOptions()
options.setReason(reason)
return Promise.resolve([
new openbis.DeletePluginsOperation(
[new openbis.PluginPermId(id)],
options
)
])
}
doGetObservedModifications() {
return {
[objectType.DYNAMIC_PROPERTY_PLUGIN]: [
objectOperation.CREATE,
objectOperation.DELETE
],
[objectType.ENTITY_VALIDATION_PLUGIN]: [
objectOperation.CREATE,
objectOperation.DELETE
]
}
}
}