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

Merge pull request #3870 from node-red/uri-fragments

Support uri fragments for nodes and groups including edit support
This commit is contained in:
Nick O'Leary 2022-09-15 21:25:50 +01:00 committed by GitHub
commit 313bab37e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 8 deletions

View File

@ -683,7 +683,8 @@
"empty": "empty", "empty": "empty",
"globalConfig": "Global Configuration Nodes", "globalConfig": "Global Configuration Nodes",
"triggerAction": "Trigger action", "triggerAction": "Trigger action",
"find": "Find in workspace" "find": "Find in workspace",
"copyItemUrl": "Copy item url"
}, },
"help": { "help": {
"name": "Help", "name": "Help",

View File

@ -249,8 +249,35 @@ var RED = (function() {
RED.nodes.import(nodes.flows); RED.nodes.import(nodes.flows);
RED.nodes.dirty(false); RED.nodes.dirty(false);
RED.view.redraw(true); RED.view.redraw(true);
if (/^#flow\/.+$/.test(currentHash)) { if (/^#(flow|node|group)\/.+$/.test(currentHash)) {
RED.workspaces.show(currentHash.substring(6),true); const hashParts = currentHash.split('/')
const showEditDialog = hashParts.length > 2 && hashParts[2] === 'edit'
if (hashParts[0] === '#flow') {
RED.workspaces.show(hashParts[1], true);
if (showEditDialog) {
RED.workspaces.edit()
}
} else if (hashParts[0] === '#node') {
const nodeToShow = RED.nodes.node(hashParts[1])
if (nodeToShow) {
setTimeout(() => {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
if (showEditDialog) {
RED.editor.edit(nodeToShow)
}
}, 50)
}
} else if (hashParts[0] === '#group') {
const nodeToShow = RED.nodes.group(hashParts[1])
if (nodeToShow) {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
if (showEditDialog) {
RED.editor.editGroup(nodeToShow)
}
}
}
} }
if (RED.workspaces.count() > 0) { if (RED.workspaces.count() > 0) {
const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}"); const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");

View File

@ -25,6 +25,7 @@ RED.sidebar.info = (function() {
var propertiesPanelHeaderLabel; var propertiesPanelHeaderLabel;
var propertiesPanelHeaderReveal; var propertiesPanelHeaderReveal;
var propertiesPanelHeaderHelp; var propertiesPanelHeaderHelp;
var propertiesPanelHeaderCopyLink;
var selectedObject; var selectedObject;
@ -67,10 +68,20 @@ RED.sidebar.info = (function() {
propertiesPanelHeaderIcon = $("<span>").appendTo(propertiesPanelHeader); propertiesPanelHeaderIcon = $("<span>").appendTo(propertiesPanelHeader);
propertiesPanelHeaderLabel = $("<span>").appendTo(propertiesPanelHeader); propertiesPanelHeaderLabel = $("<span>").appendTo(propertiesPanelHeader);
propertiesPanelHeaderHelp = $('<button class="red-ui-button red-ui-button-small"><i class="fa fa-book"></button>').css({
propertiesPanelHeaderCopyLink = $('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-link"></button>').css({
position: 'absolute', position: 'absolute',
top: '12px', top: '12px',
right: '32px' right: '32px'
}).on("click", function(evt) {
RED.actions.invoke('core:copy-item-url',selectedObject)
}).appendTo(propertiesPanelHeader);
RED.popover.tooltip(propertiesPanelHeaderCopyLink,RED._("sidebar.info.copyItemUrl"));
propertiesPanelHeaderHelp = $('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-book"></button>').css({
position: 'absolute',
top: '12px',
right: '56px'
}).on("click", function(evt) { }).on("click", function(evt) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
@ -80,8 +91,7 @@ RED.sidebar.info = (function() {
}).appendTo(propertiesPanelHeader); }).appendTo(propertiesPanelHeader);
RED.popover.tooltip(propertiesPanelHeaderHelp,RED._("sidebar.help.showHelp")); RED.popover.tooltip(propertiesPanelHeaderHelp,RED._("sidebar.help.showHelp"));
propertiesPanelHeaderReveal = $('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-search"></button>').css({
propertiesPanelHeaderReveal = $('<button class="red-ui-button red-ui-button-small"><i class="fa fa-search"></button>').css({
position: 'absolute', position: 'absolute',
top: '12px', top: '12px',
right: '8px' right: '8px'
@ -185,6 +195,7 @@ RED.sidebar.info = (function() {
propertiesPanelHeaderLabel.text(""); propertiesPanelHeaderLabel.text("");
propertiesPanelHeaderReveal.hide(); propertiesPanelHeaderReveal.hide();
propertiesPanelHeaderHelp.hide(); propertiesPanelHeaderHelp.hide();
propertiesPanelHeaderCopyLink.hide();
return; return;
} else if (Array.isArray(node)) { } else if (Array.isArray(node)) {
// Multiple things selected // Multiple things selected
@ -196,6 +207,7 @@ RED.sidebar.info = (function() {
propertiesPanelHeaderLabel.text("Selection"); propertiesPanelHeaderLabel.text("Selection");
propertiesPanelHeaderReveal.hide(); propertiesPanelHeaderReveal.hide();
propertiesPanelHeaderHelp.hide(); propertiesPanelHeaderHelp.hide();
propertiesPanelHeaderCopyLink.hide();
selectedObject = null; selectedObject = null;
var types = { var types = {
@ -277,9 +289,11 @@ RED.sidebar.info = (function() {
if (node.type === "tab" || node.type === "subflow") { if (node.type === "tab" || node.type === "subflow") {
// If nothing is selected, but we're on a flow or subflow tab. // If nothing is selected, but we're on a flow or subflow tab.
propertiesPanelHeaderHelp.hide(); propertiesPanelHeaderHelp.hide();
propertiesPanelHeaderCopyLink.show();
} else if (node.type === "group") { } else if (node.type === "group") {
propertiesPanelHeaderHelp.hide(); propertiesPanelHeaderHelp.hide();
propertiesPanelHeaderCopyLink.show();
propRow = $('<tr class="red-ui-help-info-row"><td>&nbsp;</td><td></td></tr>').appendTo(tableBody); propRow = $('<tr class="red-ui-help-info-row"><td>&nbsp;</td><td></td></tr>').appendTo(tableBody);
@ -304,8 +318,10 @@ RED.sidebar.info = (function() {
} }
} else if (node.type === 'junction') { } else if (node.type === 'junction') {
propertiesPanelHeaderHelp.hide(); propertiesPanelHeaderHelp.hide();
propertiesPanelHeaderCopyLink.hide();
} else { } else {
propertiesPanelHeaderHelp.show(); propertiesPanelHeaderHelp.show();
propertiesPanelHeaderCopyLink.show();
if (!subflowRegex) { if (!subflowRegex) {
propRow = $('<tr class="red-ui-help-info-row"><td>'+RED._("sidebar.info.type")+'</td><td></td></tr>').appendTo(tableBody); propRow = $('<tr class="red-ui-help-info-row"><td>'+RED._("sidebar.info.type")+'</td><td></td></tr>').appendTo(tableBody);

View File

@ -1192,6 +1192,30 @@ RED.view.tools = (function() {
RED.view.redraw(true); RED.view.redraw(true);
} }
function copyItemUrl(node, isEdit) {
if (!node) {
const selection = RED.view.selection();
if (selection.nodes && selection.nodes.length > 0) {
node = selection.nodes[0]
}
}
if (node) {
let thingType = 'node'
if (node.type === 'group') {
thingType = 'group'
} else if (node.type === 'tab' || node.type === 'subflow') {
thingType = 'flow'
}
let url = `${window.location.origin}${window.location.pathname}#${thingType}/${node.id}`
if (isEdit) {
url += '/edit'
}
if (RED.clipboard.copyText(url)) {
RED.notify('Copied url to clipboard', { timeout: 2000 })
}
}
}
return { return {
init: function() { init: function() {
RED.actions.add("core:show-selected-node-labels", function() { setSelectedNodeLabelState(true); }) RED.actions.add("core:show-selected-node-labels", function() { setSelectedNodeLabelState(true); })
@ -1258,6 +1282,9 @@ RED.view.tools = (function() {
RED.actions.add("core:generate-node-names", generateNodeNames ) RED.actions.add("core:generate-node-names", generateNodeNames )
RED.actions.add("core:copy-item-url", function (node) { copyItemUrl(node) })
RED.actions.add("core:copy-item-edit-url", function (node) { copyItemUrl(node, true) })
// RED.actions.add("core:add-node", function() { addNode() }) // RED.actions.add("core:add-node", function() { addNode() })
}, },
/** /**

View File

@ -6137,7 +6137,9 @@ RED.view = (function() {
if (node.z && (node.type === "group" || node._def.category !== 'config')) { if (node.z && (node.type === "group" || node._def.category !== 'config')) {
node.dirty = true; node.dirty = true;
RED.workspaces.show(node.z); RED.workspaces.show(node.z);
if (node.type === "group" && !node.w && !node.h) {
_redraw();
}
var screenSize = [chart[0].clientWidth/scaleFactor,chart[0].clientHeight/scaleFactor]; var screenSize = [chart[0].clientWidth/scaleFactor,chart[0].clientHeight/scaleFactor];
var scrollPos = [chart.scrollLeft()/scaleFactor,chart.scrollTop()/scaleFactor]; var scrollPos = [chart.scrollLeft()/scaleFactor,chart.scrollTop()/scaleFactor];
var cx = node.x; var cx = node.x;

View File

@ -138,7 +138,7 @@ RED.workspaces = (function() {
activeWorkspace = tab.id; activeWorkspace = tab.id;
window.location.hash = 'flow/'+tab.id; window.location.hash = 'flow/'+tab.id;
$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!tab.disabled); $("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!tab.disabled);
} else { } else {
$("#red-ui-workspace-chart").hide(); $("#red-ui-workspace-chart").hide();
activeWorkspace = 0; activeWorkspace = 0;
window.location.hash = ''; window.location.hash = '';