1
0
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:
Nick O'Leary 2016-04-27 10:30:52 +01:00
parent 088e3e5374
commit 2a089f7d90
2 changed files with 61 additions and 18 deletions

View File

@ -230,22 +230,32 @@ module.exports = {
} }
} }
for (id in newConfig.allNodes) { var madeChange;
if (newConfig.allNodes.hasOwnProperty(id)) { // Loop through the nodes looking for references to changed config nodes
node = newConfig.allNodes[id]; // Repeat the loop if anything is marked as changed as it may need to be
for (var prop in node) { // propagated to parent nodes.
if (node.hasOwnProperty(prop) && prop != "z" && prop != "id" && prop != "wires") { // TODO: looping through all nodes every time is a bit inefficient - could be more targeted
// This node has a property that references a changed/removed node do {
// Assume it is a config node change and mark this node as madeChange = false;
// changed. for (id in newConfig.allNodes) {
if (changed[node[prop]] || removed[node[prop]]) { if (newConfig.allNodes.hasOwnProperty(id)) {
if (!changed[node.id]) { node = newConfig.allNodes[id];
changed[node.id] = node; for (var prop in node) {
if (newConfig.allNodes[node.z]) { if (node.hasOwnProperty(prop) && prop != "z" && prop != "id" && prop != "wires") {
changed[node.z] = newConfig.allNodes[node.z]; // This node has a property that references a changed/removed node
if (changed[node.z].type === "subflow") { // Assume it is a config node change and mark this node as
changedSubflows[node.z] = changed[node.z]; // changed.
delete changed[node.id]; if (changed[node[prop]] || removed[node[prop]]) {
if (!changed[node.id]) {
madeChange = true;
changed[node.id] = node;
// This node exists within subflow template
// Mark the template as having changed
if (newConfig.allNodes[node.z]) {
changed[node.z] = newConfig.allNodes[node.z];
if (changed[node.z].type === "subflow") {
changedSubflows[node.z] = changed[node.z];
}
} }
} }
} }
@ -253,8 +263,18 @@ module.exports = {
} }
} }
} }
} } 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];
}
}
}
// 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);

View File

@ -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() {