From ef10ade0ccc7bedd662cdd4e2fd5602ac77f4031 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 25 Sep 2015 17:43:28 +0100 Subject: [PATCH] Improve handling of imported config nodes Avoid creating unnecessary duplicates of config nodes, whilst honouring the scope of the any existing node. Also, 'undo' now removes any added config node --- editor/js/nodes.js | 100 +++++++++++++++++++++++++++++-------------- editor/js/ui/view.js | 2 +- 2 files changed, 70 insertions(+), 32 deletions(-) diff --git a/editor/js/nodes.js b/editor/js/nodes.js index d1cc69cef..b573f9944 100644 --- a/editor/js/nodes.js +++ b/editor/js/nodes.js @@ -291,7 +291,6 @@ RED.nodes = (function() { var result = removeNode(removedNodes[n].id); removedLinks = removedLinks.concat(result.links); } - console.log(removedLinks); return {nodes:removedNodes,links:removedLinks}; } @@ -554,8 +553,11 @@ RED.nodes = (function() { return nns; } - function compareNodes(nodeA,nodeB) { - if (nodeA.id != nodeB.id || nodeA.type != nodeB.type) { + function compareNodes(nodeA,nodeB,idMustMatch) { + if (idMustMatch && nodeA.id != nodeB.id) { + return false; + } + if (nodeA.type != nodeB.type) { return false; } var def = nodeA._def; @@ -694,26 +696,6 @@ RED.nodes = (function() { }); new_subflows.push(n); addSubflow(n,createNewIds); - } else { - def = registry.getNodeType(n.type); - if (def && def.category == "config") { - var existingConfigNode = RED.nodes.node(n.id); - if (!existingConfigNode || !compareNodes(existingConfigNode,n) || existingConfigNode._def.exclusive) { - var configNode = {id:n.id, z:n.z, type:n.type, users:[]}; - for (var d in def.defaults) { - if (def.defaults.hasOwnProperty(d)) { - configNode[d] = n[d]; - } - } - configNode.label = def.label; - configNode._def = def; - if (existingConfigNode || createNewIds) { - configNode.id = getID(); - } - node_map[n.id] = configNode; - RED.nodes.add(configNode); - } - } } } if (defaultWorkspace == null) { @@ -724,6 +706,60 @@ RED.nodes = (function() { activeWorkspace = RED.workspaces.active(); } + for (i=0;i