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

Get group order right in history events to ensure proper handling

This commit is contained in:
Nick O'Leary 2020-07-06 15:59:50 +01:00
parent 73448a6039
commit ef7c9b5c2a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 30 additions and 2 deletions

View File

@ -85,7 +85,7 @@ RED.history = (function() {
}
if (ev.groups) {
inverseEv.groups = [];
for (i=0;i<ev.groups.length;i++) {
for (i = ev.groups.length - 1;i>=0;i--) {
group = ev.groups[i];
modifiedTabs[group.z] = true;
// The order of groups is important
@ -214,7 +214,7 @@ RED.history = (function() {
inverseEv.groups = [];
var groupsToAdd = {};
ev.groups.forEach(function(g) { groupsToAdd[g.id] = g; });
for (i=0;i<ev.groups.length;i++) {
for (i = ev.groups.length - 1;i>=0;i--) {
RED.nodes.addGroup(ev.groups[i])
modifiedTabs[ev.groups[i].z] = true;
// The order of groups is important

View File

@ -1427,6 +1427,9 @@ RED.nodes = (function() {
delete n.status.wires;
}
}
// Order the groups to ensure they are outer-most to inner-most
var groupDepthMap = {};
console.log(new_groups);
for (i=0;i<new_groups.length;i++) {
n = new_groups[i];
if (n.g && node_map[n.g]) {
@ -1437,8 +1440,33 @@ RED.nodes = (function() {
n.nodes = n.nodes.map(function(id) {
return node_map[id];
})
n.nodes = n.nodes.filter(function(v) { return !!v});
if (!n.g) {
groupDepthMap[n.id] = 0;
}
}
var changedDepth;
do {
changedDepth = false;
for (i=0;i<new_groups.length;i++) {
n = new_groups[i];
if (n.g) {
if (groupDepthMap[n.id] !== groupDepthMap[n.g] + 1) {
groupDepthMap[n.id] = groupDepthMap[n.g] + 1;
changedDepth = true;
}
}
}
} while(changedDepth);
new_groups.sort(function(A,B) {
return groupDepthMap[A.id] - groupDepthMap[B.id];
});
for (i=0;i<new_groups.length;i++) {
n = new_groups[i];
addGroup(n);
}
// Now the nodes have been fully updated, add them.
for (i=0;i<new_nodes.length;i++) {
var node = new_nodes[i];