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

Increment subflow name on import of duplicate

This commit is contained in:
Nick O'Leary 2015-03-28 22:12:18 +00:00
parent f4ec9a72d5
commit 216b5fba7a

View File

@ -260,7 +260,24 @@ RED.nodes = (function() {
return {nodes:removedNodes,links:removedLinks}; return {nodes:removedNodes,links:removedLinks};
} }
function addSubflow(sf) { function addSubflow(sf, createNewIds) {
if (createNewIds) {
var subflowNames = Object.keys(subflows).map(function(sfid) {
return subflows[sfid].name;
});
subflowNames.sort();
var copyNumber = 1;
var subflowName = sf.name;
subflowNames.forEach(function(name) {
if (subflowName == name) {
copyNumber++;
subflowName = sf.name+" ("+copyNumber+")";
}
});
sf.name = subflowName;
}
subflows[sf.id] = sf; subflows[sf.id] = sf;
RED.nodes.registerType("subflow:"+sf.id, { RED.nodes.registerType("subflow:"+sf.id, {
defaults:{name:{value:""}}, defaults:{name:{value:""}},
@ -612,7 +629,7 @@ RED.nodes = (function() {
output.id = getID(); output.id = getID();
}); });
new_subflows.push(n); new_subflows.push(n);
addSubflow(n); addSubflow(n,createNewIds);
} else { } else {
def = registry.getNodeType(n.type); def = registry.getNodeType(n.type);
if (def && def.category == "config") { if (def && def.category == "config") {