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, inputs:0,
outputs:1, outputs:1,
outputLabels: function(index) { outputLabels: function(index) {
var lab = this.payloadType; var lab = '';
if (lab === "json") {
try { // if only payload and topic - display payload type
lab = typeof JSON.parse(this.payload); // if only one property - show it's type
if (lab === "object") { // if more than one property (other than payload and topic) - show "x properties" where x is the number of properties.
if (Array.isArray(JSON.parse(this.payload))) { lab = "Array"; }
// 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;
} }
} catch(e) {
return this._("inject.label.invalid"); } // 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;
} }
var name = "inject.label."+lab; }else{
var label = this._(name); lab = 'legacy payload';
if (name !== label) {
return label;
} }
return lab; return lab;
}, },
label: function() { label: function() {