Improved the configuration screen to allow larger range of delays/rates and to make it more obvious what the values mean

This commit is contained in:
Ben Hardill 2013-10-02 12:31:12 +01:00
parent 0b1c14c07e
commit 56da5faae2
2 changed files with 56 additions and 5 deletions

View File

@ -27,11 +27,26 @@
<div id="delay-details" class="form-row">
<label for="node-input-timeout"><i class="icon-wrench"></i> Delay</label>
<input type="text" id="node-input-timeout" placeholder="Time">
<label for="node-input-timeoutUnits"> For </label>
<select id="node-input-timeoutUnits">
<option value="milliseconds">Milliseconds</option>
<option value="seconds">Seconds</option>
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
<option value="days">Days</option>
</select>
</div>
<div id="rate-details" class="form-row">
<label for="node-input-rate"><i class="icon-wrench"></i> Rate</label>
<input type="text" id="node-input-rate" placeholder="msg/second">
<label for="node-input-rateUnits"> Per </label>
<select id="node-input-rateUnits">
<option value="second">Second</option>
<option value="minute">Minute</option>
<option value="hour">Hour</option>
<option value="day">Day</option>
</select>
</div>
<div class="form-row">
@ -57,16 +72,20 @@
name: {value:""}, // along with default values.
pauseType: {value:"delay", required:true},
timeout: {value:"5", required:true, validate:RED.validators.number()},
rate: {value:"1", 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
if (this.pauseType == "delay") {
return this.name||"delay "+this.timeout+" s";
var units = this.timeoutUnits ? this.timeoutUnits.charAt(0) : "s";
return this.name||"delay "+this.timeout+" " + units;
} else if (this.pauseType == "rate") {
return this.name||"limit "+this.rate+" msg/s";
var units = this.rateUnits ? this.rateUnits.charAt(0) : "s";
return this.name||"limit "+this.rate+" msg/"+ units;
}
return "foo";
},
@ -82,6 +101,12 @@
$("#rate-details").show();
}
if (!this.timeoutUnits) {
$("#node-input-timeoutUnits option").filter(function() {
return $(this).val() == 'seconds';
}).attr('selected', true);
}
$("#node-input-pauseType").on("change",function() {
if (this.value == "delay") {
$("#delay-details").show();

View File

@ -24,8 +24,34 @@ function DelayNode(n) {
RED.nodes.createNode(this,n);
this.pauseType = n.pauseType;
this.timeout = n.timeout * 1000;
this.rate = 1000/n.rate;
this.timeoutUnits = n.timeoutUnits;
this.rateUnits = n.rateUnits;
if (n.timeoutUnits == "milliseconds") {
this.timeout = n.timout;
} else if (n.timeoutUnits == "seconds") {
this.timeout = n.timeout * 1000;
} else if (n.timeoutUnits == "minutes") {
this.timeout = n.timeout * (60 * 1000);
} else if (n.timeoutUnits == "hours") {
this.timeout = n.timeout * (60 * 60 * 1000);
} 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") {
this.rate = (60 * 1000)/n.rate;
} else if (n.rateUnits == "hour") {
this.rate = (60 * 60 * 1000)/n.rate;
} else if (n.rateUnits == "day") {
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.idList = [];
this.buffer = [];