This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
MultiInstanceLoopCharacteristics.js
186 lines (143 loc) · 5.37 KB
/
MultiInstanceLoopCharacteristics.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/
import {
getBusinessObject
} from 'bpmn-js/lib/util/ModelUtil';
import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
import elementHelper from 'bpmn-js-properties-panel/lib/helper/ElementHelper';
import cmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper';
import extensionElementsHelper from 'bpmn-js-properties-panel/lib/helper/ExtensionElementsHelper';
export default function(element, bpmnFactory, translate) {
function getProperty(element, propertyName) {
const loopCharacteristics = getLoopCharacteristics(element),
zeebeLoopCharacteristics = getZeebeLoopCharacteristics(loopCharacteristics);
return zeebeLoopCharacteristics && zeebeLoopCharacteristics.get(propertyName);
}
function setProperties(element, values) {
const loopCharacteristics = getLoopCharacteristics(element),
commands = [];
// ensure extensionElements
let extensionElements = loopCharacteristics.get('extensionElements');
if (!extensionElements) {
extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, loopCharacteristics, bpmnFactory);
commands.push(cmdHelper.updateBusinessObject(element, loopCharacteristics, { extensionElements: extensionElements }));
}
// ensure zeebe:LoopCharacteristics
let zeebeLoopCharacteristics = getZeebeLoopCharacteristics(loopCharacteristics);
if (!zeebeLoopCharacteristics) {
zeebeLoopCharacteristics = elementHelper.createElement('zeebe:LoopCharacteristics', { }, extensionElements, bpmnFactory);
commands.push(cmdHelper.addAndRemoveElementsFromList(
element,
extensionElements,
'values',
'extensionElements',
[ zeebeLoopCharacteristics ],
[]
));
}
commands.push(cmdHelper.updateBusinessObject(element, zeebeLoopCharacteristics, values));
return commands;
}
let entries = [];
// input collection //////////////////////////////////////////////////////////////
entries.push(entryFactory.textField({
id: 'multiInstance-inputCollection',
label: translate('Input Collection'),
modelProperty: 'inputCollection',
get: function(element) {
return {
inputCollection: getProperty(element, 'inputCollection')
};
},
set: function(element, values) {
return setProperties(element, {
inputCollection: values.inputCollection || undefined
});
},
validate: function(element, values) {
const loopCharacteristics = getLoopCharacteristics(element),
zeebeLoopCharacteristics = getZeebeLoopCharacteristics(loopCharacteristics);
let validation = {};
if (zeebeLoopCharacteristics) {
const {
inputCollection
} = values;
if (!inputCollection) {
validation = {
inputCollection: 'input collection must not be empty'
};
}
}
return validation;
}
}));
// input element //////////////////////////////////////////////////////////////////
entries.push(entryFactory.textField({
id: 'multiInstance-inputElement',
label: translate('Input Element'),
modelProperty: 'inputElement',
get: function(element) {
return {
inputElement: getProperty(element, 'inputElement')
};
},
set: function(element, values) {
return setProperties(element, {
inputElement: values.inputElement || undefined
});
}
}));
// output collection ////////////////////////////////////////////////////////////
entries.push(entryFactory.textField({
id: 'multiInstance-outputCollection',
label: translate('Output Collection'),
modelProperty: 'outputCollection',
get: function(element) {
return {
outputCollection: getProperty(element, 'outputCollection')
};
},
set: function(element, values) {
return setProperties(element, {
outputCollection: values.outputCollection || undefined
});
},
}));
// output element //////////////////////////////////////////////////////
entries.push(entryFactory.textField({
id: 'multiInstance-outputElement',
label: translate('Output Element'),
modelProperty: 'outputElement',
get: function(element) {
return {
outputElement: getProperty(element, 'outputElement')
};
},
set: function(element, values) {
return setProperties(element, {
outputElement: values.outputElement || undefined
});
},
}));
return entries;
}
// helper /////////
function getExtensionElements(bo, type, prop) {
const elements = extensionElementsHelper.getExtensionElements(bo, type) || [];
return !prop ? elements : (elements[0] || {})[prop] || [];
}
function getZeebeLoopCharacteristics(loopCharacteristics) {
const extensionElements = getExtensionElements(loopCharacteristics, 'zeebe:LoopCharacteristics');
return extensionElements && extensionElements[0];
}
function getLoopCharacteristics(element) {
const bo = getBusinessObject(element);
return bo.loopCharacteristics;
}