mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Tweaks to timer node - limit delays/rate to +ve numbers... add bit more info, slight tidy up.
This commit is contained in:
parent
81d6a4b04f
commit
426444b042
@ -14,14 +14,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- First, the content of the edit dialog is defined. -->
|
|
||||||
<script type="text/x-red" data-template-name="delay">
|
<script type="text/x-red" data-template-name="delay">
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-pauseType"><i class="icon-tasks"></i> Action</label>
|
<label for="node-input-pauseType"><i class="icon-tasks"></i> Action</label>
|
||||||
<select id="node-input-pauseType" style="width:270px !important">
|
<select id="node-input-pauseType" style="width:270px !important">
|
||||||
<option value="delay">Delay message</option>
|
<option value="delay">Delay message</option>
|
||||||
<option value="rate">Limit rate to</option>
|
<option value="rate">Limit message rate</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="delay-details" class="form-row">
|
<div id="delay-details" class="form-row">
|
||||||
@ -35,11 +33,10 @@
|
|||||||
<option value="days">Days</option>
|
<option value="days">Days</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="rate-details" class="form-row">
|
<div id="rate-details" class="form-row">
|
||||||
<label for="node-input-rate"><i class="icon-time"></i> To</label>
|
<label for="node-input-rate"><i class="icon-time"></i> To</label>
|
||||||
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:50px !important">
|
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:40px !important">
|
||||||
<label for="node-input-reateUnits">message(s) per</label>
|
<label for="node-input-rateUnits" style="width:120px !important">message(s) per</label>
|
||||||
<select id="node-input-rateUnits" style="width:140px !important">
|
<select id="node-input-rateUnits" style="width:140px !important">
|
||||||
<option value="second">Second</option>
|
<option value="second">Second</option>
|
||||||
<option value="minute">Minute</option>
|
<option value="minute">Minute</option>
|
||||||
@ -47,37 +44,35 @@
|
|||||||
<option value="day">Day</option>
|
<option value="day">Day</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
|
||||||
<script type="text/x-red" data-help-name="delay">
|
<script type="text/x-red" data-help-name="delay">
|
||||||
<p>Introduces a delay into a flow or rate limts messges</p>
|
<p>Introduces a delay into a flow or rate limits messages</p>
|
||||||
<p>Default delay is 5 seconds and rate limit of 1 msg/second, but both can be configured</p>
|
<p>Default delay is 5 seconds or rate limit of 1 message/second, but both can be configured</p>
|
||||||
|
<p>The rate limiter will delay messages by buffering in a time released queue. A warning is generated if the buffer is larger than 1000 items.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('delay',{
|
RED.nodes.registerType('delay',{
|
||||||
category: 'function', // the palette category
|
category: 'function',
|
||||||
color:"#E6E0F8",
|
color:"#E6E0F8",
|
||||||
defaults: { // defines the editable properties of the node
|
defaults: {
|
||||||
name: {value:""}, // along with default values.
|
name: {value:""},
|
||||||
pauseType: {value:"delay", required:true},
|
pauseType: {value:"delay", required:true},
|
||||||
timeout: {value:"5", required:true, validate:RED.validators.number()},
|
timeout: {value:"5", required:true, validate:RED.validators.number()},
|
||||||
timeoutUnits: {value:"seconds"},
|
timeoutUnits: {value:"seconds"},
|
||||||
rate: {value:"1", required:true, validate:RED.validators.number()},
|
rate: {value:"1", required:true, validate:RED.validators.number()},
|
||||||
rateUnits: {value: "second"}
|
rateUnits: {value: "second"}
|
||||||
},
|
},
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
inputs:1,
|
||||||
outputs:1, // set the number of outputs - 0 to n
|
outputs:1,
|
||||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
icon: "timer.png",
|
||||||
label: function() { // sets the default label contents
|
label: function() {
|
||||||
if (this.pauseType == "delay") {
|
if (this.pauseType == "delay") {
|
||||||
var units = this.timeoutUnits ? this.timeoutUnits.charAt(0) : "s";
|
var units = this.timeoutUnits ? this.timeoutUnits.charAt(0) : "s";
|
||||||
return this.name||"delay "+this.timeout+" " + units;
|
return this.name||"delay "+this.timeout+" " + units;
|
||||||
@ -85,15 +80,15 @@
|
|||||||
var units = this.rateUnits ? this.rateUnits.charAt(0) : "s";
|
var units = this.rateUnits ? this.rateUnits.charAt(0) : "s";
|
||||||
return this.name||"limit "+this.rate+" msg/"+ units;
|
return this.name||"limit "+this.rate+" msg/"+ units;
|
||||||
}
|
}
|
||||||
return "foo";
|
return "";
|
||||||
},
|
},
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
$( "#node-input-timeout" ).spinner();
|
$( "#node-input-timeout" ).spinner({ min:1, max:60 });
|
||||||
$( "#node-input-rate" ).spinner();
|
$( "#node-input-rate" ).spinner({ min:1});
|
||||||
|
|
||||||
if (this.pauseType == "delay") {
|
if (this.pauseType == "delay") {
|
||||||
$("#delay-details").show();
|
$("#delay-details").show();
|
||||||
$("#rate-details").hide();
|
$("#rate-details").hide();
|
||||||
@ -101,13 +96,13 @@
|
|||||||
$("#delay-details").hide();
|
$("#delay-details").hide();
|
||||||
$("#rate-details").show();
|
$("#rate-details").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.timeoutUnits) {
|
if (!this.timeoutUnits) {
|
||||||
$("#node-input-timeoutUnits option").filter(function() {
|
$("#node-input-timeoutUnits option").filter(function() {
|
||||||
return $(this).val() == 'seconds';
|
return $(this).val() == 'seconds';
|
||||||
}).attr('selected', true);
|
}).attr('selected', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#node-input-pauseType").on("change",function() {
|
$("#node-input-pauseType").on("change",function() {
|
||||||
if (this.value == "delay") {
|
if (this.value == "delay") {
|
||||||
$("#delay-details").show();
|
$("#delay-details").show();
|
||||||
|
@ -13,20 +13,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// Simple node to introduce a pause into a flow
|
// Simple node to introduce a pause into a flow
|
||||||
|
|
||||||
// Require main module
|
|
||||||
var RED = require("../../red/red");
|
var RED = require("../../red/red");
|
||||||
|
|
||||||
// main node definition
|
|
||||||
function DelayNode(n) {
|
function DelayNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
this.pauseType = n.pauseType;
|
this.pauseType = n.pauseType;
|
||||||
this.timeoutUnits = n.timeoutUnits;
|
this.timeoutUnits = n.timeoutUnits;
|
||||||
this.rateUnits = n.rateUnits;
|
this.rateUnits = n.rateUnits;
|
||||||
|
|
||||||
if (n.timeoutUnits == "milliseconds") {
|
if (n.timeoutUnits == "milliseconds") {
|
||||||
this.timeout = n.timout;
|
this.timeout = n.timout;
|
||||||
} else if (n.timeoutUnits == "seconds") {
|
} else if (n.timeoutUnits == "seconds") {
|
||||||
@ -38,7 +36,7 @@ function DelayNode(n) {
|
|||||||
} else if (n.timeoutUnits == "days") {
|
} else if (n.timeoutUnits == "days") {
|
||||||
this.timeout = n.timeout * (24 * 60 * 60 * 1000);
|
this.timeout = n.timeout * (24 * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n.rateUnits == "second") {
|
if (n.rateUnits == "second") {
|
||||||
this.rate = 1000/n.rate;
|
this.rate = 1000/n.rate;
|
||||||
} else if (n.rateUnits == "minute") {
|
} else if (n.rateUnits == "minute") {
|
||||||
@ -48,13 +46,13 @@ function DelayNode(n) {
|
|||||||
} else if (n.rateUnits == "day") {
|
} else if (n.rateUnits == "day") {
|
||||||
this.rate = (24 * 60 * 60 * 1000)/n.rate;
|
this.rate = (24 * 60 * 60 * 1000)/n.rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.idList = [];
|
this.idList = [];
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.intervalID = -1;
|
this.intervalID = -1;
|
||||||
var node= this;
|
var node= this;
|
||||||
|
|
||||||
if (this.pauseType == "delay") {
|
if (this.pauseType == "delay") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
var node= this;
|
var node= this;
|
||||||
@ -73,7 +71,7 @@ function DelayNode(n) {
|
|||||||
this.idList = [];
|
this.idList = [];
|
||||||
});
|
});
|
||||||
} else if (this.pauseType == "rate") {
|
} else if (this.pauseType == "rate") {
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if ( node.intervalID != -1) {
|
if ( node.intervalID != -1) {
|
||||||
node.buffer.push(msg);
|
node.buffer.push(msg);
|
||||||
@ -87,7 +85,7 @@ function DelayNode(n) {
|
|||||||
clearInterval(node.intervalID);
|
clearInterval(node.intervalID);
|
||||||
node.intervalID = -1;
|
node.intervalID = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.buffer.length > 0) {
|
if (node.buffer.length > 0) {
|
||||||
node.send(node.buffer.shift());
|
node.send(node.buffer.shift());
|
||||||
}
|
}
|
||||||
@ -101,9 +99,4 @@ function DelayNode(n) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// register node
|
|
||||||
RED.nodes.registerType("delay",DelayNode);
|
RED.nodes.registerType("delay",DelayNode);
|
||||||
|
|
||||||
|
BIN
public/icons/timer.png
Normal file
BIN
public/icons/timer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user