mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
function for group analysis added
This commit is contained in:
parent
30ea300f65
commit
d7a10328c0
@ -129,6 +129,65 @@ class Flow {
|
|||||||
this.parent.log(msg);
|
this.parent.log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if node A and node B are in the same group.
|
||||||
|
* Node B can also be placed in a subgroup.
|
||||||
|
* If node A is not in any group, false is returned
|
||||||
|
* @param {[type]} nodeIdA [description]
|
||||||
|
* @param {[type]} nodeIdB [description]
|
||||||
|
* @returns {[type]} Returns true if all nodes are in the same group. If not, then false or if node A is not in a group then also false.
|
||||||
|
*/
|
||||||
|
isNodeInSameGroup(nodeIdA, nodeIdB) {
|
||||||
|
const groups = this.global.groups;
|
||||||
|
let result = false;
|
||||||
|
for(let key in groups) {
|
||||||
|
let group = groups[key];
|
||||||
|
|
||||||
|
if(!group.nodes.includes(nodeIdA.id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(group.nodes.includes(nodeIdB.id)) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subfunction to recursively search the groups for matches
|
||||||
|
* @param {[type]} targetNode [description]
|
||||||
|
* @param {[type]} targetGroup [description]
|
||||||
|
* @returns Returns true if a match was found. Otherwise false.
|
||||||
|
*/
|
||||||
|
const isInSubGroup = (targetNode, targetGroup) => {
|
||||||
|
let _result = false;
|
||||||
|
if(targetGroup.nodes.includes(targetNode.id)) {
|
||||||
|
_result = true;
|
||||||
|
} else {
|
||||||
|
for(let nodeId of targetGroup.nodes) {
|
||||||
|
let node = this.getGroupNode(nodeId);
|
||||||
|
|
||||||
|
if(!node){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(node.type === "group"){
|
||||||
|
let result = isInSubGroup(targetNode, node);
|
||||||
|
if(result === true){
|
||||||
|
_result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _result;
|
||||||
|
};
|
||||||
|
|
||||||
|
result = isInSubGroup(nodeIdB, group);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start this flow.
|
* Start this flow.
|
||||||
* The `diff` argument helps define what needs to be started in the case
|
* The `diff` argument helps define what needs to be started in the case
|
||||||
|
Loading…
Reference in New Issue
Block a user