Change inject node to use tick boxes for days of week instead of select.

This commit is contained in:
dceejay 2015-02-03 11:21:29 +00:00
parent 5e5a220f68
commit 84e6417877
3 changed files with 465 additions and 400 deletions

View File

@ -1,142 +1,165 @@
<!-- <!--
Copyright 2013 IBM Corp. Copyright 2013,2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<script type="text/x-red" data-template-name="inject"> <script type="text/x-red" data-template-name="inject">
<div class="form-row node-input-payload"> <div class="form-row node-input-payload">
<label for="node-input-payloadType"><i class="fa fa-envelope"></i> Payload</label> <label for="node-input-payloadType"><i class="fa fa-envelope"></i> Payload</label>
<select id="node-input-payloadType" style="width:125px !important"> <select id="node-input-payloadType" style="width:73%">
<option value="date">timestamp</option> <option value="date">timestamp</option>
<option value="none">blank</option> <option value="string">string</option>
<option value="string">string</option> <option value="none">blank</option>
</select> </select>
</div> </div>
<div class="form-row" id="node-input-row-payload"> <div class="form-row" id="node-input-row-payload">
<label for="node-input-payload"></label> <label for="node-input-payload"></label>
<input type="text" id="node-input-payload" placeholder="payload"> <input type="text" id="node-input-payload" placeholder="payload" style="width:70%">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="topic"> <input type="text" id="node-input-topic" placeholder="topic" style="width: 70%x">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for=""><i class="fa fa-repeat"></i> Repeat</label> <label for=""><i class="fa fa-repeat"></i> Repeat</label>
<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> <select id="inject-time-type-select" style="width: 73%"><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-repeat" placeholder="payload">
<input type="hidden" id="node-input-crontab" placeholder="payload"> <input type="hidden" id="node-input-crontab" placeholder="payload">
</div> </div>
<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> --> <!-- 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">
at every <select style="width: 90px" id="inject-time-interval-time-units" class="inject-time-int-count" value="1"> 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="1">1</option>
<option value="2">2</option> <option value="2">2</option>
<option value="3">3</option> <option value="3">3</option>
<option value="4">4</option> <option value="4">4</option>
<option value="5">5</option> <option value="5">5</option>
<option value="6">6</option> <option value="6">6</option>
<option value="10">10</option> <option value="10">10</option>
<option value="12">12</option> <option value="12">12</option>
<option value="15">15</option> <option value="15">15</option>
<option value="20">20</option> <option value="20">20</option>
<option value="30">30</option> <option value="30">30</option>
<option value="0">60</option> <option value="0">60</option>
</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> <!-- on <select id="inject-time-interval-time-days" class="inject-time-days"></select> -->
</div> <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 class="form-row inject-time-row hidden" id="inject-time-row-time"> <label><input type='checkbox' class="cb1" value='1'/> Monday</label>
at <input id="inject-time-time" value="12:00"></input><br/> <label><input type='checkbox' class="cb1" value='2'/> Tuesday</label>
on <select id="inject-time-time-days" class="inject-time-days"></select> <label><input type='checkbox' class="cb1" value='3'/> Wednesday</label>
</div> <label><input type='checkbox' class="cb1" value='4'/> Thursday</label>
<label><input type='checkbox' class="cb1" value='5'/> Friday</label>
<div class="form-row" id="node-once"> <label><input type='checkbox' class="cb1" value='6'/> Saturday</label>
<label>&nbsp;</label> <label><input type='checkbox' class="cb1" value='0'/> Sunday</label>
<input type="checkbox" id="node-input-once" style="display: inline-block; width: auto; vertical-align: top;"> <!-- <div><input type='checkbox' id="cb1selectall" value='*'/> Everyday</div> -->
<label for="node-input-once" style="width: 70%;">Fire once at start ?</label> </td></tr></table>
</div> </div>
</div>
<div class="form-row">
<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>
</div>
<div class="form-row" id="node-once">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-once" style="width: 70%;">Fire once at start ?</label>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="name"> <input type="text" id="node-input-name" placeholder="name">
</div> </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> <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> </script>
<style> <style>
.inject-time-row { .inject-time-row {
padding-left: 110px; padding-left: 110px;
} }
.inject-time-row select { .inject-time-row select {
margin: 3px 0; margin: 3px 0;
} }
.inject-time-days { //.inject-time-days {
width: 262px; // width: 262px;
} //}
.inject-time-times { .inject-time-times {
width: 90px; width: 90px;
} }
.inject-time-row > .ui-spinner { .inject-time-row > .ui-spinner {
height: 28px; height: 28px;
margin: 3px 0; margin: 3px 0;
border-color: rgb(204, 204, 204); border-color: rgb(204, 204, 204);
} }
#inject-time-time { #inject-time-time {
margin-top: 3px; margin-top: 3px;
width: 75px; width: 75px;
} }
.inject-time-count { .inject-time-count {
width: 40px !important; width: 40px !important;
} }
</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 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>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 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>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. <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> If you want every 20 minutes from now - use the basic "interval" option.</p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
RED.nodes.registerType('inject',{ RED.nodes.registerType('inject',{
category: 'input', category: 'input',
color:"#a6bbcf", color:"#a6bbcf",
defaults: { defaults: {
name: {value:""}, name: {value:""},
topic: {value:""}, topic: {value:""},
payload: {value:""}, payload: {value:""},
payloadType: {value:"date"}, payloadType: {value:"date"},
repeat: {value:""}, repeat: {value:""},
crontab: {value:""}, crontab: {value:""},
once: {value:false} once: {value:false}
}, },
inputs:0, inputs:0,
outputs:1, outputs:1,
icon: "inject.png", icon: "inject.png",
label: function() { label: function() {
if (this.payloadType === "string") { if (this.payloadType === "string") {
if ((this.topic !== "") && ((this.topic.length + this.payload.length) <= 32)) { if ((this.topic !== "") && ((this.topic.length + this.payload.length) <= 32)) {
return this.name||this.topic + ":" + this.payload; return this.name||this.topic + ":" + this.payload;
@ -144,118 +167,135 @@
else if (this.payload.length < 24) { else if (this.payload.length < 24) {
return this.name||this.payload; return this.name||this.payload;
} }
} }
if ((this.topic.length < 24) && (this.topic.length > 0)) { if ((this.topic.length < 24) && (this.topic.length > 0)) {
return this.name||this.topic; return this.name||this.topic;
} }
else { return this.name||(this.payloadType==="date"?"timestamp":null)||"inject"; } else { return this.name||(this.payloadType==="date"?"timestamp":null)||"inject"; }
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";
}, },
oneditprepare: function() { oneditprepare: function() {
$("#inject-time-type-select").change(function() { $("#inject-time-type-select").change(function() {
$("#node-input-crontab").val(''); $("#node-input-crontab").val('');
var id = $("#inject-time-type-select option:selected").val(); var id = $("#inject-time-type-select option:selected").val();
$(".inject-time-row").hide(); $(".inject-time-row").hide();
$("#inject-time-row-"+id).show(); $("#inject-time-row-"+id).show();
if ((id == "none") || (id == "interval")) { if ((id == "none") || (id == "interval")) {
$("#node-once").show(); $("#node-once").show();
} }
else { else {
$("#node-once").hide(); $("#node-once").hide();
$("#node-input-once").prop('checked', false); $("#node-input-once").prop('checked', false);
} }
}); });
var days = [ //$("#cb1selectall").click(function () {
{v:"*",t:"every day"}, // $('.cb1').attr('checked', this.checked);
{v:"1-5",t:"Mondays to Fridays"}, //});
{v:"0,6",t:"Saturdays and Sundays"}, //$(".cb1").click(function(){
{v:"1",t:"Mondays"}, // if($(".cb1:checked").length == 7) {
{v:"2",t:"Tuesdays"}, // $("#cb1selectall").attr("checked", "checked");
{v:"3",t:"Wednesdays"}, // } else {
{v:"4",t:"Thursdays"}, // $("#cb1selectall").removeAttr("checked");
{v:"5",t:"Fridays"}, // }
{v:"6",t:"Saturdays"}, //});
{v:"0",t:"Sundays"}
]; //var days = [
// {v:"*",t:"every day"},
$(".inject-time-days").each(function() { // {v:"1-5",t:"Mondays to Fridays"},
for (var d in days) { // {v:"0,6",t:"Saturdays and Sundays"},
$(this).append($("<option></option>").val(days[d].v).text(days[d].t)); // {v:"1",t:"Mondays"},
} // {v:"2",t:"Tuesdays"},
}); // {v:"3",t:"Wednesdays"},
// {v:"4",t:"Thursdays"},
$(".inject-time-times").each(function() { // {v:"5",t:"Fridays"},
for (var i=0;i<24;i++) { // {v:"6",t:"Saturdays"},
var l = (i<10?"0":"")+i+":00"; // {v:"0",t:"Sundays"}
$(this).append($("<option></option>").val(i).text(l)); //];
}
}); //$(".inject-time-days").each(function() {
// for (var d in days) {
$(".inject-time-count").spinner({ // $(this).append($("<option></option>").val(days[d].v).text(days[d].t));
//max:60, // }
min:1 //});
});
$(".inject-time-times").each(function() {
$("#inject-time-interval-units").change(function() { for (var i=0;i<24;i++) {
var units = $("#inject-time-interval-units option:selected").val(); var l = (i<10?"0":"")+i+":00";
//$("#inject-time-interval-days").prop("disabled",(units == "s")?"disabled":false); $(this).append($("<option></option>").val(i).text(l));
//$(".inject-time-count").spinner("option","max",(units == "h")?24:60); }
}); });
$.widget( "ui.injecttimespinner", $.ui.spinner, { $(".inject-time-count").spinner({
options: { //max:60,
// seconds min:1
step: 60 * 1000, });
// hours
page: 60 $("#inject-time-interval-units").change(function() {
}, var units = $("#inject-time-interval-units option:selected").val();
_parse: function( value ) { //$("#inject-time-interval-days").prop("disabled",(units == "s")?"disabled":false);
if ( typeof value === "string" ) { //$(".inject-time-count").spinner("option","max",(units == "h")?24:60);
// already a timestamp });
if ( Number( value ) == value ) {
return Number( value ); $.widget( "ui.injecttimespinner", $.ui.spinner, {
} options: {
var p = value.split(":"); // seconds
var offset = new Date().getTimezoneOffset(); step: 60 * 1000,
return (((Number(p[0])+1)*60)+Number(p[1])+offset)*60*1000; // hours
} page: 60
return value; },
}, _parse: function( value ) {
_format: function( value ) { if ( typeof value === "string" ) {
var d = new Date(value); // already a timestamp
var h = d.getHours(); if ( Number( value ) == value ) {
var m = d.getMinutes(); return Number( value );
}
var p = value.split(":");
var offset = new Date().getTimezoneOffset();
return (((Number(p[0])+1)*60)+Number(p[1])+offset)*60*1000;
}
return value;
},
_format: function( value ) {
var d = new Date(value);
var h = d.getHours();
var m = d.getMinutes();
return ((h < 10)?"0":"")+h+":"+((m < 10)?"0":"")+m; return ((h < 10)?"0":"")+h+":"+((m < 10)?"0":"")+m;
} }
}); });
$("#inject-time-time").injecttimespinner(); $("#inject-time-time").injecttimespinner();
var repeattype = "none"; var repeattype = "none";
if (this.repeat != "" && this.repeat != 0) { if (this.repeat != "" && this.repeat != 0) {
repeattype = "interval"; repeattype = "interval";
var r = "s"; var r = "s";
var c = this.repeat; var c = this.repeat;
if (this.repeat % 60 === 0) { r = "m"; c = c/60; } if (this.repeat % 60 === 0) { r = "m"; c = c/60; }
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-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(" ");
var days = cronparts[4]; var days = cronparts[4];
if (!isNaN(cronparts[0]) && !isNaN(cronparts[1])) { if (!isNaN(cronparts[0]) && !isNaN(cronparts[1])) {
repeattype = "time"; repeattype = "time";
// Fixed time // Fixed time
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); //$("#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");
}
}
//else if (cronparts[0] == "0") { //else if (cronparts[0] == "0") {
// // interval - hours // // interval - hours
// var hours = cronparts[1].slice(2); // var hours = cronparts[1].slice(2);
@ -274,20 +314,26 @@
// $("#inject-time-interval-units option").filter(function() {return $(this).val() == "m";}).attr('selected',true); // $("#inject-time-interval-units option").filter(function() {return $(this).val() == "m";}).attr('selected',true);
//} //}
else { 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); //$("#inject-time-interval-time-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
var time = cronparts[1]; if (days == "*") { days = "1,2,3,4,5,6,0"; }
var timeparts = time.split(","); var daya = days.split(",");
var start; for(var i = 0; i < daya.length; i++) {
var end; $("#inject-time-interval-time-days [value=" + daya[i] + "]").attr("checked", "checked");
if (timeparts.length == 1) { }
// 0 or 0-10
var hours = timeparts[0].split("-"); var time = cronparts[1];
if (hours.length == 1) { var timeparts = time.split(",");
var start;
var end;
if (timeparts.length == 1) {
// 0 or 0-10
var hours = timeparts[0].split("-");
if (hours.length == 1) {
if (hours[0] === "") { if (hours[0] === "") {
start = "0"; start = "0";
end = "0"; end = "0";
@ -296,150 +342,160 @@
start = hours[0]; start = hours[0];
end = Number(hours[0])+1; end = Number(hours[0])+1;
} }
} else { } else {
start = hours[0]; start = hours[0];
end = (Number(hours[1])+1)%24; end = (Number(hours[1])+1)%24;
} }
} else { } else {
// 23,0 or 17-23,0-10 or 23,0-2 or 17-23,0 // 23,0 or 17-23,0-10 or 23,0-2 or 17-23,0
var startparts = timeparts[0].split("-"); var startparts = timeparts[0].split("-");
start = startparts[0]; start = startparts[0];
var endparts = timeparts[1].split("-"); var endparts = timeparts[1].split("-");
if (endparts.length == 1) { if (endparts.length == 1) {
end = Number(endparts[0])+1; end = Number(endparts[0])+1;
} else { } else {
end = Number(endparts[1])+1; end = Number(endparts[1])+1;
} }
} }
$("#inject-time-interval-time-start option").filter(function() {return $(this).val() == start;}).attr('selected',true); $("#inject-time-interval-time-start option").filter(function() {return $(this).val() == start;}).attr('selected',true);
$("#inject-time-interval-time-end option").filter(function() {return $(this).val() == end;}).attr('selected',true); $("#inject-time-interval-time-end option").filter(function() {return $(this).val() == end;}).attr('selected',true);
} }
} else { } else {
$("#inject-time-type-select option").filter(function() {return $(this).val() == "none";}).attr('selected',true); $("#inject-time-type-select option").filter(function() {return $(this).val() == "none";}).attr('selected',true);
} }
$(".inject-time-row").hide(); $(".inject-time-row").hide();
$("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true); $("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true);
$("#inject-time-row-"+repeattype).show(); $("#inject-time-row-"+repeattype).show();
if (this.payloadType == null) { if (this.payloadType == null) {
if (this.payload == "") { if (this.payload == "") {
this.payloadType = "date"; this.payloadType = "date";
} else { } else {
this.payloadType = "string"; this.payloadType = "string";
} }
} }
$("#node-input-payloadType").change(function() { $("#node-input-payloadType").change(function() {
var id = $("#node-input-payloadType option:selected").val(); var id = $("#node-input-payloadType option:selected").val();
if (id === "string") { if (id === "string") {
$("#node-input-row-payload").show(); $("#node-input-row-payload").show();
} else { } else {
$("#node-input-row-payload").hide(); $("#node-input-row-payload").hide();
} }
}); });
$("#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();
}, },
oneditsave: function() { oneditsave: function() {
var repeat = ""; var repeat = "";
var crontab = ""; var crontab = "";
var type = $("#inject-time-type-select option:selected").val(); var type = $("#inject-time-type-select option:selected").val();
if (type == "none") { if (type == "none") {
// nothing // nothing
} 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(); //var days = $("#inject-time-interval-days option:selected").val();
if (units == "s") { if (units == "s") {
repeat = count; repeat = count;
} else { } else {
if (units == "m") { if (units == "m") {
//crontab = "*/"+count+" * * * "+days; //crontab = "*/"+count+" * * * "+days;
repeat = count * 60; repeat = count * 60;
} else if (units == "h") { } else if (units == "h") {
//crontab = "0 */"+count+" * * "+days; //crontab = "0 */"+count+" * * "+days;
repeat = count * 60 * 60; repeat = count * 60 * 60;
} }
} }
} else if (type == "interval-time") { } else if (type == "interval-time") {
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 option:selected").val();
var timerange = "*"; var days = $('.cb1:checked').map(function(_, el) {
if (startTime == endTime) { return $(el).val()
//TODO: invalid }).get();
repeat = ""; if (days.length == 7) { days="*"; }
crontab = ""; else { days = days.join(","); }
} else if (endTime == 0) { var timerange = "";
timerange = startTime+"-23"; if (startTime == endTime) {
} else if (startTime+1 < endTime) { //TODO: invalid
timerange = startTime+"-"+(endTime-1); repeat = "";
} else if (startTime+1 == endTime) { crontab = "";
timerange = startTime; } else if (endTime == 0) {
} else { timerange = startTime+"-23";
var startpart = ""; } else if (startTime+1 < endTime) {
var endpart = ""; timerange = startTime+"-"+(endTime-1);
if (startTime == 23) { } else if (startTime+1 == endTime) {
startpart = "23"; timerange = startTime;
} else { } else {
startpart = startTime+"-23"; var startpart = "";
} var endpart = "";
if (endTime == 1) { if (startTime == 23) {
endpart = "0"; startpart = "23";
} else { } else {
endpart = "0-"+(endTime-1); startpart = startTime+"-23";
} }
timerange = startpart+","+endpart; if (endTime == 1) {
} endpart = "0";
repeat = ""; } else {
endpart = "0-"+(endTime-1);
}
timerange = startpart+","+endpart;
}
repeat = "";
if (count === "0") { if (count === "0") {
crontab = count+" "+timerange+" * * "+days; crontab = count+" "+timerange+" * * "+days;
} }
else { else {
crontab = "*/"+count+" "+timerange+" * * "+days; 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 option:selected").val();
var parts = time.split(":"); var days = $('.cb2:checked').map(function(_, el) {
repeat = ""; return $(el).val()
crontab = parts[1]+" "+parts[0]+" * * "+days; }).get();
} if (days.length == 7) { days="*"; }
else { days = days.join(","); }
$("#node-input-repeat").val(repeat); var parts = time.split(":");
$("#node-input-crontab").val(crontab); repeat = "";
crontab = parts[1]+" "+parts[0]+" * * "+days;
}, }
button: {
onclick: function() { $("#node-input-repeat").val(repeat);
var label = (this.name||this.payload).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); $("#node-input-crontab").val(crontab);
},
button: {
onclick: function() {
var label = (this.name||this.payload).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
if (this.payloadType === "date") { label = "timestamp"; } if (this.payloadType === "date") { label = "timestamp"; }
if (this.payloadType === "none") { label = "blank"; } if (this.payloadType === "none") { label = "blank"; }
d3.xhr("inject/"+this.id).post(function(err,resp) { d3.xhr("inject/"+this.id).post(function(err,resp) {
if (err) { if (err) {
if (err.status == 404) { if (err.status == 404) {
RED.notify("<strong>Error</strong>: inject node not deployed","error"); RED.notify("<strong>Error</strong>: inject node not deployed","error");
} else if (err.status == 500) { } else if (err.status == 500) {
RED.notify("<strong>Error</strong>: inject failed, see log for details.","error"); RED.notify("<strong>Error</strong>: inject failed, see log for details.","error");
} else if (err.status == 0) { } else if (err.status == 0) {
RED.notify("<strong>Error</strong>: no response from server","error"); RED.notify("<strong>Error</strong>: no response from server","error");
} else { } else {
RED.notify("<strong>Error</strong>: unexpected error: ("+err.status+")"+err.response,"error"); RED.notify("<strong>Error</strong>: unexpected error: ("+err.status+")"+err.response,"error");
} }
} else if (resp.status == 200) { } else if (resp.status == 200) {
RED.notify("Successfully injected: "+label,"success"); RED.notify("Successfully injected: "+label,"success");
} else { } else {
RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error"); RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error");
} }
}); });
} }
} }
}); });
</script> </script>

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var cron = require("cron"); var cron = require("cron");
function InjectNode(n) { function InjectNode(n) {
@ -54,7 +55,7 @@ module.exports = function(RED) {
this.on("input",function(msg) { this.on("input",function(msg) {
var msg = {topic:this.topic}; var msg = {topic:this.topic};
if ( (this.payloadType == null && this.payload == "") || this.payloadType == "date") { if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
msg.payload = Date.now(); msg.payload = Date.now();
} else if (this.payloadType == null || this.payloadType === "string") { } else if (this.payloadType == null || this.payloadType === "string") {
msg.payload = this.payload; msg.payload = this.payload;

View File

@ -42,7 +42,7 @@ body {
display: none; display: none;
} }
#dropTarget div { #dropTarget div {
display: table-cell; display: table-cell;
vertical-align: middle; vertical-align: middle;
text-align: center; text-align: center;
font-size: 40px; font-size: 40px;
@ -292,7 +292,7 @@ li.open #btn-sidemenu {
padding: 5px; padding: 5px;
overflow-y: auto; overflow-y: auto;
box-sizing:border-box; box-sizing:border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
} }
.palette-spinner { .palette-spinner {
padding-top: 40px; padding-top: 40px;
@ -310,7 +310,7 @@ li.open #btn-sidemenu {
padding: 3px; padding: 3px;
border-top: 1px solid #999; border-top: 1px solid #999;
box-sizing:border-box; box-sizing:border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
} }
#palette-search i.fa-search { #palette-search i.fa-search {
position: absolute; position: absolute;
@ -339,9 +339,9 @@ li.open #btn-sidemenu {
margin: 0px; margin: 0px;
height: 30px; height: 30px;
box-sizing:border-box; box-sizing:border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
} }
#palette-search input:focus { #palette-search input:focus {
border: none; border: none;
box-shadow: none; box-shadow: none;
@ -412,7 +412,7 @@ li.open #btn-sidemenu {
top:8px; top:8px;
left: -5px; left: -5px;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
background:#d9d9d9; background:#d9d9d9;
border-radius: 3px; border-radius: 3px;
width: 10px; width: 10px;
@ -431,7 +431,7 @@ li.open #btn-sidemenu {
#sidebar { #sidebar {
background: #fff; background: #fff;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
} }
#sidebar.closing { #sidebar.closing {
background: #eee; background: #eee;
@ -760,6 +760,16 @@ 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;
@ -1019,7 +1029,7 @@ ul.red-ui-tabs li {
} }
ul.red-ui-tabs li a.red-ui-tab-label { ul.red-ui-tabs li a.red-ui-tab-label {
display: block; display: block;
padding: 3px 16px; padding: 3px 16px;
color: #666; color: #666;
} }
@ -1224,7 +1234,7 @@ i.spinner {
#header ul.dropdown-menu li.disabled a { #header ul.dropdown-menu li.disabled a {
color: #666; color: #666;
} }
/* Deploy menu customisations */ /* Deploy menu customisations */
#header ul#btn-deploy-options-submenu { #header ul#btn-deploy-options-submenu {
width: 300px !important; width: 300px !important;
@ -1241,5 +1251,3 @@ i.spinner {
#header ul#btn-deploy-options-submenu li a > i.fa { #header ul#btn-deploy-options-submenu li a > i.fa {
display: none !important; display: none !important;
} }