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

Propagate changed flag to parent subflow

This commit is contained in:
Nick O'Leary 2015-03-20 21:20:04 +00:00
parent 35042132fa
commit 1d10eba0cc
2 changed files with 11 additions and 2 deletions

View File

@ -28,17 +28,22 @@ RED.editor = (function() {
*/ */
function validateNode(node) { function validateNode(node) {
var oldValue = node.valid; var oldValue = node.valid;
var oldChanged = node.changed;
node.valid = true; node.valid = true;
var subflow; var subflow;
var isValid; var isValid;
var hasChanged;
if (node.type.indexOf("subflow:")===0) { if (node.type.indexOf("subflow:")===0) {
subflow = RED.nodes.subflow(node.type.substring(8)); subflow = RED.nodes.subflow(node.type.substring(8));
isValid = subflow.valid; isValid = subflow.valid;
hasChanged = subflow.changed;
if (isValid === undefined) { if (isValid === undefined) {
isValid = validateNode(subflow); isValid = validateNode(subflow);
hasChanged = subflow.changed;
} }
node.valid = isValid; node.valid = isValid;
node.changed = hasChanged;
} else if (node._def) { } else if (node._def) {
node.valid = validateNodeProperties(node, node._def.defaults, node); node.valid = validateNodeProperties(node, node._def.defaults, node);
if (node._def._creds) { if (node._def._creds) {
@ -48,15 +53,19 @@ RED.editor = (function() {
var subflowNodes = RED.nodes.filterNodes({z:node.id}); var subflowNodes = RED.nodes.filterNodes({z:node.id});
for (var i=0;i<subflowNodes.length;i++) { for (var i=0;i<subflowNodes.length;i++) {
isValid = subflowNodes[i].valid; isValid = subflowNodes[i].valid;
hasChanged = subflowNodes[i].changed;
if (isValid === undefined) { if (isValid === undefined) {
isValid = validateNode(subflowNodes[i]); isValid = validateNode(subflowNodes[i]);
hasChanged = subflowNodes[i].changed;
} }
node.valid = node.valid && isValid; node.valid = node.valid && isValid;
node.changed = node.changed || hasChanged;
} }
var subflowInstances = RED.nodes.filterNodes({type:"subflow:"+node.id}); var subflowInstances = RED.nodes.filterNodes({type:"subflow:"+node.id});
var modifiedTabs = {}; var modifiedTabs = {};
for (i=0;i<subflowInstances.length;i++) { for (i=0;i<subflowInstances.length;i++) {
subflowInstances[i].valid = node.valid; subflowInstances[i].valid = node.valid;
subflowInstances[i].changed = node.changed;
subflowInstances[i].dirty = true; subflowInstances[i].dirty = true;
modifiedTabs[subflowInstances[i].z] = true; modifiedTabs[subflowInstances[i].z] = true;
} }
@ -67,7 +76,7 @@ RED.editor = (function() {
} }
}); });
} }
if (oldValue !== node.valid) { if (oldValue !== node.valid || oldChanged !== node.changed) {
node.dirty = true; node.dirty = true;
subflow = RED.nodes.subflow(node.z); subflow = RED.nodes.subflow(node.z);
if (subflow) { if (subflow) {

View File

@ -333,7 +333,6 @@ RED.view = (function() {
if (!m) { if (!m) {
nn.inputs = nn._def.inputs || 0; nn.inputs = nn._def.inputs || 0;
nn.outputs = nn._def.outputs; nn.outputs = nn._def.outputs;
nn.changed = true;
for (var d in nn._def.defaults) { for (var d in nn._def.defaults) {
if (nn._def.defaults.hasOwnProperty(d)) { if (nn._def.defaults.hasOwnProperty(d)) {
@ -350,6 +349,7 @@ RED.view = (function() {
nn.outputs = subflow.out.length; nn.outputs = subflow.out.length;
} }
nn.changed = true;
nn.h = Math.max(node_height,(nn.outputs||0) * 15); nn.h = Math.max(node_height,(nn.outputs||0) * 15);
RED.history.push({t:'add',nodes:[nn.id],dirty:RED.nodes.dirty()}); RED.history.push({t:'add',nodes:[nn.id],dirty:RED.nodes.dirty()});
RED.nodes.add(nn); RED.nodes.add(nn);