@5minds/node-red-contrib-processcube 1.1.4-feature-f15f2e-m06hsqhu → 1.1.4-feature-285569-m0c23so4
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/usertask-event-listener.html +22 -0
- package/usertask-event-listener.js +108 -32
package/package.json
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
engine: { value: '', type: 'processcube-engine-config' },
|
8
8
|
usertask: { value: '', required: false },
|
9
9
|
eventtype: { value: '', required: true },
|
10
|
+
query: { value: '{}' },
|
11
|
+
query_type: { value: 'json' },
|
10
12
|
},
|
11
13
|
inputs: 0,
|
12
14
|
outputs: 1,
|
@@ -14,6 +16,22 @@
|
|
14
16
|
label: function () {
|
15
17
|
return this.name || 'usertask-event-listener';
|
16
18
|
},
|
19
|
+
oneditprepare: function () {
|
20
|
+
$('#node-input-query').typedInput({
|
21
|
+
default: 'json',
|
22
|
+
types: ['json'],
|
23
|
+
});
|
24
|
+
|
25
|
+
$('#node-input-query').typedInput('value', this.query);
|
26
|
+
$('#node-input-query').typedInput('type', this.query_type);
|
27
|
+
},
|
28
|
+
oneditsave: function () {
|
29
|
+
if ($('#node-input-query').typedInput('value') == '') {
|
30
|
+
$('#node-input-query').typedInput('value', '{}')
|
31
|
+
}
|
32
|
+
(this.query = $('#node-input-query').typedInput('value')),
|
33
|
+
(this.query_type = $('#node-input-query').typedInput('type'));
|
34
|
+
},
|
17
35
|
});
|
18
36
|
</script>
|
19
37
|
|
@@ -39,6 +57,10 @@
|
|
39
57
|
<option value="reservation-canceled">reservation-canceled</option>
|
40
58
|
</select>
|
41
59
|
</div>
|
60
|
+
<div class="form-row">
|
61
|
+
<label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
|
62
|
+
<input type="text" id="node-input-query" />
|
63
|
+
</div>
|
42
64
|
</script>
|
43
65
|
|
44
66
|
<script type="text/markdown" data-help-name="usertask-event-listener">
|
@@ -15,66 +15,142 @@ module.exports = function (RED) {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
let subscription;
|
18
|
+
const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
|
19
|
+
|
20
|
+
async function filterAndSend(query) {
|
21
|
+
const newQuery = {
|
22
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
23
|
+
...query,
|
24
|
+
};
|
25
|
+
|
26
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, {
|
27
|
+
identity: currentIdentity,
|
28
|
+
});
|
29
|
+
|
30
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
31
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
32
|
+
|
33
|
+
node.send({
|
34
|
+
payload: { userTask: userTask },
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}
|
18
38
|
|
19
39
|
async function subscribe() {
|
20
40
|
switch (config.eventtype) {
|
21
41
|
case 'new':
|
22
42
|
return await client.userTasks.onUserTaskWaiting(
|
23
|
-
(userTaskNotification) => {
|
43
|
+
async (userTaskNotification) => {
|
24
44
|
if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
45
|
+
const newQuery = {
|
46
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
47
|
+
...query,
|
48
|
+
};
|
49
|
+
|
50
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, {
|
51
|
+
identity: currentIdentity,
|
32
52
|
});
|
53
|
+
|
54
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
55
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
56
|
+
|
57
|
+
node.send({
|
58
|
+
payload: {
|
59
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
60
|
+
userTaskEvent: userTaskNotification,
|
61
|
+
userTask: userTask,
|
62
|
+
action: 'new',
|
63
|
+
type: 'usertask',
|
64
|
+
},
|
65
|
+
});
|
66
|
+
}
|
33
67
|
},
|
34
68
|
{ identity: currentIdentity }
|
35
69
|
);
|
36
70
|
case 'finished':
|
37
71
|
return await client.userTasks.onUserTaskFinished(
|
38
|
-
(userTaskNotification) => {
|
72
|
+
async (userTaskNotification) => {
|
39
73
|
if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
74
|
+
const newQuery = {
|
75
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
76
|
+
...query,
|
77
|
+
};
|
78
|
+
|
79
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, {
|
80
|
+
identity: currentIdentity,
|
47
81
|
});
|
82
|
+
|
83
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
84
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
85
|
+
|
86
|
+
node.send({
|
87
|
+
payload: {
|
88
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
89
|
+
userTaskEvent: userTaskNotification,
|
90
|
+
userTask: userTask,
|
91
|
+
action: 'finished',
|
92
|
+
type: 'usertask',
|
93
|
+
},
|
94
|
+
});
|
95
|
+
}
|
48
96
|
},
|
49
97
|
{ identity: currentIdentity }
|
50
98
|
);
|
51
99
|
case 'reserved':
|
52
100
|
return await client.userTasks.onUserTaskReserved(
|
53
|
-
(userTaskNotification) => {
|
101
|
+
async (userTaskNotification) => {
|
54
102
|
if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
103
|
+
const newQuery = {
|
104
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
105
|
+
...query,
|
106
|
+
};
|
107
|
+
|
108
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, {
|
109
|
+
identity: currentIdentity,
|
62
110
|
});
|
111
|
+
|
112
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
113
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
114
|
+
|
115
|
+
node.send({
|
116
|
+
payload: {
|
117
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
118
|
+
userTaskEvent: userTaskNotification,
|
119
|
+
userTask: userTask,
|
120
|
+
action: 'reserved',
|
121
|
+
type: 'usertask',
|
122
|
+
},
|
123
|
+
});
|
124
|
+
}
|
63
125
|
},
|
64
126
|
{ identity: currentIdentity }
|
65
127
|
);
|
66
128
|
case 'reservation-canceled':
|
67
129
|
return await client.userTasks.onUserTaskReservationCanceled(
|
68
|
-
(userTaskNotification) => {
|
130
|
+
async (userTaskNotification) => {
|
69
131
|
if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
132
|
+
const newQuery = {
|
133
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
134
|
+
...query,
|
135
|
+
};
|
136
|
+
|
137
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, {
|
138
|
+
identity: currentIdentity,
|
77
139
|
});
|
140
|
+
|
141
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
142
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
143
|
+
|
144
|
+
node.send({
|
145
|
+
payload: {
|
146
|
+
flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
|
147
|
+
userTaskEvent: userTaskNotification,
|
148
|
+
userTask: userTask,
|
149
|
+
action: 'reservation-canceled',
|
150
|
+
type: 'usertask',
|
151
|
+
},
|
152
|
+
});
|
153
|
+
}
|
78
154
|
},
|
79
155
|
{ identity: currentIdentity }
|
80
156
|
);
|