cmmn-js-properties-panel-flowable 2.0.0-next.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ function getListenerType(listener) {
18
18
  return 'delegateExpression';
19
19
  }
20
20
 
21
- if (script !== undefined) {
21
+ if (script !== undefined || (listener && listener.get('type') === 'script')) {
22
22
  return 'script';
23
23
  }
24
24
 
@@ -94,6 +94,9 @@ module.exports = function(element, cmmnFactory, translate, options) {
94
94
  update[delegateExpressionProp] = type === delegateExpressionProp ? '' : undefined;
95
95
  update[scriptProp] = type === scriptProp ? cmmnFactory.create('flowable:Script') : undefined;
96
96
 
97
+ // Flowable runs a script listener only with type="script"
98
+ update.type = type === scriptProp ? 'script' : undefined;
99
+
97
100
  return cmdHelper.updateProperties(listener, update, element);
98
101
 
99
102
  }
@@ -147,6 +150,7 @@ module.exports = function(element, cmmnFactory, translate, options) {
147
150
 
148
151
 
149
152
  entries = entries.concat(ScriptProp(element, translate, {
153
+ getListener: getListener,
150
154
  getScript: function(element, node) {
151
155
  var listener = getListener(element, node),
152
156
  type = getListenerType(listener);
@@ -3,13 +3,25 @@
3
3
  var cmdHelper = require('../../../../helper/CmdHelper'),
4
4
  entryFactory = require('../../../../factory/EntryFactory');
5
5
 
6
+
7
+ /**
8
+ * The script of a listener, in the form Flowable reads: the listener has
9
+ * type="script" and a <flowable:script> with a language, an optional result
10
+ * variable and the script as its text.
11
+ *
12
+ * A script in the Camunda form, with scriptFormat and possibly an external
13
+ * resource, is shown so it can be changed: editing it writes the Flowable
14
+ * form.
15
+ */
6
16
  module.exports = function(element, translate, options) {
7
17
 
8
18
 
9
19
  var EXTERNAL_TYPE = 'external',
10
20
  INLINE_TYPE = 'inline';
11
21
 
12
- var scriptFormatProp = 'scriptFormat',
22
+ var languageProp = 'language',
23
+ scriptFormatProp = 'scriptFormat',
24
+ resultVariableProp = 'resultVariable',
13
25
  valueProp = 'value',
14
26
  resourceProp = 'resource';
15
27
 
@@ -29,27 +41,44 @@ module.exports = function(element, translate, options) {
29
41
  options = options || {};
30
42
 
31
43
  var getScript = options.getScript,
44
+ getListener = options.getListener,
32
45
  reference = 'definitionRef';
33
46
 
34
- var getValue = function(prop) {
47
+
48
+ /**
49
+ * Commands that update the script, and give the listener type="script",
50
+ * without which Flowable does not run it.
51
+ */
52
+ function updateScript(element, node, update) {
53
+ var script = getScript(element, node),
54
+ listener = getListener && getListener(element, node),
55
+ commands = [ cmdHelper.updateProperties(script, update, element) ];
56
+
57
+ if (listener && listener.get('type') !== 'script') {
58
+ commands.push(cmdHelper.updateProperties(listener, { type: 'script' }, element));
59
+ }
60
+
61
+ return commands;
62
+ }
63
+
64
+ var getValue = function(prop, modelProperty) {
35
65
  return function(element, node) {
36
66
  var script = getScript(element, node),
37
67
  value = {};
38
68
 
39
- value[prop] = (script && script.get(prop)) || undefined;
69
+ value[modelProperty || prop] = (script && script.get(prop)) || undefined;
40
70
 
41
71
  return value;
42
72
  };
43
73
  };
44
74
 
45
- var setValue = function(prop, defaultValue) {
75
+ var setValue = function(prop, modelProperty, defaultValue) {
46
76
  return function(element, values, node) {
47
- var script = getScript(element, node),
48
- update = {};
77
+ var update = {};
49
78
 
50
- update[prop] = values[prop] || defaultValue;
79
+ update[prop] = values[modelProperty || prop] || defaultValue;
51
80
 
52
- return cmdHelper.updateProperties(script, update, element);
81
+ return updateScript(element, node, update);
53
82
  };
54
83
  };
55
84
 
@@ -74,21 +103,57 @@ module.exports = function(element, translate, options) {
74
103
  };
75
104
 
76
105
 
77
- var scriptFormatEntry = entryFactory.textField({
106
+ var languageEntry = entryFactory.textField({
78
107
 
79
- id: 'scriptFormant',
80
- label: translate('Script Format'),
81
- modelProperty: scriptFormatProp,
108
+ id: 'scriptLanguage',
109
+ label: translate('Script Language'),
110
+ description: translate('For example groovy or javascript'),
111
+ modelProperty: 'scriptLanguage',
82
112
  reference: reference,
83
113
 
84
- get: getValue(scriptFormatProp),
85
- set: setValue(scriptFormatProp),
114
+ get: function(element, node) {
115
+ var script = getScript(element, node);
116
+
117
+ return {
118
+ scriptLanguage: (script && (script.get(languageProp) || script.get(scriptFormatProp))) || undefined
119
+ };
120
+ },
121
+
122
+ // write the language as Flowable reads it, in place of a script format
123
+ set: function(element, values, node) {
124
+ var update = {};
125
+
126
+ update[languageProp] = values.scriptLanguage || undefined;
127
+ update[scriptFormatProp] = undefined;
128
+
129
+ return updateScript(element, node, update);
130
+ },
131
+
86
132
  hideEntry: hideEntry(),
87
- validate: validate(scriptFormatProp)
133
+
134
+ validate: function(element, values, node) {
135
+ var listener = getListener && getListener(element, node);
136
+
137
+ if (!values.scriptLanguage) {
138
+ return { scriptLanguage: translate('Must provide a value') };
139
+ }
140
+
141
+ if (listener && listener.get('type') !== 'script') {
142
+ return {
143
+ scriptLanguage: {
144
+ warning: translate('Flowable runs the script only with type="script"; editing the script adds it')
145
+ }
146
+ };
147
+ }
148
+
149
+ return {};
150
+ }
88
151
 
89
152
  });
90
153
 
91
154
 
155
+ // an external resource is of the Camunda form only; offered to change it
156
+ // to an inline script
92
157
  var scriptTypeEntry = entryFactory.selectBox({
93
158
 
94
159
  id: 'scriptType',
@@ -111,18 +176,17 @@ module.exports = function(element, translate, options) {
111
176
 
112
177
  set: function(element, values, node) {
113
178
 
114
- var script = getScript(element, node),
115
- type = values.type || undefined,
179
+ var type = values.type || undefined,
116
180
  update = {};
117
181
 
118
182
  update[resourceProp] = type === EXTERNAL_TYPE ? '' : undefined;
119
183
  update[valueProp] = undefined;
120
184
 
121
- return cmdHelper.updateProperties(script, update, element);
185
+ return updateScript(element, node, update);
122
186
 
123
187
  },
124
188
 
125
- hideEntry: hideEntry()
189
+ hideEntry: hideEntry(EXTERNAL_TYPE)
126
190
 
127
191
  });
128
192
 
@@ -146,16 +210,31 @@ module.exports = function(element, translate, options) {
146
210
 
147
211
  id: 'scriptResource',
148
212
  label: translate('Resource'),
213
+ description: translate('Not read by Flowable; choose an inline script'),
149
214
  modelProperty: resourceProp,
150
215
  reference: reference,
151
216
 
152
217
  get: getValue(resourceProp),
153
- set: setValue(resourceProp, ''),
218
+ set: setValue(resourceProp, resourceProp, ''),
154
219
  hideEntry: hideEntry(EXTERNAL_TYPE),
155
220
  validate: validate(resourceProp)
156
221
 
157
222
  });
158
223
 
159
- return [ scriptFormatEntry, scriptTypeEntry, scriptValueEntry, scriptResouceEntry ];
224
+
225
+ var resultVariableEntry = entryFactory.textField({
226
+
227
+ id: 'scriptResultVariable',
228
+ label: translate('Result Variable'),
229
+ modelProperty: 'scriptResultVariable',
230
+ reference: reference,
231
+
232
+ get: getValue(resultVariableProp, 'scriptResultVariable'),
233
+ set: setValue(resultVariableProp, 'scriptResultVariable'),
234
+ hideEntry: hideEntry(INLINE_TYPE)
235
+
236
+ });
237
+
238
+ return [ languageEntry, scriptTypeEntry, scriptValueEntry, scriptResouceEntry, resultVariableEntry ];
160
239
 
161
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmmn-js-properties-panel-flowable",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.1",
4
4
  "description": "A simple properties panel for cmmn-js with flowable namespaces",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -33,7 +33,7 @@
33
33
  "diagram-js": "^15.29.0",
34
34
  "eslint": "^5.2.0",
35
35
  "eslint-plugin-bpmn-io": "^0.5.3",
36
- "flowable-cmmn-moddle": "^1.2.0-next.6",
36
+ "flowable-cmmn-moddle": "^1.2.0-next.7",
37
37
  "karma": "^4.1.0",
38
38
  "karma-chrome-launcher": "^2.2.0",
39
39
  "karma-firefox-launcher": "^1.0.1",