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

Tidy up info tab handling of subflows and comments

This commit is contained in:
Nick O'Leary 2015-02-10 21:29:27 +00:00
parent 0accfade02
commit e357352240
2 changed files with 53 additions and 50 deletions

View File

@ -30,7 +30,7 @@
</script> </script>
<script type="text/x-red" data-help-name="comment"> <script type="text/x-red" data-help-name="comment">
<p>Comment</p> <p>A node you can use to add comments to your flows.</p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -58,68 +58,71 @@ RED.sidebar.info = (function() {
function refresh(node) { function refresh(node) {
var table = '<table class="node-info"><tbody>'; var table = '<table class="node-info"><tbody>';
//table += '<tr class="blank"><td colspan="2">Node</td></tr>'; table += '<tr class="blank"><td colspan="2">Node</td></tr>';
table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
if (node.type.indexOf("subflow") === 0) { table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
var m = /^subflow(:(.+))?$/.exec(node.type);
if (m) {
var subflowNode;
if (m[2]) {
subflowNode = RED.nodes.subflow(m[2]);
} else {
subflowNode = node;
}
table += '<tr class="blank"><td colspan="2">Subflow</td></tr>';
var userCount = 0; var userCount = 0;
var subflowType = "subflow:"+subflowNode.id;
RED.nodes.eachNode(function(n) { RED.nodes.eachNode(function(n) {
if (n.type === node.type) { if (n.type === subflowType) {
userCount++; userCount++;
} }
}); });
node.name = node.name || ""; table += "<tr><td>name</td><td>"+subflowNode.name+"</td></tr>";
if (node.type !== "subflow") { table += "<tr><td>instances</td><td>"+userCount+"</td></tr>";
table += "<tr><td>Type</td><td>&nbsp;"+(RED.nodes.subflow(node.type.split(":")[1]).name||node.type)+"</td></tr>";
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += "<tr><td>name</td><td>"+node.name+"</td></tr>";
table += "<tr><td>inputs</td><td>"+node.inputs+"</td></tr>";
table += "<tr><td>outputs</td><td>"+node.outputs+"</td></tr>";
table += "<tr><td>instances</td><td>"+userCount+"</td></tr>";
} else {
table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += "<tr><td>name</td><td>"+node.name+"</td></tr>";
}
} }
else if (node._def) {
if (node.type !== "comment") { if (node.type != "subflow" && node.type != "comment") {
table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += '<tr class="blank"><td colspan="2">Properties</td></tr>'; table += '<tr class="blank"><td colspan="2">Properties</td></tr>';
for (var n in node._def.defaults) { if (node._def) {
if (node._def.defaults.hasOwnProperty(n)) { for (var n in node._def.defaults) {
var val = node[n]||""; if (node._def.defaults.hasOwnProperty(n)) {
var type = typeof val; var val = node[n]||"";
if (type === "string") { var type = typeof val;
if (val.length > 30) { if (type === "string") {
val = val.substring(0,30)+" ..."; if (val.length > 30) {
val = val.substring(0,30)+" ...";
}
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
} 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;");
} }
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
} else if (type === "number") { table += "<tr><td>"+n+"</td><td>"+val+"</td></tr>";
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>"+n+"</td><td>"+val+"</td></tr>";
} }
} }
}
} }
table += "</tbody></table><br/>"; table += "</tbody></table><br/>";
var helpText = $("script[data-help-name|='"+node.type+"']").html()||""; if (node.type != "comment") {
table += '<div class="node-help">'+helpText+"</div>"; var helpText = $("script[data-help-name|='"+node.type+"']").html()||"";
table += '<div class="node-help">'+helpText+"</div>";
}
if (node._def && node._def.info) { if (node._def && node._def.info) {
var info = node._def.info; var info = node._def.info;