mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
tab-info node properties use RED.utils.createObjectElement
This commit is contained in:
parent
a1d6cbd5fd
commit
0ca3cdb9ae
@ -67,13 +67,15 @@ RED.sidebar.info = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refresh(node) {
|
function refresh(node) {
|
||||||
var table = '<table class="node-info"><tbody>';
|
$(content).empty();
|
||||||
table += '<tr class="blank"><td colspan="2">'+RED._("sidebar.info.node")+'</td></tr>';
|
var table = $('<table class="node-info"></table>');
|
||||||
|
var tableBody = $('<tbody>').appendTo(table);
|
||||||
|
$('<tr class="blank"><td colspan="2">'+RED._("sidebar.info.node")+'</td></tr>').appendTo(tableBody);
|
||||||
if (node.type != "subflow" && node.name) {
|
if (node.type != "subflow" && node.name) {
|
||||||
table += '<tr><td>'+RED._("common.label.name")+'</td><td> <span class="bidiAware" dir="'+RED.text.bidi.resolveBaseTextDir(node.name)+'">'+node.name+'</span></td></tr>';
|
$('<tr><td>'+RED._("common.label.name")+'</td><td> <span class="bidiAware" dir="'+RED.text.bidi.resolveBaseTextDir(node.name)+'">'+node.name+'</span></td></tr>').appendTo(tableBody);
|
||||||
}
|
}
|
||||||
table += "<tr><td>"+RED._("sidebar.info.type")+"</td><td> "+node.type+"</td></tr>";
|
$("<tr><td>"+RED._("sidebar.info.type")+"</td><td> "+node.type+"</td></tr>").appendTo(tableBody);
|
||||||
table += "<tr><td>"+RED._("sidebar.info.id")+"</td><td> "+node.id+"</td></tr>";
|
$("<tr><td>"+RED._("sidebar.info.id")+"</td><td> "+node.id+"</td></tr>").appendTo(tableBody);
|
||||||
|
|
||||||
var m = /^subflow(:(.+))?$/.exec(node.type);
|
var m = /^subflow(:(.+))?$/.exec(node.type);
|
||||||
var subflowNode;
|
var subflowNode;
|
||||||
@ -84,7 +86,7 @@ RED.sidebar.info = (function() {
|
|||||||
subflowNode = node;
|
subflowNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
table += '<tr class="blank"><td colspan="2">'+RED._("sidebar.info.subflow")+'</td></tr>';
|
$('<tr class="blank"><td colspan="2">'+RED._("sidebar.info.subflow")+'</td></tr>').appendTo(tableBody);
|
||||||
|
|
||||||
var userCount = 0;
|
var userCount = 0;
|
||||||
var subflowType = "subflow:"+subflowNode.id;
|
var subflowType = "subflow:"+subflowNode.id;
|
||||||
@ -93,65 +95,38 @@ RED.sidebar.info = (function() {
|
|||||||
userCount++;
|
userCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
table += '<tr><td>'+RED._("common.label.name")+'</td><td><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.name)+'">'+subflowNode.name+'</span></td></tr>';
|
$('<tr><td>'+RED._("common.label.name")+'</td><td><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.name)+'">'+subflowNode.name+'</span></td></tr>').appendTo(tableBody);
|
||||||
table += "<tr><td>"+RED._("sidebar.info.instances")+"</td><td>"+userCount+"</td></tr>";
|
$("<tr><td>"+RED._("sidebar.info.instances")+"</td><td>"+userCount+"</td></tr>").appendTo(tableBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m && node.type != "subflow" && node.type != "comment") {
|
if (!m && node.type != "subflow" && node.type != "comment") {
|
||||||
table += '<tr class="blank"><td colspan="2"><a href="#" class="node-info-property-header"><i style="width: 10px; text-align: center;" class="fa fa-caret-'+(propertiesExpanded?"down":"right")+'"></i> '+RED._("sidebar.info.properties")+'</a></td></tr>';
|
$('<tr class="blank"><td colspan="2"><a href="#" class="node-info-property-header"><i style="width: 10px; text-align: center;" class="fa fa-caret-'+(propertiesExpanded?"down":"right")+'"></i> '+RED._("sidebar.info.properties")+'</a></td></tr>').appendTo(tableBody);
|
||||||
if (node._def) {
|
if (node._def) {
|
||||||
for (var n in node._def.defaults) {
|
for (var n in node._def.defaults) {
|
||||||
if (n != "name" && node._def.defaults.hasOwnProperty(n)) {
|
if (n != "name" && node._def.defaults.hasOwnProperty(n)) {
|
||||||
var val = node[n];
|
var val = node[n];
|
||||||
var type = typeof val;
|
var type = typeof val;
|
||||||
if (val === null || val === undefined) {
|
var propRow = $('<tr class="node-info-property-row'+(propertiesExpanded?"":" hide")+'"><td>'+n+"</td><td></td></tr>").appendTo(tableBody);
|
||||||
val = '<span style="font-style: italic; color: #ccc;">'+RED._("sidebar.info.null")+'</span>';
|
RED.utils.createObjectElement(val).appendTo(propRow.children()[1]);
|
||||||
} else if (type === "string") {
|
|
||||||
if (val.length === 0) {
|
|
||||||
val = '<span style="font-style: italic; color: #ccc;">'+RED._("sidebar.info.blank")+'</span>';
|
|
||||||
} else {
|
|
||||||
if (val.length > 30) {
|
|
||||||
val = val.substring(0,30)+" ...";
|
|
||||||
}
|
|
||||||
val = val.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
|
||||||
}
|
|
||||||
} 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,"&").replace(/</g,"<").replace(/>/g,">");
|
|
||||||
val += " "+i+": "+vv+"<br/>";
|
|
||||||
}
|
|
||||||
if (node[n].length > 10) {
|
|
||||||
val += " ... "+RED._("sidebar.info.arrayItems",{count:node[n].length})+"<br/>";
|
|
||||||
}
|
|
||||||
val += "]";
|
|
||||||
} else {
|
|
||||||
val = JSON.stringify(val,jsonFilter," ");
|
|
||||||
val = val.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
|
||||||
}
|
|
||||||
|
|
||||||
table += '<tr class="node-info-property-row'+(propertiesExpanded?"":" hide")+'"><td>'+n+"</td><td>"+val+"</td></tr>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table += "</tbody></table><hr/>";
|
$(table).appendTo(content);
|
||||||
|
$("<hr/>").appendTo(content);
|
||||||
if (!subflowNode && node.type != "comment") {
|
if (!subflowNode && node.type != "comment") {
|
||||||
var helpText = $("script[data-help-name$='"+node.type+"']").html()||"";
|
var helpText = $("script[data-help-name$='"+node.type+"']").html()||"";
|
||||||
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(helpText)+'">'+helpText+'</span></div>';
|
$('<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(helpText)+'">'+helpText+'</span></div>').appendTo(content);
|
||||||
}
|
}
|
||||||
if (subflowNode) {
|
if (subflowNode) {
|
||||||
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.info||"")+'">'+marked(subflowNode.info||"")+'</span></div>';
|
$('<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.info||"")+'">'+marked(subflowNode.info||"")+'</span></div>').appendTo(content);
|
||||||
} else if (node._def && node._def.info) {
|
} else if (node._def && node._def.info) {
|
||||||
var info = node._def.info;
|
var info = node._def.info;
|
||||||
var textInfo = (typeof info === "function" ? info.call(node) : info);
|
var textInfo = (typeof info === "function" ? info.call(node) : info);
|
||||||
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(textInfo)+'">'+marked(textInfo)+'</span></div>';
|
$('<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(textInfo)+'">'+marked(textInfo)+'</span></div>').appendTo(content);
|
||||||
//table += '<div class="node-help">'+(typeof info === "function" ? info.call(node) : info)+'</div>';
|
//$('<div class="node-help">'+(typeof info === "function" ? info.call(node) : info)+'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$(content).html(table);
|
|
||||||
|
|
||||||
$(".node-info-property-header").click(function(e) {
|
$(".node-info-property-header").click(function(e) {
|
||||||
var icon = $(this).find("i");
|
var icon = $(this).find("i");
|
||||||
|
Loading…
Reference in New Issue
Block a user