Skip to content

Commit 691b083

Browse files
committed
Update trigger node ui to use typedInputs
1 parent b74a35b commit 691b083

4 files changed

Lines changed: 176 additions & 113 deletions

File tree

nodes/core/core/89-trigger.html

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,49 @@
1616

1717
<script type="text/x-red" data-template-name="trigger">
1818
<div class="form-row">
19-
<span data-i18n="trigger.send"></span>
20-
<select id="node-input-op1type" style="width:200px !important">
21-
<option value="val" data-i18n="trigger.output.string"></option>
22-
<option value="num" data-i18n="trigger.output.number"></option>
23-
<option value="pay" data-i18n="trigger.output.existing"></option>
24-
<option value="nul" data-i18n="trigger.output.nothing"></option>
25-
</select>
26-
<input style="width: 180px !important" type="text" id="node-input-op1">
19+
<label data-i18n="trigger.send" for="node-input-op1"></label>
20+
<input type="hidden" id="node-input-op1type">
21+
<input style="width: 70%" type="text" id="node-input-op1">
2722
</div>
2823
<div class="form-row">
29-
<span data-i18n="trigger.then"></span>
30-
<select id="node-then-type" style="width:150px;">
24+
<label data-i18n="trigger.then"></label>
25+
<select id="node-then-type" style="width:70%;">
3126
<option value="block" data-i18n="trigger.wait-reset"></option>
3227
<option value="wait" data-i18n="trigger.wait-for"></option>
3328
</select>
34-
<span class="node-type-wait">
35-
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
36-
<select id="node-input-units" style="width:140px !important">
37-
<option value="ms" data-i18n="trigger.duration.ms"></option>
38-
<option value="s" data-i18n="trigger.duration.s"></option>
39-
<option value="min" data-i18n="trigger.duration.m"></option>
40-
<option value="hr" data-i18n="trigger.duration.h"></option>
41-
</select>
42-
</span>
4329
</div>
4430
<div class="form-row node-type-wait">
31+
<label></label>
32+
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
33+
<select id="node-input-units" style="width:140px !important">
34+
<option value="ms" data-i18n="trigger.duration.ms"></option>
35+
<option value="s" data-i18n="trigger.duration.s"></option>
36+
<option value="min" data-i18n="trigger.duration.m"></option>
37+
<option value="hr" data-i18n="trigger.duration.h"></option>
38+
</select>
39+
</div>
40+
<div class="form-row node-type-wait">
41+
<label></label>
4542
<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>
4643
</div>
4744
<div class="form-row node-type-wait">
48-
<span data-i18n="trigger.then-send"></span>
49-
<select id="node-input-op2type" style="width:200px !important">
50-
<option value="val" data-i18n="trigger.output.string"></option>
51-
<option value="num" data-i18n="trigger.output.number"></option>
52-
<option value="pay" data-i18n="trigger.output.original"></option>
53-
<option value="payl" data-i18n="trigger.output.latest"></option>
54-
<option value="nul" data-i18n="trigger.output.nothing"></option>
55-
</select>
56-
<input style="width: 145px !important" type="text" id="node-input-op2">
45+
<label data-i18n="trigger.then-send"></label>
46+
<input type="hidden" id="node-input-op2type">
47+
<input style="width: 70%" type="text" id="node-input-op2">
5748
</div>
5849
<div class="form-row">
59-
<span data-i18n="trigger.label.reset"></span><input type="text" id="node-input-reset" style="width:240px" data-i18n="[placeholder]trigger.label.resetprompt">
50+
<label data-i18n="trigger.label.reset" style="width:auto"></label>
51+
<div style="display:inline-block; width:70%;vertical-align:top">
52+
<ul>
53+
<li data-i18n="trigger.label.resetMessage"></li>
54+
<li><span data-i18n="trigger.label.resetPayload"></span> <input type="text" id="node-input-reset" style="width:150px" data-i18n="[placeholder]trigger.label.resetprompt"></li>
55+
</ul>
6056
</div>
6157
<br/>
6258
<div class="form-row">
6359
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
6460
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
6561
</div>
66-
<div class="form-tips" data-i18n="[html]trigger.tip"></div>
6762
</script>
6863

6964
<script type="text/x-red" data-help-name="trigger">
@@ -118,34 +113,48 @@
118113
$("#node-then-type").change(function() {
119114
if ($(this).val() == "block") {
120115
$(".node-type-wait").hide();
121-
$(".form-tips").show();
122116
} else {
123117
$(".node-type-wait").show();
124-
$(".form-tips").hide();
125118
}
126119
});
127-
$("#node-input-op1type").change(function() {
128-
if (($(this).val() == "val")||($(this).val() == "num")) {
129-
$("#node-input-op1").show();
130-
} else {
131-
$("#node-input-op1").hide();
132-
}
120+
121+
if (this.op1type === 'val') {
122+
$("#node-input-op1type").val('str');
123+
}
124+
if (this.op2type === 'val') {
125+
$("#node-input-op2type").val('str');
126+
}
127+
128+
var optionNothing = {value:"nul",label:this._("trigger.output.nothing"),hasValue:false};
129+
var optionPayload = {value:"pay",label:this._("trigger.output.existing"),hasValue:false}
130+
131+
var optionOriginalPayload = {value:"pay",label:this._("trigger.output.original"),hasValue:false}
132+
var optionLatestPayload = {value:"payl",label:this._("trigger.output.latest"),hasValue:false}
133+
134+
$("#node-input-op1").typedInput({
135+
default: 'str',
136+
typeField: $("#node-input-op1type"),
137+
types:['flow','global','str','num','bool','json',
138+
optionPayload,
139+
optionNothing
140+
]
133141
});
134-
$("#node-input-op2type").change(function() {
135-
if (($(this).val() == "val")||($(this).val() == "num")) {
136-
$("#node-input-op2").show();
137-
} else {
138-
$("#node-input-op2").hide();
139-
}
142+
$("#node-input-op2").typedInput({
143+
default: 'str',
144+
typeField: $("#node-input-op2type"),
145+
types:['flow','global','str','num','bool','json',
146+
optionOriginalPayload,
147+
optionLatestPayload,
148+
optionNothing
149+
]
140150
});
151+
141152
if (this.duration == "0") {
142153
$("#node-then-type").val("block");
143154
} else {
144155
$("#node-then-type").val("wait");
145156
}
146157
$("#node-then-type").change();
147-
$("#node-input-op1type").change();
148-
$("#node-input-op2type").change();
149158

150159
if (this.extend === "true" || this.extend === true) {
151160
$("#node-input-extend").prop("checked",true);

nodes/core/core/89-trigger.js

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,29 @@ module.exports = function(RED) {
2121
RED.nodes.createNode(this,n);
2222
this.op1 = n.op1 || "1";
2323
this.op2 = n.op2 || "0";
24-
this.op1type = n.op1type || "val";
25-
this.op2type = n.op2type || "val";
24+
this.op1type = n.op1type || "str";
25+
this.op2type = n.op2type || "str";
26+
27+
if (this.op1type === 'val') {
28+
if (this.op1 === 'true' || this.op1 === 'false') {
29+
this.op1type = 'bool'
30+
} else if (this.op1 === 'null') {
31+
this.op1type = 'null';
32+
this.op1 = null;
33+
} else {
34+
this.op1type = 'str';
35+
}
36+
}
37+
if (this.op2type === 'val') {
38+
if (this.op2 === 'true' || this.op2 === 'false') {
39+
this.op2type = 'bool'
40+
} else if (this.op2 === 'null') {
41+
this.op2type = 'null';
42+
this.op2 = null;
43+
} else {
44+
this.op2type = 'str';
45+
}
46+
}
2647
this.extend = n.extend || "false";
2748
this.units = n.units || "ms";
2849
this.reset = n.reset || '';
@@ -33,14 +54,10 @@ module.exports = function(RED) {
3354
if (this.units == "min") { this.duration = this.duration * 1000 * 60; }
3455
if (this.units == "hr") { this.duration = this.duration * 1000 *60 * 60; }
3556
}
36-
this.op1Templated = this.op1.indexOf("{{") != -1;
37-
this.op2Templated = this.op2.indexOf("{{") != -1;
57+
this.op1Templated = (this.op1type === 'str' && this.op1.indexOf("{{") != -1);
58+
this.op2Templated = (this.op2type === 'str' && this.op2.indexOf("{{") != -1);
3859
if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); }
3960
if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); }
40-
if (this.op1 == "true") { this.op1 = true; }
41-
if (this.op2 == "true") { this.op2 = true; }
42-
if (this.op1 == "false") { this.op1 = false; }
43-
if (this.op2 == "false") { this.op2 = false; }
4461
if (this.op1 == "null") { this.op1 = null; }
4562
if (this.op2 == "null") { this.op2 = null; }
4663
//try { this.op1 = JSON.parse(this.op1); }
@@ -59,20 +76,31 @@ module.exports = function(RED) {
5976
}
6077
else {
6178
if ((!tout) && (tout !== 0)) {
62-
if (node.op2type === "pay") { m2 = msg.payload; }
63-
else if (node.op2type === "payl") { m2 = msg.payload; }
79+
if (node.op2type === "pay" || node.op2type === "payl") { m2 = msg.payload; }
6480
else if (node.op2Templated) { m2 = mustache.render(node.op2,msg); }
65-
else { m2 = node.op2; }
81+
else if (node.op2type !== "nul") {
82+
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
83+
}
84+
6685
if (node.op1type === "pay") { }
6786
else if (node.op1Templated) { msg.payload = mustache.render(node.op1,msg); }
68-
else { msg.payload = node.op1; }
87+
else if (node.op1type !== "nul") {
88+
msg.payload = RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg);
89+
}
90+
6991
if (node.op1type !== "nul") { node.send(msg); }
92+
7093
if (node.duration === 0) { tout = 0; }
7194
else {
7295
tout = setTimeout(function() {
73-
var msg2 = RED.util.cloneMessage(msg);
74-
msg2.payload = m2;
75-
if (node.op2type !== "nul") { node.send(msg2); }
96+
if (node.op2type !== "nul") {
97+
var msg2 = RED.util.cloneMessage(msg);
98+
if (node.op2type === "flow" || node.op2type === "global") {
99+
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
100+
}
101+
msg2.payload = m2;
102+
node.send(msg2);
103+
}
76104
tout = null;
77105
node.status({});
78106
},node.duration);
@@ -83,9 +111,14 @@ module.exports = function(RED) {
83111
clearTimeout(tout);
84112
if (node.op2type === "payl") { m2 = msg.payload; }
85113
tout = setTimeout(function() {
86-
var msg2 = RED.util.cloneMessage(msg);
87-
msg2.payload = m2;
88-
if (node.op2type !== "nul") { node.send(msg2); }
114+
if (node.op2type !== "nul") {
115+
var msg2 = RED.util.cloneMessage(msg);
116+
if (node.op2type === "flow" || node.op2type === "global") {
117+
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
118+
}
119+
msg2.payload = m2;
120+
node.send(msg2);
121+
}
89122
tout = null;
90123
node.status({});
91124
},node.duration);

nodes/core/locales/en-US/messages.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,13 @@
228228
"h": "Hours"
229229
},
230230
"extend": " extend delay if new message arrives",
231-
"tip": "The node can also be reset by sending a message with the <code>msg.reset</code> property set to any value.",
232231
"label": {
233232
"trigger": "trigger",
234233
"trigger-block": "trigger & block",
235-
"reset": "and reset if msg.payload == ",
236-
"resetprompt": "(optional reset value)"
234+
"reset": "Reset the trigger if:",
235+
"resetMessage":"msg.reset is set",
236+
"resetPayload":"msg.payload equals",
237+
"resetprompt": "optional"
237238
}
238239
},
239240
"comment": {

0 commit comments

Comments
 (0)