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
/
TaskDefinitionProps.js
159 lines (123 loc) · 4.34 KB
/
TaskDefinitionProps.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
/**
* 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 elementHelper from 'bpmn-js-properties-panel/lib/helper/ElementHelper';
import cmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper';
import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';
import {
containsSpace
} from 'bpmn-js-properties-panel/lib/Utils';
import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
import extensionElementsHelper from 'bpmn-js-properties-panel/lib/helper/ExtensionElementsHelper';
export default function(group, element, bpmnFactory, translate) {
if (!is(element, 'bpmn:ServiceTask')) {
return;
}
function getElements(bo, type, prop) {
const elems = extensionElementsHelper.getExtensionElements(bo, type) || [];
return !prop ? elems : (elems[0] || {})[prop] || [];
}
function getTaskDefinition(element) {
const bo = getBusinessObject(element);
return (getElements(bo, 'zeebe:TaskDefinition') || [])[0];
}
group.entries.push(entryFactory.validationAwareTextField({
id: 'taskDefinitionType',
label: translate('Type'),
modelProperty: 'type',
getProperty: function(element, node) {
return (getTaskDefinition(element) || {}).type;
},
setProperty: function(element, values, node) {
const bo = getBusinessObject(element);
const commands = [];
// create extensionElements
let extensionElements = bo.get('extensionElements');
if (!extensionElements) {
extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, bo, bpmnFactory);
commands.push(cmdHelper.updateProperties(element, { extensionElements: extensionElements }));
}
// create taskDefinition
let taskDefinition = getTaskDefinition(element);
if (!taskDefinition) {
taskDefinition = elementHelper.createElement('zeebe:TaskDefinition', { }, extensionElements, bpmnFactory);
commands.push(cmdHelper.addAndRemoveElementsFromList(
element,
extensionElements,
'values',
'extensionElements',
[ taskDefinition ],
[]
));
}
commands.push(cmdHelper.updateBusinessObject(element, taskDefinition, values));
return commands;
},
validate: function(element, values, node) {
const bo = getTaskDefinition(element);
let validation = {};
if (bo) {
const {
type
} = values;
if (type) {
if (containsSpace(type)) {
validation = {
type: 'Type must not contain spaces'
};
}
}
else {
validation = {
type: 'ServiceTask must have a type'
};
}
}
return validation;
}
}));
group.entries.push(entryFactory.textField({
id: 'taskDefinitionRetries',
label: translate('Retries'),
modelProperty: 'retries',
get: function(element) {
return {
retries: (getTaskDefinition(element) || {}).retries
};
},
set: function(element, values) {
const bo = getBusinessObject(element);
const commands = [];
// create extensionElements
let extensionElements = bo.get('extensionElements');
if (!extensionElements) {
extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, bo, bpmnFactory);
commands.push(cmdHelper.updateProperties(element, { extensionElements: extensionElements }));
}
// create taskDefinition
let taskDefinition = getTaskDefinition(element);
if (!taskDefinition) {
taskDefinition = elementHelper.createElement('zeebe:TaskDefinition', { }, extensionElements, bpmnFactory);
commands.push(cmdHelper.addAndRemoveElementsFromList(
element,
extensionElements,
'values',
'extensionElements',
[ taskDefinition ],
[]
));
}
commands.push(cmdHelper.updateBusinessObject(element, taskDefinition, values));
return commands;
}
}));
}