Skip to content

Commit

Permalink
Fix inject so more backwards compatible
Browse files Browse the repository at this point in the history
reuse old payload property and copy over topic if a string.
  • Loading branch information
Dave Conway-Jones committed May 11, 2020
1 parent 13932b2 commit 247fa0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
22 changes: 14 additions & 8 deletions packages/node_modules/@node-red/nodes/core/common/20-inject.html
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@
v: this.topic ? this.topic : '',
vt:'string'
}

this.props = [payload,topic];
}

Expand All @@ -499,12 +498,6 @@

},
oneditsave: function() {
/* Cleanup Legacy */
delete this.payload;
delete this.payloadType
delete this.topic
/* */

var repeat = "";
var crontab = "";
var type = $("#inject-time-type-select").val();
Expand Down Expand Up @@ -599,6 +592,9 @@
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 = {
Expand All @@ -607,7 +603,17 @@
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');
node.props.push(p);
if (p.p === "payload") { // save payload to old "legacy" property
node.payloadType = p.vt;
node.payload = p.v;
}
else if (p.p === "topic" && p.vt === "str") {
node.topic = p.v;
node.props.push(p);
}
else {
node.props.push(p);
}
}
});
},
Expand Down
35 changes: 19 additions & 16 deletions packages/node_modules/@node-red/nodes/core/common/20-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ module.exports = function(RED) {
this.onceDelay = (n.onceDelay || 0.1) * 1000;
this.interval_id = null;
this.cronjob = null;
if (n.payload && n.payloadType) { // load up original payload
this.props.unshift({p:"payload",v:n.payload,vt:n.payloadType});
}
var node = this;

node.props.forEach(function (prop) {
Expand All @@ -64,29 +67,29 @@ module.exports = function(RED) {
}

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));
}
this.interval_id = setInterval(function() {
node.emit("input", {});
}, this.repeat);
} else if (this.crontab) {
if (RED.settings.verbose) {
this.log(RED._("inject.crontab", 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.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) {
Expand Down

0 comments on commit 247fa0c

Please sign in to comment.