mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Ensure parent nodes marked as changed due to child config node changes
This commit is contained in:
parent
088e3e5374
commit
2a089f7d90
@ -230,6 +230,13 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var madeChange;
|
||||||
|
// Loop through the nodes looking for references to changed config nodes
|
||||||
|
// Repeat the loop if anything is marked as changed as it may need to be
|
||||||
|
// propagated to parent nodes.
|
||||||
|
// TODO: looping through all nodes every time is a bit inefficient - could be more targeted
|
||||||
|
do {
|
||||||
|
madeChange = false;
|
||||||
for (id in newConfig.allNodes) {
|
for (id in newConfig.allNodes) {
|
||||||
if (newConfig.allNodes.hasOwnProperty(id)) {
|
if (newConfig.allNodes.hasOwnProperty(id)) {
|
||||||
node = newConfig.allNodes[id];
|
node = newConfig.allNodes[id];
|
||||||
@ -240,21 +247,34 @@ module.exports = {
|
|||||||
// changed.
|
// changed.
|
||||||
if (changed[node[prop]] || removed[node[prop]]) {
|
if (changed[node[prop]] || removed[node[prop]]) {
|
||||||
if (!changed[node.id]) {
|
if (!changed[node.id]) {
|
||||||
|
madeChange = true;
|
||||||
changed[node.id] = node;
|
changed[node.id] = node;
|
||||||
|
// This node exists within subflow template
|
||||||
|
// Mark the template as having changed
|
||||||
if (newConfig.allNodes[node.z]) {
|
if (newConfig.allNodes[node.z]) {
|
||||||
changed[node.z] = newConfig.allNodes[node.z];
|
changed[node.z] = newConfig.allNodes[node.z];
|
||||||
if (changed[node.z].type === "subflow") {
|
if (changed[node.z].type === "subflow") {
|
||||||
changedSubflows[node.z] = changed[node.z];
|
changedSubflows[node.z] = changed[node.z];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(madeChange===true)
|
||||||
|
|
||||||
|
// Find any nodes that exist on a subflow template and remove from changed
|
||||||
|
// list as the parent subflow will now be marked as containing a change
|
||||||
|
for (id in newConfig.allNodes) {
|
||||||
|
if (newConfig.allNodes.hasOwnProperty(id)) {
|
||||||
|
node = newConfig.allNodes[id];
|
||||||
|
if (newConfig.allNodes[node.z] && newConfig.allNodes[node.z].type === "subflow") {
|
||||||
delete changed[node.id];
|
delete changed[node.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Recursively mark all instances of changed subflows as changed
|
// Recursively mark all instances of changed subflows as changed
|
||||||
var changedSubflowStack = Object.keys(changedSubflows);
|
var changedSubflowStack = Object.keys(changedSubflows);
|
||||||
|
@ -308,7 +308,7 @@ describe('flows/util', function() {
|
|||||||
diffResult.linked.sort().should.eql(["3"]);
|
diffResult.linked.sort().should.eql(["3"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('identifies config nodes changes', function() {
|
it('identifies config nodes changes, node->config', function() {
|
||||||
var config = [
|
var config = [
|
||||||
{id:"1",type:"test",foo:"configNode",wires:[["2"]]},
|
{id:"1",type:"test",foo:"configNode",wires:[["2"]]},
|
||||||
{id:"2",type:"test",bar:"b",wires:[["3"]]},
|
{id:"2",type:"test",bar:"b",wires:[["3"]]},
|
||||||
@ -329,7 +329,30 @@ describe('flows/util', function() {
|
|||||||
diffResult.removed.should.have.length(0);
|
diffResult.removed.should.have.length(0);
|
||||||
diffResult.rewired.should.have.length(0);
|
diffResult.rewired.should.have.length(0);
|
||||||
diffResult.linked.sort().should.eql(["2","3"]);
|
diffResult.linked.sort().should.eql(["2","3"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('identifies config nodes changes, node->config->config', function() {
|
||||||
|
var config = [
|
||||||
|
{id:"1",type:"test",foo:"configNode1",wires:[["2"]]},
|
||||||
|
{id:"2",type:"test",bar:"b",wires:[["3"]]},
|
||||||
|
{id:"3",type:"test",foo:"a",wires:[]},
|
||||||
|
{id:"configNode1",foo:"configNode2",type:"testConfig"},
|
||||||
|
{id:"configNode2",type:"testConfig"}
|
||||||
|
];
|
||||||
|
var newConfig = clone(config);
|
||||||
|
newConfig[4].foo = "bar";
|
||||||
|
|
||||||
|
var originalConfig = flowUtil.parseConfig(config);
|
||||||
|
var changedConfig = flowUtil.parseConfig(newConfig);
|
||||||
|
|
||||||
|
originalConfig.missingTypes.should.have.length(0);
|
||||||
|
|
||||||
|
var diffResult = flowUtil.diffConfigs(originalConfig,changedConfig);
|
||||||
|
diffResult.added.should.have.length(0);
|
||||||
|
diffResult.changed.sort().should.eql(["1","configNode1","configNode2"]);
|
||||||
|
diffResult.removed.should.have.length(0);
|
||||||
|
diffResult.rewired.should.have.length(0);
|
||||||
|
diffResult.linked.sort().should.eql(["2","3"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('marks a parent subflow as changed for an internal property change', function() {
|
it('marks a parent subflow as changed for an internal property change', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user