1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

[inject] Tidy up node label

This commit is contained in:
Nick O'Leary 2020-05-05 17:35:08 +01:00
parent 9cbc40a229
commit 189389f96a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -224,38 +224,6 @@
return lab;
},
label: function() {
if (Array.isArray(this.props)) {
// find the payload & topic
var payloadProperty;
var topicProperty;
var payload;
var payloadType;
var topic;
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;
}
var suffix = "";
// if fire once then add small indication
if (this.once) {
@ -267,7 +235,34 @@
}
if (this.name) {
return this.name+suffix;
} else if (payloadType === "string" ||
}
var payloadProperty;
var topicProperty;
var payload;
var payloadType;
var topic;
if (Array.isArray(this.props)) {
// 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];
}
}
payload = payloadProperty === undefined ? "" : payloadProperty.v;
payloadType = payloadProperty === undefined ? "str" : payloadProperty.vt;
topic = topicProperty === undefined ? "" : topicProperty.v;
} else {
/* Legacy */
payload = this.payload || "";
payloadType = this.payloadType || "str";
topic = this.topic || "";
}
if (payloadType === "string" ||
payloadType === "str" ||
payloadType === "num" ||
payloadType === "bool" ||
@ -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);