mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #4182 from node-red/4101-merge-group-env-vars
Combine existing env vars when merging groups
This commit is contained in:
commit
5e2e0b2e39
@ -401,7 +401,7 @@ RED.group = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var existingGroup;
|
var existingGroup;
|
||||||
|
var mergedEnv = {}
|
||||||
// Second pass, ungroup any groups in the selection and add their contents
|
// Second pass, ungroup any groups in the selection and add their contents
|
||||||
// to the selection
|
// to the selection
|
||||||
for (var i=0; i<selection.nodes.length; i++) {
|
for (var i=0; i<selection.nodes.length; i++) {
|
||||||
@ -410,6 +410,11 @@ RED.group = (function() {
|
|||||||
if (!existingGroup) {
|
if (!existingGroup) {
|
||||||
existingGroup = n;
|
existingGroup = n;
|
||||||
}
|
}
|
||||||
|
if (n.env && n.env.length > 0) {
|
||||||
|
n.env.forEach(env => {
|
||||||
|
mergedEnv[env.name] = env
|
||||||
|
})
|
||||||
|
}
|
||||||
ungroupHistoryEvent.groups.push(n);
|
ungroupHistoryEvent.groups.push(n);
|
||||||
nodes = nodes.concat(ungroup(n));
|
nodes = nodes.concat(ungroup(n));
|
||||||
} else {
|
} else {
|
||||||
@ -427,6 +432,7 @@ RED.group = (function() {
|
|||||||
group.style = existingGroup.style;
|
group.style = existingGroup.style;
|
||||||
group.name = existingGroup.name;
|
group.name = existingGroup.name;
|
||||||
}
|
}
|
||||||
|
group.env = Object.values(mergedEnv)
|
||||||
RED.view.select({nodes:[group]})
|
RED.view.select({nodes:[group]})
|
||||||
}
|
}
|
||||||
historyEvent.events.push({
|
historyEvent.events.push({
|
||||||
|
@ -232,6 +232,63 @@ RED.view = (function() {
|
|||||||
return api
|
return api
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
const selectedGroups = (function() {
|
||||||
|
let groups = new Set()
|
||||||
|
const api = {
|
||||||
|
add: function(g, includeNodes, addToMovingSet) {
|
||||||
|
groups.add(g)
|
||||||
|
if (!g.selected) {
|
||||||
|
g.selected = true;
|
||||||
|
g.dirty = true;
|
||||||
|
}
|
||||||
|
if (addToMovingSet !== false) {
|
||||||
|
movingSet.add(g);
|
||||||
|
}
|
||||||
|
if (includeNodes) {
|
||||||
|
var currentSet = new Set(movingSet.nodes());
|
||||||
|
var allNodes = RED.group.getNodes(g,true);
|
||||||
|
allNodes.forEach(function(n) {
|
||||||
|
if (!currentSet.has(n)) {
|
||||||
|
movingSet.add(n)
|
||||||
|
}
|
||||||
|
n.dirty = true;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
selectedLinks.clearUnselected()
|
||||||
|
},
|
||||||
|
remove: function(g) {
|
||||||
|
groups.delete(g)
|
||||||
|
if (g.selected) {
|
||||||
|
g.selected = false;
|
||||||
|
g.dirty = true;
|
||||||
|
}
|
||||||
|
const allNodes = RED.group.getNodes(g,true);
|
||||||
|
const nodeSet = new Set(allNodes);
|
||||||
|
nodeSet.add(g);
|
||||||
|
for (let i = movingSet.length()-1; i >= 0; i -= 1) {
|
||||||
|
const msn = movingSet.get(i);
|
||||||
|
if (nodeSet.has(msn.n) || msn.n === g) {
|
||||||
|
msn.n.selected = false;
|
||||||
|
msn.n.dirty = true;
|
||||||
|
movingSet.remove(msn.n,i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectedLinks.clearUnselected()
|
||||||
|
},
|
||||||
|
length: () => groups.length,
|
||||||
|
forEach: (func) => { groups.forEach(func) },
|
||||||
|
toArray: () => [...groups],
|
||||||
|
clear: function () {
|
||||||
|
groups.forEach(g => {
|
||||||
|
g.selected = false
|
||||||
|
g.dirty = true
|
||||||
|
})
|
||||||
|
groups.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return api
|
||||||
|
})()
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
@ -1136,7 +1193,7 @@ RED.view = (function() {
|
|||||||
var touchTrigger = options.touchTrigger;
|
var touchTrigger = options.touchTrigger;
|
||||||
|
|
||||||
if (targetGroup) {
|
if (targetGroup) {
|
||||||
selectGroup(targetGroup,false);
|
selectedGroups.add(targetGroup,false);
|
||||||
RED.view.redraw();
|
RED.view.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1462,7 +1519,7 @@ RED.view = (function() {
|
|||||||
clearSelection();
|
clearSelection();
|
||||||
nn.selected = true;
|
nn.selected = true;
|
||||||
if (targetGroup) {
|
if (targetGroup) {
|
||||||
selectGroup(targetGroup,false);
|
selectedGroups.add(targetGroup,false);
|
||||||
}
|
}
|
||||||
movingSet.add(nn);
|
movingSet.add(nn);
|
||||||
updateActiveNodes();
|
updateActiveNodes();
|
||||||
@ -1926,7 +1983,7 @@ RED.view = (function() {
|
|||||||
if (!movingSet.has(n) && !n.selected) {
|
if (!movingSet.has(n) && !n.selected) {
|
||||||
// group entirely within lasso
|
// group entirely within lasso
|
||||||
if (n.x > x && n.y > y && n.x + n.w < x2 && n.y + n.h < y2) {
|
if (n.x > x && n.y > y && n.x + n.w < x2 && n.y + n.h < y2) {
|
||||||
selectGroup(n, true)
|
selectedGroups.add(n, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -2276,7 +2333,7 @@ RED.view = (function() {
|
|||||||
clearSelection();
|
clearSelection();
|
||||||
activeGroups.forEach(function(g) {
|
activeGroups.forEach(function(g) {
|
||||||
if (!g.g) {
|
if (!g.g) {
|
||||||
selectGroup(g, true);
|
selectedGroups.add(g, true);
|
||||||
if (!g.selected) {
|
if (!g.selected) {
|
||||||
g.selected = true;
|
g.selected = true;
|
||||||
g.dirty = true;
|
g.dirty = true;
|
||||||
@ -2346,10 +2403,7 @@ RED.view = (function() {
|
|||||||
}
|
}
|
||||||
movingSet.clear();
|
movingSet.clear();
|
||||||
selectedLinks.clear();
|
selectedLinks.clear();
|
||||||
activeGroups.forEach(function(g) {
|
selectedGroups.clear();
|
||||||
g.selected = false;
|
|
||||||
g.dirty = true;
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastSelection = null;
|
var lastSelection = null;
|
||||||
@ -3438,7 +3492,7 @@ RED.view = (function() {
|
|||||||
if (!groupNodeSelectPrimed && !d.selected && d.g && RED.nodes.group(d.g).selected) {
|
if (!groupNodeSelectPrimed && !d.selected && d.g && RED.nodes.group(d.g).selected) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
|
||||||
selectGroup(RED.nodes.group(d.g), false);
|
selectedGroups.add(RED.nodes.group(d.g), false);
|
||||||
|
|
||||||
mousedown_node.selected = true;
|
mousedown_node.selected = true;
|
||||||
movingSet.add(mousedown_node);
|
movingSet.add(mousedown_node);
|
||||||
@ -3859,14 +3913,14 @@ RED.view = (function() {
|
|||||||
lastClickNode = g;
|
lastClickNode = g;
|
||||||
|
|
||||||
if (g.selected && (d3.event.ctrlKey||d3.event.metaKey)) {
|
if (g.selected && (d3.event.ctrlKey||d3.event.metaKey)) {
|
||||||
deselectGroup(g);
|
selectedGroups.remove(g);
|
||||||
d3.event.stopPropagation();
|
d3.event.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
if (!g.selected) {
|
if (!g.selected) {
|
||||||
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
}
|
}
|
||||||
selectGroup(g,true);//!wasSelected);
|
selectedGroups.add(g,true);//!wasSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d3.event.button != 2) {
|
if (d3.event.button != 2) {
|
||||||
@ -3882,45 +3936,6 @@ RED.view = (function() {
|
|||||||
d3.event.stopPropagation();
|
d3.event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectGroup(g, includeNodes, addToMovingSet) {
|
|
||||||
if (!g.selected) {
|
|
||||||
g.selected = true;
|
|
||||||
g.dirty = true;
|
|
||||||
}
|
|
||||||
if (addToMovingSet !== false) {
|
|
||||||
movingSet.add(g);
|
|
||||||
}
|
|
||||||
if (includeNodes) {
|
|
||||||
var currentSet = new Set(movingSet.nodes());
|
|
||||||
var allNodes = RED.group.getNodes(g,true);
|
|
||||||
allNodes.forEach(function(n) {
|
|
||||||
if (!currentSet.has(n)) {
|
|
||||||
movingSet.add(n)
|
|
||||||
}
|
|
||||||
n.dirty = true;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
selectedLinks.clearUnselected()
|
|
||||||
}
|
|
||||||
|
|
||||||
function deselectGroup(g) {
|
|
||||||
if (g.selected) {
|
|
||||||
g.selected = false;
|
|
||||||
g.dirty = true;
|
|
||||||
}
|
|
||||||
const allNodes = RED.group.getNodes(g,true);
|
|
||||||
const nodeSet = new Set(allNodes);
|
|
||||||
nodeSet.add(g);
|
|
||||||
for (let i = movingSet.length()-1; i >= 0; i -= 1) {
|
|
||||||
const msn = movingSet.get(i);
|
|
||||||
if (nodeSet.has(msn.n) || msn.n === g) {
|
|
||||||
msn.n.selected = false;
|
|
||||||
msn.n.dirty = true;
|
|
||||||
movingSet.remove(msn.n,i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selectedLinks.clearUnselected()
|
|
||||||
}
|
|
||||||
function getGroupAt(x, y, ignoreSelected) {
|
function getGroupAt(x, y, ignoreSelected) {
|
||||||
// x,y expected to be in node-co-ordinate space
|
// x,y expected to be in node-co-ordinate space
|
||||||
var candidateGroups = {};
|
var candidateGroups = {};
|
||||||
@ -5905,7 +5920,6 @@ RED.view = (function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var selectedGroups = activeGroups.filter(function(g) { return g.selected });
|
|
||||||
selectedGroups.forEach(function(g) {
|
selectedGroups.forEach(function(g) {
|
||||||
var groupNodes = RED.group.getNodes(g,true);
|
var groupNodes = RED.group.getNodes(g,true);
|
||||||
groupNodes.forEach(function(n) {
|
groupNodes.forEach(function(n) {
|
||||||
@ -6114,7 +6128,7 @@ RED.view = (function() {
|
|||||||
n.dirty = true;
|
n.dirty = true;
|
||||||
movingSet.add(n);
|
movingSet.add(n);
|
||||||
} else {
|
} else {
|
||||||
selectGroup(n,true);
|
selectedGroups.add(n,true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user