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">
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> -->
</div>
<div class="form-row inject-time-row hidden" id="inject-time-row-interval-time">
@ -64,34 +63,45 @@
</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> -->
<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">
<label><input type='checkbox' class="cb1" value='1'/> Monday</label>
<label><input type='checkbox' class="cb1" value='2'/> Tuesday</label>
<label><input type='checkbox' class="cb1" value='3'/> Wednesday</label>
<label><input type='checkbox' class="cb1" value='4'/> Thursday</label>
<label><input type='checkbox' class="cb1" value='5'/> Friday</label>
<label><input type='checkbox' class="cb1" value='6'/> Saturday</label>
<label><input type='checkbox' class="cb1" value='0'/> Sunday</label>
<!-- <div><input type='checkbox' id="cb1selectall" value='*'/> Everyday</div> -->
</td></tr></table>
<div style="display: inline-block; vertical-align: top;margin-right: 5px;">on </div>
<div style="display:inline-block;">
<div>
<label><input type='checkbox' checked value='1'/> Monday</label>
<label><input type='checkbox' checked value='2'/> Tuesday</label>
<label><input type='checkbox' checked value='3'/> Wednesday</label>
</div>
<div>
<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 class="form-row inject-time-row hidden" id="inject-time-row-time">
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">
<table style="width:100% !important"><tr><td valign="top">on&nbsp;</td><td valign="top">
<label><input type='checkbox' class="cb2" value='1'/> Monday</label>
<label><input type='checkbox' class="cb2" value='2'/> Tuesday</label>
<label><input type='checkbox' class="cb2" value='3'/> Wednesday</label>
<label><input type='checkbox' class="cb2" value='4'/> Thursday</label>
<label><input type='checkbox' class="cb2" value='5'/> Friday</label>
<label><input type='checkbox' class="cb2" value='6'/> Saturday</label>
<label><input type='checkbox' class="cb2" value='0'/> Sunday</label>
</td></tr></table>
<div style="display: inline-block; vertical-align: top;margin-right: 5px;">on </div>
<div style="display:inline-block;">
<div>
<label><input type='checkbox' checked value='1'/> Monday</label>
<label><input type='checkbox' checked value='2'/> Tuesday</label>
<label><input type='checkbox' checked value='3'/> Wednesday</label>
</div>
<div>
<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>
@ -115,9 +125,18 @@
.inject-time-row select {
margin: 3px 0;
}
//.inject-time-days {
// width: 262px;
//}
.inject-time-days label {
-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 {
width: 90px;
}
@ -135,12 +154,17 @@
}
</style>
<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>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 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 basic "interval" option.</p>
<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>The payload defaults to the current time in millisecs since 1970, but can
also be set to a String or left blank.</p>
<p>The repeat function allows the payload to be sent on the required schedule.</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 type="text/javascript">
@ -191,42 +215,28 @@
}
});
//$("#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() {
for (var i=0;i<24;i++) {
var l = (i<10?"0":"")+i+":00";
$(this).append($("<option></option>").val(i).text(l));
}
});
$("#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({
//max:60,
@ -235,8 +245,6 @@
$("#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);
});
$.widget( "ui.injecttimespinner", $.ui.spinner, {
@ -277,7 +285,6 @@
if (this.repeat % 1440 === 0) { r = "h"; c = c/60; }
$("#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(" ");
@ -288,44 +295,28 @@
var time = cronparts[1]+":"+cronparts[0];
$("#inject-time-time").val(time);
$("#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 == "*") { days = "1,2,3,4,5,6,0"; }
var daya = days.split(",");
for(var i = 0; i < daya.length; i++) {
$("#inject-time-time-days [value=" + daya[i] + "]").attr("checked", "checked");
if (days == "*") {
$("#inject-time-time-days input[type=checkbox]").prop("checked",true);
} else {
$("#inject-time-time-days input[type=checkbox]").removeAttr("checked");
days.split(",").forEach(function(v) {
$("#inject-time-time-days [value=" + v + "]").prop("checked", true);
});
}
}
//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 {
} else {
repeattype = "interval-time";
// interval - time period
var minutes = cronparts[0].slice(2);
if (minutes === "") { minutes = "0"; }
$("#inject-time-interval-time-units").val(minutes);
//$("#inject-time-interval-time-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
if (days == "*") { days = "1,2,3,4,5,6,0"; }
var daya = days.split(",");
for(var i = 0; i < daya.length; i++) {
$("#inject-time-interval-time-days [value=" + daya[i] + "]").attr("checked", "checked");
if (days == "*") {
$("#inject-time-interval-time-days input[type=checkbox]").prop("checked",true);
} else {
$("#inject-time-interval-time-days input[type=checkbox]").removeAttr("checked");
days.split(",").forEach(function(v) {
$("#inject-time-interval-time-days [value=" + v + "]").prop("checked", true);
});
}
var time = cronparts[1];
var timeparts = time.split(",");
var start;
@ -389,6 +380,7 @@
$("#node-input-payloadType").val(this.payloadType);
$("#node-input-payloadType").change();
$("#inject-time-type-select").change();
$("#inject-time-interval-time-start").change();
},
oneditsave: function() {
@ -400,7 +392,6 @@
} else if (type == "interval") {
var count = $("#inject-time-interval-count").val();
var units = $("#inject-time-interval-units option:selected").val();
//var days = $("#inject-time-interval-days option:selected").val();
if (units == "s") {
repeat = count;
} else {
@ -413,64 +404,70 @@
}
}
} else if (type == "interval-time") {
repeat = "";
var count = $("#inject-time-interval-time-units").val();
var startTime = Number($("#inject-time-interval-time-start 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 = $('.cb1:checked').map(function(_, el) {
var days = $('#inject-time-interval-time-days input[type=checkbox]:checked').map(function(_, el) {
return $(el).val()
}).get();
if (days.length == 7) { days="*"; }
else { days = days.join(","); }
var timerange = "";
if (startTime == endTime) {
//TODO: invalid
repeat = "";
if (days.length == 0) {
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 {
var startpart = "";
var endpart = "";
if (startTime == 23) {
startpart = "23";
if (days.length == 7) {
days="*";
} else {
startpart = startTime+"-23";
days = days.join(",");
}
if (endTime == 1) {
endpart = "0";
var timerange = "";
if (endTime == 0) {
timerange = startTime+"-23";
} else if (startTime+1 < endTime) {
timerange = startTime+"-"+(endTime-1);
} else if (startTime+1 == endTime) {
timerange = startTime;
} 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") {
var time = $("#inject-time-time").val();
//var days = $("#inject-time-time-days option:selected").val();
var days = $('.cb2:checked').map(function(_, el) {
var days = $('#inject-time-time-days input[type=checkbox]:checked').map(function(_, el) {
return $(el).val()
}).get();
if (days.length == 7) { days="*"; }
else { days = days.join(","); }
var parts = time.split(":");
repeat = "";
crontab = parts[1]+" "+parts[0]+" * * "+days;
if (days.length == 0) {
crontab = "";
} else {
if (days.length == 7) {
days="*";
} else {
days = days.join(",");
}
var parts = time.split(":");
repeat = "";
crontab = parts[1]+" "+parts[0]+" * * "+days;
}
}
$("#node-input-repeat").val(repeat);
$("#node-input-crontab").val(crontab);
},
button: {
onclick: function() {

View File

@ -765,16 +765,6 @@ g.link_unknown path.link_line {
.form-row input {
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 {
border-top-right-radius: 0px;