mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow a node label to be hidden
This commit is contained in:
parent
6bd0682e8c
commit
0376e0d711
@ -509,6 +509,12 @@ RED.nodes = (function() {
|
|||||||
node.icon = n.icon;
|
node.icon = n.icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((!n._def.defaults || !n._def.defaults.hasOwnProperty("l")) && n.hasOwnProperty('l')) {
|
||||||
|
var isLink = /^link (in|out)$/.test(node.type);
|
||||||
|
if (isLink == n.l) {
|
||||||
|
node.l = n.l;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (n.info) {
|
if (n.info) {
|
||||||
node.info = n.info;
|
node.info = n.info;
|
||||||
@ -961,6 +967,9 @@ RED.nodes = (function() {
|
|||||||
changed:false,
|
changed:false,
|
||||||
_config:{}
|
_config:{}
|
||||||
};
|
};
|
||||||
|
if (n.hasOwnProperty('l')) {
|
||||||
|
node.l = n.l;
|
||||||
|
}
|
||||||
if (createNewIds) {
|
if (createNewIds) {
|
||||||
if (subflow_blacklist[n.z]) {
|
if (subflow_blacklist[n.z]) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -775,41 +775,21 @@ RED.editor = (function() {
|
|||||||
function buildAppearanceForm(container,node) {
|
function buildAppearanceForm(container,node) {
|
||||||
var dialogForm = $('<form class="dialog-form form-horizontal" autocomplete="off"></form>').appendTo(container);
|
var dialogForm = $('<form class="dialog-form form-horizontal" autocomplete="off"></form>').appendTo(container);
|
||||||
|
|
||||||
var inputCount = node.inputs || node._def.inputs || 0;
|
|
||||||
var outputCount = node.outputs || node._def.outputs || 0;
|
|
||||||
if (node.type === 'subflow') {
|
|
||||||
inputCount = node.in.length;
|
|
||||||
outputCount = node.out.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
var inputLabels = node.inputLabels || [];
|
|
||||||
var outputLabels = node.outputLabels || [];
|
|
||||||
|
|
||||||
var inputPlaceholder = node._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
|
||||||
var outputPlaceholder = node._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
|
||||||
|
|
||||||
var i,row;
|
var i,row;
|
||||||
$('<div class="form-row"><span data-i18n="editor.labelInputs"></span><div id="node-label-form-inputs"></div></div>').appendTo(dialogForm);
|
|
||||||
var inputsDiv = $("#node-label-form-inputs");
|
$('<div class="form-row">'+
|
||||||
if (inputCount > 0) {
|
'<label style="margin:0; margin-right: 20px; width: auto" for="node-input-show-label" data-i18n="">Show node label</label>'+
|
||||||
for (i=0;i<inputCount;i++) {
|
'<input style="margin:0;" type="checkbox" id="node-input-show-label"/>'+
|
||||||
buildLabelRow("input",i,inputLabels[i],inputPlaceholder).appendTo(inputsDiv);
|
'</div>').appendTo(dialogForm);
|
||||||
}
|
|
||||||
} else {
|
if (!node.hasOwnProperty("l")) {
|
||||||
buildLabelRow().appendTo(inputsDiv);
|
// Show label if type not link
|
||||||
}
|
node.l = !/^link (in|out)$/.test(node._def.type);
|
||||||
$('<div class="form-row"><span data-i18n="editor.labelOutputs"></span><div id="node-label-form-outputs"></div></div>').appendTo(dialogForm);
|
|
||||||
var outputsDiv = $("#node-label-form-outputs");
|
|
||||||
if (outputCount > 0) {
|
|
||||||
for (i=0;i<outputCount;i++) {
|
|
||||||
buildLabelRow("output",i,outputLabels[i],outputPlaceholder).appendTo(outputsDiv);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buildLabelRow().appendTo(outputsDiv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#node-input-show-label").prop("checked",node.l);
|
||||||
|
|
||||||
if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon"))) {
|
if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon"))) {
|
||||||
$('<hr>').appendTo(dialogForm);
|
|
||||||
var iconRow = $('<div class="form-row"></div>').appendTo(dialogForm);
|
var iconRow = $('<div class="form-row"></div>').appendTo(dialogForm);
|
||||||
$('<label style="width: 50px" data-i18n="editor.settingIcon">').appendTo(iconRow);
|
$('<label style="width: 50px" data-i18n="editor.settingIcon">').appendTo(iconRow);
|
||||||
|
|
||||||
@ -839,6 +819,41 @@ RED.editor = (function() {
|
|||||||
})
|
})
|
||||||
$('<div class="uneditable-input" id="node-settings-icon">').text(node.icon).appendTo(iconRow);
|
$('<div class="uneditable-input" id="node-settings-icon">').text(node.icon).appendTo(iconRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('<hr>').appendTo(dialogForm);
|
||||||
|
|
||||||
|
|
||||||
|
var inputCount = node.inputs || node._def.inputs || 0;
|
||||||
|
var outputCount = node.outputs || node._def.outputs || 0;
|
||||||
|
if (node.type === 'subflow') {
|
||||||
|
inputCount = node.in.length;
|
||||||
|
outputCount = node.out.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
var inputLabels = node.inputLabels || [];
|
||||||
|
var outputLabels = node.outputLabels || [];
|
||||||
|
|
||||||
|
var inputPlaceholder = node._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
||||||
|
var outputPlaceholder = node._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
||||||
|
|
||||||
|
$('<div class="form-row"><span data-i18n="editor.labelInputs"></span><div id="node-label-form-inputs"></div></div>').appendTo(dialogForm);
|
||||||
|
var inputsDiv = $("#node-label-form-inputs");
|
||||||
|
if (inputCount > 0) {
|
||||||
|
for (i=0;i<inputCount;i++) {
|
||||||
|
buildLabelRow("input",i,inputLabels[i],inputPlaceholder).appendTo(inputsDiv);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buildLabelRow().appendTo(inputsDiv);
|
||||||
|
}
|
||||||
|
$('<div class="form-row"><span data-i18n="editor.labelOutputs"></span><div id="node-label-form-outputs"></div></div>').appendTo(dialogForm);
|
||||||
|
var outputsDiv = $("#node-label-form-outputs");
|
||||||
|
if (outputCount > 0) {
|
||||||
|
for (i=0;i<outputCount;i++) {
|
||||||
|
buildLabelRow("output",i,outputLabels[i],outputPlaceholder).appendTo(outputsDiv);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buildLabelRow().appendTo(outputsDiv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLabels(editing_node, changes, outputMap) {
|
function updateLabels(editing_node, changes, outputMap) {
|
||||||
@ -1165,6 +1180,42 @@ RED.editor = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$("#node-input-show-label").prop('checked')) {
|
||||||
|
// Not checked - hide label
|
||||||
|
if (!/^link (in|out)$/.test(node.type)) {
|
||||||
|
// Not a link node - default state is true
|
||||||
|
if (node.l !== false) {
|
||||||
|
changes.l = node.l
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
node.l = false;
|
||||||
|
} else {
|
||||||
|
// A link node - default state is false
|
||||||
|
if (node.hasOwnProperty('l')) {
|
||||||
|
changes.l = node.l
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
delete node.l;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Checked - show label
|
||||||
|
if (!/^link (in|out)$/.test(node.type)) {
|
||||||
|
// Not a link node - default state is true
|
||||||
|
if (node.hasOwnProperty('l')) {
|
||||||
|
changes.l = node.l
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
delete node.l;
|
||||||
|
} else {
|
||||||
|
if (!node.l) {
|
||||||
|
changes.l = node.l
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
node.l = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.resize = true;
|
||||||
|
|
||||||
var oldInfo = node.info;
|
var oldInfo = node.info;
|
||||||
if (nodeInfoEditor) {
|
if (nodeInfoEditor) {
|
||||||
var newInfo = nodeInfoEditor.getValue();
|
var newInfo = nodeInfoEditor.getValue();
|
||||||
|
@ -2073,7 +2073,7 @@ RED.view = (function() {
|
|||||||
|
|
||||||
nodeEnter.each(function(d,i) {
|
nodeEnter.each(function(d,i) {
|
||||||
var node = d3.select(this);
|
var node = d3.select(this);
|
||||||
var isLink = d.type === "link in" || d.type === "link out";
|
var isLink = d.hasOwnProperty('l')?!d.l : (d.type === "link in" || d.type === "link out")
|
||||||
node.attr("id",d.id);
|
node.attr("id",d.id);
|
||||||
var l = RED.utils.getNodeLabel(d);
|
var l = RED.utils.getNodeLabel(d);
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
@ -2160,7 +2160,7 @@ RED.view = (function() {
|
|||||||
var nodeBody = d3.select(this);
|
var nodeBody = d3.select(this);
|
||||||
nodeBody.classed("node_hovered",true);
|
nodeBody.classed("node_hovered",true);
|
||||||
clearTimeout(portLabelHoverTimeout);
|
clearTimeout(portLabelHoverTimeout);
|
||||||
if (d.type === "link in" || d.type === "link out") {
|
if (d.hasOwnProperty('l')?!d.l : (d.type === "link in" || d.type === "link out")) {
|
||||||
portLabelHoverTimeout = setTimeout(function() {
|
portLabelHoverTimeout = setTimeout(function() {
|
||||||
var tooltip;
|
var tooltip;
|
||||||
if (d._def.label) {
|
if (d._def.label) {
|
||||||
@ -2243,8 +2243,13 @@ RED.view = (function() {
|
|||||||
//icon.style("pointer-events","none");
|
//icon.style("pointer-events","none");
|
||||||
icon_group.style("pointer-events","none");
|
icon_group.style("pointer-events","none");
|
||||||
}
|
}
|
||||||
if (!isLink) {
|
var text = node.append("svg:text")
|
||||||
var text = node.append("svg:text").attr("class","node_label").attr("x", 38).attr("dy", ".35em").attr("text-anchor","start");
|
.attr("class","node_label")
|
||||||
|
.attr("x", 38)
|
||||||
|
.attr("dy", ".35em")
|
||||||
|
.attr("text-anchor","start")
|
||||||
|
.classed("hidden",isLink);
|
||||||
|
|
||||||
if (d._def.align) {
|
if (d._def.align) {
|
||||||
text.attr("class","node_label node_label_"+d._def.align);
|
text.attr("class","node_label node_label_"+d._def.align);
|
||||||
if (d._def.align === "right") {
|
if (d._def.align === "right") {
|
||||||
@ -2253,15 +2258,13 @@ RED.view = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var status = node.append("svg:g").attr("class","node_status_group").style("display","none");
|
var status = node.append("svg:g").attr("class","node_status_group").style("display","none");
|
||||||
|
|
||||||
var statusRect = status.append("rect").attr("class","node_status")
|
var statusRect = status.append("rect").attr("class","node_status")
|
||||||
.attr("x",6).attr("y",1).attr("width",9).attr("height",9)
|
.attr("x",6).attr("y",1).attr("width",9).attr("height",9)
|
||||||
.attr("rx",2).attr("ry",2).attr("stroke-width","3");
|
.attr("rx",2).attr("ry",2).attr("stroke-width","3");
|
||||||
|
|
||||||
var statusLabel = status.append("svg:text")
|
var statusLabel = status.append("svg:text")
|
||||||
.attr("class","node_status_label")
|
.attr("class","node_status_label")
|
||||||
.attr("x",20).attr("y",9);
|
.attr("x",20).attr("y",9);
|
||||||
}
|
|
||||||
//node.append("circle").attr({"class":"centerDot","cx":0,"cy":0,"r":5});
|
//node.append("circle").attr({"class":"centerDot","cx":0,"cy":0,"r":5});
|
||||||
|
|
||||||
//node.append("path").attr("class","node_error").attr("d","M 3,-3 l 10,0 l -5,-8 z");
|
//node.append("path").attr("class","node_error").attr("d","M 3,-3 l 10,0 l -5,-8 z");
|
||||||
@ -2273,13 +2276,18 @@ RED.view = (function() {
|
|||||||
|
|
||||||
node.each(function(d,i) {
|
node.each(function(d,i) {
|
||||||
if (d.dirty) {
|
if (d.dirty) {
|
||||||
var isLink = d.type === "link in" || d.type === "link out";
|
var isLink = d.hasOwnProperty('l')?!d.l : (d.type === "link in" || d.type === "link out")
|
||||||
dirtyNodes[d.id] = d;
|
dirtyNodes[d.id] = d;
|
||||||
//if (d.x < -50) deleteSelection(); // Delete nodes if dragged back to palette
|
//if (d.x < -50) deleteSelection(); // Delete nodes if dragged back to palette
|
||||||
if (!isLink && d.resize) {
|
if (/*!isLink &&*/ d.resize) {
|
||||||
var l = RED.utils.getNodeLabel(d);
|
var l = RED.utils.getNodeLabel(d);
|
||||||
var ow = d.w;
|
var ow = d.w;
|
||||||
|
if (isLink) {
|
||||||
|
d.w = node_height;
|
||||||
|
} else {
|
||||||
d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/20)) );
|
d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/20)) );
|
||||||
|
}
|
||||||
|
// d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/20)) );
|
||||||
d.h = Math.max(node_height,(d.outputs||0) * 15);
|
d.h = Math.max(node_height,(d.outputs||0) * 15);
|
||||||
d.x += (d.w-ow)/2;
|
d.x += (d.w-ow)/2;
|
||||||
d.resize = false;
|
d.resize = false;
|
||||||
@ -2287,7 +2295,6 @@ RED.view = (function() {
|
|||||||
var thisNode = d3.select(this);
|
var thisNode = d3.select(this);
|
||||||
//thisNode.selectAll(".centerDot").attr({"cx":function(d) { return d.w/2;},"cy":function(d){return d.h/2}});
|
//thisNode.selectAll(".centerDot").attr({"cx":function(d) { return d.w/2;},"cy":function(d){return d.h/2}});
|
||||||
thisNode.attr("transform", function(d) { return "translate(" + (d.x-d.w/2) + "," + (d.y-d.h/2) + ")"; });
|
thisNode.attr("transform", function(d) { return "translate(" + (d.x-d.w/2) + "," + (d.y-d.h/2) + ")"; });
|
||||||
|
|
||||||
if (mouse_mode != RED.state.MOVING_ACTIVE) {
|
if (mouse_mode != RED.state.MOVING_ACTIVE) {
|
||||||
thisNode.selectAll(".node")
|
thisNode.selectAll(".node")
|
||||||
.attr("width",function(d){return d.w})
|
.attr("width",function(d){return d.w})
|
||||||
@ -2373,8 +2380,7 @@ RED.view = (function() {
|
|||||||
}
|
}
|
||||||
return "node_label"+
|
return "node_label"+
|
||||||
(d._def.align?" node_label_"+d._def.align:"")+s;
|
(d._def.align?" node_label_"+d._def.align:"")+s;
|
||||||
});
|
}).classed("hidden",isLink);
|
||||||
|
|
||||||
if (d._def.icon) {
|
if (d._def.icon) {
|
||||||
var icon = thisNode.select(".node_icon");
|
var icon = thisNode.select(".node_icon");
|
||||||
var faIcon = thisNode.select(".fa-lg");
|
var faIcon = thisNode.select(".fa-lg");
|
||||||
|
@ -56,7 +56,7 @@ RED.workspaces = (function() {
|
|||||||
RED.sidebar.config.refresh();
|
RED.sidebar.config.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showRenameWorkspaceDialog(id) {
|
function showEditWorkspaceDialog(id) {
|
||||||
var workspace = RED.nodes.workspace(id);
|
var workspace = RED.nodes.workspace(id);
|
||||||
RED.view.state(RED.state.EDITING);
|
RED.view.state(RED.state.EDITING);
|
||||||
var tabflowEditor;
|
var tabflowEditor;
|
||||||
@ -235,7 +235,7 @@ RED.workspaces = (function() {
|
|||||||
},
|
},
|
||||||
ondblclick: function(tab) {
|
ondblclick: function(tab) {
|
||||||
if (tab.type != "subflow") {
|
if (tab.type != "subflow") {
|
||||||
showRenameWorkspaceDialog(tab.id);
|
showEditWorkspaceDialog(tab.id);
|
||||||
} else {
|
} else {
|
||||||
RED.editor.editSubflow(RED.nodes.subflow(tab.id));
|
RED.editor.editSubflow(RED.nodes.subflow(tab.id));
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ RED.workspaces = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function editWorkspace(id) {
|
function editWorkspace(id) {
|
||||||
showRenameWorkspaceDialog(id||activeWorkspace);
|
showEditWorkspaceDialog(id||activeWorkspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeWorkspace(ws) {
|
function removeWorkspace(ws) {
|
||||||
|
Loading…
Reference in New Issue
Block a user