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

Functional Fix for Inject node

addresses Issue #209
Interval is now wholly timeout based.
Now works on Sundays
This commit is contained in:
Dave C-J 2014-04-29 16:20:45 +01:00
parent 02eb1d9a64
commit f2e9b43866
2 changed files with 43 additions and 21 deletions

View File

@ -26,29 +26,41 @@
<div class="form-row" id="node-input-row-payload">
<label for="node-input-payload"></label>
<input type="text" id="node-input-payload" placeholder="Payload">
<input type="text" id="node-input-payload" placeholder="payload">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
<input type="text" id="node-input-topic" placeholder="topic">
</div>
<div class="form-row">
<label for=""><i class="icon-repeat"></i> Repeat</label>
<select id="inject-time-type-select"><option value="none">None</option><option value="interval">interval</option><option value="interval-time">interval between times</option><option value="time">at a specific time</option></select>
<input type="hidden" id="node-input-repeat" placeholder="Payload">
<input type="hidden" id="node-input-crontab" placeholder="Payload">
<select id="inject-time-type-select" style="width: 288px"><option value="none">none</option><option value="interval">interval</option><option value="interval-time">interval between times</option><option value="time">at a specific time</option></select>
<input type="hidden" id="node-input-repeat" placeholder="payload">
<input type="hidden" id="node-input-crontab" placeholder="payload">
</div>
<div class="form-row inject-time-row hidden" id="inject-time-row-interval">
every <input id="inject-time-interval-count" class="inject-time-count" value="1"></input>
<select style="width: 100px" id="inject-time-interval-units"><option value="s">seconds</option><option value="m">minutes</option><option value="h">hours</option></select><br/>
on <select disabled id="inject-time-interval-days" class="inject-time-days"></select>
<!-- on <select disabled id="inject-time-interval-days" class="inject-time-days"></select> -->
</div>
<div class="form-row inject-time-row hidden" id="inject-time-row-interval-time">
every <input id="inject-time-interval-time-units" class="inject-time-count" value="1"></input> minutes<br/>
at every <select style="width: 90px" id="inject-time-interval-time-units" class="inject-time-int-count" value="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="30">30</option>
</select> minutes<br/>
between <select id="inject-time-interval-time-start" class="inject-time-times"></select>
and <select id="inject-time-interval-time-end" class="inject-time-times"></select><br/>
on <select id="inject-time-interval-time-days" class="inject-time-days"></select>
@ -67,9 +79,10 @@
<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">
<input type="text" id="node-input-name" placeholder="name">
</div>
<div class="form-tips"><b>Note:</b> "interval between times" and "at a specific time" will use cron.<br/>See info box for details.</div>
<script>
{
$("#inject-time-type-select").change(function() {
@ -89,14 +102,14 @@
var days = [
{v:"*",t:"every day"},
{v:"1-5",t:"Mondays to Fridays"},
{v:"6-7",t:"Saturdays and Sundays"},
{v:"0,6",t:"Saturdays and Sundays"},
{v:"1",t:"Mondays"},
{v:"2",t:"Tuesdays"},
{v:"3",t:"Wednesdays"},
{v:"4",t:"Thursdays"},
{v:"5",t:"Fridays"},
{v:"6",t:"Saturdays"},
{v:"7",t:"Sundays"}
{v:"0",t:"Sundays"}
];
$(".inject-time-days").each(function() {
@ -113,14 +126,14 @@
});
$(".inject-time-count").spinner({
min:1,
max:60
//max:60,
min:1
});
$("#inject-time-interval-units").change(function() {
var units = $("#inject-time-interval-units option:selected").val();
$("#inject-time-interval-days").prop("disabled",(units == "s")?"disabled":false);
$(".inject-time-count").spinner("option","max",(units == "h")?24:60);
//$("#inject-time-interval-days").prop("disabled",(units == "s")?"disabled":false);
//$(".inject-time-count").spinner("option","max",(units == "h")?24:60);
});
$.widget( "ui.injecttimespinner", $.ui.spinner, {
@ -164,7 +177,7 @@
margin: 3px 0;
}
.inject-time-days {
width: 225px;
width: 262px;
}
.inject-time-times {
width: 90px;
@ -179,7 +192,7 @@
width: 75px;
}
.inject-time-count {
width: 30px !important;
width: 40px !important;
}
</style>
<script type="text/x-red" data-help-name="inject">
@ -187,6 +200,8 @@
<p>If no payload is specified the payload is set to the current time in millisecs since 1970. This allows subsequent functions to perform time based actions.</p>
<p>The repeat function does what it says on the tin and continuously sends the payload every x seconds.</p>
<p>The Fire once at start option actually waits 50mS before firing to give other nodes a chance to instantiate properly.</p>
<p><b>Note: </b>"Interval between times" and "at a specific time" will use cron. This means that 20 mins will be at the next hour, 20 mins past and 40 mins past - not in 20 minutes time.
If you want every 20 mins from now - use the basic "interval" option.</p>
</script>
<script type="text/javascript">
@ -218,8 +233,13 @@
var repeattype = "none";
if (this.repeat != "" && this.repeat != 0) {
repeattype = "interval";
$("#inject-time-interval-units option").filter(function() {return $(this).val() == "s";}).attr('selected',true);
$("#inject-time-interval-count").val(this.repeat);
var r = "s";
var c = this.repeat;
if (this.repeat % 60 === 0) { r = "m"; c = c/60; }
if (this.repeat % 1440 === 0) { r = "h"; c = c/24; }
$("#inject-time-interval-count").val(c);
$("#inject-time-interval-units").val(r);
//$("#inject-time-interval-units option").filter(function() {return $(this).val() == "s";}).attr('selected',true);
$("#inject-time-interval-days").prop("disabled","disabled");
} else if (this.crontab) {
var cronparts = this.crontab.split(" ");
@ -327,9 +347,11 @@
repeat = count;
} else {
if (units == "m") {
crontab = "*/"+count+" * * * "+days;
//crontab = "*/"+count+" * * * "+days;
repeat = count * 60;
} else if (units == "h") {
crontab = "0 */"+count+" * * "+days;
//crontab = "0 */"+count+" * * "+days;
repeat = count * 60 * 24;
}
}
} else if (type == "interval-time") {

View File

@ -53,7 +53,7 @@ function InjectNode(n) {
}
if (this.once) {
setTimeout( function(){ node.emit("input",{}); }, 50);
setTimeout( function(){ node.emit("input",{}); }, 100);
}
this.on("input",function(msg) {