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

Merge pull request #1557 from node-red/inject-node-spinner-and-hours-fixes

remove inject node at specific time spinner
This commit is contained in:
Nick O'Leary 2018-01-25 13:51:27 +00:00 committed by GitHub
commit 2cea3b6435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 48 deletions

View File

@ -28,9 +28,9 @@
<div class="form-row" id="node-once">
<label for="node-input-once">&nbsp;</label>
<input type="checkbox" id="node-input-once" style="display:inline-block;width:15px;vertical-align:baseline;">
<input type="checkbox" id="node-input-once" style="display:inline-block; width:15px; vertical-align:baseline;">
<span data-i18n="inject.onstart"></span>&nbsp;
<input type="text" id="node-input-onceDelay" placeholder="0.1" style="width:45px">&nbsp;
<input type="text" id="node-input-onceDelay" placeholder="0.1" style="width:45px; height:28px;">&nbsp;
<span data-i18n="inject.onceDelay"></span>
</div>
@ -49,7 +49,7 @@
<div class="form-row inject-time-row hidden" id="inject-time-row-interval">
<span data-i18n="inject.every"></span>
<input id="inject-time-interval-count" class="inject-time-count" value="1"></input>
<select style="width: 100px" id="inject-time-interval-units">
<select style="width:100px" id="inject-time-interval-units">
<option value="s" data-i18n="inject.seconds"></option>
<option value="m" data-i18n="inject.minutes"></option>
<option value="h" data-i18n="inject.hours"></option>
@ -57,7 +57,7 @@
</div>
<div class="form-row inject-time-row hidden" id="inject-time-row-interval-time">
<span data-i18n="inject.every"></span> <select style="width:90px" id="inject-time-interval-time-units" class="inject-time-int-count" value="1">
<span data-i18n="inject.every"></span> <select style="width:90px; margin-left:20px;" 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>
@ -73,8 +73,8 @@
</select> <span data-i18n="inject.minutes"></span><br/>
<span data-i18n="inject.between"></span> <select id="inject-time-interval-time-start" class="inject-time-times"></select>
<span data-i18n="inject.and"></span> <select id="inject-time-interval-time-end" class="inject-time-times"></select><br/>
<div id="inject-time-interval-time-days" class="inject-time-days">
<div style="display: inline-block; vertical-align: top;margin-right:5px;" data-i18n="inject.on">on</div>
<div id="inject-time-interval-time-days" class="inject-time-days" style="margin-top:5px">
<div style="display:inline-block; vertical-align:top; margin-right:5px;" data-i18n="inject.on">on</div>
<div style="display:inline-block;">
<div>
<label><input type='checkbox' checked value='1'/> <span data-i18n="inject.days.0"></span></label>
@ -94,9 +94,9 @@
</div>
<div class="form-row inject-time-row hidden" id="inject-time-row-time">
<span data-i18n="inject.at"></span> <input id="inject-time-time" value="12:00"></input><br/>
<span data-i18n="inject.at"></span> <input type="text" id="inject-time-time" value="12:00"></input><br/>
<div id="inject-time-time-days" class="inject-time-days">
<div style="display: inline-block; vertical-align: top;margin-right: 5px;" data-i18n="inject.on"></div>
<div style="display:inline-block; vertical-align:top; margin-right:5px;" data-i18n="inject.on"></div>
<div style="display:inline-block;">
<div>
<label><input type='checkbox' checked value='1'/> <span data-i18n="inject.days.0"></span></label>
@ -134,17 +134,20 @@
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
vertical-align: top;
vertical-align: baseline;
width: 100px;
}
.inject-time-days input {
width: auto;
vertical-align: baseline;
}
.inject-time-times {
width: 90px;
}
#inject-time-time {
width: 75px;
margin-left: 8px;
margin-bottom: 8px;
}
.inject-time-count {
width: 40px !important;
@ -167,6 +170,8 @@ The default payload is a timestamp of the current time in millisecs since Januar
<p>By default, the node is triggered manually by clicking on its button within the editor. It can also be set to
inject at regular intervals or according to a schedule.</p>
<p>It can also be configured to inject once each time the flows are started.</p>
<p>The maximum <i>Interval</i> that can be specified is about 596 hours / 24 days. However if you are looking at intervals
greater than one day you should consider using a scheduler node that can cope with power outages and restarts.</p>
<p><b>Note</b>: The <i>"Interval between times"</i> and <i>"at a specific time"</i> options use the standard cron system.
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 <i>"interval"</i> option.</p>
@ -182,7 +187,7 @@ If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
topic: {value:""},
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
payloadType: {value:"date"},
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0))) }},
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
crontab: {value:""},
once: {value:false},
onceDelay: {value:0.1}
@ -275,6 +280,10 @@ If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
}
});
$("#node-input-once").change(function() {
$("#node-input-onceDelay").attr('disabled', !$("#node-input-once").prop('checked'));
})
$(".inject-time-times").each(function() {
for (var i=0; i<24; i++) {
var l = (i<10?"0":"")+i+":00";
@ -303,35 +312,6 @@ If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
min:1
});
$.widget( "ui.injecttimespinner", $.ui.spinner, {
options: {
// seconds
step: 60 * 1000,
// hours
page: 60
},
_parse: function( value ) {
if ( typeof value === "string" ) {
// already a timestamp
if ( Number( value ) == value ) {
return Number( value );
}
var p = value.split(":");
var offset = new Date().getTimezoneOffset();
return ((Number(p[0])*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;
}
});
$("#inject-time-time").injecttimespinner();
var repeattype = "none";
if (this.repeat != "" && this.repeat != 0) {
repeattype = "interval";
@ -501,9 +481,14 @@ If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
days = days.join(",");
}
var parts = time.split(":");
if (parts.length === 2) {
repeat = "";
parts[1] = ("00" + (parseInt(parts[1]) % 60)).substr(-2);
parts[0] = ("00" + (parseInt(parts[0]) % 24)).substr(-2);
crontab = parts[1]+" "+parts[0]+" * * "+days;
}
else { crontab = ""; }
}
}
$("#node-input-repeat").val(repeat);

View File

@ -27,9 +27,14 @@ module.exports = function(RED) {
this.crontab = n.crontab;
this.once = n.once;
this.onceDelay = (n.onceDelay || 0.1) * 1000;
var node = this;
this.interval_id = null;
this.cronjob = null;
var node = this;
if (node.repeat > 2147483) {
node.error(RED._("inject.errors.toolong", this));
delete node.repeat;
}
node.repeaterSetup = function () {
if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) {

View File

@ -62,10 +62,11 @@
"on": "on",
"onstart": "Inject once after",
"onceDelay": "seconds, then",
"tip": "<b>Note:</b> \"interval between times\" and \"at a specific time\" will use cron.<br/>See info box for details.",
"tip": "<b>Note:</b> \"interval between times\" and \"at a specific time\" will use cron.<br/>\"interval\" should be less than 596 hours.<br/>See info box for details.",
"success": "Successfully injected: __label__",
"errors": {
"failed": "inject failed, see log for details"
"failed": "inject failed, see log for details",
"toolong": "Interval too large"
}
},
"catch": {