mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
trigger node, add configurable reset
and make it do strings when it says so, and numbers if you want.
This commit is contained in:
parent
bb06585748
commit
fb09f4b22d
@ -19,6 +19,7 @@
|
||||
<span data-i18n="trigger.send"></span>
|
||||
<select id="node-input-op1type" style="width:200px !important">
|
||||
<option value="val" data-i18n="trigger.output.string"></option>
|
||||
<option value="num" data-i18n="trigger.output.number"></option>
|
||||
<option value="pay" data-i18n="trigger.output.existing"></option>
|
||||
<option value="nul" data-i18n="trigger.output.nothing"></option>
|
||||
</select>
|
||||
@ -44,13 +45,17 @@
|
||||
<span data-i18n="trigger.then-send"></span>
|
||||
<select id="node-input-op2type" style="width:200px !important">
|
||||
<option value="val" data-i18n="trigger.output.string"></option>
|
||||
<option value="num" data-i18n="trigger.output.number"></option>
|
||||
<option value="pay" data-i18n="trigger.output.existing"></option>
|
||||
<option value="nul" data-i18n="trigger.output.nothing"></option>
|
||||
</select>
|
||||
<input style="width: 145px !important" type="text" id="node-input-op2">
|
||||
</div>
|
||||
<div class="form-row node-type-wait">
|
||||
<input type="checkbox" id="node-input-extend" style="margin-left: 5px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></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">
|
||||
<span data-i18n="trigger.label.reset"></span><input type="text" id="node-input-reset" style="width:240px" data-i18n="[placeholder]trigger.label.resetprompt">
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
@ -88,7 +93,8 @@
|
||||
op2type: {value:"val"},
|
||||
duration: {value:"250",required:true,validate:RED.validators.number()},
|
||||
extend: {value:"false"},
|
||||
units: {value: "ms"},
|
||||
units: {value:"ms"},
|
||||
reset: {value:""},
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
@ -116,14 +122,14 @@
|
||||
}
|
||||
});
|
||||
$("#node-input-op1type").change(function() {
|
||||
if ($(this).val() == "val") {
|
||||
if (($(this).val() == "val")||($(this).val() == "num")) {
|
||||
$("#node-input-op1").show();
|
||||
} else {
|
||||
$("#node-input-op1").hide();
|
||||
}
|
||||
});
|
||||
$("#node-input-op2type").change(function() {
|
||||
if ($(this).val() == "val") {
|
||||
if (($(this).val() == "val")||($(this).val() == "num")) {
|
||||
$("#node-input-op2").show();
|
||||
} else {
|
||||
$("#node-input-op2").hide();
|
||||
|
@ -25,6 +25,7 @@ module.exports = function(RED) {
|
||||
this.op2type = n.op2type || "val";
|
||||
this.extend = n.extend || "false";
|
||||
this.units = n.units || "ms";
|
||||
this.reset = n.reset || '';
|
||||
this.duration = n.duration || 250;
|
||||
if (this.duration <= 0) { this.duration = 0; }
|
||||
else {
|
||||
@ -34,24 +35,24 @@ module.exports = function(RED) {
|
||||
}
|
||||
this.op1Templated = this.op1.indexOf("{{") != -1;
|
||||
this.op2Templated = this.op2.indexOf("{{") != -1;
|
||||
if (!isNaN(this.op1)) { this.op1 = Number(this.op1); }
|
||||
if (!isNaN(this.op2)) { this.op2 = Number(this.op2); }
|
||||
if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); }
|
||||
if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); }
|
||||
if (this.op1 == "true") { this.op1 = true; }
|
||||
if (this.op2 == "true") { this.op2 = true; }
|
||||
if (this.op1 == "false") { this.op1 = false; }
|
||||
if (this.op2 == "false") { this.op2 = false; }
|
||||
if (this.op1 == "null") { this.op1 = null; }
|
||||
if (this.op2 == "null") { this.op2 = null; }
|
||||
try { this.op1 = JSON.parse(this.op1); }
|
||||
catch(e) { this.op1 = this.op1; }
|
||||
try { this.op2 = JSON.parse(this.op2); }
|
||||
catch(e) { this.op2 = this.op2; }
|
||||
//try { this.op1 = JSON.parse(this.op1); }
|
||||
//catch(e) { this.op1 = this.op1; }
|
||||
//try { this.op2 = JSON.parse(this.op2); }
|
||||
//catch(e) { this.op2 = this.op2; }
|
||||
|
||||
var node = this;
|
||||
var tout = null;
|
||||
var m2;
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (msg.hasOwnProperty("reset") || ((node.reset !== '')&&(msg.payload == node.reset)) ) {
|
||||
clearTimeout(tout);
|
||||
tout = null;
|
||||
node.status({});
|
||||
|
@ -177,8 +177,9 @@
|
||||
"then": "then",
|
||||
"then-send": "then send",
|
||||
"output": {
|
||||
"string": "the string payload",
|
||||
"existing": "the existing message",
|
||||
"string": "the string",
|
||||
"number": "the number",
|
||||
"existing": "the existing msg.payload",
|
||||
"nothing": "nothing"
|
||||
},
|
||||
"wait-reset": "wait to be reset",
|
||||
@ -189,11 +190,13 @@
|
||||
"m": "Minutes",
|
||||
"h": "Hours"
|
||||
},
|
||||
"extend": "extend delay if new message arrives",
|
||||
"tip": "The node can be reset by sending a message with the <b>msg.reset</b> property set",
|
||||
"extend": " extend delay if new message arrives",
|
||||
"tip": "The node can also be reset by sending a message with the <b>msg.reset</b> property set to any value.",
|
||||
"label": {
|
||||
"trigger": "trigger",
|
||||
"trigger-block": "trigger & block"
|
||||
"trigger-block": "trigger & block",
|
||||
"reset": "and reset if msg.payload == ",
|
||||
"resetprompt": "(optional reset value)"
|
||||
}
|
||||
},
|
||||
"comment": {
|
||||
|
Loading…
Reference in New Issue
Block a user