Tweaks to timer node - limit delays/rate to +ve numbers... add bit more info, slight tidy up.

This commit is contained in:
Dave C-J 2013-10-17 22:45:17 +01:00
parent 81d6a4b04f
commit 426444b042
3 changed files with 30 additions and 42 deletions

View File

@ -14,14 +14,12 @@
limitations under the License.
-->
<!-- First, the content of the edit dialog is defined. -->
<script type="text/x-red" data-template-name="delay">
<div class="form-row">
<label for="node-input-pauseType"><i class="icon-tasks"></i> Action</label>
<select id="node-input-pauseType" style="width:270px !important">
<option value="delay">Delay message</option>
<option value="rate">Limit rate to</option>
<option value="rate">Limit message rate</option>
</select>
</div>
<div id="delay-details" class="form-row">
@ -35,11 +33,10 @@
<option value="days">Days</option>
</select>
</div>
<div id="rate-details" class="form-row">
<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">
<label for="node-input-reateUnits">message(s) per</label>
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:40px !important">
<label for="node-input-rateUnits" style="width:120px !important">message(s) per</label>
<select id="node-input-rateUnits" style="width:140px !important">
<option value="second">Second</option>
<option value="minute">Minute</option>
@ -47,37 +44,35 @@
<option value="day">Day</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="delay">
<p>Introduces a delay into a flow or rate limts messges</p>
<p>Default delay is 5 seconds and rate limit of 1 msg/second, but both can be configured</p>
<p>Introduces a delay into a flow or rate limits messages</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>
<!-- Finally, the node type is registered along with all of its properties -->
<script type="text/javascript">
RED.nodes.registerType('delay',{
category: 'function', // the palette category
category: 'function',
color:"#E6E0F8",
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
defaults: {
name: {value:""},
pauseType: {value:"delay", required:true},
timeout: {value:"5", required:true, validate:RED.validators.number()},
timeoutUnits: {value:"seconds"},
rate: {value:"1", required:true, validate:RED.validators.number()},
rateUnits: {value: "second"}
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "arrow-in.png", // set the icon (held in public/icons)
label: function() { // sets the default label contents
inputs:1,
outputs:1,
icon: "timer.png",
label: function() {
if (this.pauseType == "delay") {
var units = this.timeoutUnits ? this.timeoutUnits.charAt(0) : "s";
return this.name||"delay "+this.timeout+" " + units;
@ -85,15 +80,15 @@
var units = this.rateUnits ? this.rateUnits.charAt(0) : "s";
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":"";
},
oneditprepare: function() {
$( "#node-input-timeout" ).spinner();
$( "#node-input-rate" ).spinner();
$( "#node-input-timeout" ).spinner({ min:1, max:60 });
$( "#node-input-rate" ).spinner({ min:1});
if (this.pauseType == "delay") {
$("#delay-details").show();
$("#rate-details").hide();
@ -101,13 +96,13 @@
$("#delay-details").hide();
$("#rate-details").show();
}
if (!this.timeoutUnits) {
$("#node-input-timeoutUnits option").filter(function() {
return $(this).val() == 'seconds';
return $(this).val() == 'seconds';
}).attr('selected', true);
}
$("#node-input-pauseType").on("change",function() {
if (this.value == "delay") {
$("#delay-details").show();

View File

@ -13,20 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
// Simple node to introduce a pause into a flow
// Require main module
var RED = require("../../red/red");
// main node definition
function DelayNode(n) {
RED.nodes.createNode(this,n);
this.pauseType = n.pauseType;
this.timeoutUnits = n.timeoutUnits;
this.rateUnits = n.rateUnits;
if (n.timeoutUnits == "milliseconds") {
this.timeout = n.timout;
} else if (n.timeoutUnits == "seconds") {
@ -38,7 +36,7 @@ function DelayNode(n) {
} else if (n.timeoutUnits == "days") {
this.timeout = n.timeout * (24 * 60 * 60 * 1000);
}
if (n.rateUnits == "second") {
this.rate = 1000/n.rate;
} else if (n.rateUnits == "minute") {
@ -48,13 +46,13 @@ function DelayNode(n) {
} else if (n.rateUnits == "day") {
this.rate = (24 * 60 * 60 * 1000)/n.rate;
}
this.name = n.name;
this.idList = [];
this.buffer = [];
this.intervalID = -1;
var node= this;
if (this.pauseType == "delay") {
this.on("input", function(msg) {
var node= this;
@ -73,7 +71,7 @@ function DelayNode(n) {
this.idList = [];
});
} else if (this.pauseType == "rate") {
this.on("input", function(msg) {
if ( node.intervalID != -1) {
node.buffer.push(msg);
@ -87,7 +85,7 @@ function DelayNode(n) {
clearInterval(node.intervalID);
node.intervalID = -1;
}
if (node.buffer.length > 0) {
node.send(node.buffer.shift());
}
@ -101,9 +99,4 @@ function DelayNode(n) {
});
}
}
// register node
RED.nodes.registerType("delay",DelayNode);

BIN
public/icons/timer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB