@5minds/node-red-contrib-processcube 1.1.4-feature-b3c80b-m14rvpwu → 1.1.4-feature-b953ba-m17k0vnb

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.1.4-feature-b3c80b-m14rvpwu",
3
+ "version": "1.1.4-feature-b953ba-m17k0vnb",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "processEventListener": "process-event-listener.js",
46
46
  "processcubeEngineConfig": "processcube-engine-config.js",
47
47
  "ProcessinstanceQuery": "processinstance-query.js",
48
+ "ProcessinstanceDelete": "processinstance-delete.js",
48
49
  "ProcessdefinitionQuery": "processdefinition-query.js",
49
50
  "messageEventTrigger": "message-event-trigger.js",
50
51
  "signalEventTrigger": "signal-event-trigger.js",
@@ -0,0 +1,58 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('processinstance-delete', {
3
+ category: 'ProcessCube DevOps',
4
+ color: '#02AFD6',
5
+ defaults: {
6
+ name: { value: '' },
7
+ engine: { value: '', type: 'processcube-engine-config' },
8
+ time: { value: '', type: 'number' },
9
+ time_type: { value: 'hours' },
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'font-awesome/fa-sign-in',
14
+ label: function () {
15
+ return this.name || 'processinstance-delete';
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="processinstance-delete">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="Name" />
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-engine"><i class="fa fa-tag"></i> Engine-URL</label>
27
+ <input type="text" id="node-input-engine" placeholder="Engine-URL" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-time"><i class="fa fa-tag"></i> Time</label>
31
+ <input type="text" id="node-input-time" />
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-time_type"><i class="fa fa-sliders"></i> Period</label>
35
+ <select id="node-input-time_type" style="width: 70%;">
36
+ <option value="hours">Hours</option>
37
+ <option value="days">Days</option>
38
+ </select>
39
+ </div>
40
+ </script>
41
+
42
+ <script type="text/markdown" data-help-name="processinstance-delete">
43
+ Delete old instances of a process model in the ProcessCube.
44
+
45
+ ## Inputs
46
+
47
+ : payload.time (number): The number of given time periods.
48
+ : payload.time_type ('hours' | 'days'): The type of time period to use.
49
+
50
+ ## Outputs
51
+
52
+ : payload (string[]): The ids of the processinstances that were deleted.
53
+
54
+ ### References
55
+
56
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
57
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
58
+ </script>
@@ -0,0 +1,55 @@
1
+ module.exports = function (RED) {
2
+ function ProcessInstanceDelete(config) {
3
+ RED.nodes.createNode(this, config);
4
+ var node = this;
5
+
6
+ node.on('input', async function (msg) {
7
+ const engine = RED.nodes.getNode(config.engine);
8
+ const client = engine.engineClient;
9
+
10
+ if (!client) {
11
+ node.error('No engine configured.');
12
+ return;
13
+ }
14
+ let timeMultiplier;
15
+ if (msg.payload.time_type) {
16
+ timeMultiplier = msg.payload.time_type == 'hours' ? 1 : 24;
17
+ } else {
18
+ timeMultiplier = config.time_type == 'hours' ? 1 : 24;
19
+ }
20
+
21
+ const timeToUse = msg.payload.time ? msg.payload.time : config.time;
22
+
23
+ try {
24
+ const fetchInstancesByState = async (state) => {
25
+ const result = await client.processInstances.query({ state });
26
+ return result.processInstances;
27
+ };
28
+
29
+ const finishedInstances = await fetchInstancesByState('finished');
30
+ const terminatedInstances = await fetchInstancesByState('terminated');
31
+ const errorInstances = await fetchInstancesByState('error');
32
+
33
+ let allInstances = [...finishedInstances, ...terminatedInstances, ...errorInstances];
34
+
35
+ const today = new Date();
36
+
37
+ const oldTasks = allInstances.filter((instance) => {
38
+ const finishedDate = new Date(instance.finishedAt);
39
+ const diffInHours = (today - finishedDate) / (1000 * 60 * 60);
40
+ return diffInHours > Number(timeToUse) * timeMultiplier;
41
+ });
42
+
43
+ const ids = oldTasks.map((obj) => obj.processInstanceId);
44
+ msg.payload = ids;
45
+
46
+ await client.processInstances.deleteProcessInstances(ids, engine.identity);
47
+ node.send(msg);
48
+ } catch (error) {
49
+ node.error(error);
50
+ }
51
+ });
52
+ }
53
+
54
+ RED.nodes.registerType('processinstance-delete', ProcessInstanceDelete);
55
+ };
@@ -7,7 +7,8 @@
7
7
  engine: { value: '', type: 'processcube-engine-config' },
8
8
  query: { value: 'payload' },
9
9
  query_type: { value: 'msg' },
10
- sendtype: { value: 'array', required: true },
10
+ force_send_array: { value: false },
11
+ multisend: { value: false },
11
12
  },
12
13
  inputs: 1,
13
14
  outputs: 1,
@@ -44,13 +45,33 @@
44
45
  <label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
45
46
  <input type="text" id="node-input-query" />
46
47
  </div>
47
- <div class="form-row">
48
- <label for="node-input-sendtype"><i class="fa fa-sliders"></i> Result</label>
49
- <select id="node-input-sendtype" style="width: 70%;">
50
- <option value="array">Send as Array</option>
51
- <option value="multi">Send Separately</option>
52
- <option value="first">Send First Task</option>
53
- </select>
48
+ <div class="form-row" style="display:flex; margin-bottom: 3px;">
49
+ <label for="node-input-force_send_array" style="vertical-align:top"
50
+ ><i class="fa fa-list-alt"></i> Force send payload as array</label
51
+ >
52
+ <div>
53
+ <input
54
+ type="checkbox"
55
+ checked
56
+ id="node-input-force_send_array"
57
+ style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;"
58
+ />
59
+ <label style="width:auto" for="node-input-force_send_array"
60
+ >Alway send an array? Only works if <i>Send multi</i> is false.</label
61
+ >
62
+ </div>
63
+ </div>
64
+ <div class="form-row" style="display:flex; margin-bottom: 3px;">
65
+ <label for="node-input-multisend" style="vertical-align:top"><i class="fa fa-list-alt"></i> Send multi</label>
66
+ <div>
67
+ <input
68
+ type="checkbox"
69
+ checked
70
+ id="node-input-multisend"
71
+ style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;"
72
+ />
73
+ <label style="width:auto" for="node-input-multisend">Send one output of each usertask input?</label>
74
+ </div>
54
75
  </div>
55
76
  </script>
56
77
 
@@ -67,6 +88,6 @@ A node which sends a payload to a usertask in the ProcessCube.
67
88
 
68
89
  ### References
69
90
 
70
- - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
71
- - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
91
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
92
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
72
93
  </script>
package/usertask-input.js CHANGED
@@ -4,6 +4,7 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', function (msg) {
7
+
7
8
  const engine = RED.nodes.getNode(config.engine);
8
9
 
9
10
  const client = engine.engineClient;
@@ -16,26 +17,46 @@ module.exports = function (RED) {
16
17
  let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
17
18
 
18
19
  query = {
19
- ...query,
20
+ ...query
20
21
  };
21
22
 
22
- client.userTasks
23
- .query(query, { identity: engine.identity })
23
+ client.userTasks.query(query, { identity: engine.identity} )
24
24
  .then((matchingFlowNodes) => {
25
- if (config.sendtype === 'array') {
26
- msg.payload = { userTasks: matchingFlowNodes.userTasks || [] };
25
+ if (
26
+ !config.force_send_array &&
27
+ matchingFlowNodes &&
28
+ matchingFlowNodes.userTasks &&
29
+ matchingFlowNodes.userTasks.length == 1
30
+ ) {
31
+ userTask = matchingFlowNodes.userTasks[0];
32
+
33
+ msg.payload = { userTask: userTask };
27
34
  node.send(msg);
28
- } else if (config.sendtype === 'multi' && matchingFlowNodes?.userTasks?.length > 1) {
29
- matchingFlowNodes.userTasks.forEach((userTask) => {
30
- msg.payload = { userTask };
35
+ } else {
36
+ if (!config.force_send_array) {
37
+ if (config.multisend && matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length > 1) {
38
+ matchingFlowNodes.userTasks.forEach((userTask) => {
39
+ msg.payload = { userTask: userTask };
40
+ node.send(msg);
41
+ });
42
+ } else {
43
+ if (matchingFlowNodes.userTasks == 1) {
44
+ msg.payload = {
45
+ userTasks: matchingFlowNodes.userTasks,
46
+ };
47
+ node.send(msg);
48
+ } else {
49
+ node.log(`No user tasks found for query: ${JSON.stringify(query)}`);
50
+ }
51
+ }
52
+ } else {
53
+ msg.payload = {
54
+ userTasks: matchingFlowNodes.userTasks || [],
55
+ };
31
56
  node.send(msg);
32
- });
33
- } else if (matchingFlowNodes?.userTasks?.length >= 1) {
34
- msg.payload = { userTask: matchingFlowNodes.userTasks[0] };
35
- node.send(msg);
36
- } else node.log(`No user tasks found for query: ${JSON.stringify(query)}`);
37
- })
38
- .catch((error) => {
57
+ }
58
+ }
59
+ }).catch((error) => {
39
60
  node.error(error);
40
61
  });
41
62
  });