@5minds/node-red-contrib-processcube 1.2.3 → 1.3.0-feature-92414d-m21x3yqt
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -2
- package/wait-for-usertask.html +77 -0
- package/wait-for-usertask.js +91 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@5minds/node-red-contrib-processcube",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.0-feature-92414d-m21x3yqt",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "Node-RED nodes for ProcessCube",
|
6
6
|
"scripts": {
|
@@ -52,7 +52,8 @@
|
|
52
52
|
"UserTaskNewListener": "usertask-new-listener.js",
|
53
53
|
"UserTaskFinishedListener": "usertask-finished-listener.js",
|
54
54
|
"UserTaskInput": "usertask-input.js",
|
55
|
-
"UserTaskOutput": "usertask-output.js"
|
55
|
+
"UserTaskOutput": "usertask-output.js",
|
56
|
+
"WaitForUsertask": "wait-for-usertask.js"
|
56
57
|
},
|
57
58
|
"examples": "examples"
|
58
59
|
},
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
RED.nodes.registerType('wait-for-usertask',{
|
3
|
+
category: 'ProcessCube',
|
4
|
+
color: '#02AFD6',
|
5
|
+
defaults: {
|
6
|
+
name: {value: ""},
|
7
|
+
engine: {value: "", type: "processcube-engine-config"},
|
8
|
+
query: {value: "payload"},
|
9
|
+
query_type: {value: "msg"},
|
10
|
+
only_for_new: {value: false}
|
11
|
+
},
|
12
|
+
inputs: 1,
|
13
|
+
outputs: 1,
|
14
|
+
icon: "font-awesome/fa-envelope-open",
|
15
|
+
label: function() {
|
16
|
+
return this.name || "wait-for-usertask";
|
17
|
+
},
|
18
|
+
oneditprepare: function() {
|
19
|
+
$("#node-input-query").typedInput({
|
20
|
+
default: 'msg',
|
21
|
+
types: ['msg', 'json']
|
22
|
+
});
|
23
|
+
|
24
|
+
$("#node-input-query").typedInput('value', this.query);
|
25
|
+
$("#node-input-query").typedInput('type', this.query_type);
|
26
|
+
},
|
27
|
+
oneditsave: function() {
|
28
|
+
this.query = $("#node-input-query").typedInput('value'),
|
29
|
+
this.query_type = $("#node-input-query").typedInput('type')
|
30
|
+
|
31
|
+
}
|
32
|
+
});
|
33
|
+
</script>
|
34
|
+
|
35
|
+
<script type="text/html" data-template-name="wait-for-usertask">
|
36
|
+
<div class="form-row">
|
37
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
38
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
39
|
+
</div>
|
40
|
+
<div class="form-row">
|
41
|
+
<label for="node-input-engine"><i class="fa fa-tag"></i> Engine-URL</label>
|
42
|
+
<input type="text" id="node-input-engine" placeholder="http://engine:8000">
|
43
|
+
</div>
|
44
|
+
<div class="form-row">
|
45
|
+
<label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
|
46
|
+
<input type="text" id="node-input-query">
|
47
|
+
</div>
|
48
|
+
<div class="form-row" style="display:flex; margin-bottom: 3px;">
|
49
|
+
<label for="node-input-only_for_new" style="vertical-align:top"><i class="fa fa-list-alt"></i> Only for new</label>
|
50
|
+
<div>
|
51
|
+
<input type="checkbox" checked id="node-input-only_for_new" style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;">
|
52
|
+
<label style="width:auto" for="node-input-multisend">Trigger only for new user task or *checked* also for old ones?</label>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
</script>
|
56
|
+
|
57
|
+
<script type="text/markdown" data-help-name="wait-for-usertask">
|
58
|
+
Waiting for Usertasks of the connected ProcessCube Engine.
|
59
|
+
|
60
|
+
### Inputs
|
61
|
+
|
62
|
+
: payload (json) : the query to filter the usertasks.
|
63
|
+
|
64
|
+
## Outputs
|
65
|
+
|
66
|
+
: payload.userTask (string) : The filtered UserTask
|
67
|
+
|
68
|
+
### Details
|
69
|
+
|
70
|
+
- `msg.payload` or a constant json to filter the UserTasks for Waiting for
|
71
|
+
- `Only for new` will trigger only for new UserTasks if checked and also for old ones if not checked.
|
72
|
+
|
73
|
+
### References
|
74
|
+
|
75
|
+
- [The ProcessCube© Developer Network](https://processcube.io) - All documentation for the ProcessCube© platform
|
76
|
+
- [ProcessCube© LowCode Integration](https://processcube.io/docs/node-red) - LowCode integration in ProcessCube©
|
77
|
+
</script>
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module.exports = function (RED) {
|
2
|
+
function WaitForUsertask(config) {
|
3
|
+
RED.nodes.createNode(this, config);
|
4
|
+
var node = this;
|
5
|
+
|
6
|
+
const engine = RED.nodes.getNode(config.engine);
|
7
|
+
|
8
|
+
const client = engine.engineClient;
|
9
|
+
|
10
|
+
let subscription = null;
|
11
|
+
let currentIdentity = engine.identity;
|
12
|
+
let subscribe = null;
|
13
|
+
|
14
|
+
node.on('input', async function (msg) {
|
15
|
+
subscribe = async () => {
|
16
|
+
if (!client) {
|
17
|
+
node.error('No engine configured.');
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
|
21
|
+
const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
|
22
|
+
|
23
|
+
subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
|
24
|
+
|
25
|
+
const newQuery = {
|
26
|
+
'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
|
27
|
+
...query
|
28
|
+
};
|
29
|
+
|
30
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
|
31
|
+
|
32
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
33
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
34
|
+
|
35
|
+
msg.payload = { userTask: userTask };
|
36
|
+
node.send(msg);
|
37
|
+
} else {
|
38
|
+
// nothing todo - wait for next notification
|
39
|
+
}
|
40
|
+
|
41
|
+
// remove subscription
|
42
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
43
|
+
}, { identity: currentIdentity });
|
44
|
+
|
45
|
+
node.log({"Handling old userTasks config.only_for_new": config.only_for_new});
|
46
|
+
|
47
|
+
if (config.only_for_new === false) {
|
48
|
+
// only check suspended user tasks
|
49
|
+
const suspendedQuery = {
|
50
|
+
'state': 'suspended',
|
51
|
+
...query
|
52
|
+
};
|
53
|
+
|
54
|
+
const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
|
55
|
+
|
56
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
|
57
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
58
|
+
|
59
|
+
msg.payload = { userTask: userTask };
|
60
|
+
node.send(msg);
|
61
|
+
|
62
|
+
// remove subscription
|
63
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
64
|
+
} else {
|
65
|
+
// let the *currentIdentity* be active
|
66
|
+
}
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
subscribe();
|
71
|
+
});
|
72
|
+
|
73
|
+
node.engine.registerOnIdentityChanged(async (identity) => {
|
74
|
+
|
75
|
+
if (subscription) {
|
76
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
77
|
+
currentIdentity = identity;
|
78
|
+
subscribe();
|
79
|
+
} else {
|
80
|
+
currentIdentity = identity;
|
81
|
+
}
|
82
|
+
});
|
83
|
+
|
84
|
+
node.on("close", async () => {
|
85
|
+
if (client != null && subscription != null) {
|
86
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
RED.nodes.registerType("wait-for-usertask", WaitForUsertask);
|
91
|
+
}
|