Propagate valid flag to parent subflows

This commit is contained in:
Nick O'Leary 2015-03-19 23:11:55 +00:00
parent ac0ca083c0
commit eb4cadb0b5
4 changed files with 83 additions and 37 deletions

View File

@ -32,10 +32,16 @@ RED.history = (function() {
pop: function() {
var ev = undo_history.pop();
var i;
var node;
var modifiedTabs = {};
if (ev) {
if (ev.t == 'add') {
if (ev.nodes) {
for (i=0;i<ev.nodes.length;i++) {
node = RED.nodes.node(ev.nodes[i]);
if (node.z) {
modifiedTabs[node.z] = true;
}
RED.nodes.remove(ev.nodes[i]);
}
}
@ -92,22 +98,21 @@ RED.history = (function() {
}
}
if (subflow) {
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+subflow.id) {
n.changed = true;
n.inputs = subflow.in.length;
n.outputs = subflow.out.length;
while (n.outputs > n.ports.length) {
n.ports.push(n.ports.length);
}
n.resize = true;
n.dirty = true;
RED.nodes.filterNodes({type:"subflow:"+subflow.id}).forEach(function(n) {
n.changed = true;
n.inputs = subflow.in.length;
n.outputs = subflow.out.length;
while (n.outputs > n.ports.length) {
n.ports.push(n.ports.length);
}
n.resize = true;
n.dirty = true;
});
}
if (ev.nodes) {
for (i=0;i<ev.nodes.length;i++) {
RED.nodes.add(ev.nodes[i]);
modifiedTabs[ev.nodes[i].z] = true;
}
}
if (ev.links) {
@ -143,13 +148,11 @@ RED.history = (function() {
ev.node.out = ev.node.out.concat(ev.subflow.outputs);
}
}
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+ev.node.id) {
n.changed = ev.changed;
n.inputs = ev.node.in.length;
n.outputs = ev.node.out.length;
RED.editor.updateNodeProperties(n);
}
RED.nodes.filterNodes({type:"subflow:"+ev.node.id}).forEach(function(n) {
n.changed = ev.changed;
n.inputs = ev.node.in.length;
n.outputs = ev.node.out.length;
RED.editor.updateNodeProperties(n);
});
RED.palette.refresh();
@ -166,11 +169,9 @@ RED.history = (function() {
ev.node.changed = ev.changed;
} else if (ev.t == "createSubflow") {
if (ev.nodes) {
RED.nodes.eachNode(function(n) {
if (n.z === ev.subflow.id) {
n.z = ev.activeWorkspace;
n.dirty = true;
}
RED.nodes.filterNodes({z:ev.subflow.id}).forEach(function(n) {
n.z = ev.activeWorkspace;
n.dirty = true;
});
for (i=0;i<ev.nodes.length;i++) {
RED.nodes.remove(ev.nodes[i]);
@ -191,6 +192,14 @@ RED.history = (function() {
}
}
}
Object.keys(modifiedTabs).forEach(function(id) {
var subflow = RED.nodes.subflow(id);
if (subflow) {
RED.editor.validateNode(subflow);
}
});
RED.nodes.dirty(ev.dirty);
RED.view.redraw(true);
RED.palette.refresh();

View File

@ -15,7 +15,6 @@
**/
RED.editor = (function() {
var editing_node = null;
// TODO: should IMPORT/EXPORT get their own dialogs?
function getCredentialsURL(nodeType, nodeID) {
var dashedType = nodeType.replace(/\s+/g, '-');
@ -28,16 +27,54 @@ RED.editor = (function() {
* @returns {boolean} whether the node is valid. Sets node.dirty if needed
*/
function validateNode(node) {
if (node._def) {
var oldValue = node.valid;
var oldValue = node.valid;
node.valid = true;
var subflow;
var isValid;
if (node.type.indexOf("subflow:")===0) {
subflow = RED.nodes.subflow(node.type.substring(8));
isValid = subflow.valid;
if (isValid === undefined) {
isValid = validateNode(subflow);
}
node.valid = isValid;
} else if (node._def) {
node.valid = validateNodeProperties(node, node._def.defaults, node);
if (node._def._creds) {
node.valid = node.valid && validateNodeProperties(node, node._def.credentials, node._def._creds);
}
if (oldValue != node.valid) {
node.dirty = true;
} else if (node.type == "subflow") {
var subflowNodes = RED.nodes.filterNodes({z:node.id});
for (var i=0;i<subflowNodes.length;i++) {
isValid = subflowNodes[i].valid;
if (isValid === undefined) {
isValid = validateNode(subflowNodes[i]);
}
node.valid = node.valid && isValid;
}
var subflowInstances = RED.nodes.filterNodes({type:"subflow:"+node.id});
var modifiedTabs = {};
for (i=0;i<subflowInstances.length;i++) {
subflowInstances[i].valid = node.valid;
subflowInstances[i].dirty = true;
modifiedTabs[subflowInstances[i].z] = true;
}
Object.keys(modifiedTabs).forEach(function(id) {
var subflow = RED.nodes.subflow(id);
if (subflow) {
validateNode(subflow);
}
});
}
if (oldValue !== node.valid) {
node.dirty = true;
subflow = RED.nodes.subflow(node.z);
if (subflow) {
validateNode(subflow);
}
}
return node.valid;
}
/**

View File

@ -387,6 +387,7 @@ RED.subflow = (function() {
dirty:RED.nodes.dirty()
});
RED.editor.validateNode(subflow);
RED.nodes.dirty(true);
RED.view.redraw(true);
}

View File

@ -815,18 +815,17 @@ RED.view = (function() {
}
if (activeSubflow) {
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+activeSubflow.id) {
n.changed = true;
n.inputs = activeSubflow.in.length;
n.outputs = activeSubflow.out.length;
while (n.outputs < n.ports.length) {
n.ports.pop();
}
n.resize = true;
n.dirty = true;
RED.nodes.filterNodes({type:"subflow:"+activeSubflow.id}).forEach(function(n) {
n.changed = true;
n.inputs = activeSubflow.in.length;
n.outputs = activeSubflow.out.length;
while (n.outputs < n.ports.length) {
n.ports.pop();
}
n.resize = true;
n.dirty = true;
});
RED.editor.validateNode(activeSubflow);
}
moving_set = [];