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

[help-sidebar] Refresh help on node selection

This commit is contained in:
Nick O'Leary 2020-05-07 15:19:56 +01:00
parent f25e4ea520
commit 4af1cf1d1f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 26 additions and 91 deletions

View File

@ -593,7 +593,8 @@
"search": "Search help", "search": "Search help",
"nodeHelp": "Node Help", "nodeHelp": "Node Help",
"showHelp": "Show help", "showHelp": "Show help",
"showTopics": "Show topics" "showTopics": "Show topics",
"noHelp": "No help topic selected"
}, },
"config": { "config": {
"name": "Configuration nodes", "name": "Configuration nodes",

View File

@ -37,15 +37,9 @@ RED.sidebar.help = (function() {
content.className = "red-ui-sidebar-info" content.className = "red-ui-sidebar-info"
toolbar = $("<div>", {class:"red-ui-sidebar-header red-ui-info-toolbar"}).appendTo(content); toolbar = $("<div>", {class:"red-ui-sidebar-header red-ui-info-toolbar"}).appendTo(content);
$('<span class="button-group"><a id="red-ui-sidebar-help-show-toc" class="red-ui-button red-ui-button-small selected" href="#"><i class="fa fa-list-ul"></i></a></span>').appendTo(toolbar)
$('<span class="button-group"><a id="red-ui-sidebar-help-show-toc" class="red-ui-sidebar-header-button selected" href="#"><i class="fa fa-angle-right"></i> <i class="fa fa-list-alt"></i></a></span>').appendTo(toolbar)
var showTOCButton = toolbar.find('#red-ui-sidebar-help-show-toc') var showTOCButton = toolbar.find('#red-ui-sidebar-help-show-toc')
RED.popover.tooltip(showTOCButton,RED._("sidebar.help.showTopics")); RED.popover.tooltip(showTOCButton,RED._("sidebar.help.showTopics"));
showTOCButton.on("click",function(e) { showTOCButton.on("click",function(e) {
e.preventDefault(); e.preventDefault();
if ($(this).hasClass('selected')) { if ($(this).hasClass('selected')) {
@ -55,15 +49,7 @@ RED.sidebar.help = (function() {
} }
}); });
// var searchInput = $('<input type="text">').appendTo(toolbar).searchBox({
// delay: 300,
// change: function() {}
// });
var stackContainer = $("<div>",{class:"red-ui-sidebar-help-stack"}).appendTo(content); var stackContainer = $("<div>",{class:"red-ui-sidebar-help-stack"}).appendTo(content);
// var container = $("<div>", {class:"red-ui-info-outline"}).css({'height': '100%'});
tocPanel = $("<div>", {class: "red-ui-sidebar-help-toc"}).appendTo(stackContainer); tocPanel = $("<div>", {class: "red-ui-sidebar-help-toc"}).appendTo(stackContainer);
var helpPanel = $("<div>").css({ var helpPanel = $("<div>").css({
@ -75,8 +61,6 @@ RED.sidebar.help = (function() {
}) })
panels.ratio(0.5); panels.ratio(0.5);
// var searchDiv = $("<div>",{class: "red-ui-help-search"}).appendTo(tocPanel);
helpSearch = $('<input type="text" data-i18n="[placeholder]sidebar.help.search">').appendTo(toolbar).searchBox({ helpSearch = $('<input type="text" data-i18n="[placeholder]sidebar.help.search">').appendTo(toolbar).searchBox({
delay: 100, delay: 100,
change: function() { change: function() {
@ -105,6 +89,8 @@ RED.sidebar.help = (function() {
"padding":"6px", "padding":"6px",
}).appendTo(helpPanel) }).appendTo(helpPanel)
$('<span class="red-ui-help-info-none">'+RED._("sidebar.help.noHelp")+'</span>').appendTo(helpSection);
treeList = $("<div>").css({width: "100%"}).appendTo(tocPanel).treeList({data: []}) treeList = $("<div>").css({width: "100%"}).appendTo(tocPanel).treeList({data: []})
treeList.on('treelistselect', function(e,item) { treeList.on('treelistselect', function(e,item) {
if (item.nodeType) { if (item.nodeType) {
@ -228,6 +214,9 @@ RED.sidebar.help = (function() {
}) })
}) })
if (nodeTypes.length > 0) { if (nodeTypes.length > 0) {
nodeTypes.sort(function(A,B) {
return A.nodeType.localeCompare(B.nodeType)
})
helpData[0].children.push({ helpData[0].children.push({
id: moduleName, id: moduleName,
icon: "fa fa-cube", icon: "fa fa-cube",
@ -288,44 +277,6 @@ RED.sidebar.help = (function() {
}); });
return el; return el;
} }
function refresh(node) {
if (node === undefined) {
refreshSelection();
return;
}
var subflowNode;
helpSection.empty();
if (node === null || Array.isArray(node)) {
return;
} else {
// A single 'thing' selected.
// Check to see if this is a subflow or subflow instance
var m = /^subflow(:(.+))?$/.exec(node.type);
if (m) {
if (m[2]) {
subflowNode = RED.nodes.subflow(m[2]);
} else {
subflowNode = node;
}
}
var helpText = "";
if (node.type === "tab" || node.type === "subflow") {
} else {
if (subflowNode && node.type !== "subflow") {
// Selected a subflow instance node.
// - The subflow template info goes into help
helpText = (RED.utils.renderMarkdown(subflowNode.info||"")||('<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+'</span>'));
setInfoText(node.type, helpText, helpSection);
} else {
helpSearch.searchBox("value",node.type);
// helpText = $("script[data-help-name='"+node.type+"']").html()||('<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+'</span>');
}
}
// $(".red-ui-sidebar-info-stack").scrollTop(0);
}
}
function setInfoText(title, infoText,target) { function setInfoText(title, infoText,target) {
if (title) { if (title) {
@ -354,41 +305,24 @@ RED.sidebar.help = (function() {
show(); show();
} }
// function refreshSelection(selection) { function refreshSelection(selection) {
// if (selection === undefined) { if (selection === undefined) {
// selection = RED.view.selection(); selection = RED.view.selection();
// } }
// if (selection.nodes) { if (selection.nodes) {
// if (selection.nodes.length == 1) { if (selection.nodes.length == 1) {
// var node = selection.nodes[0]; var node = selection.nodes[0];
// if (node.type === "subflow" && node.direction) { if (node.type === "subflow" && node.direction) {
// refresh(RED.nodes.subflow(node.z)); // ignore subflow virtual ports
// } else { } else if (node.type !== 'group'){
// refresh(node); showHelp(node.type);
// } }
// } else { } else {
// refresh(selection.nodes); refresh(selection.nodes);
// } }
// } else if (selection.flows || selection.subflows) { }
// refresh(selection.flows); }
// } else { RED.events.on("view:selection-changed",refreshSelection);
// var activeWS = RED.workspaces.active();
//
// var flow = RED.nodes.workspace(activeWS) || RED.nodes.subflow(activeWS);
// if (flow) {
// refresh(flow);
// } else {
// var workspace = RED.nodes.workspace(RED.workspaces.active());
// if (workspace && workspace.info) {
// refresh(workspace);
// } else {
// refresh(null)
// // clear();
// }
// }
// }
// }
// RED.events.on("view:selection-changed",refreshSelection);
return { return {
init: init, init: init,