Allow trigger node delay to be overridden with msg.delay

This commit is contained in:
Nick O'Leary
2020-09-28 21:10:23 +01:00
parent b595e84c30
commit cf84ec78fa
5 changed files with 83 additions and 6 deletions

View File

@@ -42,6 +42,10 @@
<label></label>
<input type="checkbox" id="node-input-extend" style="margin-left:0px; vertical-align:top; width:auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
</div>
<div class="form-row node-type-wait">
<label></label>
<input type="checkbox" id="node-input-overrideDelay" style="margin-left:0px; vertical-align:top; width:auto !important;"> <label style="width:auto !important;" for="node-input-overrideDelay" data-i18n="trigger.override"></label>
</div>
<div class="form-row node-type-wait">
<label data-i18n="trigger.then-send"></label>
<input type="hidden" id="node-input-op2type">
@@ -89,6 +93,7 @@
op2type: {value:"val"},
duration: {value:"250",required:true,validate:RED.validators.number()},
extend: {value:"false"},
overrideDelay: {value:"false"},
units: {value:"ms"},
reset: {value:""},
bytopic: {value:"all"},
@@ -126,7 +131,7 @@
if (this.outputs == 2) { $("#node-input-second").prop('checked', true) }
else { $("#node-input-second").prop('checked', false) }
$("#node-input-second").change(function() {
if ($("#node-input-second").is(":checked")) {
$("#node-input-outputs").val(2);
@@ -208,7 +213,11 @@
} else {
$("#node-input-extend").prop("checked",false);
}
if (this.overrideDelay === "true" || this.overrideDelay === true) {
$("#node-input-overrideDelay").prop("checked",true);
} else {
$("#node-input-overrideDelay").prop("checked",false);
}
},
oneditsave: function() {
if ($("#node-then-type").val() == "block") {

View File

@@ -48,6 +48,7 @@ module.exports = function(RED) {
}
}
this.extend = n.extend || "false";
this.overrideDelay = n.overrideDelay || false;
this.units = n.units || "ms";
this.reset = n.reset || '';
this.duration = parseFloat(n.duration);
@@ -117,12 +118,16 @@ module.exports = function(RED) {
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};
else return {fill:"blue",shape:"dot",text:l};
}
var processMessage = function(msg) {
var topic = RED.util.getMessageProperty(msg,node.topic) || "_none";
var promise;
var delayDuration = node.duration;
if (node.overrideDelay && msg.hasOwnProperty("delay") && !isNaN(parseFloat(msg.delay))) {
delayDuration = parseFloat(msg.delay);
}
if (node.bytopic === "all") { topic = "_none"; }
node.topics[topic] = node.topics[topic] || {};
if (msg.hasOwnProperty("reset") || ((node.reset !== '') && msg.hasOwnProperty("payload") && (msg.payload !== null) && msg.payload.toString && (msg.payload.toString() == node.reset)) ) {
@@ -217,7 +222,7 @@ module.exports = function(RED) {
node.status(stat());
}
}, node.duration);
}, delayDuration);
}
}
node.status(stat());
@@ -262,7 +267,7 @@ module.exports = function(RED) {
}).catch(err => {
node.error(err);
});
}, node.duration);
}, delayDuration);
}
// else {
// if (node.op2type === "payl") {node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }