mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'dev' into pr_2490
This commit is contained in:
@@ -16,14 +16,12 @@
|
||||
|
||||
<script type="text/html" data-template-name="inject">
|
||||
<div class="form-row">
|
||||
<label for="node-input-payload"><i class="fa fa-envelope"></i> <span data-i18n="common.label.payload"></span></label>
|
||||
<input type="text" id="node-input-payload" style="width:70%">
|
||||
<input type="hidden" id="node-input-payloadType">
|
||||
<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>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
||||
<input type="text" id="node-input-topic">
|
||||
<div class="form-row node-input-property-container-row">
|
||||
<ol id="node-input-property-container"></ol>
|
||||
</div>
|
||||
|
||||
<div class="form-row" id="node-once">
|
||||
@@ -114,12 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
<div class="form-tips" data-i18n="[html]inject.tip"></div>
|
||||
</script>
|
||||
<style>
|
||||
.inject-time-row {
|
||||
@@ -155,37 +148,76 @@
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
RED.nodes.registerType('inject',{
|
||||
category: 'common',
|
||||
color:"#a6bbcf",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
topic: {value:""},
|
||||
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
|
||||
payloadType: {value:"date"},
|
||||
props:{value:[{p:"payload"},{p:"topic",vt:"str"}]},
|
||||
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
|
||||
crontab: {value:""},
|
||||
once: {value:false},
|
||||
onceDelay: {value:0.1}
|
||||
onceDelay: {value:0.1},
|
||||
topic: {value:""},
|
||||
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
|
||||
payloadType: {value:"date"},
|
||||
},
|
||||
icon: "inject.svg",
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
outputLabels: function(index) {
|
||||
var lab = this.payloadType;
|
||||
if (lab === "json") {
|
||||
try {
|
||||
lab = typeof JSON.parse(this.payload);
|
||||
if (lab === "object") {
|
||||
if (Array.isArray(JSON.parse(this.payload))) { lab = "Array"; }
|
||||
}
|
||||
} catch(e) {
|
||||
return this._("inject.label.invalid"); }
|
||||
var lab = '';
|
||||
|
||||
// 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
|
||||
//
|
||||
var props = this.props;
|
||||
if (!Array.isArray(props)) {
|
||||
props = [
|
||||
{ p:"payload", v: this.payload, vt: this.payloadType },
|
||||
{ p:"topic", v: this.topic, vt: "str" }
|
||||
]
|
||||
}
|
||||
var name = "inject.label."+lab;
|
||||
var label = this._(name);
|
||||
if (name !== label) {
|
||||
return label;
|
||||
if (props) {
|
||||
for (var i=0,l=props.length; i<l; i++) {
|
||||
if (i > 0) lab += "\n";
|
||||
if (i === 5) {
|
||||
lab += " + "+(props.length-4);
|
||||
break;
|
||||
}
|
||||
lab += props[i].p+": ";
|
||||
|
||||
var propType = props[i].p === "payload"? this.payloadType : props[i].vt;
|
||||
if (propType === "json") {
|
||||
try {
|
||||
var parsedProp = JSON.parse(props[i].p === "payload"? this.payload : props[i].v);
|
||||
propType = typeof parsedProp;
|
||||
if (propType === "object" && Array.isArray(parsedProp)) {
|
||||
propType = "Array";
|
||||
}
|
||||
} catch(e) {
|
||||
propType = "invalid";
|
||||
}
|
||||
}
|
||||
lab += this._("inject.label."+propType);
|
||||
}
|
||||
}
|
||||
return lab;
|
||||
},
|
||||
@@ -201,27 +233,33 @@
|
||||
}
|
||||
if (this.name) {
|
||||
return this.name+suffix;
|
||||
} else if (this.payloadType === "string" ||
|
||||
this.payloadType === "str" ||
|
||||
this.payloadType === "num" ||
|
||||
this.payloadType === "bool" ||
|
||||
this.payloadType === "json") {
|
||||
if ((this.topic !== "") && ((this.topic.length + this.payload.length) <= 32)) {
|
||||
return this.topic + ":" + this.payload+suffix;
|
||||
} else if (this.payload.length > 0 && this.payload.length < 24) {
|
||||
return this.payload+suffix;
|
||||
}
|
||||
|
||||
var payload = this.payload || "";
|
||||
var payloadType = this.payloadType || "str";
|
||||
var topic = this.topic || "";
|
||||
|
||||
if (payloadType === "string" ||
|
||||
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;
|
||||
} else {
|
||||
return this._("inject.inject")+suffix;
|
||||
}
|
||||
} else if (this.payloadType === 'date') {
|
||||
if ((this.topic !== "") && (this.topic.length <= 16)) {
|
||||
return this.topic + ":" + this._("inject.timestamp")+suffix;
|
||||
} else if (payloadType === 'date' || payloadType === 'bin' || payloadType === 'env') {
|
||||
if ((topic !== "") && (topic.length <= 16)) {
|
||||
return topic + ":" + this._('inject.label.'+payloadType)+suffix;
|
||||
} else {
|
||||
return this._("inject.timestamp")+suffix;
|
||||
return this._('inject.label.'+payloadType)+suffix;
|
||||
}
|
||||
} else if (this.payloadType === 'flow' || this.payloadType === 'global') {
|
||||
var key = RED.utils.parseContextKey(this.payload);
|
||||
return this.payloadType+"."+key.key+suffix;
|
||||
} else if (payloadType === 'flow' || payloadType === 'global') {
|
||||
var key = RED.utils.parseContextKey(payload);
|
||||
return payloadType+"."+key.key+suffix;
|
||||
} else {
|
||||
return this._("inject.inject")+suffix;
|
||||
}
|
||||
@@ -239,13 +277,6 @@
|
||||
} else if (this.payloadType === 'string' || this.payloadType === 'none') {
|
||||
this.payloadType = "str";
|
||||
}
|
||||
$("#node-input-payloadType").val(this.payloadType);
|
||||
|
||||
$("#node-input-payload").typedInput({
|
||||
default: 'str',
|
||||
typeField: $("#node-input-payloadType"),
|
||||
types:['flow','global','str','num','bool','json','bin','date','env']
|
||||
});
|
||||
|
||||
$("#inject-time-type-select").on("change", function() {
|
||||
$("#node-input-crontab").val('');
|
||||
@@ -259,6 +290,11 @@
|
||||
$("#node-once").hide();
|
||||
$("#node-input-once").prop('checked', false);
|
||||
}
|
||||
|
||||
// Scroll down
|
||||
var scrollDiv = $("#dialog-form").parent();
|
||||
scrollDiv.scrollTop(scrollDiv.prop('scrollHeight'));
|
||||
resizeDialog();
|
||||
});
|
||||
|
||||
$("#node-input-once").on("change", function() {
|
||||
@@ -378,7 +414,70 @@
|
||||
$("#inject-time-type-select").val(repeattype);
|
||||
$("#inject-time-row-"+repeattype).show();
|
||||
|
||||
$("#node-input-payload").typedInput('type',this.payloadType);
|
||||
/* */
|
||||
|
||||
$('#node-input-property-container').css('min-height','120px').css('min-width','450px').editableList({
|
||||
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:['msg','flow','global','str','num','bool','json','bin','date','jsonata','env']});
|
||||
|
||||
propertyName.typedInput('value',prop.p);
|
||||
|
||||
propertyValue.typedInput('value',prop.v);
|
||||
propertyValue.typedInput('type',prop.vt);
|
||||
},
|
||||
removable: true,
|
||||
sortable: true
|
||||
});
|
||||
|
||||
if (!this.props) {
|
||||
var payload = {
|
||||
p:'payload',
|
||||
v: this.payload ? this.payload : '',
|
||||
vt:this.payloadType ? this.payloadType : 'date'
|
||||
};
|
||||
var topic = {
|
||||
p:'topic',
|
||||
v: this.topic ? this.topic : '',
|
||||
vt:'string'
|
||||
}
|
||||
this.props = [payload,topic];
|
||||
}
|
||||
|
||||
for (var i=0; i<this.props.length; i++) {
|
||||
var prop = this.props[i];
|
||||
var newProp = { p: prop.p, v: prop.v, vt: prop.vt };
|
||||
if (newProp.v === undefined) {
|
||||
if (prop.p === 'payload') {
|
||||
newProp.v = this.payload ? this.payload : '';
|
||||
newProp.vt = this.payloadType ? this.payloadType : 'date';
|
||||
} else if (prop.p === 'topic' && prop.vt === "str") {
|
||||
newProp.v = this.topic ? this.topic : '';
|
||||
}
|
||||
}
|
||||
$("#node-input-property-container").editableList('addItem',newProp);
|
||||
}
|
||||
|
||||
$("#inject-time-type-select").trigger("change");
|
||||
$("#inject-time-interval-time-start").trigger("change");
|
||||
@@ -474,6 +573,34 @@
|
||||
|
||||
$("#node-input-repeat").val(repeat);
|
||||
$("#node-input-crontab").val(crontab);
|
||||
|
||||
/* Gather the injected properties of the msg object */
|
||||
var props = $("#node-input-property-container").editableList('items');
|
||||
var node = this;
|
||||
node.props= [];
|
||||
delete node.payloadType;
|
||||
delete node.payload;
|
||||
delete node.topic;
|
||||
props.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 (p.p === "payload") { // save payload to old "legacy" property
|
||||
node.payloadType = p.vt;
|
||||
node.payload = p.v;
|
||||
delete p.v;
|
||||
delete p.vt;
|
||||
} else if (p.p === "topic" && p.vt === "str") {
|
||||
node.topic = p.v;
|
||||
delete p.v;
|
||||
}
|
||||
node.props.push(p);
|
||||
}
|
||||
});
|
||||
},
|
||||
button: {
|
||||
enabled: function() {
|
||||
@@ -483,12 +610,7 @@
|
||||
if (this.changed) {
|
||||
return RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.undeployedChanges")}),"warning");
|
||||
}
|
||||
var payload = this.payload;
|
||||
if ((this.payloadType === 'flow') ||
|
||||
(this.payloadType === 'global')) {
|
||||
var key = RED.utils.parseContextKey(payload);
|
||||
payload = this.payloadType+"."+key.key;
|
||||
}
|
||||
|
||||
var label = this._def.label.call(this);
|
||||
if (label.length > 30) {
|
||||
label = label.substring(0,50)+"...";
|
||||
@@ -514,7 +636,8 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
oneditresize: resizeDialog
|
||||
});
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
@@ -20,9 +20,32 @@ module.exports = function(RED) {
|
||||
|
||||
function InjectNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.topic = n.topic;
|
||||
this.payload = n.payload;
|
||||
this.payloadType = n.payloadType;
|
||||
|
||||
/* Handle legacy */
|
||||
if(!Array.isArray(n.props)){
|
||||
n.props = [];
|
||||
n.props.push({
|
||||
p:'payload',
|
||||
v:n.payload,
|
||||
vt:n.payloadType
|
||||
});
|
||||
n.props.push({
|
||||
p:'topic',
|
||||
v:n.topic,
|
||||
vt:'str'
|
||||
});
|
||||
} else {
|
||||
for (var i=0,l=n.props.length; i<l; i++) {
|
||||
if (n.props[i].p === 'payload' && !n.props[i].hasOwnProperty('v')) {
|
||||
n.props[i].v = n.payload;
|
||||
n.props[i].vt = n.payloadType;
|
||||
} else if (n.props[i].p === 'topic' && n.props[i].vt === 'str' && !n.props[i].hasOwnProperty('v')) {
|
||||
n.props[i].v = n.topic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.props = n.props;
|
||||
this.repeat = n.repeat;
|
||||
this.crontab = n.crontab;
|
||||
this.once = n.once;
|
||||
@@ -31,65 +54,83 @@ module.exports = function(RED) {
|
||||
this.cronjob = null;
|
||||
var node = this;
|
||||
|
||||
node.props.forEach(function (prop) {
|
||||
if (prop.vt === "jsonata") {
|
||||
try {
|
||||
var val = prop.v ? prop.v : "";
|
||||
prop.exp = RED.util.prepareJSONataExpression(val, node);
|
||||
}
|
||||
catch (err) {
|
||||
node.error(RED._("inject.errors.invalid-expr", {error:err.message}));
|
||||
prop.exp = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
this.repeat = this.repeat * 1000;
|
||||
if (RED.settings.verbose) {
|
||||
this.log(RED._("inject.repeat", this));
|
||||
if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) {
|
||||
this.repeat = this.repeat * 1000;
|
||||
if (RED.settings.verbose) {
|
||||
this.log(RED._("inject.repeat", this));
|
||||
}
|
||||
this.interval_id = setInterval(function() {
|
||||
node.emit("input", {});
|
||||
}, this.repeat);
|
||||
} else if (this.crontab) {
|
||||
if (RED.settings.verbose) {
|
||||
this.log(RED._("inject.crontab", this));
|
||||
}
|
||||
this.cronjob = new cron.CronJob(this.crontab, function() { node.emit("input", {}); }, null, true);
|
||||
}
|
||||
this.interval_id = setInterval(function() {
|
||||
node.emit("input", {});
|
||||
}, this.repeat);
|
||||
} else if (this.crontab) {
|
||||
if (RED.settings.verbose) {
|
||||
this.log(RED._("inject.crontab", this));
|
||||
}
|
||||
this.cronjob = new cron.CronJob(this.crontab, function() { node.emit("input", {}); }, null, true);
|
||||
}
|
||||
};
|
||||
|
||||
if (this.once) {
|
||||
this.onceTimeout = setTimeout( function() {
|
||||
node.emit("input",{});
|
||||
node.repeaterSetup();
|
||||
node.emit("input",{});
|
||||
node.repeaterSetup();
|
||||
}, this.onceDelay);
|
||||
} else {
|
||||
node.repeaterSetup();
|
||||
node.repeaterSetup();
|
||||
}
|
||||
|
||||
this.on("input",function(msg) {
|
||||
msg.topic = this.topic;
|
||||
if (this.payloadType !== 'flow' && this.payloadType !== 'global') {
|
||||
try {
|
||||
if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
|
||||
msg.payload = Date.now();
|
||||
} else if (this.payloadType == null) {
|
||||
msg.payload = this.payload;
|
||||
} else if (this.payloadType === 'none') {
|
||||
msg.payload = "";
|
||||
} else {
|
||||
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
|
||||
}
|
||||
this.send(msg);
|
||||
msg = null;
|
||||
} catch(err) {
|
||||
this.error(err,msg);
|
||||
}
|
||||
} else {
|
||||
RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg, function(err,res) {
|
||||
if (err) {
|
||||
node.error(err,msg);
|
||||
} else {
|
||||
msg.payload = res;
|
||||
node.send(msg);
|
||||
}
|
||||
this.on("input", function(msg) {
|
||||
var errors = [];
|
||||
|
||||
});
|
||||
this.props.forEach(p => {
|
||||
var property = p.p;
|
||||
var value = p.v ? p.v : '';
|
||||
var valueType = p.vt ? p.vt : 'str';
|
||||
|
||||
if (!property) return;
|
||||
|
||||
if (valueType === "jsonata") {
|
||||
if (p.exp) {
|
||||
try {
|
||||
var val = RED.util.evaluateJSONataExpression(p.exp, msg);
|
||||
RED.util.setMessageProperty(msg, property, val, true);
|
||||
}
|
||||
catch (err) {
|
||||
errors.push(err.message);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
RED.util.setMessageProperty(msg,property,RED.util.evaluateNodeProperty(value, valueType, this, msg),true);
|
||||
} catch (err) {
|
||||
errors.push(err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
if (errors.length) {
|
||||
node.error(errors.join('; '), msg);
|
||||
} else {
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -6,25 +6,30 @@
|
||||
<input id="node-input-complete" type="hidden">
|
||||
<input id="node-input-targetType" type="hidden">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-tosidebar"><i class="fa fa-random"></i> <span data-i18n="debug.to"></span></label>
|
||||
<label for="node-input-tosidebar" style="width:70%">
|
||||
<input type="checkbox" id="node-input-tosidebar" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toSidebar"></span>
|
||||
<input type="checkbox" id="node-input-tosidebar" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toSidebar"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-console"> </label>
|
||||
<label for="node-input-console" style="width:70%">
|
||||
<input type="checkbox" id="node-input-console" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toConsole"></span>
|
||||
<input type="checkbox" id="node-input-console" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toConsole"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row" id="node-tostatus-line">
|
||||
<div class="form-row">
|
||||
<label for="node-input-tostatus"> </label>
|
||||
<label for="node-input-tostatus" style="width:70%">
|
||||
<input type="checkbox" id="node-input-tostatus" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toStatus"></span>
|
||||
<input type="checkbox" id="node-input-tostatus" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toStatus"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row" id="node-tostatus-line">
|
||||
<label for="node-input-typed-status"><i class="fa fa-ellipsis-h"></i> <span data-i18n="debug.status"></span></label>
|
||||
<input id="node-input-typed-status" type="text" style="width: 70%">
|
||||
<input id="node-input-statusVal" type="hidden">
|
||||
<input id="node-input-statusType" type="hidden">
|
||||
</div>
|
||||
<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">
|
||||
@@ -45,7 +50,9 @@
|
||||
console: {value:false},
|
||||
tostatus: {value:false},
|
||||
complete: {value:"false", required:true},
|
||||
targetType: {value:undefined}
|
||||
targetType: {value:undefined},
|
||||
statusVal: {value:""},
|
||||
statusType: {value:"auto"}
|
||||
},
|
||||
label: function() {
|
||||
var suffix = "";
|
||||
@@ -308,10 +315,20 @@
|
||||
window.removeEventListener("message",this.handleWindowMessage);
|
||||
RED.actions.remove("core:show-debug-tab");
|
||||
RED.actions.remove("core:clear-debug-messages");
|
||||
|
||||
delete RED._debug;
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var autoType = {
|
||||
value: "auto",
|
||||
label: RED._("node-red:debug.autostatus"),
|
||||
hasValue: false
|
||||
};
|
||||
$("#node-input-typed-status").typedInput({
|
||||
default: "auto",
|
||||
types:[autoType, "msg", "jsonata"],
|
||||
typeField: $("#node-input-statusType")
|
||||
});
|
||||
var that = this;
|
||||
var none = {
|
||||
value: "none",
|
||||
label: RED._("node-red:debug.none"),
|
||||
@@ -321,6 +338,14 @@
|
||||
this.tosidebar = true;
|
||||
$("#node-input-tosidebar").prop('checked', true);
|
||||
}
|
||||
if (this.statusVal === undefined) {
|
||||
this.statusVal = (this.complete === "false") ? "payload" : ((this.complete === "true") ? "payload" : this.complete+"");
|
||||
$("#node-input-typed-status").typedInput('value',this.statusVal || "");
|
||||
}
|
||||
if (this.statusType === undefined) {
|
||||
this.statusType = this.targetType;
|
||||
$("#node-input-typed-status").typedInput('type',this.statusType || "auto");
|
||||
}
|
||||
if (typeof this.console === "string") {
|
||||
this.console = (this.console == 'true');
|
||||
$("#node-input-console").prop('checked', this.console);
|
||||
@@ -331,6 +356,7 @@
|
||||
label: RED._("node-red:debug.msgobj"),
|
||||
hasValue: false
|
||||
};
|
||||
|
||||
$("#node-input-typed-complete").typedInput({
|
||||
default: "msg",
|
||||
types:['msg', fullType, "jsonata"],
|
||||
@@ -354,17 +380,29 @@
|
||||
) {
|
||||
$("#node-input-typed-complete").typedInput('value','payload');
|
||||
}
|
||||
if ($("#node-input-typed-complete").typedInput('type') === 'full') {
|
||||
$("#node-tostatus-line").hide();
|
||||
} else {
|
||||
});
|
||||
|
||||
$("#node-input-tostatus").on('change',function() {
|
||||
if ($(this).is(":checked")) {
|
||||
if (!that.hasOwnProperty("statusVal") || that.statusVal === "") {
|
||||
var type = $("#node-input-typed-complete").typedInput('type');
|
||||
var comp = "payload";
|
||||
if (type !== 'full') {
|
||||
comp = $("#node-input-typed-complete").typedInput('value');
|
||||
}
|
||||
that.statusType = "auto";
|
||||
that.statusVal = comp;
|
||||
}
|
||||
$("#node-input-typed-status").typedInput('type',that.statusType);
|
||||
$("#node-input-typed-status").typedInput('value',that.statusVal);
|
||||
$("#node-tostatus-line").show();
|
||||
}
|
||||
});
|
||||
$("#node-input-complete").on('change',function() {
|
||||
if ($("#node-input-typed-complete").typedInput('type') === 'full') {
|
||||
else {
|
||||
$("#node-tostatus-line").hide();
|
||||
} else {
|
||||
$("#node-tostatus-line").show();
|
||||
that.statusType = "auto";
|
||||
that.statusVal = "";
|
||||
$("#node-input-typed-status").typedInput('type',that.statusType);
|
||||
$("#node-input-typed-status").typedInput('value',that.statusVal);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -375,6 +413,7 @@
|
||||
} else {
|
||||
$("#node-input-complete").val($("#node-input-typed-complete").typedInput('value'));
|
||||
}
|
||||
$("#node-input-statusVal").val($("#node-input-typed-status").typedInput('value'));
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
@@ -2,7 +2,7 @@ module.exports = function(RED) {
|
||||
"use strict";
|
||||
var util = require("util");
|
||||
var events = require("events");
|
||||
var path = require("path");
|
||||
//var path = require("path");
|
||||
var debuglength = RED.settings.debugMaxLength || 1000;
|
||||
var useColors = RED.settings.debugUseColors || false;
|
||||
util.inspect.styles.boolean = "red";
|
||||
@@ -15,36 +15,20 @@ module.exports = function(RED) {
|
||||
this.complete = hasEditExpression ? null : (n.complete||"payload").toString();
|
||||
if (this.complete === "false") { this.complete = "payload"; }
|
||||
this.console = ""+(n.console || false);
|
||||
this.tostatus = (this.complete !== "true") && (n.tostatus || false);
|
||||
this.tostatus = n.tostatus || false;
|
||||
this.statusType = n.statusType || "msg";
|
||||
this.statusVal = n.statusVal || this.complete;
|
||||
this.tosidebar = n.tosidebar;
|
||||
if (this.tosidebar === undefined) { this.tosidebar = true; }
|
||||
this.severity = n.severity || 40;
|
||||
this.active = (n.active === null || typeof n.active === "undefined") || n.active;
|
||||
if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); }
|
||||
else { this.status({}); }
|
||||
var hasStatExpression = (n.statusType === "jsonata");
|
||||
var statExpression = hasStatExpression ? n.statusVal : null;
|
||||
|
||||
var node = this;
|
||||
var levels = {
|
||||
off: 1,
|
||||
fatal: 10,
|
||||
error: 20,
|
||||
warn: 30,
|
||||
info: 40,
|
||||
debug: 50,
|
||||
trace: 60,
|
||||
audit: 98,
|
||||
metric: 99
|
||||
};
|
||||
var colors = {
|
||||
"0": "grey",
|
||||
"10": "grey",
|
||||
"20": "red",
|
||||
"30": "yellow",
|
||||
"40": "grey",
|
||||
"50": "green",
|
||||
"60": "blue"
|
||||
};
|
||||
var preparedEditExpression = null;
|
||||
var preparedStatExpression = null;
|
||||
if (editExpression) {
|
||||
try {
|
||||
preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this);
|
||||
@@ -54,16 +38,22 @@ module.exports = function(RED) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (statExpression) {
|
||||
try {
|
||||
preparedStatExpression = RED.util.prepareJSONataExpression(statExpression, this);
|
||||
}
|
||||
catch (e) {
|
||||
node.error(RED._("debug.invalid-exp", {error: editExpression}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function prepareValue(msg, done) {
|
||||
// Either apply the jsonata expression or...
|
||||
if (preparedEditExpression) {
|
||||
RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => {
|
||||
if (err) {
|
||||
done(RED._("debug.invalid-exp", {error: editExpression}));
|
||||
} else {
|
||||
done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value});
|
||||
}
|
||||
if (err) { done(RED._("debug.invalid-exp", {error: editExpression})); }
|
||||
else { done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value}); }
|
||||
});
|
||||
} else {
|
||||
// Extract the required message property
|
||||
@@ -71,17 +61,67 @@ module.exports = function(RED) {
|
||||
var output = msg[property];
|
||||
if (node.complete !== "false" && typeof node.complete !== "undefined") {
|
||||
property = node.complete;
|
||||
try {
|
||||
output = RED.util.getMessageProperty(msg,node.complete);
|
||||
} catch(err) {
|
||||
output = undefined;
|
||||
}
|
||||
try { output = RED.util.getMessageProperty(msg,node.complete); }
|
||||
catch(err) { output = undefined; }
|
||||
}
|
||||
done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, property:property, msg:output});
|
||||
}
|
||||
}
|
||||
|
||||
function prepareStatus(msg, done) {
|
||||
if (node.statusType === "auto") {
|
||||
if (node.complete === "true") {
|
||||
done(null,{msg:msg.payload});
|
||||
}
|
||||
else {
|
||||
prepareValue(msg,function(err,debugMsg) {
|
||||
if (err) { node.error(err); return; }
|
||||
done(null,{msg:debugMsg.msg});
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Either apply the jsonata expression or...
|
||||
if (preparedStatExpression) {
|
||||
RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => {
|
||||
if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }
|
||||
else { done(null,{msg:value}); }
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Extract the required message property
|
||||
var output;
|
||||
try { output = RED.util.getMessageProperty(msg,node.statusVal); }
|
||||
catch(err) { output = undefined; }
|
||||
done(null,{msg:output});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.on("input", function(msg, send, done) {
|
||||
if (node.tostatus === true) {
|
||||
prepareStatus(msg, function(err,debugMsg) {
|
||||
if (err) { node.error(err); return; }
|
||||
var output = debugMsg.msg;
|
||||
var st = (typeof output === 'string') ? output : util.inspect(output);
|
||||
var fill = "grey";
|
||||
var shape = "dot";
|
||||
if (node.statusType === "auto") {
|
||||
if (msg.hasOwnProperty("error")) {
|
||||
fill = "red";
|
||||
st = msg.error.message;
|
||||
}
|
||||
if (msg.hasOwnProperty("status")) {
|
||||
if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; }
|
||||
if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; }
|
||||
if (msg.status.hasOwnProperty("text")) { st = msg.status.text; }
|
||||
}
|
||||
}
|
||||
if (st.length > 32) { st = st.substr(0,32) + "..."; }
|
||||
node.status({fill:fill, shape:shape, text:st});
|
||||
});
|
||||
}
|
||||
|
||||
if (this.complete === "true") {
|
||||
// debug complete msg object
|
||||
if (this.console === "true") {
|
||||
@@ -91,7 +131,8 @@ module.exports = function(RED) {
|
||||
sendDebug({id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:msg});
|
||||
}
|
||||
done();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
prepareValue(msg,function(err,debugMsg) {
|
||||
if (err) {
|
||||
node.error(err);
|
||||
@@ -107,12 +148,6 @@ module.exports = function(RED) {
|
||||
node.log(util.inspect(output, {colors:useColors}));
|
||||
}
|
||||
}
|
||||
if (node.tostatus === true) {
|
||||
var st = (typeof output === 'string')?output:util.inspect(output);
|
||||
var severity = node.severity;
|
||||
if (st.length > 32) { st = st.substr(0,32) + "..."; }
|
||||
node.status({fill:colors[severity], shape:"dot", text:st});
|
||||
}
|
||||
if (node.active) {
|
||||
if (node.tosidebar == true) {
|
||||
sendDebug(debugMsg);
|
||||
|
@@ -89,7 +89,8 @@
|
||||
node: n,
|
||||
label: label,
|
||||
sublabel: sublabel,
|
||||
selected: isChecked
|
||||
selected: isChecked,
|
||||
checkbox: true
|
||||
};
|
||||
items.push(nodeItemMap[n.id]);
|
||||
});
|
||||
|
@@ -104,7 +104,8 @@
|
||||
node: n,
|
||||
label: label,
|
||||
sublabel: sublabel,
|
||||
selected: isChecked
|
||||
selected: isChecked,
|
||||
checkbox: true
|
||||
};
|
||||
items.push(nodeItemMap[n.id]);
|
||||
});
|
||||
|
@@ -92,7 +92,8 @@
|
||||
node: n,
|
||||
label: label,
|
||||
sublabel: sublabel,
|
||||
selected: isChecked
|
||||
selected: isChecked,
|
||||
checkbox: true
|
||||
};
|
||||
items.push(nodeItemMap[n.id]);
|
||||
});
|
||||
|
@@ -83,7 +83,8 @@
|
||||
id: n.id,
|
||||
node: n,
|
||||
label: n.name||n.id,
|
||||
selected: isChecked
|
||||
selected: isChecked,
|
||||
checkbox: true
|
||||
})
|
||||
}
|
||||
});
|
||||
|
@@ -457,7 +457,7 @@ RED.debug = (function() {
|
||||
var metaRow = $('<div class="red-ui-debug-msg-meta"></div>').appendTo(msg);
|
||||
$('<span class="red-ui-debug-msg-date">'+ getTimestamp()+'</span>').appendTo(metaRow);
|
||||
if (sourceNode) {
|
||||
$('<a>',{href:"#",class:"red-ui-debug-msg-name"}).text('node: '+sanitize(o.name||sourceNode.name||sourceNode.id))
|
||||
$('<a>',{href:"#",class:"red-ui-debug-msg-name"}).text('node: '+(o.name||sourceNode.name||sourceNode.id))
|
||||
.appendTo(metaRow)
|
||||
.on("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
|
@@ -4,19 +4,54 @@
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||
<div style="display: inline-block; width: calc(100% - 105px)"><input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></div>
|
||||
</div>
|
||||
<div class="form-row" style="margin-bottom: 0px;">
|
||||
<label for="node-input-func"><i class="fa fa-wrench"></i> <span data-i18n="function.label.function"></span></label>
|
||||
<input type="hidden" id="node-input-func" autofocus="autofocus">
|
||||
<input type="hidden" id="node-input-noerr">
|
||||
|
||||
<div class="form-row">
|
||||
<ul style="min-width: 600px; margin-bottom: 20px;" id="func-tabs"></ul>
|
||||
</div>
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="position: absolute; right:0; bottom:calc(100% + 3px);"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-func-editor" ></div>
|
||||
</div>
|
||||
<div class="form-row" style="margin-bottom: 0px">
|
||||
<label for="node-input-outputs"><i class="fa fa-random"></i> <span data-i18n="function.label.outputs"></span></label>
|
||||
<input id="node-input-outputs" style="width: 60px;" value="1">
|
||||
|
||||
<div id="func-tabs-content" style="min-height: calc(100% - 95px);">
|
||||
|
||||
<div id="func-tab-init" style="display:none">
|
||||
<div class="form-row" style="margin-bottom: 0px;">
|
||||
<input type="hidden" id="node-input-initialize" autofocus="autofocus">
|
||||
</div>
|
||||
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-init-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 250px; min-height:150px; margin-top: 30px;" class="node-text-editor" id="node-input-init-editor" ></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="func-tab-body" style="display:none">
|
||||
<div class="form-row" style="margin-bottom: 0px;">
|
||||
<input type="hidden" id="node-input-func" autofocus="autofocus">
|
||||
<input type="hidden" id="node-input-noerr">
|
||||
</div>
|
||||
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 220px; min-height:120px; margin-top: 30px;" class="node-text-editor" id="node-input-func-editor" ></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row" style="margin-bottom: 0px">
|
||||
<label for="node-input-outputs"><i class="fa fa-random"></i> <span data-i18n="function.label.outputs"></span></label>
|
||||
<input id="node-input-outputs" style="width: 60px;" value="1">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="func-tab-finalize" style="display:none">
|
||||
<div class="form-row" style="margin-bottom: 0px;">
|
||||
<input type="hidden" id="node-input-finalize" autofocus="autofocus">
|
||||
</div>
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-finalize-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 250px; min-height:150px; margin-top: 30px;" class="node-text-editor" id="node-input-finalize-editor" ></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -27,7 +62,9 @@
|
||||
name: {value:""},
|
||||
func: {value:"\nreturn msg;"},
|
||||
outputs: {value:1},
|
||||
noerr: {value:0,required:true,validate:function(v) { return !v; }}
|
||||
noerr: {value:0,required:true,validate:function(v) { return !v; }},
|
||||
initialize: {value:""},
|
||||
finalize: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
@@ -40,6 +77,28 @@
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var that = this;
|
||||
|
||||
var tabs = RED.tabs.create({
|
||||
id: "func-tabs",
|
||||
onchange: function(tab) {
|
||||
$("#func-tabs-content").children().hide();
|
||||
$("#" + tab.id).show();
|
||||
}
|
||||
});
|
||||
tabs.addTab({
|
||||
id: "func-tab-init",
|
||||
label: that._("function.label.initialize")
|
||||
});
|
||||
tabs.addTab({
|
||||
id: "func-tab-body",
|
||||
label: that._("function.label.function")
|
||||
});
|
||||
tabs.addTab({
|
||||
id: "func-tab-finalize",
|
||||
label: that._("function.label.finalize")
|
||||
});
|
||||
tabs.activateTab("func-tab-body");
|
||||
|
||||
$( "#node-input-outputs" ).spinner({
|
||||
min:0,
|
||||
change: function(event, ui) {
|
||||
@@ -50,75 +109,145 @@
|
||||
}
|
||||
});
|
||||
|
||||
this.editor = RED.editor.createEditor({
|
||||
id: 'node-input-func-editor',
|
||||
mode: 'ace/mode/nrjavascript',
|
||||
value: $("#node-input-func").val(),
|
||||
globals: {
|
||||
msg:true,
|
||||
context:true,
|
||||
RED: true,
|
||||
util: true,
|
||||
flow: true,
|
||||
global: true,
|
||||
console: true,
|
||||
Buffer: true,
|
||||
setTimeout: true,
|
||||
clearTimeout: true,
|
||||
setInterval: true,
|
||||
clearInterval: true
|
||||
var buildEditor = function(id, value, defaultValue) {
|
||||
var editor = RED.editor.createEditor({
|
||||
id: id,
|
||||
mode: 'ace/mode/nrjavascript',
|
||||
value: value || defaultValue || "",
|
||||
globals: {
|
||||
msg:true,
|
||||
context:true,
|
||||
RED: true,
|
||||
util: true,
|
||||
flow: true,
|
||||
global: true,
|
||||
console: true,
|
||||
Buffer: true,
|
||||
setTimeout: true,
|
||||
clearTimeout: true,
|
||||
setInterval: true,
|
||||
clearInterval: true
|
||||
}
|
||||
});
|
||||
if (defaultValue && value === "") {
|
||||
editor.moveCursorTo(defaultValue.split("\n").length - 1, 0);
|
||||
}
|
||||
});
|
||||
return editor;
|
||||
}
|
||||
this.initEditor = buildEditor('node-input-init-editor',$("#node-input-initialize").val(),RED._("node-red:function.text.initialize"))
|
||||
this.editor = buildEditor('node-input-func-editor',$("#node-input-func").val())
|
||||
this.finalizeEditor = buildEditor('node-input-finalize-editor',$("#node-input-finalize").val(),RED._("node-red:function.text.finalize"))
|
||||
|
||||
RED.library.create({
|
||||
url: "functions", // where to get the data from
|
||||
type: "function", // the type of object the library is for
|
||||
editor: this.editor, // the field name the main text body goes to
|
||||
nodeInfoEditor: this.nodeInfoEditor,
|
||||
mode: "ace/mode/nrjavascript",
|
||||
fields: ['name', 'outputs', 'info'],
|
||||
ext: "js"
|
||||
url:"functions", // where to get the data from
|
||||
type:"function", // the type of object the library is for
|
||||
editor:this.editor, // the field name the main text body goes to
|
||||
mode:"ace/mode/nrjavascript",
|
||||
fields:[
|
||||
'name', 'outputs',
|
||||
{
|
||||
name: 'initialize',
|
||||
get: function() {
|
||||
return that.initEditor.getValue();
|
||||
},
|
||||
set: function(v) {
|
||||
that.initEditor.setValue(v||RED._("node-red:function.text.initialize"), -1);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'finalize',
|
||||
get: function() {
|
||||
return that.finalizeEditor.getValue();
|
||||
},
|
||||
set: function(v) {
|
||||
that.finalizeEditor.setValue(v||RED._("node-red:function.text.finalize"), -1);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'info',
|
||||
get: function() {
|
||||
return that.infoEditor.getValue();
|
||||
},
|
||||
set: function(v) {
|
||||
that.infoEditor.setValue(v||"", -1);
|
||||
}
|
||||
}
|
||||
],
|
||||
ext:"js"
|
||||
});
|
||||
this.editor.focus();
|
||||
|
||||
RED.popover.tooltip($("#node-function-expand-js"), RED._("node-red:common.label.expand"));
|
||||
|
||||
$("#node-function-expand-js").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var value = that.editor.getValue();
|
||||
RED.editor.editJavaScript({
|
||||
value: value,
|
||||
width: "Infinity",
|
||||
cursor: that.editor.getCursorPosition(),
|
||||
mode: "ace/mode/nrjavascript",
|
||||
complete: function(v,cursor) {
|
||||
that.editor.setValue(v, -1);
|
||||
that.editor.gotoLine(cursor.row+1,cursor.column,false);
|
||||
setTimeout(function() {
|
||||
that.editor.focus();
|
||||
},300);
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
oneditsave: function() {
|
||||
var annot = this.editor.getSession().getAnnotations();
|
||||
this.noerr = 0;
|
||||
$("#node-input-noerr").val(0);
|
||||
for (var k=0; k < annot.length; k++) {
|
||||
//console.log(annot[k].type,":",annot[k].text, "on line", annot[k].row);
|
||||
if (annot[k].type === "error") {
|
||||
$("#node-input-noerr").val(annot.length);
|
||||
this.noerr = annot.length;
|
||||
var expandButtonClickHandler = function(editor) {
|
||||
return function(e) {
|
||||
e.preventDefault();
|
||||
var value = editor.getValue();
|
||||
RED.editor.editJavaScript({
|
||||
value: value,
|
||||
width: "Infinity",
|
||||
cursor: editor.getCursorPosition(),
|
||||
mode: "ace/mode/nrjavascript",
|
||||
complete: function(v,cursor) {
|
||||
editor.setValue(v, -1);
|
||||
editor.gotoLine(cursor.row+1,cursor.column,false);
|
||||
setTimeout(function() {
|
||||
editor.focus();
|
||||
},300);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
$("#node-input-func").val(this.editor.getValue());
|
||||
this.editor.destroy();
|
||||
delete this.editor;
|
||||
$("#node-init-expand-js").on("click", expandButtonClickHandler(this.initEditor));
|
||||
$("#node-function-expand-js").on("click", expandButtonClickHandler(this.editor));
|
||||
$("#node-finalize-expand-js").on("click", expandButtonClickHandler(this.finalizeEditor));
|
||||
|
||||
RED.popover.tooltip($("#node-init-expand-js"), RED._("node-red:common.label.expand"));
|
||||
RED.popover.tooltip($("#node-function-expand-js"), RED._("node-red:common.label.expand"));
|
||||
RED.popover.tooltip($("#node-finalize-expand-js"), RED._("node-red:common.label.expand"));
|
||||
|
||||
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
var noerr = 0;
|
||||
$("#node-input-noerr").val(0);
|
||||
|
||||
var disposeEditor = function(editorName,targetName,defaultValue) {
|
||||
var editor = node[editorName];
|
||||
var annot = editor.getSession().getAnnotations();
|
||||
for (var k=0; k < annot.length; k++) {
|
||||
if (annot[k].type === "error") {
|
||||
noerr += annot.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var val = editor.getValue();
|
||||
if (defaultValue && val == defaultValue) {
|
||||
val = "";
|
||||
}
|
||||
editor.destroy();
|
||||
delete node[editorName];
|
||||
$("#"+targetName).val(val);
|
||||
}
|
||||
disposeEditor("editor","node-input-func");
|
||||
disposeEditor("initEditor","node-input-initialize", RED._("node-red:function.text.initialize"));
|
||||
disposeEditor("finalizeEditor","node-input-finalize", RED._("node-red:function.text.finalize"));
|
||||
|
||||
$("#node-input-noerr").val(noerr);
|
||||
this.noerr = noerr;
|
||||
|
||||
},
|
||||
oneditcancel: function() {
|
||||
this.editor.destroy();
|
||||
delete this.editor;
|
||||
var node = this;
|
||||
|
||||
node.editor.destroy();
|
||||
delete node.editor;
|
||||
|
||||
node.initEditor.destroy();
|
||||
delete node.initEditor;
|
||||
|
||||
node.finalizeEditor.destroy();
|
||||
delete node.finalizeEditor;
|
||||
},
|
||||
oneditresize: function(size) {
|
||||
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
|
||||
@@ -130,6 +259,16 @@
|
||||
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
||||
$(".node-text-editor").css("height",height+"px");
|
||||
this.editor.resize();
|
||||
|
||||
var height = size.height;
|
||||
$("#node-input-init-editor").css("height", (height -105)+"px");
|
||||
$("#node-input-func-editor").css("height", (height -145)+"px");
|
||||
$("#node-input-finalize-editor").css("height", (height -105)+"px");
|
||||
|
||||
this.initEditor.resize();
|
||||
this.editor.resize();
|
||||
this.finalizeEditor.resize();
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -57,17 +57,50 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
|
||||
function createVMOpt(node, kind) {
|
||||
var opt = {
|
||||
filename: 'Function node'+kind+':'+node.id+(node.name?' ['+node.name+']':''), // filename for stack traces
|
||||
displayErrors: true
|
||||
// Using the following options causes node 4/6 to not include the line number
|
||||
// in the stack output. So don't use them.
|
||||
// lineOffset: -11, // line number offset to be used for stack traces
|
||||
// columnOffset: 0, // column number offset to be used for stack traces
|
||||
};
|
||||
return opt;
|
||||
}
|
||||
|
||||
function updateErrorInfo(err) {
|
||||
if (err.stack) {
|
||||
var stack = err.stack.toString();
|
||||
var m = /^([^:]+):([^:]+):(\d+).*/.exec(stack);
|
||||
if (m) {
|
||||
var line = parseInt(m[3]) -1;
|
||||
var kind = "body:";
|
||||
if (/setup/.exec(m[1])) {
|
||||
kind = "setup:";
|
||||
}
|
||||
if (/cleanup/.exec(m[1])) {
|
||||
kind = "cleanup:";
|
||||
}
|
||||
err.message += " ("+kind+"line "+line+")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function FunctionNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
this.name = n.name;
|
||||
this.func = n.func;
|
||||
node.name = n.name;
|
||||
node.func = n.func;
|
||||
node.ini = n.initialize ? n.initialize : "";
|
||||
node.fin = n.finalize ? n.finalize : "";
|
||||
|
||||
var handleNodeDoneCall = true;
|
||||
|
||||
// Check to see if the Function appears to call `node.done()`. If so,
|
||||
// we will assume it is well written and does actually call node.done().
|
||||
// Otherwise, we will call node.done() after the function returns regardless.
|
||||
if (/node\.done\s*\(\s*\)/.test(this.func)) {
|
||||
if (/node\.done\s*\(\s*\)/.test(node.func)) {
|
||||
handleNodeDoneCall = false;
|
||||
}
|
||||
|
||||
@@ -87,11 +120,13 @@ module.exports = function(RED) {
|
||||
"send:function(msgs,cloneMsg){ __node__.send(__send__,__msgid__,msgs,cloneMsg);},"+
|
||||
"done:__done__"+
|
||||
"};\n"+
|
||||
this.func+"\n"+
|
||||
node.func+"\n"+
|
||||
"})(msg,send,done);";
|
||||
this.topic = n.topic;
|
||||
this.outstandingTimers = [];
|
||||
this.outstandingIntervals = [];
|
||||
var finScript = null;
|
||||
var finOpt = null;
|
||||
node.topic = n.topic;
|
||||
node.outstandingTimers = [];
|
||||
node.outstandingIntervals = [];
|
||||
var sandbox = {
|
||||
console:console,
|
||||
util:util,
|
||||
@@ -182,12 +217,12 @@ module.exports = function(RED) {
|
||||
arguments[0] = function() {
|
||||
sandbox.clearTimeout(timerId);
|
||||
try {
|
||||
func.apply(this,arguments);
|
||||
func.apply(node,arguments);
|
||||
} catch(err) {
|
||||
node.error(err,{});
|
||||
}
|
||||
};
|
||||
timerId = setTimeout.apply(this,arguments);
|
||||
timerId = setTimeout.apply(node,arguments);
|
||||
node.outstandingTimers.push(timerId);
|
||||
return timerId;
|
||||
},
|
||||
@@ -203,12 +238,12 @@ module.exports = function(RED) {
|
||||
var timerId;
|
||||
arguments[0] = function() {
|
||||
try {
|
||||
func.apply(this,arguments);
|
||||
func.apply(node,arguments);
|
||||
} catch(err) {
|
||||
node.error(err,{});
|
||||
}
|
||||
};
|
||||
timerId = setInterval.apply(this,arguments);
|
||||
timerId = setInterval.apply(node,arguments);
|
||||
node.outstandingIntervals.push(timerId);
|
||||
return timerId;
|
||||
},
|
||||
@@ -226,35 +261,46 @@ module.exports = function(RED) {
|
||||
sandbox.setTimeout(function(){ resolve(value); }, after);
|
||||
});
|
||||
};
|
||||
sandbox.promisify = util.promisify;
|
||||
}
|
||||
var context = vm.createContext(sandbox);
|
||||
try {
|
||||
this.script = vm.createScript(functionText, {
|
||||
filename: 'Function node:'+this.id+(this.name?' ['+this.name+']':''), // filename for stack traces
|
||||
displayErrors: true
|
||||
// Using the following options causes node 4/6 to not include the line number
|
||||
// in the stack output. So don't use them.
|
||||
// lineOffset: -11, // line number offset to be used for stack traces
|
||||
// columnOffset: 0, // column number offset to be used for stack traces
|
||||
});
|
||||
this.on("input", function(msg,send,done) {
|
||||
var iniScript = null;
|
||||
var iniOpt = null;
|
||||
if (node.ini && (node.ini !== "")) {
|
||||
var iniText = "(async function () {\n"+node.ini +"\n})();";
|
||||
iniOpt = createVMOpt(node, " setup");
|
||||
iniScript = new vm.Script(iniText, iniOpt);
|
||||
}
|
||||
node.script = vm.createScript(functionText, createVMOpt(node, ""));
|
||||
if (node.fin && (node.fin !== "")) {
|
||||
var finText = "(function () {\n"+node.fin +"\n})();";
|
||||
finOpt = createVMOpt(node, " cleanup");
|
||||
finScript = new vm.Script(finText, finOpt);
|
||||
}
|
||||
var promise = Promise.resolve();
|
||||
if (iniScript) {
|
||||
promise = iniScript.runInContext(context, iniOpt);
|
||||
}
|
||||
|
||||
function processMessage(msg, send, done) {
|
||||
try {
|
||||
var start = process.hrtime();
|
||||
context.msg = msg;
|
||||
context.send = send;
|
||||
context.done = done;
|
||||
|
||||
this.script.runInContext(context);
|
||||
sendResults(this,send,msg._msgid,context.results,false);
|
||||
node.script.runInContext(context);
|
||||
sendResults(node,send,msg._msgid,context.results,false);
|
||||
if (handleNodeDoneCall) {
|
||||
done();
|
||||
}
|
||||
|
||||
var duration = process.hrtime(start);
|
||||
var converted = Math.floor((duration[0] * 1e9 + duration[1])/10000)/100;
|
||||
this.metric("duration", msg, converted);
|
||||
node.metric("duration", msg, converted);
|
||||
if (process.env.NODE_RED_FUNCTION_TIME) {
|
||||
this.status({fill:"yellow",shape:"dot",text:""+converted});
|
||||
node.status({fill:"yellow",shape:"dot",text:""+converted});
|
||||
}
|
||||
} catch(err) {
|
||||
if ((typeof err === "object") && err.hasOwnProperty("stack")) {
|
||||
@@ -295,22 +341,66 @@ module.exports = function(RED) {
|
||||
done(JSON.stringify(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const RESOLVING = 0;
|
||||
const RESOLVED = 1;
|
||||
const ERROR = 2;
|
||||
var state = RESOLVING;
|
||||
var messages = [];
|
||||
|
||||
node.on("input", function(msg,send,done) {
|
||||
if(state === RESOLVING) {
|
||||
messages.push({msg:msg, send:send, done:done});
|
||||
}
|
||||
else if(state === RESOLVED) {
|
||||
processMessage(msg, send, done);
|
||||
}
|
||||
});
|
||||
this.on("close", function() {
|
||||
node.on("close", function() {
|
||||
if (finScript) {
|
||||
try {
|
||||
finScript.runInContext(context, finOpt);
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
}
|
||||
}
|
||||
while (node.outstandingTimers.length > 0) {
|
||||
clearTimeout(node.outstandingTimers.pop());
|
||||
}
|
||||
while (node.outstandingIntervals.length > 0) {
|
||||
clearInterval(node.outstandingIntervals.pop());
|
||||
}
|
||||
this.status({});
|
||||
node.status({});
|
||||
});
|
||||
} catch(err) {
|
||||
|
||||
promise.then(function (v) {
|
||||
var msgs = messages;
|
||||
messages = [];
|
||||
while (msgs.length > 0) {
|
||||
msgs.forEach(function (s) {
|
||||
processMessage(s.msg, s.send, s.done);
|
||||
});
|
||||
msgs = messages;
|
||||
messages = [];
|
||||
}
|
||||
state = RESOLVED;
|
||||
}).catch((error) => {
|
||||
messages = [];
|
||||
state = ERROR;
|
||||
node.error(error);
|
||||
});
|
||||
|
||||
}
|
||||
catch(err) {
|
||||
// eg SyntaxError - which v8 doesn't include line number information
|
||||
// so we can't do better than this
|
||||
this.error(err);
|
||||
updateErrorInfo(err);
|
||||
node.error(err);
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("function",FunctionNode);
|
||||
RED.library.register("functions");
|
||||
};
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
|
||||
<script type="text/html" data-template-name="change">
|
||||
<style>
|
||||
ol#node-input-rule-container .red-ui-typedInput-container {
|
||||
flex:1;
|
||||
}
|
||||
</style>
|
||||
<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">
|
||||
@@ -76,11 +81,6 @@
|
||||
var replace = this._("change.action.replace");
|
||||
var regex = this._("change.label.regex");
|
||||
|
||||
function resizeRule(rule) {
|
||||
var newWidth = rule.width();
|
||||
rule.find('.red-ui-typedInput').typedInput("width",newWidth-130);
|
||||
|
||||
}
|
||||
$('#node-input-rule-container').css('min-height','150px').css('min-width','450px').editableList({
|
||||
addItem: function(container,i,opt) {
|
||||
var rule = opt;
|
||||
@@ -106,10 +106,11 @@
|
||||
overflow: 'hidden',
|
||||
whiteSpace: 'nowrap'
|
||||
});
|
||||
var row1 = $('<div/>').appendTo(container);
|
||||
var row2 = $('<div/>',{style:"margin-top:8px;"}).appendTo(container);
|
||||
var row3 = $('<div/>',{style:"margin-top:8px;"}).appendTo(container);
|
||||
var row4 = $('<div/>',{style:"margin-top:8px;"}).appendTo(container);
|
||||
let fragment = document.createDocumentFragment();
|
||||
var row1 = $('<div/>',{style:"display:flex;"}).appendTo(fragment);
|
||||
var row2 = $('<div/>',{style:"display:flex;margin-top:8px;"}).appendTo(fragment);
|
||||
var row3 = $('<div/>',{style:"margin-top:8px;"}).appendTo(fragment);
|
||||
var row4 = $('<div/>',{style:"display:flex;margin-top:8px;"}).appendTo(fragment);
|
||||
|
||||
var selectField = $('<select/>',{class:"node-input-rule-type",style:"width:110px; margin-right:10px;"}).appendTo(row1);
|
||||
var selectOptions = [{v:"set",l:set},{v:"change",l:change},{v:"delete",l:del},{v:"move",l:move}];
|
||||
@@ -124,41 +125,82 @@
|
||||
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||
.text(to)
|
||||
.appendTo(row2);
|
||||
var propertyValue = $('<input/>',{class:"node-input-rule-property-value",type:"text"})
|
||||
|
||||
function createPropertyValue() {
|
||||
return $('<input/>',{class:"node-input-rule-property-value",type:"text"})
|
||||
.appendTo(row2)
|
||||
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json','bin','date','jsonata','env']});
|
||||
}
|
||||
|
||||
var row3_1 = $('<div/>').appendTo(row3);
|
||||
var row3_1 = $('<div/>', {style:"display:flex;"}).appendTo(row3);
|
||||
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||
.text(search)
|
||||
.appendTo(row3_1);
|
||||
var fromValue = $('<input/>',{class:"node-input-rule-property-search-value",type:"text"})
|
||||
|
||||
function createFromValue() {
|
||||
return $('<input/>',{class:"node-input-rule-property-search-value",type:"text"})
|
||||
.appendTo(row3_1)
|
||||
.typedInput({default:'str',types:['msg','flow','global','str','re','num','bool','env']});
|
||||
}
|
||||
|
||||
var row3_2 = $('<div/>',{style:"margin-top:8px;"}).appendTo(row3);
|
||||
var row3_2 = $('<div/>',{style:"display:flex;margin-top:8px;"}).appendTo(row3);
|
||||
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||
.text(replace)
|
||||
.appendTo(row3_2);
|
||||
var toValue = $('<input/>',{class:"node-input-rule-property-replace-value",type:"text"})
|
||||
|
||||
function createToValue() {
|
||||
return $('<input/>',{class:"node-input-rule-property-replace-value",type:"text"})
|
||||
.appendTo(row3_2)
|
||||
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json','bin','env']});
|
||||
}
|
||||
|
||||
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||
.text(to)
|
||||
.appendTo(row4);
|
||||
var moveValue = $('<input/>',{class:"node-input-rule-property-move-value",type:"text"})
|
||||
|
||||
function createMoveValue() {
|
||||
return $('<input/>',{class:"node-input-rule-property-move-value",type:"text"})
|
||||
.appendTo(row4)
|
||||
.typedInput({default:'msg',types:['msg','flow','global']});
|
||||
}
|
||||
|
||||
let propertyValue = null;
|
||||
let fromValue = null;
|
||||
let toValue = null;
|
||||
let moveValue = null;
|
||||
|
||||
selectField.on("change", function() {
|
||||
var width = $("#node-input-rule-container").width();
|
||||
var type = $(this).val();
|
||||
if (propertyValue) {
|
||||
propertyValue.typedInput('hide');
|
||||
}
|
||||
if (fromValue) {
|
||||
fromValue.typedInput('hide');
|
||||
}
|
||||
if (toValue) {
|
||||
toValue.typedInput('hide');
|
||||
}
|
||||
if (moveValue) {
|
||||
moveValue.typedInput('hide');
|
||||
}
|
||||
|
||||
if (type == "set") {
|
||||
if(!propertyValue) {
|
||||
propertyValue = createPropertyValue();
|
||||
}
|
||||
propertyValue.typedInput('show');
|
||||
row2.show();
|
||||
row3.hide();
|
||||
row4.hide();
|
||||
} else if (type == "change") {
|
||||
if(!fromValue) {
|
||||
fromValue = createFromValue();
|
||||
}
|
||||
fromValue.typedInput('show');
|
||||
if(!toValue) {
|
||||
toValue = createToValue();
|
||||
}
|
||||
toValue.typedInput('show');
|
||||
row2.hide();
|
||||
row3.show();
|
||||
row4.hide();
|
||||
@@ -167,30 +209,48 @@
|
||||
row3.hide();
|
||||
row4.hide();
|
||||
} else if (type == "move") {
|
||||
if(!moveValue) {
|
||||
moveValue = createMoveValue();
|
||||
}
|
||||
moveValue.typedInput('show');
|
||||
row2.hide();
|
||||
row3.hide();
|
||||
row4.show();
|
||||
}
|
||||
resizeRule(container);
|
||||
});
|
||||
|
||||
selectField.val(rule.t);
|
||||
propertyName.typedInput('value',rule.p);
|
||||
propertyName.typedInput('type',rule.pt);
|
||||
propertyValue.typedInput('value',rule.to);
|
||||
propertyValue.typedInput('type',rule.tot);
|
||||
moveValue.typedInput('value',rule.to);
|
||||
moveValue.typedInput('type',rule.tot);
|
||||
fromValue.typedInput('value',rule.from);
|
||||
fromValue.typedInput('type',rule.fromt);
|
||||
toValue.typedInput('value',rule.to);
|
||||
toValue.typedInput('type',rule.tot);
|
||||
if (rule.t == "set") {
|
||||
if(!propertyValue) {
|
||||
propertyValue = createPropertyValue();
|
||||
}
|
||||
propertyValue.typedInput('value',rule.to);
|
||||
propertyValue.typedInput('type',rule.tot);
|
||||
}
|
||||
if (rule.t == "move") {
|
||||
if(!moveValue) {
|
||||
moveValue = createMoveValue();
|
||||
}
|
||||
moveValue.typedInput('value',rule.to);
|
||||
moveValue.typedInput('type',rule.tot);
|
||||
}
|
||||
if (rule.t == "change") {
|
||||
if(!fromValue) {
|
||||
fromValue = createFromValue();
|
||||
}
|
||||
fromValue.typedInput('value',rule.from);
|
||||
fromValue.typedInput('type',rule.fromt);
|
||||
if (!toValue) {
|
||||
toValue = createToValue();
|
||||
}
|
||||
toValue.typedInput('value',rule.to);
|
||||
toValue.typedInput('type',rule.tot);
|
||||
}
|
||||
selectField.change();
|
||||
|
||||
var newWidth = $("#node-input-rule-container").width();
|
||||
resizeRule(container);
|
||||
container[0].appendChild(fragment);
|
||||
},
|
||||
resizeItem: resizeRule,
|
||||
removable: true,
|
||||
sortable: true
|
||||
});
|
||||
|
@@ -18,7 +18,7 @@
|
||||
<div class="form-row">
|
||||
<label data-i18n="trigger.send" for="node-input-op1"></label>
|
||||
<input type="hidden" id="node-input-op1type">
|
||||
<input style="width: 70%" type="text" id="node-input-op1" placeholder="1">
|
||||
<input style="width:70%" type="text" id="node-input-op1" placeholder="1">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label data-i18n="trigger.then"></label>
|
||||
@@ -40,13 +40,17 @@
|
||||
</div>
|
||||
<div class="form-row node-type-wait">
|
||||
<label></label>
|
||||
<input type="checkbox" id="node-input-extend" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
|
||||
<input type="checkbox" id="node-input-extend" style="margin-left:0px; vertical-align:top; width:auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
|
||||
</div>
|
||||
<div class="form-row node-type-wait">
|
||||
<label data-i18n="trigger.then-send"></label>
|
||||
<input type="hidden" id="node-input-op2type">
|
||||
<input style="width: 70%" type="text" id="node-input-op2" placeholder="0">
|
||||
<input style="width:70%" type="text" id="node-input-op2" placeholder="0">
|
||||
</div>
|
||||
<div class="form-row" id="node-second-output">
|
||||
<label></label>
|
||||
<input type="checkbox" id="node-input-second" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-second" data-i18n="trigger.second"></label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label data-i18n="trigger.label.reset" style="width:auto"></label>
|
||||
<div style="display:inline-block; width:70%;vertical-align:top">
|
||||
@@ -58,10 +62,13 @@
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
<label data-i18n="trigger.for" for="node-input-bytopic"></label>
|
||||
<select id="node-input-bytopic">
|
||||
<select id="node-input-bytopic" style="width:120px;">
|
||||
<option value="all" data-i18n="trigger.alltopics"></option>
|
||||
<option value="topic" data-i18n="trigger.bytopics"></option>
|
||||
</select>
|
||||
<span class="form-row" id="node-stream-topic">
|
||||
<input type="text" id="node-input-topic" style="width:46%;"/>
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||
@@ -74,6 +81,7 @@
|
||||
category: 'function',
|
||||
color:"#E6E0F8",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
op1: {value:"1", validate: RED.validators.typedInput("op1type")},
|
||||
op2: {value:"0", validate: RED.validators.typedInput("op2type")},
|
||||
op1type: {value:"val"},
|
||||
@@ -82,8 +90,9 @@
|
||||
extend: {value:"false"},
|
||||
units: {value:"ms"},
|
||||
reset: {value:""},
|
||||
bytopic: {value: "all"},
|
||||
name: {value:""}
|
||||
bytopic: {value:"all"},
|
||||
topic: {value:"topic",required:true},
|
||||
outputs: {value:1}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
@@ -103,17 +112,48 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var that = this;
|
||||
if (this.topic === undefined) { $("#node-input-topic").val("topic"); }
|
||||
$("#node-input-topic").typedInput({default:'msg',types:['msg']});
|
||||
$("#node-input-bytopic").on("change", function() {
|
||||
if ($("#node-input-bytopic").val() === "all") {
|
||||
$("#node-stream-topic").hide();
|
||||
} else {
|
||||
$("#node-stream-topic").show();
|
||||
}
|
||||
});
|
||||
|
||||
if (this.outputs == 2) { $("#node-input-second").prop('checked', true) }
|
||||
else { $("#node-input-second").prop('checked', false) }
|
||||
|
||||
$("#node-input-second").change(function() {
|
||||
if ($("#node-input-second").is(":checked")) {
|
||||
that.outputs = 2;
|
||||
}
|
||||
else {
|
||||
that.outputs = 1;
|
||||
}
|
||||
});
|
||||
$("#node-then-type").on("change", function() {
|
||||
if ($(this).val() == "block") {
|
||||
$(".node-type-wait").hide();
|
||||
$(".node-type-duration").hide();
|
||||
$("#node-second-output").hide();
|
||||
$("#node-input-second").prop('checked', false);
|
||||
that.outputs = 1;
|
||||
}
|
||||
else if ($(this).val() == "loop") {
|
||||
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
|
||||
$(".node-type-wait").hide();
|
||||
$(".node-type-duration").show();
|
||||
$("#node-second-output").hide();
|
||||
$("#node-input-second").prop('checked', false);
|
||||
that.outputs = 1;
|
||||
} else {
|
||||
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
|
||||
$(".node-type-wait").show();
|
||||
$(".node-type-duration").show();
|
||||
$("#node-second-output").show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -176,8 +216,6 @@
|
||||
if ($("#node-then-type").val() == "loop") {
|
||||
$("#node-input-duration").val($("#node-input-duration").val() * -1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -24,6 +24,8 @@ module.exports = function(RED) {
|
||||
this.op2 = n.op2 || "0";
|
||||
this.op1type = n.op1type || "str";
|
||||
this.op2type = n.op2type || "str";
|
||||
this.second = (n.outputs == 2) ? true : false;
|
||||
this.topic = n.topic || "topic";
|
||||
|
||||
if (this.op1type === 'val') {
|
||||
if (this.op1 === 'true' || this.op1 === 'false') {
|
||||
@@ -76,6 +78,7 @@ module.exports = function(RED) {
|
||||
var node = this;
|
||||
node.topics = {};
|
||||
|
||||
var npay = {};
|
||||
var pendingMessages = [];
|
||||
var activeMessagePromise = null;
|
||||
var processMessageQueue = function(msg) {
|
||||
@@ -106,14 +109,19 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
|
||||
var npay;
|
||||
this.on('input', function(msg) {
|
||||
if (node.op2type === "payl") { npay = RED.util.cloneMessage(msg); }
|
||||
processMessageQueue(msg);
|
||||
});
|
||||
|
||||
var stat = function() {
|
||||
var l = Object.keys(node.topics).length;
|
||||
if (l === 0) { return {} }
|
||||
else if (l === 1) { return {fill:"blue",shape:"dot"} }
|
||||
else return {fill:"blue",shape:"dot",text:l};
|
||||
}
|
||||
|
||||
var processMessage = function(msg) {
|
||||
var topic = msg.topic || "_none";
|
||||
var topic = RED.util.getMessageProperty(msg,node.topic) || "_none";
|
||||
var promise;
|
||||
if (node.bytopic === "all") { topic = "_none"; }
|
||||
node.topics[topic] = node.topics[topic] || {};
|
||||
@@ -121,9 +129,10 @@ module.exports = function(RED) {
|
||||
if (node.loop === true) { clearInterval(node.topics[topic].tout); }
|
||||
else { clearTimeout(node.topics[topic].tout); }
|
||||
delete node.topics[topic];
|
||||
node.status({});
|
||||
node.status(stat());
|
||||
}
|
||||
else {
|
||||
if (node.op2type === "payl") { npay[topic] = RED.util.cloneMessage(msg); }
|
||||
if (((!node.topics[topic].tout) && (node.topics[topic].tout !== 0)) || (node.loop === true)) {
|
||||
promise = Promise.resolve();
|
||||
if (node.op2type === "pay") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
|
||||
@@ -188,23 +197,30 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
promise.then(() => {
|
||||
msg2.payload = node.topics[topic].m2;
|
||||
if (node.op2type === "payl") {
|
||||
if (node.second === true) { node.send([null,npay[topic]]); }
|
||||
else { node.send(npay[topic]); }
|
||||
delete npay[topic];
|
||||
}
|
||||
else {
|
||||
msg2.payload = node.topics[topic].m2;
|
||||
if (node.second === true) { node.send([null,msg2]); }
|
||||
else { node.send(msg2); }
|
||||
}
|
||||
delete node.topics[topic];
|
||||
if (node.op2type === "payl") { node.send(npay); }
|
||||
else { node.send(msg2); }
|
||||
node.status({});
|
||||
node.status(stat());
|
||||
}).catch(err => {
|
||||
node.error(err);
|
||||
});
|
||||
} else {
|
||||
delete node.topics[topic];
|
||||
node.status({});
|
||||
node.status(stat());
|
||||
}
|
||||
|
||||
}, node.duration);
|
||||
}
|
||||
}
|
||||
node.status({fill:"blue",shape:"dot",text:" "});
|
||||
node.status(stat());
|
||||
if (node.op1type !== "nul") { node.send(RED.util.cloneMessage(msg)); }
|
||||
});
|
||||
});
|
||||
@@ -240,8 +256,9 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
delete node.topics[topic];
|
||||
node.status({});
|
||||
node.send(msg2);
|
||||
node.status(stat());
|
||||
if (node.second === true) { node.send([null,msg2]); }
|
||||
else { node.send(msg2); }
|
||||
}).catch(err => {
|
||||
node.error(err);
|
||||
});
|
||||
@@ -262,7 +279,7 @@ module.exports = function(RED) {
|
||||
delete node.topics[t];
|
||||
}
|
||||
}
|
||||
node.status({});
|
||||
node.status(stat());
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("trigger",TriggerNode);
|
||||
|
@@ -145,7 +145,7 @@ module.exports = function(RED) {
|
||||
if (error.signal) { msg3.payload.signal = error.signal; }
|
||||
if (error.code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); }
|
||||
else { node.status({fill:"red",shape:"dot",text:"error:"+error.code}); }
|
||||
node.log('error:' + error);
|
||||
if (RED.settings.verbose) { node.log('error:' + error); }
|
||||
}
|
||||
else if (node.oldrc === "false") {
|
||||
msg3 = RED.util.cloneMessage(msg);
|
||||
|
@@ -303,7 +303,7 @@
|
||||
return this.name;
|
||||
}
|
||||
var b = this.broker;
|
||||
if (b === "") { b = "undefined"; }
|
||||
if (!b) { b = "undefined"; }
|
||||
var lab = "";
|
||||
lab = (this.clientid?this.clientid+"@":"")+b;
|
||||
if (b.indexOf("://") === -1){
|
||||
|
@@ -153,7 +153,12 @@ module.exports = function(RED) {
|
||||
this.brokerurl="mqtt://";
|
||||
}
|
||||
if (this.broker !== "") {
|
||||
this.brokerurl = this.brokerurl+this.broker+":";
|
||||
//Check for an IPv6 address
|
||||
if (/(?:^|(?<=\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=\s|$)/.test(this.broker)) {
|
||||
this.brokerurl = this.brokerurl+"["+this.broker+"]:";
|
||||
} else {
|
||||
this.brokerurl = this.brokerurl+this.broker+":";
|
||||
}
|
||||
// port now defaults to 1883 if unset.
|
||||
if (!this.port){
|
||||
this.brokerurl = this.brokerurl+"1883";
|
||||
@@ -464,6 +469,7 @@ module.exports = function(RED) {
|
||||
this.broker = n.broker;
|
||||
this.brokerConn = RED.nodes.getNode(this.broker);
|
||||
var node = this;
|
||||
var chk = /[\+#]/;
|
||||
|
||||
if (this.brokerConn) {
|
||||
this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
||||
@@ -482,6 +488,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
if ( msg.hasOwnProperty("payload")) {
|
||||
if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) { // topic must exist
|
||||
if (chk.test(msg.topic)) { node.warn(RED._("mqtt.errors.invalid-topic")); }
|
||||
this.brokerConn.publish(msg, done); // send the message
|
||||
} else {
|
||||
node.warn(RED._("mqtt.errors.invalid-topic"));
|
||||
|
@@ -163,7 +163,7 @@
|
||||
if (root === "") {
|
||||
$("#node-config-ws-tip").hide();
|
||||
} else {
|
||||
$("#node-config-ws-path").html(root);
|
||||
$("#node-config-ws-path").html(RED._("node-red:websocket.tip.path2", { path: root }));
|
||||
$("#node-config-ws-tip").show();
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@
|
||||
</div>
|
||||
<div class="form-tips">
|
||||
<span data-i18n="[html]websocket.tip.path1"></span>
|
||||
<p id="node-config-ws-tip"><span data-i18n="[html]websocket.tip.path2"></span><code><span id="node-config-ws-path"></span></code>.</p>
|
||||
<p id="node-config-ws-tip"><span id="node-config-ws-path"></span></p>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
@@ -170,15 +170,14 @@
|
||||
$("#node-input-port-row").hide();
|
||||
$("#node-input-host-row").hide();
|
||||
$("#node-input-end-row").hide();
|
||||
} else if (sockettype == "client"){
|
||||
$("#node-input-port-row").show();
|
||||
$("#node-input-host-row").show();
|
||||
$("#node-input-end-row").show();
|
||||
} else {
|
||||
$("#node-input-port-row").show();
|
||||
$("#node-input-end-row").show();
|
||||
}
|
||||
|
||||
if (sockettype == "client") {
|
||||
$("#node-input-host-row").show();
|
||||
} else {
|
||||
$("#node-input-host-row").hide();
|
||||
$("#node-input-end-row").show();
|
||||
}
|
||||
};
|
||||
updateOptions();
|
||||
|
@@ -74,7 +74,7 @@ module.exports = function(RED) {
|
||||
buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
||||
node.connected = true;
|
||||
node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port}));
|
||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||
node.status({fill:"green",shape:"dot",text:"common.status.connected",_session:{type:"tcp",id:id}});
|
||||
});
|
||||
client.setKeepAlive(true,120000);
|
||||
connectionPool[id] = client;
|
||||
@@ -121,7 +121,7 @@ module.exports = function(RED) {
|
||||
client.on('close', function() {
|
||||
delete connectionPool[id];
|
||||
node.connected = false;
|
||||
node.status({fill:"red",shape:"ring",text:"common.status.disconnected"});
|
||||
node.status({fill:"red",shape:"ring",text:"common.status.disconnected",_session:{type:"tcp",id:id}});
|
||||
if (!node.closing) {
|
||||
if (end) { // if we were asked to close then try to reconnect once very quick.
|
||||
end = false;
|
||||
|
@@ -180,6 +180,10 @@ module.exports = function(RED) {
|
||||
node.tout = setTimeout(function() {
|
||||
if (udpInputPortsInUse[p]) {
|
||||
sock = udpInputPortsInUse[p];
|
||||
if (node.multicast != "false") {
|
||||
sock.setBroadcast(true);
|
||||
sock.setMulticastLoopback(false);
|
||||
}
|
||||
node.log(RED._("udp.status.re-use",{outport:node.outport,host:node.addr,port:node.port}));
|
||||
if (node.iface) { node.status({text:n.iface+" : "+node.iface}); }
|
||||
}
|
||||
|
@@ -28,11 +28,15 @@
|
||||
</div>
|
||||
<div class="form-row" style="padding-left:20px;">
|
||||
<label><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.input"></span></label>
|
||||
<span data-i18n="csv.label.skip-s"></span> <input type="text" id="node-input-skip" style="width:30px; height:25px;"/> <span data-i18n="csv.label.skip-e"></span><br/>
|
||||
<span data-i18n="csv.label.skip-s"></span> <input type="text" id="node-input-skip" style="width:40px; height:25px;"/> <span data-i18n="csv.label.skip-e"></span><br/>
|
||||
<label> </label>
|
||||
<input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-hdrin"><label style="width:auto; margin-top:7px;" for="node-input-hdrin"><span data-i18n="csv.label.firstrow"></span></label><br/>
|
||||
<label> </label>
|
||||
<input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-strings"><label style="width:auto; margin-top:7px;" for="node-input-strings"><span data-i18n="csv.label.usestrings"></span></label><br/>
|
||||
<label> </label>
|
||||
<input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-include_empty_strings"><label style="width:auto; margin-top:7px;" for="node-input-include_empty_strings"><span data-i18n="csv.label.include_empty_strings"></span></label><br/>
|
||||
<label> </label>
|
||||
<input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-include_null_values"><label style="width:auto; margin-top:7px;" for="node-input-include_null_values"><span data-i18n="csv.label.include_null_values"></span></label><br/>
|
||||
</div>
|
||||
<div class="form-row" style="padding-left:20px;">
|
||||
<label><i class="fa fa-sign-out"></i> <span data-i18n="csv.label.output"></span></label>
|
||||
@@ -45,8 +49,13 @@
|
||||
<label style="width:100%;"><span data-i18n="csv.label.o2c"></span></label>
|
||||
</div>
|
||||
<div class="form-row" style="padding-left:20px;">
|
||||
<label><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.output"></span></label>
|
||||
<input style="width:20px; vertical-align:top; margin-right:5px;" type="checkbox" id="node-input-hdrout"><label style="width:auto;" for="node-input-hdrout"><span data-i18n="csv.label.includerow"></span></span>
|
||||
<label><i class="fa fa-sign-out"></i> <span data-i18n="csv.label.output"></span></label>
|
||||
<!-- <input style="width:20px; vertical-align:top; margin-right:5px;" type="checkbox" id="node-input-hdrout"><label style="width:auto;" for="node-input-hdrout"><span data-i18n="csv.label.includerow"></span></span> -->
|
||||
<select style="width:60%" id="node-input-hdrout">
|
||||
<option value="none" data-i18n="csv.hdrout.none"></option>
|
||||
<option value="all" data-i18n="csv.hdrout.all"></option>
|
||||
<option value="once" data-i18n="csv.hdrout.once"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row" style="padding-left:20px;">
|
||||
<label></label>
|
||||
@@ -69,12 +78,14 @@
|
||||
sep: {value:',',required:true,validate:RED.validators.regex(/^.{1,2}$/)},
|
||||
//quo: {value:'"',required:true},
|
||||
hdrin: {value:""},
|
||||
hdrout: {value:""},
|
||||
hdrout: {value:"none"},
|
||||
multi: {value:"one",required:true},
|
||||
ret: {value:'\\n'},
|
||||
temp: {value:""},
|
||||
skip: {value:"0"},
|
||||
strings: {value:true}
|
||||
strings: {value:true},
|
||||
include_empty_strings: {value:""},
|
||||
include_null_values: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
@@ -86,6 +97,8 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.hdrout === false) { this.hdrout = "none"; $("#node-input-hdrout").val("none"); }
|
||||
if (this.hdrout === true) { this.hdrout = "all"; $("#node-input-hdrout").val("all");}
|
||||
if (this.strings === undefined) { this.strings = true; $("#node-input-strings").prop('checked', true); }
|
||||
if (this.skip === undefined) { this.skip = 0; $("#node-input-skip").val("0");}
|
||||
$("#node-input-skip").spinner({ min:0 });
|
||||
|
@@ -26,12 +26,16 @@ module.exports = function(RED) {
|
||||
this.lineend = "\n";
|
||||
this.multi = n.multi || "one";
|
||||
this.hdrin = n.hdrin || false;
|
||||
this.hdrout = n.hdrout || false;
|
||||
this.hdrout = n.hdrout || "none";
|
||||
this.goodtmpl = true;
|
||||
this.skip = parseInt(n.skip || 0);
|
||||
this.store = [];
|
||||
this.parsestrings = n.strings;
|
||||
this.include_empty_strings = n.include_empty_strings || false;
|
||||
this.include_null_values = n.include_null_values || false;
|
||||
if (this.parsestrings === undefined) { this.parsestrings = true; }
|
||||
if (this.hdrout === false) { this.hdrout = "none"; }
|
||||
if (this.hdrout === true) { this.hdrout = "all"; }
|
||||
var tmpwarn = true;
|
||||
var node = this;
|
||||
|
||||
@@ -49,14 +53,22 @@ module.exports = function(RED) {
|
||||
return col;
|
||||
}
|
||||
node.template = clean(node.template);
|
||||
node.hdrSent = false;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
node.hdrSent = false;
|
||||
}
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
if (typeof msg.payload == "object") { // convert object to CSV string
|
||||
try {
|
||||
var ou = "";
|
||||
if (node.hdrout) {
|
||||
if (node.hdrout !== "none" && node.hdrSent === false) {
|
||||
if ((node.template.length === 1) && (node.template[0] === '') && (msg.hasOwnProperty("columns"))) {
|
||||
node.template = clean((msg.columns || "").split(","));
|
||||
}
|
||||
ou += node.template.join(node.sep) + node.ret;
|
||||
if (node.hdrout === "once") { node.hdrSent = true; }
|
||||
}
|
||||
if (!Array.isArray(msg.payload)) { msg.payload = [ msg.payload ]; }
|
||||
for (var s = 0; s < msg.payload.length; s++) {
|
||||
@@ -75,13 +87,15 @@ module.exports = function(RED) {
|
||||
ou += msg.payload[s].join(node.sep) + node.ret;
|
||||
}
|
||||
else {
|
||||
if ((node.template.length === 1) && (node.template[0] === '') && (msg.hasOwnProperty("columns"))) {
|
||||
node.template = clean((msg.columns || "").split(","));
|
||||
}
|
||||
if ((node.template.length === 1) && (node.template[0] === '')) {
|
||||
/* istanbul ignore else */
|
||||
if (tmpwarn === true) { // just warn about missing template once
|
||||
node.warn(RED._("csv.errors.obj_csv"));
|
||||
tmpwarn = false;
|
||||
}
|
||||
ou = "";
|
||||
for (var p in msg.payload[0]) {
|
||||
/* istanbul ignore else */
|
||||
if (msg.payload[0].hasOwnProperty(p)) {
|
||||
@@ -125,6 +139,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
msg.payload = ou;
|
||||
msg.columns = node.template.join(',');
|
||||
if (msg.payload !== '') { node.send(msg); }
|
||||
}
|
||||
catch(e) { node.error(e,msg); }
|
||||
@@ -173,20 +188,29 @@ module.exports = function(RED) {
|
||||
}
|
||||
else if ((line[i] === node.sep) && f) { // if it is the end of the line then finish
|
||||
if (!node.goodtmpl) { node.template[j] = "col"+(j+1); }
|
||||
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "" ) ) {
|
||||
if ( (node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
o[node.template[j]] = k[j];
|
||||
if ( node.template[j] && (node.template[j] !== "") ) {
|
||||
// if no value between separators ('1,,"3"...') or if the line beings with separator (',1,"2"...') treat value as null
|
||||
if (line[i-1] === node.sep || line[i-1].includes('\n','\r')) k[j] = null;
|
||||
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
if (node.include_null_values && k[j] === null) o[node.template[j]] = k[j];
|
||||
if (node.include_empty_strings && k[j] === "") o[node.template[j]] = k[j];
|
||||
if (k[j] !== null && k[j] !== "") o[node.template[j]] = k[j];
|
||||
}
|
||||
j += 1;
|
||||
k[j] = "";
|
||||
// if separator is last char in processing string line (without end of line), add null value at the end - example: '1,2,3\n3,"3",'
|
||||
k[j] = line.length - 1 === i ? null : "";
|
||||
}
|
||||
else if ((line[i] === "\n") || (line[i] === "\r")) { // handle multiple lines
|
||||
else if (((line[i] === "\n") || (line[i] === "\r")) && f) { // handle multiple lines
|
||||
//console.log(j,k,o,k[j]);
|
||||
if (!node.goodtmpl) { node.template[j] = "col"+(j+1); }
|
||||
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) {
|
||||
if ( (node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
else { k[j].replace(/\r$/,''); }
|
||||
o[node.template[j]] = k[j];
|
||||
if ( node.template[j] && (node.template[j] !== "") ) {
|
||||
// if separator before end of line, set null value ie. '1,2,"3"\n1,2,\n1,2,3'
|
||||
if (line[i-1] === node.sep) k[j] = null;
|
||||
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
else { if (k[j] !== null) k[j].replace(/\r$/,''); }
|
||||
if (node.include_null_values && k[j] === null) o[node.template[j]] = k[j];
|
||||
if (node.include_empty_strings && k[j] === "") o[node.template[j]] = k[j];
|
||||
if (k[j] !== null && k[j] !== "") o[node.template[j]] = k[j];
|
||||
}
|
||||
if (JSON.stringify(o) !== "{}") { // don't send empty objects
|
||||
a.push(o); // add to the array
|
||||
@@ -202,17 +226,21 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
// Finished so finalize and send anything left
|
||||
//console.log(j,k,o,k[j]);
|
||||
if (f === false) { node.warn(RED._("csv.errors.bad_csv")); }
|
||||
if (!node.goodtmpl) { node.template[j] = "col"+(j+1); }
|
||||
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) {
|
||||
if ( (node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
else { k[j].replace(/\r$/,''); }
|
||||
o[node.template[j]] = k[j];
|
||||
|
||||
if ( node.template[j] && (node.template[j] !== "") ) {
|
||||
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
|
||||
else { if (k[j] !== null) k[j].replace(/\r$/,''); }
|
||||
if (node.include_null_values && k[j] === null) o[node.template[j]] = k[j];
|
||||
if (node.include_empty_strings && k[j] === "") o[node.template[j]] = k[j];
|
||||
if (k[j] !== null && k[j] !== "") o[node.template[j]] = k[j];
|
||||
}
|
||||
if (JSON.stringify(o) !== "{}") { // don't send empty objects
|
||||
a.push(o); // add to the array
|
||||
}
|
||||
var has_parts = msg.hasOwnProperty("parts");
|
||||
|
||||
if (node.multi !== "one") {
|
||||
msg.payload = a;
|
||||
if (has_parts) {
|
||||
@@ -221,12 +249,14 @@ module.exports = function(RED) {
|
||||
}
|
||||
if (msg.parts.index + 1 === msg.parts.count) {
|
||||
msg.payload = node.store;
|
||||
msg.columns = node.template.filter(val => val).join(',');
|
||||
delete msg.parts;
|
||||
node.send(msg);
|
||||
node.store = [];
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg.columns = node.template.filter(val => val).join(',');
|
||||
node.send(msg); // finally send the array
|
||||
}
|
||||
}
|
||||
@@ -234,6 +264,7 @@ module.exports = function(RED) {
|
||||
var len = a.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var newMessage = RED.util.cloneMessage(msg);
|
||||
newMessage.columns = node.template.filter(val => val).join(',');
|
||||
newMessage.payload = a[i];
|
||||
if (!has_parts) {
|
||||
newMessage.parts = {
|
||||
@@ -259,7 +290,11 @@ module.exports = function(RED) {
|
||||
}
|
||||
else { node.warn(RED._("csv.errors.csv_js")); }
|
||||
}
|
||||
else { node.send(msg); } // If no payload - just pass it on.
|
||||
else {
|
||||
if (!msg.hasOwnProperty("reset")) {
|
||||
node.send(msg); // If no payload and not reset - just pass it on.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("csv",CSVNode);
|
||||
|
@@ -292,7 +292,6 @@ module.exports = function(RED) {
|
||||
reduceMessageGroup(node,msgs,exp,fixup,count,result,done);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
function reduceAndSendGroup(node, group, done) {
|
||||
var is_right = node.reduce_right;
|
||||
@@ -331,7 +330,7 @@ module.exports = function(RED) {
|
||||
var pending_count = node.pending_count;
|
||||
var gid = msg.parts.id;
|
||||
var count;
|
||||
if(!pending.hasOwnProperty(gid)) {
|
||||
if (!pending.hasOwnProperty(gid)) {
|
||||
if(parts.hasOwnProperty('count')) {
|
||||
count = msg.parts.count;
|
||||
}
|
||||
@@ -361,7 +360,6 @@ module.exports = function(RED) {
|
||||
}
|
||||
return done();
|
||||
}
|
||||
|
||||
if (msgs.length === group.count) {
|
||||
delete pending[gid];
|
||||
pending_count -= msgs.length;
|
||||
@@ -408,7 +406,7 @@ module.exports = function(RED) {
|
||||
if (this.joinerType === "str") {
|
||||
this.joiner = this.joiner.replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\e/g,"\e").replace(/\\f/g,"\f").replace(/\\0/g,"\0");
|
||||
} else if (this.joinerType === "bin") {
|
||||
var joinArray = JSON.parse(n.joiner)
|
||||
var joinArray = JSON.parse(n.joiner || "[]");
|
||||
if (Array.isArray(joinArray)) {
|
||||
this.joiner = Buffer.from(joinArray);
|
||||
} else {
|
||||
@@ -429,7 +427,7 @@ module.exports = function(RED) {
|
||||
|
||||
var completeSend = function(partId) {
|
||||
var group = inflight[partId];
|
||||
clearTimeout(group.timeout);
|
||||
if (group.timeout) { clearTimeout(group.timeout); }
|
||||
if ((node.accumulate !== true) || group.msg.hasOwnProperty("complete")) { delete inflight[partId]; }
|
||||
if (group.type === 'array' && group.arrayLen > 1) {
|
||||
var newArray = [];
|
||||
@@ -448,6 +446,9 @@ module.exports = function(RED) {
|
||||
buffers.push(joinBuffer);
|
||||
bufferLen += joinBuffer.length;
|
||||
}
|
||||
if (!Buffer.isBuffer(group.payload[i])) {
|
||||
group.payload[i] = Buffer.from(group.payload[i]);
|
||||
}
|
||||
buffers.push(group.payload[i]);
|
||||
bufferLen += group.payload[i].length;
|
||||
}
|
||||
@@ -629,7 +630,13 @@ module.exports = function(RED) {
|
||||
var group = inflight[partId];
|
||||
if (payloadType === 'buffer') {
|
||||
if (property !== undefined) {
|
||||
inflight[partId].bufferLen += property.length;
|
||||
if (Buffer.isBuffer(property) || (typeof property === "string") || Array.isArray(property)) {
|
||||
inflight[partId].bufferLen += property.length;
|
||||
}
|
||||
else {
|
||||
node.error(RED._("join.errors.invalid-type",{error:(typeof property)}),msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payloadType === 'object') {
|
||||
|
@@ -179,6 +179,11 @@ module.exports = function(RED) {
|
||||
}
|
||||
node.pending = [];
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
node.pending = [];
|
||||
node.pending_count = 0;
|
||||
return;
|
||||
}
|
||||
var queue = node.pending;
|
||||
queue.push(msg);
|
||||
node.pending_count++;
|
||||
@@ -204,11 +209,26 @@ module.exports = function(RED) {
|
||||
var interval = Number(n.interval || "0") *1000;
|
||||
var allow_empty_seq = n.allowEmptySequence;
|
||||
node.pending = []
|
||||
var timer = setInterval(function() {
|
||||
function msgHandler() {
|
||||
send_interval(node, allow_empty_seq);
|
||||
node.pending_count = 0;
|
||||
}, interval);
|
||||
}
|
||||
var timer = undefined;
|
||||
if (interval > 0) {
|
||||
timer = setInterval(msgHandler, interval);
|
||||
}
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (timer !== undefined) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
node.pending = [];
|
||||
node.pending_count = 0;
|
||||
if (interval > 0) {
|
||||
timer = setInterval(msgHandler, interval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
node.pending.push(msg);
|
||||
node.pending_count++;
|
||||
var max_msgs = max_kept_msgs_count(node);
|
||||
@@ -219,7 +239,9 @@ module.exports = function(RED) {
|
||||
}
|
||||
});
|
||||
this.on("close", function() {
|
||||
clearInterval(timer);
|
||||
if (timer !== undefined) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
node.pending = [];
|
||||
node.pending_count = 0;
|
||||
});
|
||||
@@ -230,6 +252,11 @@ module.exports = function(RED) {
|
||||
});
|
||||
node.pending = {};
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
node.pending = {};
|
||||
node.pending_count = 0;
|
||||
return;
|
||||
}
|
||||
concat_msg(node, msg);
|
||||
});
|
||||
this.on("close", function() {
|
||||
|
Reference in New Issue
Block a user