Skip to content

Commit

Permalink
[help-sidebar] Refresh help on node selection
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed May 7, 2020
1 parent f25e4ea commit 4af1cf1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 91 deletions.
Expand Up @@ -593,7 +593,8 @@
"search": "Search help",
"nodeHelp": "Node Help",
"showHelp": "Show help",
"showTopics": "Show topics"
"showTopics": "Show topics",
"noHelp": "No help topic selected"
},
"config": {
"name": "Configuration nodes",
Expand Down
114 changes: 24 additions & 90 deletions packages/node_modules/@node-red/editor-client/src/js/ui/tab-help.js
Expand Up @@ -37,15 +37,9 @@ RED.sidebar.help = (function() {
content.className = "red-ui-sidebar-info"

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-sidebar-header-button selected" href="#"><i class="fa fa-angle-right"></i> <i class="fa fa-list-alt"></i></a></span>').appendTo(toolbar)


$('<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)
var showTOCButton = toolbar.find('#red-ui-sidebar-help-show-toc')

RED.popover.tooltip(showTOCButton,RED._("sidebar.help.showTopics"));


showTOCButton.on("click",function(e) {
e.preventDefault();
if ($(this).hasClass('selected')) {
Expand All @@ -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 container = $("<div>", {class:"red-ui-info-outline"}).css({'height': '100%'});


tocPanel = $("<div>", {class: "red-ui-sidebar-help-toc"}).appendTo(stackContainer);
var helpPanel = $("<div>").css({
Expand All @@ -75,8 +61,6 @@ RED.sidebar.help = (function() {
})
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({
delay: 100,
change: function() {
Expand Down Expand Up @@ -105,6 +89,8 @@ RED.sidebar.help = (function() {
"padding":"6px",
}).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.on('treelistselect', function(e,item) {
if (item.nodeType) {
Expand Down Expand Up @@ -228,6 +214,9 @@ RED.sidebar.help = (function() {
})
})
if (nodeTypes.length > 0) {
nodeTypes.sort(function(A,B) {
return A.nodeType.localeCompare(B.nodeType)
})
helpData[0].children.push({
id: moduleName,
icon: "fa fa-cube",
Expand Down Expand Up @@ -288,44 +277,6 @@ RED.sidebar.help = (function() {
});
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) {
if (title) {
Expand Down Expand Up @@ -354,41 +305,24 @@ RED.sidebar.help = (function() {
show();
}

// function refreshSelection(selection) {
// if (selection === undefined) {
// selection = RED.view.selection();
// }
// if (selection.nodes) {
// if (selection.nodes.length == 1) {
// var node = selection.nodes[0];
// if (node.type === "subflow" && node.direction) {
// refresh(RED.nodes.subflow(node.z));
// } else {
// refresh(node);
// }
// } else {
// refresh(selection.nodes);
// }
// } else if (selection.flows || selection.subflows) {
// refresh(selection.flows);
// } else {
// 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);
function refreshSelection(selection) {
if (selection === undefined) {
selection = RED.view.selection();
}
if (selection.nodes) {
if (selection.nodes.length == 1) {
var node = selection.nodes[0];
if (node.type === "subflow" && node.direction) {
// ignore subflow virtual ports
} else if (node.type !== 'group'){
showHelp(node.type);
}
} else {
refresh(selection.nodes);
}
}
}
RED.events.on("view:selection-changed",refreshSelection);

return {
init: init,
Expand Down

0 comments on commit 4af1cf1

Please sign in to comment.