@5minds/node-red-contrib-processcube 0.13.0-feature-c433c3-lyfh9zgz → 0.13.0-feature-f7cd16-lyfhy1jh
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -2
- package/usertask-new-listener.js +1 -1
- package/wait-for-usertask.html +76 -0
- package/wait-for-usertask.js +88 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@5minds/node-red-contrib-processcube",
|
3
|
-
"version": "0.13.0-feature-
|
3
|
+
"version": "0.13.0-feature-f7cd16-lyfhy1jh",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "Node-RED nodes for ProcessCube",
|
6
6
|
"authors": [
|
@@ -44,7 +44,8 @@
|
|
44
44
|
"UserTaskNewListener": "usertask-new-listener.js",
|
45
45
|
"UserTaskFinishedListener": "usertask-finished-listener.js",
|
46
46
|
"UserTaskInput": "usertask-input.js",
|
47
|
-
"UserTaskOutput": "usertask-output.js"
|
47
|
+
"UserTaskOutput": "usertask-output.js",
|
48
|
+
"WaitForUsertask": "wait-for-usertask.js"
|
48
49
|
}
|
49
50
|
},
|
50
51
|
"dependencies": {
|
package/usertask-new-listener.js
CHANGED
@@ -0,0 +1,76 @@
|
|
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© Plattform
|
76
|
+
</script>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
const process = require('process');
|
2
|
+
|
3
|
+
const engine_client = require('@5minds/processcube_engine_client');
|
4
|
+
const { userInfo } = require('os');
|
5
|
+
|
6
|
+
module.exports = function (RED) {
|
7
|
+
function WaitForUsertask(config) {
|
8
|
+
RED.nodes.createNode(this, config);
|
9
|
+
var node = this;
|
10
|
+
var nodeContext = node.context();
|
11
|
+
|
12
|
+
this.engine = this.server = RED.nodes.getNode(config.engine);
|
13
|
+
|
14
|
+
const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';
|
15
|
+
|
16
|
+
var client = nodeContext.get('client');
|
17
|
+
|
18
|
+
if (!client) {
|
19
|
+
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
20
|
+
client = nodeContext.get('client');
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
let currentIdentity = null;
|
25
|
+
let subscription = null;
|
26
|
+
|
27
|
+
node.on('input', async function (msg) {
|
28
|
+
currentIdentity = node.server.identity;
|
29
|
+
|
30
|
+
const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
|
31
|
+
|
32
|
+
subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
|
33
|
+
|
34
|
+
const newQuery = {
|
35
|
+
'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
|
36
|
+
...query
|
37
|
+
};
|
38
|
+
|
39
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
|
40
|
+
|
41
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
42
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
43
|
+
|
44
|
+
msg.payload = { userTask: userTask };
|
45
|
+
node.send(msg);
|
46
|
+
} else {
|
47
|
+
// nothing todo - wait for next notification
|
48
|
+
}
|
49
|
+
|
50
|
+
// remove subscription
|
51
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
52
|
+
}, { identity: currentIdentity });
|
53
|
+
|
54
|
+
console.debug('Handling old userTasks config.only_for_new', config.only_for_new);
|
55
|
+
|
56
|
+
if (config.only_for_new === false) {
|
57
|
+
// only check suspended user tasks
|
58
|
+
const suspendedQuery = {
|
59
|
+
'state': 'suspended',
|
60
|
+
...query
|
61
|
+
};
|
62
|
+
|
63
|
+
const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
|
64
|
+
|
65
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
|
66
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
67
|
+
|
68
|
+
msg.payload = { userTask: userTask };
|
69
|
+
node.send(msg);
|
70
|
+
|
71
|
+
// remove subscription
|
72
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
73
|
+
} else {
|
74
|
+
// let the *currentIdentity* be active
|
75
|
+
}
|
76
|
+
}
|
77
|
+
});
|
78
|
+
|
79
|
+
node.on("close", async () => {
|
80
|
+
if (client != null) {
|
81
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
82
|
+
client.dispose();
|
83
|
+
client = null;
|
84
|
+
}
|
85
|
+
});
|
86
|
+
}
|
87
|
+
RED.nodes.registerType("wait-for-usertask", WaitForUsertask);
|
88
|
+
}
|