2014-06-25 22:36:28 +02:00
|
|
|
<!--
|
2015-07-01 23:36:27 +02:00
|
|
|
Copyright 2014, 2015 IBM Corp.
|
2014-06-25 22:36:28 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script type="text/x-red" data-template-name="trigger">
|
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.send" for="node-input-op1"></label>
|
|
|
|
<input type="hidden" id="node-input-op1type">
|
|
|
|
<input style="width: 70%" type="text" id="node-input-op1">
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.then"></label>
|
|
|
|
<select id="node-then-type" style="width:70%;">
|
2015-07-01 23:36:27 +02:00
|
|
|
<option value="block" data-i18n="trigger.wait-reset"></option>
|
|
|
|
<option value="wait" data-i18n="trigger.wait-for"></option>
|
2014-06-25 22:36:28 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2016-04-24 18:42:24 +02:00
|
|
|
<div class="form-row node-type-wait">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label></label>
|
|
|
|
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
|
|
|
|
<select id="node-input-units" style="width:140px !important">
|
|
|
|
<option value="ms" data-i18n="trigger.duration.ms"></option>
|
|
|
|
<option value="s" data-i18n="trigger.duration.s"></option>
|
|
|
|
<option value="min" data-i18n="trigger.duration.m"></option>
|
|
|
|
<option value="hr" data-i18n="trigger.duration.h"></option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-type-wait">
|
|
|
|
<label></label>
|
2016-04-24 18:42:24 +02:00
|
|
|
<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>
|
2015-07-01 23:36:27 +02:00
|
|
|
<div class="form-row node-type-wait">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.then-send"></label>
|
|
|
|
<input type="hidden" id="node-input-op2type">
|
|
|
|
<input style="width: 70%" type="text" id="node-input-op2">
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
2016-02-04 22:05:15 +01:00
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.label.reset" style="width:auto"></label>
|
|
|
|
<div style="display:inline-block; width:70%;vertical-align:top">
|
|
|
|
<ul>
|
|
|
|
<li data-i18n="trigger.label.resetMessage"></li>
|
|
|
|
<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>
|
|
|
|
</ul>
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
2015-07-01 23:36:27 +02:00
|
|
|
<br/>
|
2014-06-25 22:36:28 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2016-03-04 11:12:07 +01:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="trigger">
|
2016-02-12 14:15:05 +01:00
|
|
|
<p>Creates two messages on the output separated by a timeout whenever <i>any</i> <code>msg</code> arrives on the input.</p>
|
2014-06-25 22:36:28 +02:00
|
|
|
<p>For example, this can be used to toggle a Raspberry PI GPIO pin on and off.</p>
|
|
|
|
<p>The two output states can be specified as can the duration of the timer.
|
|
|
|
Either output can be set to a value, or templated from the inbound
|
2016-02-12 14:15:05 +01:00
|
|
|
<code>msg</code> using mustache syntax. <pre>The payload is {{payload}}</pre></p>
|
|
|
|
<p>If the <code>msg.payload</code> is an object then setting the output to
|
|
|
|
<i>existing payload</i> will pass the complete payload object through.</p>
|
2014-06-25 22:36:28 +02:00
|
|
|
<p>Optionally the timer can be extended by being retriggered... or not.</p>
|
|
|
|
<p>By setting the first output to <i>nothing</i>, and selecting extend timer - a watchdog timer can be created.
|
|
|
|
No output will happen as long as repeated inputs occur within the timeout period.</p>
|
|
|
|
<p>Setting the timer to 0 creates an "infinite" timeout - the first output will happen but the second
|
|
|
|
never will, and neither can the first be retriggered - so a true one shot.</p>
|
2016-02-12 14:15:05 +01:00
|
|
|
<p>If a <code>msg.reset</code> property is present, or the <code>msg.payload</code>
|
|
|
|
matches the optional reset value, any timeout currently in progress
|
2014-06-25 22:36:28 +02:00
|
|
|
will be cleared and the second output will not happen.</p>
|
2015-10-22 17:27:07 +02:00
|
|
|
<p>The blue status icon will be visible while the node is active.</p>
|
2014-06-25 22:36:28 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('trigger',{
|
|
|
|
category: 'function',
|
2014-06-26 14:05:34 +02:00
|
|
|
color:"#E6E0F8",
|
2014-06-25 22:36:28 +02:00
|
|
|
defaults: {
|
2014-09-07 23:11:58 +02:00
|
|
|
op1: {value:"1"},
|
|
|
|
op2: {value:"0"},
|
2015-03-21 20:27:22 +01:00
|
|
|
op1type: {value:"val"},
|
|
|
|
op2type: {value:"val"},
|
2014-06-25 22:36:28 +02:00
|
|
|
duration: {value:"250",required:true,validate:RED.validators.number()},
|
|
|
|
extend: {value:"false"},
|
2016-02-04 22:05:15 +01:00
|
|
|
units: {value:"ms"},
|
|
|
|
reset: {value:""},
|
2014-06-25 22:36:28 +02:00
|
|
|
name: {value:""}
|
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:1,
|
|
|
|
icon: "trigger.png",
|
|
|
|
label: function() {
|
|
|
|
if (this.duration > 0) {
|
2015-07-01 23:36:27 +02:00
|
|
|
return this.name|| this._("trigger.label.trigger")+" "+this.duration+this.units;
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-07-01 23:36:27 +02:00
|
|
|
return this.name|| this._("trigger.label.trigger-block");
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
2015-07-01 23:36:27 +02:00
|
|
|
$("#node-then-type").change(function() {
|
|
|
|
if ($(this).val() == "block") {
|
|
|
|
$(".node-type-wait").hide();
|
|
|
|
} else {
|
|
|
|
$(".node-type-wait").show();
|
|
|
|
}
|
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
|
|
|
|
if (this.op1type === 'val') {
|
|
|
|
$("#node-input-op1type").val('str');
|
|
|
|
}
|
|
|
|
if (this.op2type === 'val') {
|
|
|
|
$("#node-input-op2type").val('str');
|
|
|
|
}
|
|
|
|
|
|
|
|
var optionNothing = {value:"nul",label:this._("trigger.output.nothing"),hasValue:false};
|
|
|
|
var optionPayload = {value:"pay",label:this._("trigger.output.existing"),hasValue:false}
|
|
|
|
|
|
|
|
var optionOriginalPayload = {value:"pay",label:this._("trigger.output.original"),hasValue:false}
|
|
|
|
var optionLatestPayload = {value:"payl",label:this._("trigger.output.latest"),hasValue:false}
|
|
|
|
|
|
|
|
$("#node-input-op1").typedInput({
|
|
|
|
default: 'str',
|
|
|
|
typeField: $("#node-input-op1type"),
|
|
|
|
types:['flow','global','str','num','bool','json',
|
|
|
|
optionPayload,
|
|
|
|
optionNothing
|
|
|
|
]
|
2015-07-01 23:36:27 +02:00
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
$("#node-input-op2").typedInput({
|
|
|
|
default: 'str',
|
|
|
|
typeField: $("#node-input-op2type"),
|
|
|
|
types:['flow','global','str','num','bool','json',
|
|
|
|
optionOriginalPayload,
|
|
|
|
optionLatestPayload,
|
|
|
|
optionNothing
|
|
|
|
]
|
2014-06-25 22:36:28 +02:00
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
|
2015-07-01 23:36:27 +02:00
|
|
|
if (this.duration == "0") {
|
|
|
|
$("#node-then-type").val("block");
|
|
|
|
} else {
|
|
|
|
$("#node-then-type").val("wait");
|
|
|
|
}
|
|
|
|
$("#node-then-type").change();
|
|
|
|
|
|
|
|
if (this.extend === "true" || this.extend === true) {
|
|
|
|
$("#node-input-extend").prop("checked",true);
|
|
|
|
} else {
|
|
|
|
$("#node-input-extend").prop("checked",false);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
if ($("#node-then-type").val() == "block") {
|
|
|
|
$("#node-input-duration").val("0");
|
|
|
|
}
|
|
|
|
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|