mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Use jquery ajax rather than d3
This commit is contained in:
parent
42cd6f94a7
commit
66005a2688
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<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:73%">
|
<select id="node-input-payloadType" style="width:73%">
|
||||||
<option value="date">timestamp</option>
|
<option value="date">timestamp</option>
|
||||||
<option value="string">string</option>
|
<option value="string">string</option>
|
||||||
@ -30,12 +30,12 @@
|
|||||||
</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" style="width: 70%x">
|
<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: 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>
|
<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">
|
||||||
@ -60,7 +60,7 @@
|
|||||||
<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/>
|
||||||
@ -102,7 +102,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<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>
|
||||||
|
|
||||||
@ -139,8 +139,8 @@
|
|||||||
<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">
|
||||||
@ -160,18 +160,18 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
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":"";
|
||||||
@ -262,7 +262,7 @@
|
|||||||
var d = new Date(value);
|
var d = new Date(value);
|
||||||
var h = d.getHours();
|
var h = d.getHours();
|
||||||
var m = d.getMinutes();
|
var m = d.getMinutes();
|
||||||
return ((h < 10)?"0":"")+h+":"+((m < 10)?"0":"")+m;
|
return ((h < 10)?"0":"")+h+":"+((m < 10)?"0":"")+m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -274,7 +274,7 @@
|
|||||||
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);
|
||||||
@ -295,29 +295,29 @@
|
|||||||
$("#inject-time-time-days [value=" + daya[i] + "]").attr("checked", "checked");
|
$("#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);
|
||||||
// repeattype = "interval";
|
// repeattype = "interval";
|
||||||
// $("#inject-time-interval-days").prop("disabled",false);
|
// $("#inject-time-interval-days").prop("disabled",false);
|
||||||
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
|
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
|
||||||
// $("#inject-time-interval-count").val(hours)
|
// $("#inject-time-interval-count").val(hours)
|
||||||
// $("#inject-time-interval-units option").filter(function() {return $(this).val() == "h";}).attr('selected',true);
|
// $("#inject-time-interval-units option").filter(function() {return $(this).val() == "h";}).attr('selected',true);
|
||||||
//} else if (cronparts[1] == "*") {
|
//} else if (cronparts[1] == "*") {
|
||||||
// // interval - minutes
|
// // interval - minutes
|
||||||
// var minutes = cronparts[0].slice(2);
|
// var minutes = cronparts[0].slice(2);
|
||||||
// repeattype = "interval";
|
// repeattype = "interval";
|
||||||
// $("#inject-time-interval-days").prop("disabled",false);
|
// $("#inject-time-interval-days").prop("disabled",false);
|
||||||
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
|
// $("#inject-time-interval-days option").filter(function() {return $(this).val() == days;}).attr('selected',true);
|
||||||
// $("#inject-time-interval-count").val(minutes)
|
// $("#inject-time-interval-count").val(minutes)
|
||||||
// $("#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);
|
||||||
if (days == "*") { days = "1,2,3,4,5,6,0"; }
|
if (days == "*") { days = "1,2,3,4,5,6,0"; }
|
||||||
@ -334,14 +334,14 @@
|
|||||||
// 0 or 0-10
|
// 0 or 0-10
|
||||||
var hours = timeparts[0].split("-");
|
var hours = timeparts[0].split("-");
|
||||||
if (hours.length == 1) {
|
if (hours.length == 1) {
|
||||||
if (hours[0] === "") {
|
if (hours[0] === "") {
|
||||||
start = "0";
|
start = "0";
|
||||||
end = "0";
|
end = "0";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
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;
|
||||||
@ -380,7 +380,7 @@
|
|||||||
|
|
||||||
$("#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();
|
||||||
@ -409,7 +409,7 @@
|
|||||||
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") {
|
||||||
@ -449,12 +449,12 @@
|
|||||||
timerange = startpart+","+endpart;
|
timerange = startpart+","+endpart;
|
||||||
}
|
}
|
||||||
repeat = "";
|
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();
|
||||||
@ -475,24 +475,26 @@
|
|||||||
button: {
|
button: {
|
||||||
onclick: function() {
|
onclick: function() {
|
||||||
var label = (this.name||this.payload).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
var label = (this.name||this.payload).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||||
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) {
|
|
||||||
if (err) {
|
$.ajax({
|
||||||
if (err.status == 404) {
|
url: "inject/"+this.id,
|
||||||
RED.notify("<strong>Error</strong>: inject node not deployed","error");
|
type:"POST",
|
||||||
} else if (err.status == 500) {
|
success: function(resp) {
|
||||||
RED.notify("<strong>Error</strong>: inject failed, see log for details.","error");
|
RED.notify("Successfully injected: "+label,"success");
|
||||||
} else if (err.status == 0) {
|
},
|
||||||
RED.notify("<strong>Error</strong>: no response from server","error");
|
error: function(jqXHR,textStatus,errorThrown) {
|
||||||
} else {
|
if (jqXHR.status == 404) {
|
||||||
RED.notify("<strong>Error</strong>: unexpected error: ("+err.status+")"+err.response,"error");
|
RED.notify("<strong>Error</strong>: inject node not deployed","error");
|
||||||
}
|
} else if (jqXHR.status == 500) {
|
||||||
} else if (resp.status == 200) {
|
RED.notify("<strong>Error</strong>: inject failed, see log for details.","error");
|
||||||
RED.notify("Successfully injected: "+label,"success");
|
} else if (jqXHR.status == 0) {
|
||||||
|
RED.notify("<strong>Error</strong>: no response from server","error");
|
||||||
} else {
|
} else {
|
||||||
RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error");
|
RED.notify("<strong>Error</strong>: unexpected error: ("+jqXHR.status+")"+textStatus,"error");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user