1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix some layout issues in the config popup and made the rate limit mode shut down the timer and make sure it sends the first message straight away when the buffer is empty.

This commit is contained in:
Ben Hardill 2013-10-03 12:41:30 +01:00
parent 56da5faae2
commit 25d8a59d6c
2 changed files with 35 additions and 26 deletions

View File

@ -18,17 +18,16 @@
<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> Type</label> <label for="node-input-pauseType"><i class="icon-tasks"></i> Action</label>
<select id="node-input-pauseType"> <select id="node-input-pauseType" style="width:270px !important">
<option value="delay">Delay</option> <option value="delay">Delay message</option>
<option value="rate">Rate Limit</option> <option value="rate">Limit rate to</option>
</select> </select>
</div> </div>
<div id="delay-details" class="form-row"> <div id="delay-details" class="form-row">
<label for="node-input-timeout"><i class="icon-wrench"></i> Delay</label> <label for="node-input-timeout"><i class="icon-time"></i> For</label>
<input type="text" id="node-input-timeout" placeholder="Time"> <input type="text" id="node-input-timeout" placeholder="Time" style="direction:rtl; width:50px !important">
<label for="node-input-timeoutUnits"> For </label> <select id="node-input-timeoutUnits" style="width:200px !important">
<select id="node-input-timeoutUnits">
<option value="milliseconds">Milliseconds</option> <option value="milliseconds">Milliseconds</option>
<option value="seconds">Seconds</option> <option value="seconds">Seconds</option>
<option value="minutes">Minutes</option> <option value="minutes">Minutes</option>
@ -38,10 +37,10 @@
</div> </div>
<div id="rate-details" class="form-row"> <div id="rate-details" class="form-row">
<label for="node-input-rate"><i class="icon-wrench"></i> Rate</label> <label for="node-input-rate"><i class="icon-time"></i> To</label>
<input type="text" id="node-input-rate" placeholder="msg/second"> <input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:50px !important">
<label for="node-input-rateUnits"> Per </label> <label for="node-input-reateUnits">message(s) per</label>
<select id="node-input-rateUnits"> <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>
<option value="hour">Hour</option> <option value="hour">Hour</option>
@ -54,7 +53,6 @@
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
<div class="form-tips">Delay value in seconds, Rate value in messages per second</div>
</script> </script>
<!-- Next, some simple help text is provided for the node. --> <!-- Next, some simple help text is provided for the node. -->
@ -93,6 +91,9 @@
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";
}, },
oneditprepare: function() { oneditprepare: function() {
$( "#node-input-timeout" ).spinner();
$( "#node-input-rate" ).spinner();
if (this.pauseType == "delay") { if (this.pauseType == "delay") {
$("#delay-details").show(); $("#delay-details").show();
$("#rate-details").hide(); $("#rate-details").hide();
@ -114,7 +115,7 @@
} else if (this.value == "rate") { } else if (this.value == "rate") {
$("#delay-details").hide(); $("#delay-details").hide();
$("#rate-details").show(); $("#rate-details").show();
} }
}); });
} }
}); });

View File

@ -48,13 +48,11 @@ 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;
} }
console.log(this.timeoutUnits + " - " + n.timeout + " = " + this.timeout);
console.log(this.rateUnits + " - " + n.rate + " = " + this.rate);
this.name = n.name; this.name = n.name;
this.idList = []; this.idList = [];
this.buffer = []; this.buffer = [];
this.intervalID = -1;
var node= this; var node= this;
if (this.pauseType == "delay") { if (this.pauseType == "delay") {
@ -69,21 +67,31 @@ function DelayNode(n) {
}); });
} else if (this.pauseType == "rate") { } else if (this.pauseType == "rate") {
this.intervalID = setInterval(function() {
if (node.buffer.length > 0) {
node.send(node.buffer.shift());
}
},this.rate);
this.on("input", function(msg) { this.on("input", function(msg) {
this.buffer.push(msg); if ( node.intervalID != -1) {
if (this.buffer.length > 1000) { node.buffer.push(msg);
this.warn(this.name + " buffer exceeded 1000 messages"); if (node.buffer.length > 1000) {
node.warn(this.name + " buffer exceeded 1000 messages");
}
} else {
node.send(msg);
node.intervalID = setInterval(function() {
if (node.buffer.length == 0) {
clearInterval(node.intervalID);
node.intervalID = -1;
}
if (node.buffer.length > 0) {
node.send(node.buffer.shift());
}
},node.rate);
} }
}); });
} }
} }
// register node // register node
RED.nodes.registerType("delay",DelayNode); RED.nodes.registerType("delay",DelayNode);