2015-02-03 12:21:29 +01:00
|
|
|
|
<!--
|
2017-01-11 16:24:33 +01:00
|
|
|
|
Copyright JS Foundation and other contributors, http://js.foundation
|
2015-02-03 12:21:29 +01:00
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
-->
|
|
|
|
|
|
2020-01-15 03:40:48 +01:00
|
|
|
|
<script type="text/html" data-template-name="inject">
|
2020-04-08 18:29:55 +02:00
|
|
|
|
<div class="form-row">
|
|
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
|
|
|
|
</div>
|
2020-05-04 16:37:09 +02:00
|
|
|
|
|
2020-01-23 14:55:50 +01:00
|
|
|
|
<div class="form-row node-input-property-container-row">
|
|
|
|
|
<ol id="node-input-property-container"></ol>
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
2018-01-11 22:50:53 +01:00
|
|
|
|
<div class="form-row" id="node-once">
|
|
|
|
|
<label for="node-input-once"> </label>
|
2018-01-14 23:16:51 +01:00
|
|
|
|
<input type="checkbox" id="node-input-once" style="display:inline-block; width:15px; vertical-align:baseline;">
|
2018-01-11 22:50:53 +01:00
|
|
|
|
<span data-i18n="inject.onstart"></span>
|
2018-01-15 10:02:52 +01:00
|
|
|
|
<input type="text" id="node-input-onceDelay" placeholder="0.1" style="width:45px; height:28px;">
|
2018-01-11 22:50:53 +01:00
|
|
|
|
<span data-i18n="inject.onceDelay"></span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2015-02-03 12:21:29 +01:00
|
|
|
|
<div class="form-row">
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label for=""><i class="fa fa-repeat"></i> <span data-i18n="inject.label.repeat"></span></label>
|
2016-06-27 00:48:59 +02:00
|
|
|
|
<select id="inject-time-type-select">
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<option value="none" data-i18n="inject.none"></option>
|
|
|
|
|
<option value="interval" data-i18n="inject.interval"></option>
|
|
|
|
|
<option value="interval-time" data-i18n="inject.interval-time"></option>
|
|
|
|
|
<option value="time" data-i18n="inject.time"></option>
|
|
|
|
|
</select>
|
|
|
|
|
<input type="hidden" id="node-input-repeat">
|
|
|
|
|
<input type="hidden" id="node-input-crontab">
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-row inject-time-row hidden" id="inject-time-row-interval">
|
2015-06-16 12:18:22 +02:00
|
|
|
|
<span data-i18n="inject.every"></span>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<input id="inject-time-interval-count" class="inject-time-count" value="1"></input>
|
2018-01-14 23:16:51 +01:00
|
|
|
|
<select style="width:100px" id="inject-time-interval-units">
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<option value="s" data-i18n="inject.seconds"></option>
|
|
|
|
|
<option value="m" data-i18n="inject.minutes"></option>
|
|
|
|
|
<option value="h" data-i18n="inject.hours"></option>
|
|
|
|
|
</select><br/>
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-row inject-time-row hidden" id="inject-time-row-interval-time">
|
2018-01-14 23:16:51 +01:00
|
|
|
|
<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">
|
2015-02-03 12:21:29 +01:00
|
|
|
|
<option value="1">1</option>
|
|
|
|
|
<option value="2">2</option>
|
|
|
|
|
<option value="3">3</option>
|
|
|
|
|
<option value="4">4</option>
|
|
|
|
|
<option value="5">5</option>
|
|
|
|
|
<option value="6">6</option>
|
|
|
|
|
<option value="10">10</option>
|
|
|
|
|
<option value="12">12</option>
|
|
|
|
|
<option value="15">15</option>
|
|
|
|
|
<option value="20">20</option>
|
|
|
|
|
<option value="30">30</option>
|
2014-11-12 12:30:30 +01:00
|
|
|
|
<option value="0">60</option>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
</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/>
|
2018-01-15 10:02:52 +01:00
|
|
|
|
<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>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
<div style="display:inline-block;">
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='1'/> <span data-i18n="inject.days.0"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='2'/> <span data-i18n="inject.days.1"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='3'/> <span data-i18n="inject.days.2"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='4'/> <span data-i18n="inject.days.3"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='5'/> <span data-i18n="inject.days.4"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='6'/> <span data-i18n="inject.days.5"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='0'/> <span data-i18n="inject.days.6"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-row inject-time-row hidden" id="inject-time-row-time">
|
2018-01-14 23:16:51 +01:00
|
|
|
|
<span data-i18n="inject.at"></span> <input type="text" id="inject-time-time" value="12:00"></input><br/>
|
2015-02-03 12:21:29 +01:00
|
|
|
|
<div id="inject-time-time-days" class="inject-time-days">
|
2018-01-15 10:02:52 +01:00
|
|
|
|
<div style="display:inline-block; vertical-align:top; margin-right:5px;" data-i18n="inject.on"></div>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
<div style="display:inline-block;">
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='1'/> <span data-i18n="inject.days.0"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='2'/> <span data-i18n="inject.days.1"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='3'/> <span data-i18n="inject.days.2"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='4'/> <span data-i18n="inject.days.3"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='5'/> <span data-i18n="inject.days.4"></span></label>
|
|
|
|
|
<label><input type='checkbox' checked value='6'/> <span data-i18n="inject.days.5"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2015-05-07 15:06:55 +02:00
|
|
|
|
<label><input type='checkbox' checked value='0'/> <span data-i18n="inject.days.6"></span></label>
|
2015-02-15 22:53:14 +01:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<style>
|
|
|
|
|
.inject-time-row {
|
|
|
|
|
padding-left: 110px;
|
|
|
|
|
}
|
|
|
|
|
.inject-time-row select {
|
|
|
|
|
margin: 3px 0;
|
|
|
|
|
}
|
2015-02-15 22:53:14 +01:00
|
|
|
|
.inject-time-days label {
|
|
|
|
|
-webkit-user-select: none;
|
|
|
|
|
-khtml-user-select: none;
|
|
|
|
|
-moz-user-select: none;
|
|
|
|
|
-ms-user-select: none;
|
|
|
|
|
user-select: none;
|
2018-01-14 23:16:51 +01:00
|
|
|
|
vertical-align: baseline;
|
2015-02-15 22:53:14 +01:00
|
|
|
|
width: 100px;
|
|
|
|
|
}
|
2018-01-14 23:16:51 +01:00
|
|
|
|
.inject-time-days input {
|
2019-10-04 08:33:31 +02:00
|
|
|
|
width: auto !important;
|
|
|
|
|
vertical-align: baseline !important;
|
2018-01-14 23:16:51 +01:00
|
|
|
|
}
|
2015-02-03 12:21:29 +01:00
|
|
|
|
.inject-time-times {
|
2019-10-04 08:33:31 +02:00
|
|
|
|
width: 90px !important;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
#inject-time-time {
|
|
|
|
|
width: 75px;
|
2018-01-14 23:16:51 +01:00
|
|
|
|
margin-left: 8px;
|
|
|
|
|
margin-bottom: 8px;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
.inject-time-count {
|
|
|
|
|
width: 40px !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2020-05-04 16:37:09 +02:00
|
|
|
|
(function() {
|
2021-05-22 11:52:44 +02:00
|
|
|
|
|
|
|
|
|
function resizeDialog(size) {
|
|
|
|
|
size = size || { height: $(".red-ui-tray-content form").height() }
|
|
|
|
|
var rows = $("#dialog-form>div:not(.node-input-property-container-row):visible");
|
|
|
|
|
var height = size.height;
|
|
|
|
|
for (var i=0; i<rows.length; i++) {
|
|
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
|
}
|
|
|
|
|
var editorRow = $("#dialog-form>div.node-input-property-container-row");
|
|
|
|
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
|
|
|
height += 16;
|
|
|
|
|
$("#node-input-property-container").editableList('height',height);
|
|
|
|
|
}
|
|
|
|
|
/** Retrieve editableList items (refactored for re-use in the form inject button)*/
|
2021-05-20 22:12:32 +02:00
|
|
|
|
function getProps(el, legacy) {
|
|
|
|
|
var result = {
|
|
|
|
|
props: []
|
|
|
|
|
}
|
|
|
|
|
el.each(function(i) {
|
|
|
|
|
var prop = $(this);
|
|
|
|
|
var p = {
|
|
|
|
|
p:prop.find(".node-input-prop-property-name").typedInput('value')
|
|
|
|
|
};
|
|
|
|
|
if (p.p) {
|
|
|
|
|
p.v = prop.find(".node-input-prop-property-value").typedInput('value');
|
|
|
|
|
p.vt = prop.find(".node-input-prop-property-value").typedInput('type');
|
|
|
|
|
if(legacy) {
|
|
|
|
|
if (p.p === "payload") { // save payload to old "legacy" property
|
|
|
|
|
result.payloadType = p.vt;
|
|
|
|
|
result.payload = p.v;
|
|
|
|
|
delete p.v;
|
|
|
|
|
delete p.vt;
|
|
|
|
|
} else if (p.p === "topic" && p.vt === "str") {
|
|
|
|
|
result.topic = p.v;
|
|
|
|
|
delete p.v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.props.push(p);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
/** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/
|
|
|
|
|
function doInject(node, customMsg) {
|
2021-07-28 11:59:16 +02:00
|
|
|
|
var label = node._def.label.call(node,customMsg?customMsg.__user_inject_props__:undefined);
|
2021-05-22 11:52:44 +02:00
|
|
|
|
if (label.length > 30) {
|
|
|
|
|
label = label.substring(0, 50) + "...";
|
2021-05-20 22:12:32 +02:00
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
label = label.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: "inject/" + node.id,
|
|
|
|
|
type: "POST",
|
2021-07-28 11:59:16 +02:00
|
|
|
|
data: JSON.stringify(customMsg||{}),
|
|
|
|
|
contentType: "application/json; charset=utf-8",
|
2021-05-22 11:52:44 +02:00
|
|
|
|
success: function (resp) {
|
|
|
|
|
RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 });
|
|
|
|
|
},
|
|
|
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
|
|
|
if (jqXHR.status == 404) {
|
|
|
|
|
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.not-deployed") }), "error");
|
|
|
|
|
} else if (jqXHR.status == 500) {
|
|
|
|
|
RED.notify(node._("common.notification.error", { message: node._("inject.errors.failed") }), "error");
|
|
|
|
|
} else if (jqXHR.status == 0) {
|
|
|
|
|
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.no-response") }), "error");
|
|
|
|
|
} else {
|
|
|
|
|
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.unexpected", { status: jqXHR.status, message: textStatus }) }), "error");
|
2021-05-20 22:12:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
});
|
2020-05-04 16:37:09 +02:00
|
|
|
|
}
|
2021-04-06 17:45:21 +02:00
|
|
|
|
RED.nodes.registerType('inject',{
|
2019-07-09 21:26:26 +02:00
|
|
|
|
category: 'common',
|
2015-02-03 12:21:29 +01:00
|
|
|
|
color:"#a6bbcf",
|
|
|
|
|
defaults: {
|
|
|
|
|
name: {value:""},
|
2021-04-06 17:45:21 +02:00
|
|
|
|
props:{value:[{p:"payload"},{p:"topic",vt:"str"}], validate:function(v) {
|
|
|
|
|
if (!v || v.length === 0) { return true }
|
|
|
|
|
for (var i=0;i<v.length;i++) {
|
|
|
|
|
if (/msg|flow|global/.test(v[i].vt)) {
|
|
|
|
|
if (!RED.utils.validatePropertyExpression(v[i].v)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (v[i].vt === "jsonata") {
|
|
|
|
|
try{jsonata(v[i].v);}catch(e){return false;}
|
|
|
|
|
} else if ([i].vt === "json") {
|
|
|
|
|
try{JSON.parse(v[i].v);}catch(e){return false;}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-01-17 10:35:47 +01:00
|
|
|
|
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
|
2015-02-03 12:21:29 +01:00
|
|
|
|
crontab: {value:""},
|
2018-01-11 22:50:53 +01:00
|
|
|
|
once: {value:false},
|
2020-01-23 14:55:50 +01:00
|
|
|
|
onceDelay: {value:0.1},
|
|
|
|
|
topic: {value:""},
|
|
|
|
|
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
|
|
|
|
|
payloadType: {value:"date"},
|
2015-02-03 12:21:29 +01:00
|
|
|
|
},
|
2019-06-21 13:36:20 +02:00
|
|
|
|
icon: "inject.svg",
|
2015-02-03 12:21:29 +01:00
|
|
|
|
inputs:0,
|
|
|
|
|
outputs:1,
|
2017-03-03 11:21:07 +01:00
|
|
|
|
outputLabels: function(index) {
|
2020-04-22 21:13:11 +02:00
|
|
|
|
var lab = '';
|
2020-05-04 16:37:09 +02:00
|
|
|
|
|
2020-04-22 21:13:11 +02:00
|
|
|
|
// if only payload and topic - display payload type
|
|
|
|
|
// if only one property - show it's type
|
|
|
|
|
// if more than one property (other than payload and topic) - show "x properties" where x is the number of properties.
|
|
|
|
|
// this.props will not be an array for legacy inject nodes until they are re-deployed
|
2020-05-04 16:37:09 +02:00
|
|
|
|
//
|
|
|
|
|
var props = this.props;
|
|
|
|
|
if (!Array.isArray(props)) {
|
|
|
|
|
props = [
|
|
|
|
|
{ p:"payload", v: this.payload, vt: this.payloadType },
|
|
|
|
|
{ p:"topic", v: this.topic, vt: "str" }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
if (props) {
|
|
|
|
|
for (var i=0,l=props.length; i<l; i++) {
|
|
|
|
|
if (i > 0) lab += "\n";
|
|
|
|
|
if (i === 5) {
|
2021-04-28 23:01:39 +02:00
|
|
|
|
lab += "... +"+(props.length-5);
|
2020-05-04 16:37:09 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
lab += props[i].p+": ";
|
|
|
|
|
|
2020-05-11 17:07:26 +02:00
|
|
|
|
var propType = props[i].p === "payload"? this.payloadType : props[i].vt;
|
2020-05-04 16:37:09 +02:00
|
|
|
|
if (propType === "json") {
|
|
|
|
|
try {
|
2020-05-11 17:07:26 +02:00
|
|
|
|
var parsedProp = JSON.parse(props[i].p === "payload"? this.payload : props[i].v);
|
2020-05-04 16:37:09 +02:00
|
|
|
|
propType = typeof parsedProp;
|
|
|
|
|
if (propType === "object" && Array.isArray(parsedProp)) {
|
|
|
|
|
propType = "Array";
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {
|
|
|
|
|
propType = "invalid";
|
2020-04-27 18:16:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-04 16:37:09 +02:00
|
|
|
|
lab += this._("inject.label."+propType);
|
2020-04-22 21:13:11 +02:00
|
|
|
|
}
|
2019-02-28 12:22:33 +01:00
|
|
|
|
}
|
|
|
|
|
return lab;
|
|
|
|
|
},
|
2021-07-28 11:59:16 +02:00
|
|
|
|
label: function(customProps) {
|
2020-05-05 18:35:08 +02:00
|
|
|
|
var suffix = "";
|
|
|
|
|
// if fire once then add small indication
|
|
|
|
|
if (this.once) {
|
|
|
|
|
suffix = " ¹";
|
|
|
|
|
}
|
|
|
|
|
// but replace with repeat one if set to repeat
|
|
|
|
|
if ((this.repeat && this.repeat != 0) || this.crontab) {
|
|
|
|
|
suffix = " ↻";
|
|
|
|
|
}
|
|
|
|
|
if (this.name) {
|
|
|
|
|
return this.name+suffix;
|
|
|
|
|
}
|
2021-07-28 11:59:16 +02:00
|
|
|
|
var payload = "";
|
|
|
|
|
var payloadType = "str";
|
|
|
|
|
var topic = "";
|
|
|
|
|
if (customProps) {
|
|
|
|
|
for (var i=0;i<customProps.length;i++) {
|
|
|
|
|
if (customProps[i].p === "payload") {
|
|
|
|
|
payload = customProps[i].v;
|
|
|
|
|
payloadType = customProps[i].vt;
|
|
|
|
|
} else if (customProps[i].p === "topic") {
|
|
|
|
|
topic = customProps[i].v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
payload = this.payload || "";
|
|
|
|
|
payloadType = this.payloadType || "str";
|
|
|
|
|
topic = this.topic || "";
|
|
|
|
|
}
|
2020-05-05 18:35:08 +02:00
|
|
|
|
if (payloadType === "string" ||
|
2020-01-23 14:55:50 +01:00
|
|
|
|
payloadType === "str" ||
|
|
|
|
|
payloadType === "num" ||
|
|
|
|
|
payloadType === "bool" ||
|
|
|
|
|
payloadType === "json") {
|
|
|
|
|
if ((topic !== "") && ((topic.length + payload.length) <= 32)) {
|
|
|
|
|
return topic + ":" + payload+suffix;
|
|
|
|
|
} else if (payload.length > 0 && payload.length < 24) {
|
|
|
|
|
return payload+suffix;
|
2016-01-04 15:15:10 +01:00
|
|
|
|
} else {
|
2016-05-18 00:36:09 +02:00
|
|
|
|
return this._("inject.inject")+suffix;
|
2014-11-12 12:30:30 +01:00
|
|
|
|
}
|
2020-01-23 14:55:50 +01:00
|
|
|
|
} else if (payloadType === 'date' || payloadType === 'bin' || payloadType === 'env') {
|
|
|
|
|
if ((topic !== "") && (topic.length <= 16)) {
|
2020-05-05 18:35:08 +02:00
|
|
|
|
return topic + ":" + this._('inject.label.'+payloadType)+suffix;
|
2016-10-11 10:27:02 +02:00
|
|
|
|
} else {
|
2020-05-05 18:35:08 +02:00
|
|
|
|
return this._('inject.label.'+payloadType)+suffix;
|
2016-10-11 10:27:02 +02:00
|
|
|
|
}
|
2020-01-23 14:55:50 +01:00
|
|
|
|
} else if (payloadType === 'flow' || payloadType === 'global') {
|
|
|
|
|
var key = RED.utils.parseContextKey(payload);
|
|
|
|
|
return payloadType+"."+key.key+suffix;
|
2016-01-04 15:15:10 +01:00
|
|
|
|
} else {
|
2016-05-18 00:36:09 +02:00
|
|
|
|
return this._("inject.inject")+suffix;
|
2014-11-12 12:30:30 +01:00
|
|
|
|
}
|
2015-02-03 12:21:29 +01:00
|
|
|
|
},
|
|
|
|
|
labelStyle: function() {
|
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
|
},
|
|
|
|
|
oneditprepare: function() {
|
2021-05-22 11:52:44 +02:00
|
|
|
|
var node = this;
|
|
|
|
|
if (node.payloadType == null) {
|
|
|
|
|
if (node.payload == "") {
|
|
|
|
|
node.payloadType = "date";
|
2016-01-04 15:15:10 +01:00
|
|
|
|
} else {
|
2021-05-22 11:52:44 +02:00
|
|
|
|
node.payloadType = "str";
|
2016-01-04 15:15:10 +01:00
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
} else if (node.payloadType === 'string' || node.payloadType === 'none') {
|
|
|
|
|
node.payloadType = "str";
|
2016-01-04 15:15:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 12:50:15 +02:00
|
|
|
|
$("#inject-time-type-select").on("change", function() {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$("#node-input-crontab").val('');
|
2016-07-04 12:21:58 +02:00
|
|
|
|
var id = $("#inject-time-type-select").val();
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$(".inject-time-row").hide();
|
|
|
|
|
$("#inject-time-row-"+id).show();
|
2017-03-24 15:01:26 +01:00
|
|
|
|
if ((id == "none") || (id == "interval") || (id == "interval-time")) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$("#node-once").show();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$("#node-once").hide();
|
|
|
|
|
$("#node-input-once").prop('checked', false);
|
|
|
|
|
}
|
2020-05-04 16:37:09 +02:00
|
|
|
|
|
2020-04-08 19:37:51 +02:00
|
|
|
|
// Scroll down
|
|
|
|
|
var scrollDiv = $("#dialog-form").parent();
|
|
|
|
|
scrollDiv.scrollTop(scrollDiv.prop('scrollHeight'));
|
2020-05-04 16:37:09 +02:00
|
|
|
|
resizeDialog();
|
2015-02-03 12:21:29 +01:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-29 12:50:15 +02:00
|
|
|
|
$("#node-input-once").on("change", function() {
|
2018-01-14 23:16:51 +01:00
|
|
|
|
$("#node-input-onceDelay").attr('disabled', !$("#node-input-once").prop('checked'));
|
|
|
|
|
})
|
|
|
|
|
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$(".inject-time-times").each(function() {
|
2017-03-23 23:04:53 +01:00
|
|
|
|
for (var i=0; i<24; i++) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
var l = (i<10?"0":"")+i+":00";
|
|
|
|
|
$(this).append($("<option></option>").val(i).text(l));
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-05-29 23:28:42 +02:00
|
|
|
|
$("<option></option>").val(24).text("00:00").appendTo("#inject-time-interval-time-end");
|
2019-04-29 12:50:15 +02:00
|
|
|
|
$("#inject-time-interval-time-start").on("change", function() {
|
2016-07-04 12:21:58 +02:00
|
|
|
|
var start = Number($("#inject-time-interval-time-start").val());
|
|
|
|
|
var end = Number($("#inject-time-interval-time-end").val());
|
2015-02-15 22:53:14 +01:00
|
|
|
|
$("#inject-time-interval-time-end option").remove();
|
2017-03-23 23:04:53 +01:00
|
|
|
|
for (var i=start+1; i<25; i++) {
|
2015-02-15 22:53:14 +01:00
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-02-03 12:21:29 +01:00
|
|
|
|
|
|
|
|
|
$(".inject-time-count").spinner({
|
|
|
|
|
//max:60,
|
|
|
|
|
min:1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var repeattype = "none";
|
2021-05-22 11:52:44 +02:00
|
|
|
|
if (node.repeat != "" && node.repeat != 0) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
repeattype = "interval";
|
|
|
|
|
var r = "s";
|
2021-05-22 11:52:44 +02:00
|
|
|
|
var c = node.repeat;
|
|
|
|
|
if (node.repeat % 60 === 0) { r = "m"; c = c/60; }
|
|
|
|
|
if (node.repeat % 1440 === 0) { r = "h"; c = c/60; }
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$("#inject-time-interval-count").val(c);
|
|
|
|
|
$("#inject-time-interval-units").val(r);
|
|
|
|
|
$("#inject-time-interval-days").prop("disabled","disabled");
|
2021-05-22 11:52:44 +02:00
|
|
|
|
} else if (node.crontab) {
|
|
|
|
|
var cronparts = node.crontab.split(" ");
|
2015-02-03 12:21:29 +01:00
|
|
|
|
var days = cronparts[4];
|
|
|
|
|
if (!isNaN(cronparts[0]) && !isNaN(cronparts[1])) {
|
|
|
|
|
repeattype = "time";
|
|
|
|
|
// Fixed time
|
|
|
|
|
var time = cronparts[1]+":"+cronparts[0];
|
|
|
|
|
$("#inject-time-time").val(time);
|
2016-07-04 12:21:58 +02:00
|
|
|
|
$("#inject-time-type-select").val("s");
|
2015-02-15 22:53:14 +01:00
|
|
|
|
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);
|
|
|
|
|
});
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
2015-02-15 22:53:14 +01:00
|
|
|
|
} else {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
repeattype = "interval-time";
|
|
|
|
|
// interval - time period
|
|
|
|
|
var minutes = cronparts[0].slice(2);
|
2014-11-12 12:30:30 +01:00
|
|
|
|
if (minutes === "") { minutes = "0"; }
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$("#inject-time-interval-time-units").val(minutes);
|
2015-02-15 22:53:14 +01:00
|
|
|
|
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);
|
|
|
|
|
});
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
var time = cronparts[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) {
|
2014-11-12 12:30:30 +01:00
|
|
|
|
if (hours[0] === "") {
|
|
|
|
|
start = "0";
|
|
|
|
|
end = "0";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
start = hours[0];
|
|
|
|
|
end = Number(hours[0])+1;
|
|
|
|
|
}
|
2015-02-03 12:21:29 +01:00
|
|
|
|
} else {
|
|
|
|
|
start = hours[0];
|
2015-05-29 23:28:42 +02:00
|
|
|
|
end = Number(hours[1])+1;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 23,0 or 17-23,0-10 or 23,0-2 or 17-23,0
|
|
|
|
|
var startparts = timeparts[0].split("-");
|
|
|
|
|
start = startparts[0];
|
|
|
|
|
|
|
|
|
|
var endparts = timeparts[1].split("-");
|
|
|
|
|
if (endparts.length == 1) {
|
|
|
|
|
end = Number(endparts[0])+1;
|
|
|
|
|
} else {
|
|
|
|
|
end = Number(endparts[1])+1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 12:21:58 +02:00
|
|
|
|
$("#inject-time-interval-time-end").val(end);
|
|
|
|
|
$("#inject-time-interval-time-start").val(start);
|
2015-02-03 12:21:29 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-07-04 12:21:58 +02:00
|
|
|
|
$("#inject-time-type-select").val("none");
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(".inject-time-row").hide();
|
2016-07-04 12:21:58 +02:00
|
|
|
|
$("#inject-time-type-select").val(repeattype);
|
2015-02-03 12:21:29 +01:00
|
|
|
|
$("#inject-time-row-"+repeattype).show();
|
|
|
|
|
|
2020-01-23 14:55:50 +01:00
|
|
|
|
/* */
|
2021-05-22 11:52:44 +02:00
|
|
|
|
|
|
|
|
|
var eList = $('#node-input-property-container').css('min-height','120px').css('min-width','450px');
|
2021-06-08 11:56:34 +02:00
|
|
|
|
|
2021-05-22 11:52:44 +02:00
|
|
|
|
eList.editableList({
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
id: "node-inject-test-inject-button",
|
2021-06-08 11:56:34 +02:00
|
|
|
|
label: node._("inject.injectNow"),
|
2021-05-22 11:52:44 +02:00
|
|
|
|
click: function(e) {
|
|
|
|
|
var items = eList.editableList('items');
|
2021-07-28 11:59:16 +02:00
|
|
|
|
var props = getProps(items);
|
|
|
|
|
var m = {__user_inject_props__: props.props};
|
2021-05-22 11:52:44 +02:00
|
|
|
|
doInject(node, m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
addItem: function(container,i,opt) {
|
|
|
|
|
var prop = opt;
|
|
|
|
|
if (!prop.hasOwnProperty('p')) {
|
|
|
|
|
prop = {p:"",v:"",vt:"str"};
|
|
|
|
|
}
|
|
|
|
|
container.css({
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
whiteSpace: 'nowrap'
|
|
|
|
|
});
|
|
|
|
|
var row = $('<div/>').appendTo(container);
|
|
|
|
|
|
|
|
|
|
var propertyName = $('<input/>',{class:"node-input-prop-property-name",type:"text"})
|
|
|
|
|
.css("width","30%")
|
|
|
|
|
.appendTo(row)
|
|
|
|
|
.typedInput({types:['msg']});
|
|
|
|
|
|
|
|
|
|
$('<div/>',{style: 'display:inline-block; padding:0px 6px;'})
|
|
|
|
|
.text('=')
|
|
|
|
|
.appendTo(row);
|
|
|
|
|
|
|
|
|
|
var propertyValue = $('<input/>',{class:"node-input-prop-property-value",type:"text"})
|
|
|
|
|
.css("width","calc(70% - 30px)")
|
|
|
|
|
.appendTo(row)
|
|
|
|
|
.typedInput({default:'str',types:['flow','global','str','num','bool','json','bin','date','jsonata','env','msg']});
|
|
|
|
|
|
|
|
|
|
propertyName.typedInput('value',prop.p);
|
|
|
|
|
|
|
|
|
|
propertyValue.typedInput('value',prop.v);
|
|
|
|
|
propertyValue.typedInput('type',prop.vt);
|
|
|
|
|
},
|
|
|
|
|
removable: true,
|
|
|
|
|
sortable: true
|
|
|
|
|
});
|
2021-06-08 11:56:34 +02:00
|
|
|
|
$('#node-inject-test-inject-button').css("float", "right").css("margin-right", "unset");
|
|
|
|
|
|
|
|
|
|
if (RED.nodes.subflow(node.z)) {
|
|
|
|
|
$('#node-inject-test-inject-button').attr("disabled",true);
|
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
|
|
|
|
|
if (!node.props) {
|
|
|
|
|
var payload = {
|
|
|
|
|
p:'payload',
|
|
|
|
|
v: node.payload ? node.payload : '',
|
|
|
|
|
vt:node.payloadType ? node.payloadType : 'date'
|
|
|
|
|
};
|
|
|
|
|
var topic = {
|
|
|
|
|
p:'topic',
|
|
|
|
|
v: node.topic ? node.topic : '',
|
|
|
|
|
vt:'string'
|
|
|
|
|
}
|
|
|
|
|
node.props = [payload,topic];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<node.props.length; i++) {
|
|
|
|
|
var prop = node.props[i];
|
|
|
|
|
var newProp = { p: prop.p, v: prop.v, vt: prop.vt };
|
|
|
|
|
if (newProp.v === undefined) {
|
|
|
|
|
if (prop.p === 'payload') {
|
|
|
|
|
newProp.v = node.payload ? node.payload : '';
|
|
|
|
|
newProp.vt = node.payloadType ? node.payloadType : 'date';
|
|
|
|
|
} else if (prop.p === 'topic' && prop.vt === "str") {
|
|
|
|
|
newProp.v = node.topic ? node.topic : '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
eList.editableList('addItem',newProp);
|
2020-01-23 14:55:50 +01:00
|
|
|
|
}
|
2020-05-04 16:37:09 +02:00
|
|
|
|
|
|
|
|
|
$("#inject-time-type-select").trigger("change");
|
|
|
|
|
$("#inject-time-interval-time-start").trigger("change");
|
2020-01-23 14:55:50 +01:00
|
|
|
|
|
2015-02-03 12:21:29 +01:00
|
|
|
|
},
|
|
|
|
|
oneditsave: function() {
|
|
|
|
|
var repeat = "";
|
|
|
|
|
var crontab = "";
|
2016-07-04 12:21:58 +02:00
|
|
|
|
var type = $("#inject-time-type-select").val();
|
2015-02-03 12:21:29 +01:00
|
|
|
|
if (type == "none") {
|
|
|
|
|
// nothing
|
|
|
|
|
} else if (type == "interval") {
|
|
|
|
|
var count = $("#inject-time-interval-count").val();
|
2016-07-04 12:21:58 +02:00
|
|
|
|
var units = $("#inject-time-interval-units").val();
|
2015-02-03 12:21:29 +01:00
|
|
|
|
if (units == "s") {
|
|
|
|
|
repeat = count;
|
|
|
|
|
} else {
|
|
|
|
|
if (units == "m") {
|
|
|
|
|
//crontab = "*/"+count+" * * * "+days;
|
|
|
|
|
repeat = count * 60;
|
|
|
|
|
} else if (units == "h") {
|
|
|
|
|
//crontab = "0 */"+count+" * * "+days;
|
2014-11-12 12:30:30 +01:00
|
|
|
|
repeat = count * 60 * 60;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (type == "interval-time") {
|
2015-02-15 22:53:14 +01:00
|
|
|
|
repeat = "";
|
2015-02-03 12:21:29 +01:00
|
|
|
|
var count = $("#inject-time-interval-time-units").val();
|
2016-07-04 12:21:58 +02:00
|
|
|
|
var startTime = Number($("#inject-time-interval-time-start").val());
|
|
|
|
|
var endTime = Number($("#inject-time-interval-time-end").val());
|
2018-01-15 10:02:52 +01:00
|
|
|
|
var days = $('#inject-time-interval-time-days input[type=checkbox]:checked').map(function(_, el) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
return $(el).val()
|
|
|
|
|
}).get();
|
2015-02-15 22:53:14 +01:00
|
|
|
|
if (days.length == 0) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
crontab = "";
|
|
|
|
|
} else {
|
2015-02-15 22:53:14 +01:00
|
|
|
|
if (days.length == 7) {
|
|
|
|
|
days="*";
|
2015-02-03 12:21:29 +01:00
|
|
|
|
} else {
|
2015-02-15 22:53:14 +01:00
|
|
|
|
days = days.join(",");
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
2015-02-15 22:53:14 +01:00
|
|
|
|
var timerange = "";
|
|
|
|
|
if (endTime == 0) {
|
|
|
|
|
timerange = startTime+"-23";
|
|
|
|
|
} else if (startTime+1 < endTime) {
|
|
|
|
|
timerange = startTime+"-"+(endTime-1);
|
|
|
|
|
} else if (startTime+1 == endTime) {
|
|
|
|
|
timerange = startTime;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
} else {
|
2015-02-15 22:53:14 +01:00
|
|
|
|
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;
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
2014-11-12 12:30:30 +01:00
|
|
|
|
}
|
2015-02-03 12:21:29 +01:00
|
|
|
|
} else if (type == "time") {
|
|
|
|
|
var time = $("#inject-time-time").val();
|
2015-02-15 22:53:14 +01:00
|
|
|
|
var days = $('#inject-time-time-days input[type=checkbox]:checked').map(function(_, el) {
|
2015-02-03 12:21:29 +01:00
|
|
|
|
return $(el).val()
|
|
|
|
|
}).get();
|
2015-02-15 22:53:14 +01:00
|
|
|
|
if (days.length == 0) {
|
|
|
|
|
crontab = "";
|
|
|
|
|
} else {
|
|
|
|
|
if (days.length == 7) {
|
|
|
|
|
days="*";
|
|
|
|
|
} else {
|
|
|
|
|
days = days.join(",");
|
|
|
|
|
}
|
|
|
|
|
var parts = time.split(":");
|
2018-01-14 23:16:51 +01:00
|
|
|
|
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 = ""; }
|
2015-02-15 22:53:14 +01:00
|
|
|
|
}
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#node-input-repeat").val(repeat);
|
|
|
|
|
$("#node-input-crontab").val(crontab);
|
2020-01-23 14:55:50 +01:00
|
|
|
|
|
2021-05-22 11:52:44 +02:00
|
|
|
|
/* Gather the properties */
|
2021-05-20 22:12:32 +02:00
|
|
|
|
var items = $("#node-input-property-container").editableList('items');
|
2021-05-22 11:52:44 +02:00
|
|
|
|
delete this.payloadType;
|
|
|
|
|
delete this.payload;
|
|
|
|
|
this.topic = "";
|
2021-05-20 22:12:32 +02:00
|
|
|
|
var result = getProps(items, true);
|
2021-05-22 11:52:44 +02:00
|
|
|
|
this.props = result.props;
|
|
|
|
|
if(result.payloadType) { this.payloadType = result.payloadType; };
|
|
|
|
|
if(result.payload) { this.payload = result.payload; };
|
|
|
|
|
if(result.topic) { this.topic = result.topic; };
|
2015-02-03 12:21:29 +01:00
|
|
|
|
},
|
|
|
|
|
button: {
|
2017-04-24 00:20:50 +02:00
|
|
|
|
enabled: function() {
|
|
|
|
|
return !this.changed
|
|
|
|
|
},
|
2021-05-20 22:12:32 +02:00
|
|
|
|
onclick: function () {
|
2021-05-22 11:52:44 +02:00
|
|
|
|
if (this.changed) {
|
2021-05-20 22:12:32 +02:00
|
|
|
|
return RED.notify(RED._("notification.warning", { message: RED._("notification.warnings.undeployedChanges") }), "warning");
|
2017-04-24 00:20:50 +02:00
|
|
|
|
}
|
2021-05-22 11:52:44 +02:00
|
|
|
|
doInject(this);
|
2015-02-03 12:21:29 +01:00
|
|
|
|
}
|
2020-01-23 14:55:50 +01:00
|
|
|
|
},
|
2020-05-04 16:37:09 +02:00
|
|
|
|
oneditresize: resizeDialog
|
2015-02-03 12:21:29 +01:00
|
|
|
|
});
|
2020-05-04 16:37:09 +02:00
|
|
|
|
})();
|
2015-02-03 12:21:29 +01:00
|
|
|
|
</script>
|