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

Corrected output label logic

This commit is contained in:
Paul Wieland 2020-04-22 15:13:11 -04:00
parent 2efc2bc186
commit 3e898c487a

View File

@ -168,21 +168,38 @@
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 name = "inject.label."+lab;
var label = this._(name);
if (name !== label) {
return label;
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
if (Array.isArray(this.props)) {
var propertyCount = this.props.length;
var payloadProperty = this.props.find(p => p.p === 'payload');
var topicProperty = this.props.find(p => p.p === 'topic' && p.vt === 'str');
if (payloadProperty && topicProperty) {
lab = payloadProperty.vt;
} else if (propertyCount > 1){
lab = propertyCount + ' properties';
} else if(propertyCount === 1){
lab = this.props[0].vt;
}
// Friendly names
switch(lab){
case 'date': lab = 'timestamp'; break;
case 'str': lab = 'string'; break;
case 'num': lab = 'number'; break;
case 'bin': lab = 'buffer'; break;
case '': lab = 'nothing'; break;
}
}else{
lab = 'legacy payload';
}
return lab;
},
label: function() {