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

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,5 +1,5 @@
<!-- <!--
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.
@ -17,26 +17,26 @@
<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>
@ -64,12 +64,35 @@
</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 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>
</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> <!-- 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>
<div class="form-row" id="node-once"> <div class="form-row" id="node-once">
@ -92,9 +115,9 @@
.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;
} }
@ -168,24 +191,35 @@
} }
}); });
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"}
];
$(".inject-time-days").each(function() { //var days = [
for (var d in days) { // {v:"*",t:"every day"},
$(this).append($("<option></option>").val(days[d].v).text(days[d].t)); // {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++) {
@ -254,7 +288,13 @@
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
@ -279,7 +319,13 @@
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);
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");
}
var time = cronparts[1]; var time = cronparts[1];
var timeparts = time.split(","); var timeparts = time.split(",");
var start; var start;
@ -354,7 +400,7 @@
} 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 {
@ -370,8 +416,13 @@
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) {
return $(el).val()
}).get();
if (days.length == 7) { days="*"; }
else { days = days.join(","); }
var timerange = "";
if (startTime == endTime) { if (startTime == endTime) {
//TODO: invalid //TODO: invalid
repeat = ""; repeat = "";
@ -406,7 +457,12 @@
} }
} 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 days = $('.cb2:checked').map(function(_, el) {
return $(el).val()
}).get();
if (days.length == 7) { days="*"; }
else { days = days.join(","); }
var parts = time.split(":"); var parts = time.split(":");
repeat = ""; repeat = "";
crontab = parts[1]+" "+parts[0]+" * * "+days; crontab = parts[1]+" "+parts[0]+" * * "+days;

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

@ -340,8 +340,8 @@ li.open #btn-sidemenu {
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;
@ -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;
@ -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;
} }