Skip to content

Add new node to listen to usertask finished #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
617 changes: 70 additions & 547 deletions nodered/node-red-contrib-processcube-flows.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions nodered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@5minds/node-red-contrib-processcube": "file:..",
"@5minds/node-red-dashboard-2-processcube-dynamic-form": "^1.0.4",
"@5minds/node-red-dashboard-2-processcube-usertask-table": "^1.0.7",
"@flowfuse/node-red-dashboard": "^1.11.1",
"node-red": "^3.1.10",
"node-red-debugger": "^1.1.1",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@5minds/node-red-contrib-processcube",
"version": "0.7.1",
"version": "0.8.0",
"license": "MIT",
"description": "Node-RED nodes for ProcessCube",
"authors": [
Expand Down Expand Up @@ -40,6 +40,7 @@
"messageEventTrigger": "message-event-trigger.js",
"signalEventTrigger": "signal-event-trigger.js",
"UserTaskNewListener": "usertask-new-listener.js",
"UserTaskFinishedListener": "usertask-finished-listener.js",
"UserTaskInput": "usertask-input.js",
"UserTaskOutput": "usertask-output.js"
}
Expand Down
1 change: 0 additions & 1 deletion processes/SampleUserTask.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<camunda:value id="value_02" name="Value 02" />
</camunda:formField>
<camunda:formField id="boolean_id" label="Boolean Label" type="boolean" />
<camunda:formField id="customer_01" label="Custom_01" type="v-text-field" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1h0giih</bpmn:incoming>
Expand Down
39 changes: 39 additions & 0 deletions usertask-finished-listener.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script type="text/javascript">
RED.nodes.registerType('usertask-finished-listener',{
category: 'ProcessCube',
color: '#00aed7',
defaults: {
name: {value: ""},
engine: {value: "", type: "processcube-engine-config"},
multisend: {value: false}
},
inputs: 0,
outputs: 1,
icon: "font-awesome/fa-envelope",
label: function() {
return this.name || "usertask-finished-listener";
}
});
</script>

<script type="text/html" data-template-name="usertask-finished-listener">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-engine"><i class="fa fa-tag"></i> Engine-URL</label>
<input type="text" id="node-input-engine" placeholder="http://engine:8000">
</div>
<div class="form-row" style="display:flex; margin-bottom: 3px;">
<label for="node-input-multisend" style="vertical-align:top"><i class="fa fa-list-alt"></i> Send multi</label>
<div>
<input type="checkbox" checked id="node-input-multisend" style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;">
<label style="width:auto" for="node-input-multisend">Send one output of each usertask input?</label>
</div>
</div>
</script>

<script type="text/html" data-help-name="usertask-finished-listener">
<p>A node which subscribes to an User Task of https://processcube.io</p>
</script>
41 changes: 41 additions & 0 deletions usertask-finished-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const process = require('process');
const EventEmitter = require('node:events');

const engine_client = require('@5minds/processcube_engine_client');

module.exports = function(RED) {
function UserTaskFinishedListener(config) {
RED.nodes.createNode(this, config);
var node = this;
var flowContext = node.context().flow;
var nodeContext = node.context();

this.engine = this.server = RED.nodes.getNode(config.engine);

const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';

var client = nodeContext.get('client');

if (!client) {
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
client = nodeContext.get('client');
}

var eventEmitter = flowContext.get('emitter');

if (!eventEmitter) {
flowContext.set('emitter', new EventEmitter());
eventEmitter = flowContext.get('emitter');
}

node.on("close", async () => {
client.dispose();
client = null;
});

client.userTasks.onUserTaskFinished((userTaskFinishedNotification) => {
node.send({ payload: { flowNodeInstanceId: userTaskFinishedNotification.flowNodeInstanceId, action: "finished", type: "usertask" } });
});
}
RED.nodes.registerType("usertask-finished-listener", UserTaskFinishedListener);
}
3 changes: 0 additions & 3 deletions usertask-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ module.exports = function(RED) {

node.on('input', function(msg) {
const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg)
console.log(query)

client.userTasks.query(query).then((matchingFlowNodes) => {

console.log(`UserTaskInput query result: ${JSON.stringify(matchingFlowNodes)}`);

if (!config.force_send_array && matchingFlowNodes && matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
userTask = matchingFlowNodes.userTasks[0];

Expand Down
2 changes: 1 addition & 1 deletion usertask-new-listener.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
</div>
</script>

<script type="text/html" data-help-name="usertask-input">
<script type="text/html" data-help-name="usertask-new-listener">
<p>A node which subscribes to an User Task of https://processcube.io</p>
</script>
4 changes: 1 addition & 3 deletions usertask-new-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ module.exports = function(RED) {
});

client.userTasks.onUserTaskWaiting((userTaskWaitingNotification) => {
console.log(`UserTask with id ${userTaskWaitingNotification.flowNodeInstanceId} is waiting.`);

node.send({ payload: { flowNodeInstanceId: userTaskWaitingNotification.flowNodeInstanceId } });
node.send({ payload: { flowNodeInstanceId: userTaskWaitingNotification.flowNodeInstanceIdaction, action: "new", type: "usertask" } });
});
}
RED.nodes.registerType("usertask-new-listener", UserTaskNewListener);
Expand Down
2 changes: 0 additions & 2 deletions usertask-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ module.exports = function(RED) {

node.on('input', function(msg) {
if (msg.payload.userTask) {
console.log(`Try to finsih UserTask with id ${msg.payload.userTask.flowNodeInstanceId}.`);

const flowNodeInstanceId = msg.payload.userTask.flowNodeInstanceId;

const userTaskResult = RED.util.evaluateNodeProperty(config.result, config.result_type, node, msg);

client.userTasks.finishUserTask(flowNodeInstanceId, userTaskResult).then(() => {
console.log(`UserTask with id ${flowNodeInstanceId} finished.`);

node.send(msg);
}).catch(error => {
Expand Down