mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
[help-sidebar] Include subflow help in sidebar
This commit is contained in:
parent
17891d373b
commit
f25e4ea520
@ -663,9 +663,14 @@
|
|||||||
return this._data;
|
return this._data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
show: function(id) {
|
show: function(item) {
|
||||||
|
if (typeof item === "string") {
|
||||||
|
item = this._items[item]
|
||||||
|
}
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var that = this;
|
var that = this;
|
||||||
var item = this._items[id];
|
|
||||||
var stack = [];
|
var stack = [];
|
||||||
var i = item;
|
var i = item;
|
||||||
while(i) {
|
while(i) {
|
||||||
@ -680,20 +685,19 @@
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
that.reveal(item);
|
that.reveal(item);
|
||||||
},isOpening?200:0);
|
},isOpening?200:0);
|
||||||
// item.treeList.parentList.editableList('show',item);
|
|
||||||
} else {
|
} else {
|
||||||
item.treeList.expand(handleStack)
|
item.treeList.expand(handleStack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleStack();
|
handleStack();
|
||||||
|
|
||||||
// for (var i=0;i<this._data.length;i++) {
|
|
||||||
// if (this._data[i].id === id) {
|
|
||||||
// this._topList.editableList('show',this._data[i]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
reveal: function(item) {
|
reveal: function(item) {
|
||||||
|
if (typeof item === "string") {
|
||||||
|
item = this._items[item]
|
||||||
|
}
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var listOffset = this._topList.offset().top;
|
var listOffset = this._topList.offset().top;
|
||||||
var itemOffset = item.treeList.label.offset().top;
|
var itemOffset = item.treeList.label.offset().top;
|
||||||
var scrollTop = this._topList.parent().scrollTop();
|
var scrollTop = this._topList.parent().scrollTop();
|
||||||
@ -705,15 +709,22 @@
|
|||||||
} else if (itemOffset+itemHeight > treeHeight) {
|
} else if (itemOffset+itemHeight > treeHeight) {
|
||||||
this._topList.parent().scrollTop(scrollTop+((itemOffset+2.5*itemHeight)-treeHeight));
|
this._topList.parent().scrollTop(scrollTop+((itemOffset+2.5*itemHeight)-treeHeight));
|
||||||
}
|
}
|
||||||
console.log("scroll now",this._topList.parent().scrollTop())
|
|
||||||
},
|
},
|
||||||
select: function(item) {
|
select: function(item, triggerEvent) {
|
||||||
|
if (typeof item === "string") {
|
||||||
|
item = this._items[item]
|
||||||
|
}
|
||||||
if (!this.options.multi) {
|
if (!this.options.multi) {
|
||||||
this._topList.find(".selected").removeClass("selected");
|
this._topList.find(".selected").removeClass("selected");
|
||||||
}
|
}
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.show(item.id);
|
this.show(item.id);
|
||||||
item.treeList.label.addClass("selected");
|
item.treeList.label.addClass("selected");
|
||||||
|
if (triggerEvent !== false) {
|
||||||
this._trigger("select",null,item)
|
this._trigger("select",null,item)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
clearSelection: function() {
|
clearSelection: function() {
|
||||||
this._topList.find(".selected").removeClass("selected");
|
this._topList.find(".selected").removeClass("selected");
|
||||||
@ -767,6 +778,9 @@
|
|||||||
return matchCount > 0
|
return matchCount > 0
|
||||||
}
|
}
|
||||||
return this._topList.editableList('filter', filter);
|
return this._topList.editableList('filter', filter);
|
||||||
|
},
|
||||||
|
get: function(id) {
|
||||||
|
return this._items[id] || null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,14 +80,15 @@ RED.sidebar.help = (function() {
|
|||||||
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() {
|
||||||
var val = $(this).val();
|
var val = $(this).val().toLowerCase();
|
||||||
if (val) {
|
if (val) {
|
||||||
showTOC();
|
showTOC();
|
||||||
var c = treeList.treeList('filter',function(item) {
|
var c = treeList.treeList('filter',function(item) {
|
||||||
if (item.depth === 0) {
|
if (item.depth === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return item.id && item.id.indexOf(val) > -1
|
return (item.nodeType && item.nodeType.indexOf(val) > -1) ||
|
||||||
|
(item.subflowLabel && item.subflowLabel.indexOf(val) > -1)
|
||||||
},true)
|
},true)
|
||||||
} else {
|
} else {
|
||||||
treeList.treeList('filter',null);
|
treeList.treeList('filter',null);
|
||||||
@ -128,19 +129,28 @@ RED.sidebar.help = (function() {
|
|||||||
$(window).on("resize", resizeStack);
|
$(window).on("resize", resizeStack);
|
||||||
$(window).on("focus", resizeStack);
|
$(window).on("focus", resizeStack);
|
||||||
|
|
||||||
var refreshTimer;
|
RED.events.on('registry:node-type-added', queueRefresh);
|
||||||
|
RED.events.on('registry:node-type-removed', queueRefresh);
|
||||||
|
RED.events.on('subflows:change', refreshSubflow);
|
||||||
|
|
||||||
RED.events.on('registry:node-type-added', function(nodeType) {
|
RED.actions.add("core:show-help-tab",show);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var refreshTimer;
|
||||||
|
function queueRefresh() {
|
||||||
if (!refreshTimer) {
|
if (!refreshTimer) {
|
||||||
refreshTimer = setTimeout(function() {
|
refreshTimer = setTimeout(function() {
|
||||||
refreshTimer = null;
|
refreshTimer = null;
|
||||||
refreshHelpIndex();
|
refreshHelpIndex();
|
||||||
},500);
|
},500);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
RED.actions.add("core:show-help-tab",show);
|
|
||||||
|
|
||||||
|
function refreshSubflow(sf) {
|
||||||
|
var item = treeList.treeList('get',"node-type:subflow:"+sf.id);
|
||||||
|
item.subflowLabel = sf._def.label().toLowerCase();
|
||||||
|
item.treeList.replaceElement(getNodeLabel({_def:sf._def,type:sf._def.label()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideTOC() {
|
function hideTOC() {
|
||||||
@ -163,6 +173,10 @@ RED.sidebar.help = (function() {
|
|||||||
panels.ratio(Math.max(0.3,Math.min(panelRatio,0.7)));
|
panels.ratio(Math.max(0.3,Math.min(panelRatio,0.7)));
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
tocPanel.css({"transition":""})
|
tocPanel.css({"transition":""})
|
||||||
|
var selected = treeList.treeList('selected');
|
||||||
|
if (selected.id) {
|
||||||
|
treeList.treeList('show',selected);
|
||||||
|
}
|
||||||
},250);
|
},250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,6 +193,24 @@ RED.sidebar.help = (function() {
|
|||||||
expanded: true
|
expanded: true
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
var subflows = RED.nodes.registry.getNodeTypes().filter(function(t) {return /subflow/.test(t)});
|
||||||
|
if (subflows.length > 0) {
|
||||||
|
helpData[0].children.push({
|
||||||
|
label: RED._("menu.label.subflows"),
|
||||||
|
children: []
|
||||||
|
})
|
||||||
|
subflows.forEach(function(nodeType) {
|
||||||
|
var sf = RED.nodes.getType(nodeType);
|
||||||
|
helpData[0].children[0].children.push({
|
||||||
|
id:"node-type:"+nodeType,
|
||||||
|
nodeType: nodeType,
|
||||||
|
subflowLabel: sf.label().toLowerCase(),
|
||||||
|
element: getNodeLabel({_def:sf,type:sf.label()})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
moduleNames.forEach(function(moduleName) {
|
moduleNames.forEach(function(moduleName) {
|
||||||
var module = modules[moduleName];
|
var module = modules[moduleName];
|
||||||
var nodeTypes = [];
|
var nodeTypes = [];
|
||||||
@ -188,7 +220,7 @@ RED.sidebar.help = (function() {
|
|||||||
module.sets[setName].types.forEach(function(nodeType) {
|
module.sets[setName].types.forEach(function(nodeType) {
|
||||||
if ($("script[data-help-name='"+nodeType+"']").length) {
|
if ($("script[data-help-name='"+nodeType+"']").length) {
|
||||||
nodeTypes.push({
|
nodeTypes.push({
|
||||||
id: moduleName+"/"+nodeType,
|
id: "node-type:"+nodeType,
|
||||||
nodeType: nodeType,
|
nodeType: nodeType,
|
||||||
element:getNodeLabel({_def:RED.nodes.getType(nodeType),type:nodeType})
|
element:getNodeLabel({_def:RED.nodes.getType(nodeType),type:nodeType})
|
||||||
})
|
})
|
||||||
@ -211,20 +243,30 @@ RED.sidebar.help = (function() {
|
|||||||
var div = $('<div>',{class:"red-ui-info-outline-item"});
|
var div = $('<div>',{class:"red-ui-info-outline-item"});
|
||||||
RED.utils.createNodeIcon(n).appendTo(div);
|
RED.utils.createNodeIcon(n).appendTo(div);
|
||||||
var contentDiv = $('<div>',{class:"red-ui-search-result-description"}).appendTo(div);
|
var contentDiv = $('<div>',{class:"red-ui-search-result-description"}).appendTo(div);
|
||||||
$('<div>',{class:"red-ui-search-result-node-label red-ui-info-outline-item-label"}).text(n.type).appendTo(contentDiv);
|
$('<div>',{class:"red-ui-search-result-node-label red-ui-info-outline-item-label"}).text(n.name||n.type).appendTo(contentDiv);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHelp(nodeType) {
|
function showHelp(nodeType) {
|
||||||
helpSection.empty();
|
helpSection.empty();
|
||||||
var helpText = $("script[data-help-name='"+nodeType+"']").html()||('<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+'</span>');
|
var helpText;
|
||||||
var title = nodeType;
|
var title;
|
||||||
|
var m = /^subflow(:(.+))?$/.exec(nodeType);
|
||||||
|
if (m && m[2]) {
|
||||||
|
var subflowNode = RED.nodes.subflow(m[2]);
|
||||||
|
helpText = (RED.utils.renderMarkdown(subflowNode.info||"")||('<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+'</span>'));
|
||||||
|
title = subflowNode.name || nodeType;
|
||||||
|
} else {
|
||||||
|
helpText = $("script[data-help-name='"+nodeType+"']").html()||('<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+'</span>');
|
||||||
|
title = nodeType;
|
||||||
|
}
|
||||||
setInfoText(title, helpText, helpSection);
|
setInfoText(title, helpText, helpSection);
|
||||||
|
|
||||||
var ratio = panels.ratio();
|
var ratio = panels.ratio();
|
||||||
if (ratio > 0.7) {
|
if (ratio > 0.7) {
|
||||||
panels.ratio(0.7)
|
panels.ratio(0.7)
|
||||||
}
|
}
|
||||||
|
treeList.treeList("select","node-type:"+nodeType, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,6 +326,7 @@ RED.sidebar.help = (function() {
|
|||||||
// $(".red-ui-sidebar-info-stack").scrollTop(0);
|
// $(".red-ui-sidebar-info-stack").scrollTop(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInfoText(title, infoText,target) {
|
function setInfoText(title, infoText,target) {
|
||||||
if (title) {
|
if (title) {
|
||||||
$("<h1>",{class:"red-ui-help-title"}).text(title).appendTo(target);
|
$("<h1>",{class:"red-ui-help-title"}).text(title).appendTo(target);
|
||||||
|
Loading…
Reference in New Issue
Block a user