Trigger node - hide second outpiut option when not appropriate

Update status to better reflect multiple streams in flight
This commit is contained in:
Dave Conway-Jones 2020-05-16 22:24:29 +01:00
parent fbd911ed27
commit b6e0568e76
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
3 changed files with 23 additions and 7 deletions

View File

@ -47,7 +47,7 @@
<input type="hidden" id="node-input-op2type">
<input style="width:70%" type="text" id="node-input-op2" placeholder="0">
</div>
<div class="form-row">
<div class="form-row" id="node-second-output">
<label></label>
<input type="checkbox" id="node-input-second" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-second" data-i18n="trigger.second"></label>
</div>
@ -138,15 +138,22 @@
if ($(this).val() == "block") {
$(".node-type-wait").hide();
$(".node-type-duration").hide();
$("#node-second-output").hide();
$("#node-input-second").prop('checked', false);
that.outputs = 1;
}
else if ($(this).val() == "loop") {
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
$(".node-type-wait").hide();
$(".node-type-duration").show();
$("#node-second-output").hide();
$("#node-input-second").prop('checked', false);
that.outputs = 1;
} else {
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
$(".node-type-wait").show();
$(".node-type-duration").show();
$("#node-second-output").show();
}
});

View File

@ -113,6 +113,13 @@ module.exports = function(RED) {
processMessageQueue(msg);
});
var stat = function() {
var l = Object.keys(node.topics).length;
if (l === 0) { return {} }
else if (l === 1) { return {fill:"blue",shape:"dot"} }
else return {fill:"blue",shape:"dot",text:l};
}
var processMessage = function(msg) {
var topic = RED.util.getMessageProperty(msg,node.topic) || "_none";
var promise;
@ -122,7 +129,7 @@ module.exports = function(RED) {
if (node.loop === true) { clearInterval(node.topics[topic].tout); }
else { clearTimeout(node.topics[topic].tout); }
delete node.topics[topic];
node.status({});
node.status(stat());
}
else {
if (node.op2type === "payl") { npay[topic] = RED.util.cloneMessage(msg); }
@ -201,19 +208,19 @@ module.exports = function(RED) {
else { node.send(msg2); }
}
delete node.topics[topic];
node.status({});
node.status(stat());
}).catch(err => {
node.error(err);
});
} else {
delete node.topics[topic];
node.status({});
node.status(stat());
}
}, node.duration);
}
}
node.status({fill:"blue",shape:"dot",text:" "});
node.status(stat());
if (node.op1type !== "nul") { node.send(RED.util.cloneMessage(msg)); }
});
});
@ -249,7 +256,7 @@ module.exports = function(RED) {
}
}
delete node.topics[topic];
node.status({});
node.status(stat());
if (node.second === true) { node.send([null,msg2]); }
else { node.send(msg2); }
}).catch(err => {
@ -272,7 +279,7 @@ module.exports = function(RED) {
delete node.topics[t];
}
}
node.status({});
node.status(stat());
});
}
RED.nodes.registerType("trigger",TriggerNode);

View File

@ -42,4 +42,6 @@
is reset by a received message.</p>
<p>Optionally, the node can be configured to treat messages as if they are separate streams,
using a msg property to identify each stream. Default <code>msg.topic</code>.</p>
<p>The status indicates the node is currently active. If multiple streams are used the status
indicates the number of streams being held.</p>
</script>