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

Improve node info properties table

This commit is contained in:
Nick O'Leary 2014-02-09 15:24:05 +00:00
parent 79d4b32e3f
commit 75fc46c05d
2 changed files with 43 additions and 6 deletions

View File

@ -499,6 +499,23 @@ RED.view = function() {
} }
} }
function jsonFilter(key,value) {
if (key == "") {
return value;
}
var t = typeof value;
if ($.isArray(value)) {
return "[array:"+value.length+"]";
} else if (t === "object") {
return "[object]"
} else if (t === "string") {
if (value.length > 30) {
return value.substring(0,30)+" ...";
}
}
return value;
}
function buildInfo(node) { function buildInfo(node) {
var table = '<table class="node-info"><tbody>'; var table = '<table class="node-info"><tbody>';
@ -506,13 +523,30 @@ RED.view = function() {
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>"; table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>'; table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
for (var n in node._def.defaults) { for (var n in node._def.defaults) {
if ((n != "func")&&(n != "template")) { var val = node[n]||"";
var safe = (node[n]||"").toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); var type = typeof val;
table += "<tr><td>&nbsp;"+n+"</td><td>"+safe+"</td></tr>"; if (type === "string") {
} if (val.length > 30) {
if ((n == "func")||(n == "template")) { val = val.substring(0,30)+" ...";
table += "<tr><td>&nbsp;"+n+"</td><td>(...)</td></tr>"; }
} else if (type === "number") {
val = val.toString();
} else if ($.isArray(val)) {
val = "[<br/>";
for (var i=0;i<Math.min(node[n].length,10);i++) {
var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
val += "&nbsp;"+i+": "+vv+"<br/>";
}
if (node[n].length > 10) {
val += "&nbsp;... "+node[n].length+" items<br/>";
}
val += "]";
} else {
val = JSON.stringify(val,jsonFilter," ");
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
} }
table += "<tr><td>&nbsp;"+n+"</td><td>"+val+"</td></tr>";
} }
table += "</tbody></table><br/>"; table += "</tbody></table><br/>";
table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>"; table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";

View File

@ -546,8 +546,11 @@ table.node-info td:first-child{
color: #000; color: #000;
vertical-align: top; vertical-align: top;
width: 90px; width: 90px;
padding: 0 3px;
border-right: 1px solid #ddd;
} }
table.node-info td:last-child{ table.node-info td:last-child{
padding-left: 5px;
color: #666; color: #666;
} }