Skip to content

Commit

Permalink
[inject] Tidy up node label
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed May 5, 2020
1 parent 9cbc40a commit 189389f
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions packages/node_modules/@node-red/nodes/core/common/20-inject.html
Expand Up @@ -224,50 +224,45 @@
return lab;
},
label: function() {
var suffix = "";
// if fire once then add small indication
if (this.once) {
suffix = " ¹";
}
// but replace with repeat one if set to repeat
if ((this.repeat && this.repeat != 0) || this.crontab) {
suffix = " ↻";
}
if (this.name) {
return this.name+suffix;
}

var payloadProperty;
var topicProperty;
var payload;
var payloadType;
var topic;

if (Array.isArray(this.props)) {
// find the payload & topic
var payloadProperty;
var topicProperty;
var payload;
var payloadType;
var topic;
// find the payload & topic if they are set
for (var i=0,l=this.props.length; i<l; i++) {
if (this.props[i].p === 'payload') {
payloadProperty = this.props[i];
} else if (this.props[i].p === 'topic' && this.props[i].vt === 'str') {
topicProperty = this.props[i];
}
}

// If no payload/topic are found, use the first property instead
if (this.props[0]){
payloadProperty = payloadProperty === undefined ? this.props[0] : payloadProperty;
topicProperty = topicProperty === undefined ? {v: payloadProperty.p} : topicProperty; // if no topic, use the property name of the payload
}

payload = payloadProperty === undefined ? "" : payloadProperty.v;
payloadType = payloadProperty === undefined ? "str" : payloadProperty.vt;
topic = topicProperty === undefined ? "" : topicProperty.v;
} else {
/* Legacy */
payload = this.payload;
payloadType = this.payloadType;
topic = this.topic;
payload = this.payload || "";
payloadType = this.payloadType || "str";
topic = this.topic || "";
}


var suffix = "";
// if fire once then add small indication
if (this.once) {
suffix = " ¹";
}
// but replace with repeat one if set to repeat
if ((this.repeat && this.repeat != 0) || this.crontab) {
suffix = " ↻";
}
if (this.name) {
return this.name+suffix;
} else if (payloadType === "string" ||
if (payloadType === "string" ||
payloadType === "str" ||
payloadType === "num" ||
payloadType === "bool" ||
Expand All @@ -281,9 +276,9 @@
}
} else if (payloadType === 'date' || payloadType === 'bin' || payloadType === 'env') {
if ((topic !== "") && (topic.length <= 16)) {
return topic + ":" + this._(`inject.label.${payloadType}`)+suffix;
return topic + ":" + this._('inject.label.'+payloadType)+suffix;
} else {
return this._(`inject.label.${payloadType}`)+suffix;
return this._('inject.label.'+payloadType)+suffix;
}
} else if (payloadType === 'flow' || payloadType === 'global') {
var key = RED.utils.parseContextKey(payload);
Expand Down

0 comments on commit 189389f

Please sign in to comment.