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

update subflow finding algorithm

This commit is contained in:
Hiroyasu Nishiyama 2021-02-19 14:35:59 +09:00
parent 5a6568e7c2
commit 74ea382cf2

View File

@ -224,66 +224,91 @@ RED.debug = (function() {
});
RED.popover.tooltip(toolbar.find("#red-ui-sidebar-debug-clear"),RED._('node-red:debug.sidebar.clearLog'),"core:clear-debug-messages");
return {
content: content,
footer: footerToolbar
}
};
}
function containsDebug(sid, map) {
if (sid in map) {
return true;
}
var nodes = RED.nodes.filterNodes({z: sid});
var item = map[sid];
if (item) {
if (item.debug === undefined) {
var sfs = Object.keys(item.subflows);
var contain = false;
nodes.forEach(function (n) {
if (contain) {
return;
}
var nt = n.type;
if (nt === "debug") {
for (var i = 0; i < sfs.length; i++) {
var sf = sfs[i];
if (containsDebug(sf, map)) {
contain = true;
return;
}
if (nt.substring(0, 8) === "subflow:") {
var id = nt.substring(8);
if (containsDebug(id, map)) {
contain = true;
return;
break;
}
}
});
if (contain) {
map[sid] = true;
item.debug = contain;
}
return contain;
return item.debug;
}
return false;
}
function refreshDebugNodeList() {
debugNodeList.editableList('empty');
var candidateNodes = RED.nodes.filterNodes({type:'debug'});
var workspaceOrder = RED.nodes.getWorkspaceOrder();
var workspaceOrderMap = {};
workspaceOrder.forEach(function(ws,i) {
workspaceOrderMap[ws] = i;
});
candidateNodes = candidateNodes.filter(function(node) {
return workspaceOrderMap.hasOwnProperty(node.z);
});
var map = {};
var candidateNodes = [];
var candidateSFs = [];
var subflows = {};
RED.nodes.eachNode(function (n) {
var nt = n.type;
if ((n.z in workspaceOrderMap) &&
(nt.substring(0, 8) === "subflow:")) {
var sid = nt.substring(8);
if (containsDebug(sid, map)) {
if (nt === "debug") {
if (n.z in workspaceOrderMap) {
candidateNodes.push(n);
}
else {
var sf = RED.nodes.subflow(n.z);
if (sf) {
subflows[sf.id] = {
debug: true,
subflows: {}
};
}
}
}
else if(nt.substring(0, 8) === "subflow:") {
if (n.z in workspaceOrderMap) {
candidateSFs.push(n);
}
else {
var psf = RED.nodes.subflow(n.z);
if (psf) {
var sid = nt.substring(8);
var item = subflows[psf.id];
if (!item) {
item = {
debug: undefined,
subflows: {}
};
subflows[psf.id] = item;
}
item.subflows[sid] = true;
}
}
}
});
candidateSFs.forEach(function (sf) {
var sid = sf.type.substring(8);
if (containsDebug(sid, subflows)) {
candidateNodes.push(sf);
}
});
candidateNodes.sort(function(A,B) {
var wsA = workspaceOrderMap[A.z];
var wsB = workspaceOrderMap[B.z];