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

Merge pull request #1937 from node-red/hide-label

Adds the ability to hide a node's label
This commit is contained in:
Nick O'Leary 2018-10-23 11:01:04 +01:00 committed by GitHub
commit 7476b4c7db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 913 additions and 803 deletions

View File

@ -79,7 +79,8 @@
"projects": "Projects",
"projects-new": "New",
"projects-open": "Open",
"projects-settings": "Project Settings"
"projects-settings": "Project Settings",
"showNodeLabelDefault": "Show label of newly added nodes"
}
},
"actions": {
@ -277,7 +278,8 @@
"editConfig": "Edit __type__ config node",
"addNewType": "Add new __type__...",
"nodeProperties": "node properties",
"portLabels": "node settings",
"label": "Label",
"portLabels": "Port labels",
"labelInputs": "Inputs",
"labelOutputs": "Outputs",
"settingIcon": "Icon",
@ -286,6 +288,8 @@
"searchIcons": "Search icons",
"useDefault": "use default",
"description": "Description",
"show": "Show",
"hide": "Hide",
"errors": {
"scopeChange": "Changing the scope will make it unavailable to nodes in other flows that use it"
}

File diff suppressed because it is too large Load Diff

View File

@ -509,6 +509,12 @@ RED.nodes = (function() {
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) {
node.info = n.info;
@ -961,6 +967,9 @@ RED.nodes = (function() {
changed:false,
_config:{}
};
if (n.hasOwnProperty('l')) {
node.l = n.l;
}
if (createNewIds) {
if (subflow_blacklist[n.z]) {
continue;

View File

@ -775,46 +775,45 @@ RED.editor = (function() {
function buildAppearanceForm(container,node) {
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;
$('<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);
$('<div class="form-row">'+
'<label for="node-input-show-label-btn" data-i18n="editor.label"></label>'+
'<button id="node-input-show-label-btn" class="editor-button" style="min-width: 80px; text-align: left;" type="button"><i id="node-input-show-label-btn-i" class="fa fa-toggle-on"></i> <span id="node-input-show-label-label"></span></button> '+
'<input type="checkbox" id="node-input-show-label" style="display: none;"/>'+
'</div>').appendTo(dialogForm);
var setToggleState = function(state) {
var i = $("#node-input-show-label-btn-i");
if (!state) {
i.addClass('fa-toggle-off');
i.removeClass('fa-toggle-on');
$("#node-input-show-label").prop("checked",false);
$("#node-input-show-label-label").text(RED._("editor.hide"));
} else {
i.addClass('fa-toggle-on');
i.removeClass('fa-toggle-off');
$("#node-input-show-label").prop("checked",true);
$("#node-input-show-label-label").text(RED._("editor.show"));
}
} 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);
dialogForm.find('#node-input-show-label-btn').on("click",function(e) {
e.preventDefault();
var i = $("#node-input-show-label-btn-i");
setToggleState(i.hasClass('fa-toggle-off'));
})
if (!node.hasOwnProperty("l")) {
// Show label if type not link
node.l = !/^link (in|out)$/.test(node._def.type);
}
setToggleState(node.l);
// If a node has icon property in defaults, the icon of the node cannot be modified. (e.g, ui_button node in dashboard)
if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon"))) {
$('<hr>').appendTo(dialogForm);
var iconRow = $('<div class="form-row"></div>').appendTo(dialogForm);
$('<label style="width: 50px" data-i18n="editor.settingIcon">').appendTo(iconRow);
$('<label data-i18n="editor.settingIcon">').appendTo(iconRow);
var iconButton = $('<button class="editor-button">').appendTo(iconRow);
var iconButton = $('<button class="editor-button" id="node-settings-icon-button">').appendTo(iconRow);
var nodeDiv = $('<div>',{class:"red-ui-search-result-node"}).appendTo(iconButton);
var colour = RED.utils.getNodeColor(node.type, node._def);
@ -838,7 +837,41 @@ RED.editor = (function() {
RED.utils.createIconElement(icon_url, iconContainer, true, node._def, node);
});
});
$('<div class="uneditable-input" id="node-settings-icon">').text(node.icon).appendTo(iconRow);
$('<div id="node-settings-icon">').text(node.icon).appendTo(iconButton);
}
$('<div class="form-row"><span data-i18n="editor.portLabels"></span></div>').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 style="margin-left: 10px;" 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 style="margin-left: 10px;" 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);
}
}
@ -1166,6 +1199,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;
if (nodeInfoEditor) {
var newInfo = nodeInfoEditor.getValue();

View File

@ -114,7 +114,8 @@ RED.userSettings = (function() {
{
title: "menu.label.nodes",
options: [
{setting:"view-node-status",oldSetting:"menu-menu-item-status",label:"menu.label.displayStatus",default: true, toggle:true,onchange:"core:toggle-status"}
{setting:"view-node-status",oldSetting:"menu-menu-item-status",label:"menu.label.displayStatus",default: true, toggle:true,onchange:"core:toggle-status"},
{setting:"view-node-show-label",label:"menu.label.showNodeLabelDefault",default: true, toggle:true}
]
},
{
@ -210,14 +211,14 @@ RED.userSettings = (function() {
}
}
allSettings[opt.setting] = opt;
if (opt.onchange) {
var value = currentEditorSettings.view[opt.setting];
if ((value === null || value === undefined) && opt.hasOwnProperty('default')) {
value = opt.default;
currentEditorSettings.view[opt.setting] = value;
editorSettingsChanged = true;
}
var value = currentEditorSettings.view[opt.setting];
if ((value === null || value === undefined) && opt.hasOwnProperty('default')) {
value = opt.default;
currentEditorSettings.view[opt.setting] = value;
editorSettingsChanged = true;
}
if (opt.onchange) {
var callback = opt.onchange;
if (typeof callback === 'string') {
callback = RED.actions.get(callback);

View File

@ -365,6 +365,11 @@ RED.view = (function() {
var historyEvent = result.historyEvent;
var nn = result.node;
var showLabel = RED.utils.getMessageProperty(RED.settings.get('editor'),"view.view-node-show-label");
if (showLabel !== undefined && !/^link (in|out)$/.test(nn._def.type) && !nn._def.defaults.hasOwnProperty("l")) {
nn.l = showLabel;
}
var helperOffset = d3.touches(ui.helper.get(0))[0]||d3.mouse(ui.helper.get(0));
var mousePos = d3.touches(this)[0]||d3.mouse(this);
@ -668,6 +673,12 @@ RED.view = (function() {
var historyEvent = result.historyEvent;
nn.x = point[0];
nn.y = point[1];
var showLabel = RED.utils.getMessageProperty(RED.settings.get('editor'),"view.view-node-show-label");
if (showLabel !== undefined && !/^link (in|out)$/.test(nn._def.type) && !nn._def.defaults.hasOwnProperty("l")) {
nn.l = showLabel;
}
if (mouse_mode === RED.state.QUICK_JOINING || quickAddLink) {
if (quickAddLink || drag_lines.length > 0) {
var drag_line = quickAddLink||drag_lines[0];
@ -2072,7 +2083,7 @@ RED.view = (function() {
nodeEnter.each(function(d,i) {
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);
var l = RED.utils.getNodeLabel(d);
if (isLink) {
@ -2159,7 +2170,7 @@ RED.view = (function() {
var nodeBody = d3.select(this);
nodeBody.classed("node_hovered",true);
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() {
var tooltip;
if (d._def.label) {
@ -2242,25 +2253,28 @@ RED.view = (function() {
//icon.style("pointer-events","none");
icon_group.style("pointer-events","none");
}
if (!isLink) {
var text = node.append("svg:text").attr("class","node_label").attr("x", 38).attr("dy", ".35em").attr("text-anchor","start");
if (d._def.align) {
text.attr("class","node_label node_label_"+d._def.align);
if (d._def.align === "right") {
text.attr("text-anchor","end");
}
var text = node.append("svg:text")
.attr("class","node_label")
.attr("x", 38)
.attr("dy", ".35em")
.attr("text-anchor","start")
.classed("hidden",isLink);
if (d._def.align) {
text.attr("class","node_label node_label_"+d._def.align);
if (d._def.align === "right") {
text.attr("text-anchor","end");
}
var status = node.append("svg:g").attr("class","node_status_group").style("display","none");
var statusRect = status.append("rect").attr("class","node_status")
.attr("x",6).attr("y",1).attr("width",9).attr("height",9)
.attr("rx",2).attr("ry",2).attr("stroke-width","3");
var statusLabel = status.append("svg:text")
.attr("class","node_status_label")
.attr("x",20).attr("y",9);
}
var status = node.append("svg:g").attr("class","node_status_group").style("display","none");
var statusRect = status.append("rect").attr("class","node_status")
.attr("x",6).attr("y",1).attr("width",9).attr("height",9)
.attr("rx",2).attr("ry",2).attr("stroke-width","3");
var statusLabel = status.append("svg:text")
.attr("class","node_status_label")
.attr("x",20).attr("y",9);
//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");
@ -2272,13 +2286,18 @@ RED.view = (function() {
node.each(function(d,i) {
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;
//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 ow = d.w;
d.w = Math.max(node_width,20*(Math.ceil((calculateTextWidth(l, "node_label", 50)+(d._def.inputs>0?7:0))/20)) );
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.h = Math.max(node_height,(d.outputs||0) * 15);
d.x += (d.w-ow)/2;
d.resize = false;
@ -2286,7 +2305,6 @@ RED.view = (function() {
var thisNode = d3.select(this);
//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) + ")"; });
if (mouse_mode != RED.state.MOVING_ACTIVE) {
thisNode.selectAll(".node")
.attr("width",function(d){return d.w})
@ -2372,8 +2390,7 @@ RED.view = (function() {
}
return "node_label"+
(d._def.align?" node_label_"+d._def.align:"")+s;
});
}).classed("hidden",isLink);
if (d._def.icon) {
var icon = thisNode.select(".node_icon");
var faIcon = thisNode.select(".fa-lg");

View File

@ -56,7 +56,7 @@ RED.workspaces = (function() {
RED.sidebar.config.refresh();
}
function showRenameWorkspaceDialog(id) {
function showEditWorkspaceDialog(id) {
var workspace = RED.nodes.workspace(id);
RED.view.state(RED.state.EDITING);
var tabflowEditor;
@ -255,7 +255,7 @@ RED.workspaces = (function() {
},
ondblclick: function(tab) {
if (tab.type != "subflow") {
showRenameWorkspaceDialog(tab.id);
showEditWorkspaceDialog(tab.id);
} else {
RED.editor.editSubflow(RED.nodes.subflow(tab.id));
}
@ -328,7 +328,7 @@ RED.workspaces = (function() {
}
function editWorkspace(id) {
showRenameWorkspaceDialog(id||activeWorkspace);
showEditWorkspaceDialog(id||activeWorkspace);
}
function removeWorkspace(ws) {

View File

@ -378,6 +378,16 @@
}
}
#node-settings-icon-button {
position: relative;
padding-left: 30px;
width: calc(100% - 150px);
.red-ui-search-result-node {
position: absolute;
top: 2px;
left: 2px;
}
}
#node-settings-icon {
margin-left: 10px;
width: calc(100% - 163px);