mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Ensure errors in node def funcs don't break view rendering
Fixes #815 - also fixes errors in the Catch/Status node label funcs #815
This commit is contained in:
parent
2e2556fdad
commit
0e2d13172a
@ -134,22 +134,27 @@ RED.palette = (function() {
|
||||
d.id = "palette_node_"+nodeTypeId;
|
||||
d.type = nt;
|
||||
|
||||
var label;
|
||||
|
||||
if (typeof def.paletteLabel === "undefined") {
|
||||
label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
||||
} else {
|
||||
label = (typeof def.paletteLabel === "function" ? def.paletteLabel.call(def) : def.paletteLabel)||"";
|
||||
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
||||
if (typeof def.paletteLabel !== "undefined") {
|
||||
try {
|
||||
label = (typeof def.paletteLabel === "function" ? def.paletteLabel.call(def) : def.paletteLabel)||"";
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+nt+".paletteLabel",err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$('<div/>',{class:"palette_label"+(def.align=="right"?" palette_label_right":"")}).appendTo(d);
|
||||
|
||||
d.className="palette_node";
|
||||
|
||||
|
||||
if (def.icon) {
|
||||
var icon_url = (typeof def.icon === "function" ? def.icon.call({}) : def.icon);
|
||||
var icon_url = "arrow-in.png";
|
||||
try {
|
||||
icon_url = (typeof def.icon === "function" ? def.icon.call({}) : def.icon);
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+nt+".icon",err);
|
||||
}
|
||||
var iconContainer = $('<div/>',{class:"palette_icon_container"+(def.align=="right"?" palette_icon_container_right":"")}).appendTo(d);
|
||||
$('<div/>',{class:"palette_icon",style:"background-image: url(icons/"+icon_url+")"}).appendTo(iconContainer);
|
||||
}
|
||||
|
@ -350,7 +350,11 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
if (nn._def.onadd) {
|
||||
nn._def.onadd.call(nn);
|
||||
try {
|
||||
nn._def.onadd.call(nn);
|
||||
} catch(err) {
|
||||
console.log("onadd:",err);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var subflow = RED.nodes.subflow(m[1]);
|
||||
@ -1253,7 +1257,11 @@ RED.view = (function() {
|
||||
d.dirty = true;
|
||||
}
|
||||
if (d._def.button.onclick) {
|
||||
d._def.button.onclick.call(d);
|
||||
try {
|
||||
d._def.button.onclick.call(d);
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".onclick",err);
|
||||
}
|
||||
}
|
||||
if (d.dirty) {
|
||||
redraw();
|
||||
@ -1408,7 +1416,12 @@ RED.view = (function() {
|
||||
var node = d3.select(this);
|
||||
node.attr("id",d.id);
|
||||
var l = d._def.label;
|
||||
l = (typeof l === "function" ? l.call(d) : l)||"";
|
||||
try {
|
||||
l = (typeof l === "function" ? l.call(d) : l)||"";
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".label",err);
|
||||
l = d.type;
|
||||
}
|
||||
d.w = Math.max(node_width,gridSize*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/gridSize)) );
|
||||
d.h = Math.max(node_height,(d.outputs||0) * 15);
|
||||
|
||||
@ -1591,7 +1604,12 @@ RED.view = (function() {
|
||||
//if (d.x < -50) deleteSelection(); // Delete nodes if dragged back to palette
|
||||
if (d.resize) {
|
||||
var l = d._def.label;
|
||||
l = (typeof l === "function" ? l.call(d) : l)||"";
|
||||
try {
|
||||
l = (typeof l === "function" ? l.call(d) : l)||"";
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".label",err);
|
||||
l = d.type;
|
||||
}
|
||||
var ow = d.w;
|
||||
d.w = Math.max(node_width,gridSize*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/gridSize)) );
|
||||
d.h = Math.max(node_height,(d.outputs||0) * 15);
|
||||
@ -1659,20 +1677,33 @@ RED.view = (function() {
|
||||
});
|
||||
}
|
||||
thisNode.selectAll('text.node_label').text(function(d,i){
|
||||
var l = "";
|
||||
if (d._def.label) {
|
||||
if (typeof d._def.label == "function") {
|
||||
return d._def.label.call(d);
|
||||
} else {
|
||||
return d._def.label;
|
||||
l = d._def.label;
|
||||
try {
|
||||
l = (typeof l === "function" ? l.call(d) : l)||"";
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".label",err);
|
||||
l = d.type;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return l;
|
||||
})
|
||||
.attr('y', function(d){return (d.h/2)-1;})
|
||||
.attr('class',function(d){
|
||||
var s = "";
|
||||
if (d._def.labelStyle) {
|
||||
s = d._def.labelStyle;
|
||||
try {
|
||||
s = (typeof s === "function" ? s.call(d) : s)||"";
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".labelStyle",err);
|
||||
s = "";
|
||||
}
|
||||
s = " "+s;
|
||||
}
|
||||
return 'node_label'+
|
||||
(d._def.align?' node_label_'+d._def.align:'')+
|
||||
(d._def.labelStyle?' '+(typeof d._def.labelStyle == "function" ? d._def.labelStyle.call(d):d._def.labelStyle):'') ;
|
||||
(d._def.align?' node_label_'+d._def.align:'')+s;
|
||||
});
|
||||
|
||||
if (d._def.icon) {
|
||||
@ -1680,7 +1711,12 @@ RED.view = (function() {
|
||||
var current_url = icon.attr("xlink:href");
|
||||
var icon_url;
|
||||
if (typeof d._def.icon == "function") {
|
||||
icon_url = d._def.icon.call(d);
|
||||
try {
|
||||
icon_url = d._def.icon.call(d);
|
||||
} catch(err) {
|
||||
console.log("icon",err);
|
||||
icon_url = "arrow-in.png";
|
||||
}
|
||||
} else {
|
||||
icon_url = d._def.icon;
|
||||
}
|
||||
@ -1744,7 +1780,12 @@ RED.view = (function() {
|
||||
thisNode.selectAll('text.node_badge_label').text(function(d,i) {
|
||||
if (d._def.badge) {
|
||||
if (typeof d._def.badge == "function") {
|
||||
return d._def.badge.call(d);
|
||||
try {
|
||||
return d._def.badge.call(d);
|
||||
} catch(err) {
|
||||
console.log("Definition error: "+d.type+".badge",err);
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return d._def.badge;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2015 IBM Corp.
|
||||
Copyright 2015, 2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -106,7 +106,7 @@
|
||||
outputs:1,
|
||||
icon: "alert.png",
|
||||
label: function() {
|
||||
return this.name||this.scope?this._("catch.catchNodes",{number:this.scope.length}):this._("catch.catch");
|
||||
return this.name||(this.scope?this._("catch.catchNodes",{number:this.scope.length}):this._("catch.catch"));
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2015 IBM Corp.
|
||||
Copyright 2015, 2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -97,7 +97,7 @@
|
||||
outputs:1,
|
||||
icon: "alert.png",
|
||||
label: function() {
|
||||
return this.name||this.scope?this._("status.statusNodes",{number:this.scope.length}):this._("status.status");
|
||||
return this.name||(this.scope?this._("status.statusNodes",{number:this.scope.length}):this._("status.status"));
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
|
Loading…
Reference in New Issue
Block a user