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

Fix Inject node handling of day selection

Fixes #564
This commit is contained in:
Nick O'Leary 2015-02-15 21:53:14 +00:00
parent cc095e4edf
commit edd9d2cb9c
2 changed files with 131 additions and 144 deletions

View File

@ -44,7 +44,6 @@
<div class="form-row inject-time-row hidden" id="inject-time-row-interval"> <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> 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/> <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> -->
</div> </div>
<div class="form-row inject-time-row hidden" id="inject-time-row-interval-time"> <div class="form-row inject-time-row hidden" id="inject-time-row-interval-time">
@ -64,34 +63,45 @@
</select> minutes<br/> </select> minutes<br/>
between <select id="inject-time-interval-time-start" class="inject-time-times"></select> 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/> 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> -->
<div id="inject-time-interval-time-days" class="inject-time-days"> <div id="inject-time-interval-time-days" class="inject-time-days">
<table style="width:100% !important"><tr><td valign="top">on&nbsp;</td><td valign="top"> <div style="display: inline-block; vertical-align: top;margin-right: 5px;">on </div>
<label><input type='checkbox' class="cb1" value='1'/> Monday</label> <div style="display:inline-block;">
<label><input type='checkbox' class="cb1" value='2'/> Tuesday</label> <div>
<label><input type='checkbox' class="cb1" value='3'/> Wednesday</label> <label><input type='checkbox' checked value='1'/> Monday</label>
<label><input type='checkbox' class="cb1" value='4'/> Thursday</label> <label><input type='checkbox' checked value='2'/> Tuesday</label>
<label><input type='checkbox' class="cb1" value='5'/> Friday</label> <label><input type='checkbox' checked value='3'/> Wednesday</label>
<label><input type='checkbox' class="cb1" value='6'/> Saturday</label> </div>
<label><input type='checkbox' class="cb1" value='0'/> Sunday</label> <div>
<!-- <div><input type='checkbox' id="cb1selectall" value='*'/> Everyday</div> --> <label><input type='checkbox' checked value='4'/> Thursday</label>
</td></tr></table> <label><input type='checkbox' checked value='5'/> Friday</label>
<label><input type='checkbox' checked value='6'/> Saturday</label>
</div>
<div>
<label><input type='checkbox' checked value='0'/> Sunday</label>
</div>
</div>
</div> </div>
</div> </div>
<div class="form-row inject-time-row hidden" id="inject-time-row-time"> <div class="form-row inject-time-row hidden" id="inject-time-row-time">
at <input id="inject-time-time" value="12:00"></input><br/> at <input id="inject-time-time" value="12:00"></input><br/>
<!-- on <select id="inject-time-time-days" class="inject-time-days"></select> -->
<div id="inject-time-time-days" class="inject-time-days"> <div id="inject-time-time-days" class="inject-time-days">
<table style="width:100% !important"><tr><td valign="top">on&nbsp;</td><td valign="top"> <div style="display: inline-block; vertical-align: top;margin-right: 5px;">on </div>
<label><input type='checkbox' class="cb2" value='1'/> Monday</label> <div style="display:inline-block;">
<label><input type='checkbox' class="cb2" value='2'/> Tuesday</label> <div>
<label><input type='checkbox' class="cb2" value='3'/> Wednesday</label> <label><input type='checkbox' checked value='1'/> Monday</label>
<label><input type='checkbox' class="cb2" value='4'/> Thursday</label> <label><input type='checkbox' checked value='2'/> Tuesday</label>
<label><input type='checkbox' class="cb2" value='5'/> Friday</label> <label><input type='checkbox' checked value='3'/> Wednesday</label>
<label><input type='checkbox' class="cb2" value='6'/> Saturday</label> </div>
<label><input type='checkbox' class="cb2" value='0'/> Sunday</label> <div>
</td></tr></table> <label><input type='checkbox' checked value='4'/> Thursday</label>
<label><input type='checkbox' checked value='5'/> Friday</label>
<label><input type='checkbox' checked value='6'/> Saturday</label>
</div>
<div>
<label><input type='checkbox' checked value='0'/> Sunday</label>
</div>
</div>
</div> </div>
</div> </div>
@ -115,9 +125,18 @@
.inject-time-row select { .inject-time-row select {
margin: 3px 0; margin: 3px 0;
} }
//.inject-time-days { .inject-time-days label {
// width: 262px; -webkit-user-select: none;
//} -khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
vertical-align: top;
width: 100px;
}
.inject-time-days input {
width: auto;
}
.inject-time-times { .inject-time-times {
width: 90px; width: 90px;
} }
@ -135,12 +154,17 @@
} }
</style> </style>
<script type="text/x-red" data-help-name="inject"> <script type="text/x-red" data-help-name="inject">
<p>Pressing the button on the left side of the node allows a message on a topic to be injected into the flow. This is mainly for test purposes.</p> <p>Pressing the button on the left side of the node allows a message on a topic
<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> to be injected into the flow. This is mainly for test purposes.</p>
<p>The repeat function does what it says on the tin and continuously sends the payload every x seconds.</p> <p>The payload defaults to the current time in millisecs since 1970, but can
<p>The Fire once at start option actually waits 50mS before firing to give other nodes a chance to instantiate properly.</p> also be set to a String or left blank.</p>
<p><b>Note: </b>"Interval between times" and "at a specific time" will use cron. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time. <p>The repeat function allows the payload to be sent on the required schedule.</p>
If you want every 20 minutes from now - use the basic "interval" option.</p> <p>The Fire once at start option actually waits a short interval before firing
to give other nodes a chance to instantiate properly.</p>
<p><b>Note: </b>"Interval between times" and "at a specific time" uses cron.
This means that 20 minutes will be at the next hour, 20 minutes past and
40 minutes past - not in 20 minutes time. If you want every 20 minutes
from now - use the "interval" option.</p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
@ -191,36 +215,6 @@
} }
}); });
//$("#cb1selectall").click(function () {
// $('.cb1').attr('checked', this.checked);
//});
//$(".cb1").click(function(){
// if($(".cb1:checked").length == 7) {
// $("#cb1selectall").attr("checked", "checked");
// } else {
// $("#cb1selectall").removeAttr("checked");
// }
//});
//var days = [
// {v:"*",t:"every day"},
// {v:"1-5",t:"Mondays to Fridays"},
// {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:"0",t:"Sundays"}
//];
//$(".inject-time-days").each(function() {
// for (var d in days) {
// $(this).append($("<option></option>").val(days[d].v).text(days[d].t));
// }
//});
$(".inject-time-times").each(function() { $(".inject-time-times").each(function() {
for (var i=0;i<24;i++) { for (var i=0;i<24;i++) {
var l = (i<10?"0":"")+i+":00"; var l = (i<10?"0":"")+i+":00";
@ -228,6 +222,22 @@
} }
}); });
$("#inject-time-interval-time-start").change(function() {
var start = Number($("#inject-time-interval-time-start option:selected").val());
var end = Number($("#inject-time-interval-time-end option:selected").val());
$("#inject-time-interval-time-end option").remove();
for (var i=start+1;i<25;i++) {
var l = (i<10?"0":"")+i+":00";
if (i==24) {
l = "00:00";
}
var opt = $("<option></option>").val(i).text(l).appendTo("#inject-time-interval-time-end");
if (i === end) {
opt.attr("selected","selected");
}
}
});
$(".inject-time-count").spinner({ $(".inject-time-count").spinner({
//max:60, //max:60,
min:1 min:1
@ -235,8 +245,6 @@
$("#inject-time-interval-units").change(function() { $("#inject-time-interval-units").change(function() {
var units = $("#inject-time-interval-units option:selected").val(); 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);
}); });
$.widget( "ui.injecttimespinner", $.ui.spinner, { $.widget( "ui.injecttimespinner", $.ui.spinner, {
@ -277,7 +285,6 @@
if (this.repeat % 1440 === 0) { r = "h"; c = c/60; } if (this.repeat % 1440 === 0) { r = "h"; c = c/60; }
$("#inject-time-interval-count").val(c); $("#inject-time-interval-count").val(c);
$("#inject-time-interval-units").val(r); $("#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"); $("#inject-time-interval-days").prop("disabled","disabled");
} else if (this.crontab) { } else if (this.crontab) {
var cronparts = this.crontab.split(" "); var cronparts = this.crontab.split(" ");
@ -288,44 +295,28 @@
var time = cronparts[1]+":"+cronparts[0]; var time = cronparts[1]+":"+cronparts[0];
$("#inject-time-time").val(time); $("#inject-time-time").val(time);
$("#inject-time-type-select option").filter(function() {return $(this).val() == "s";}).attr('selected',true); $("#inject-time-type-select option").filter(function() {return $(this).val() == "s";}).attr('selected',true);
//$("#inject-time-time-days option").filter(function() {return $(this).val() == days;}).attr('selected',true); if (days == "*") {
if (days == "*") { days = "1,2,3,4,5,6,0"; } $("#inject-time-time-days input[type=checkbox]").prop("checked",true);
var daya = days.split(","); } else {
for(var i = 0; i < daya.length; i++) { $("#inject-time-time-days input[type=checkbox]").removeAttr("checked");
$("#inject-time-time-days [value=" + daya[i] + "]").attr("checked", "checked"); days.split(",").forEach(function(v) {
$("#inject-time-time-days [value=" + v + "]").prop("checked", true);
});
} }
} else {
}
//else if (cronparts[0] == "0") {
// // interval - hours
// var hours = cronparts[1].slice(2);
// repeattype = "interval";
// $("#inject-time-interval-days").prop("disabled",false);
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
// $("#inject-time-interval-count").val(hours)
// $("#inject-time-interval-units option").filter(function() {return $(this).val() == "h";}).attr('selected',true);
//} else if (cronparts[1] == "*") {
// // interval - minutes
// var minutes = cronparts[0].slice(2);
// repeattype = "interval";
// $("#inject-time-interval-days").prop("disabled",false);
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
// $("#inject-time-interval-count").val(minutes)
// $("#inject-time-interval-units option").filter(function() {return $(this).val() == "m";}).attr('selected',true);
//}
else {
repeattype = "interval-time"; repeattype = "interval-time";
// interval - time period // interval - time period
var minutes = cronparts[0].slice(2); var minutes = cronparts[0].slice(2);
if (minutes === "") { minutes = "0"; } if (minutes === "") { minutes = "0"; }
$("#inject-time-interval-time-units").val(minutes); $("#inject-time-interval-time-units").val(minutes);
//$("#inject-time-interval-time-days option").filter(function() {return $(this).val() == days;}).attr('selected',true); if (days == "*") {
if (days == "*") { days = "1,2,3,4,5,6,0"; } $("#inject-time-interval-time-days input[type=checkbox]").prop("checked",true);
var daya = days.split(","); } else {
for(var i = 0; i < daya.length; i++) { $("#inject-time-interval-time-days input[type=checkbox]").removeAttr("checked");
$("#inject-time-interval-time-days [value=" + daya[i] + "]").attr("checked", "checked"); days.split(",").forEach(function(v) {
$("#inject-time-interval-time-days [value=" + v + "]").prop("checked", true);
});
} }
var time = cronparts[1]; var time = cronparts[1];
var timeparts = time.split(","); var timeparts = time.split(",");
var start; var start;
@ -389,6 +380,7 @@
$("#node-input-payloadType").val(this.payloadType); $("#node-input-payloadType").val(this.payloadType);
$("#node-input-payloadType").change(); $("#node-input-payloadType").change();
$("#inject-time-type-select").change(); $("#inject-time-type-select").change();
$("#inject-time-interval-time-start").change();
}, },
oneditsave: function() { oneditsave: function() {
@ -400,7 +392,6 @@
} else if (type == "interval") { } else if (type == "interval") {
var count = $("#inject-time-interval-count").val(); var count = $("#inject-time-interval-count").val();
var units = $("#inject-time-interval-units option:selected").val(); var units = $("#inject-time-interval-units option:selected").val();
//var days = $("#inject-time-interval-days option:selected").val();
if (units == "s") { if (units == "s") {
repeat = count; repeat = count;
} else { } else {
@ -413,64 +404,70 @@
} }
} }
} else if (type == "interval-time") { } else if (type == "interval-time") {
repeat = "";
var count = $("#inject-time-interval-time-units").val(); var count = $("#inject-time-interval-time-units").val();
var startTime = Number($("#inject-time-interval-time-start option:selected").val()); var startTime = Number($("#inject-time-interval-time-start option:selected").val());
var endTime = Number($("#inject-time-interval-time-end option:selected").val()); var endTime = Number($("#inject-time-interval-time-end option:selected").val());
//var days = $("#inject-time-interval-time-days option:selected").val(); var days = $('#inject-time-interval-time-days input[type=checkbox]:checked').map(function(_, el) {
var days = $('.cb1:checked').map(function(_, el) {
return $(el).val() return $(el).val()
}).get(); }).get();
if (days.length == 7) { days="*"; } if (days.length == 0) {
else { days = days.join(","); }
var timerange = "";
if (startTime == endTime) {
//TODO: invalid
repeat = "";
crontab = ""; crontab = "";
} else if (endTime == 0) {
timerange = startTime+"-23";
} else if (startTime+1 < endTime) {
timerange = startTime+"-"+(endTime-1);
} else if (startTime+1 == endTime) {
timerange = startTime;
} else { } else {
var startpart = ""; if (days.length == 7) {
var endpart = ""; days="*";
if (startTime == 23) {
startpart = "23";
} else { } else {
startpart = startTime+"-23"; days = days.join(",");
} }
if (endTime == 1) { var timerange = "";
endpart = "0"; if (endTime == 0) {
timerange = startTime+"-23";
} else if (startTime+1 < endTime) {
timerange = startTime+"-"+(endTime-1);
} else if (startTime+1 == endTime) {
timerange = startTime;
} else { } else {
endpart = "0-"+(endTime-1); var startpart = "";
var endpart = "";
if (startTime == 23) {
startpart = "23";
} else {
startpart = startTime+"-23";
}
if (endTime == 1) {
endpart = "0";
} else {
endpart = "0-"+(endTime-1);
}
timerange = startpart+","+endpart;
}
if (count === "0") {
crontab = count+" "+timerange+" * * "+days;
} else {
crontab = "*/"+count+" "+timerange+" * * "+days;
} }
timerange = startpart+","+endpart;
}
repeat = "";
if (count === "0") {
crontab = count+" "+timerange+" * * "+days;
}
else {
crontab = "*/"+count+" "+timerange+" * * "+days;
} }
} else if (type == "time") { } else if (type == "time") {
var time = $("#inject-time-time").val(); var time = $("#inject-time-time").val();
//var days = $("#inject-time-time-days option:selected").val(); var days = $('#inject-time-time-days input[type=checkbox]:checked').map(function(_, el) {
var days = $('.cb2:checked').map(function(_, el) {
return $(el).val() return $(el).val()
}).get(); }).get();
if (days.length == 7) { days="*"; } if (days.length == 0) {
else { days = days.join(","); } crontab = "";
var parts = time.split(":"); } else {
repeat = ""; if (days.length == 7) {
crontab = parts[1]+" "+parts[0]+" * * "+days; days="*";
} else {
days = days.join(",");
}
var parts = time.split(":");
repeat = "";
crontab = parts[1]+" "+parts[0]+" * * "+days;
}
} }
$("#node-input-repeat").val(repeat); $("#node-input-repeat").val(repeat);
$("#node-input-crontab").val(crontab); $("#node-input-crontab").val(crontab);
}, },
button: { button: {
onclick: function() { onclick: function() {

View File

@ -765,16 +765,6 @@ g.link_unknown path.link_line {
.form-row input { .form-row input {
width:70%; width:70%;
} }
.form-row label .cb1 {
display: inline !important;
width: auto !important;
vertical-align: top !important;
}
.form-row label .cb2 {
display: inline !important;
width: auto !important;
vertical-align: top !important;
}
input.input-append-left { input.input-append-left {
border-top-right-radius: 0px; border-top-right-radius: 0px;