mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Copy/clone config nodes properly on import/export
This commit is contained in:
parent
f70e9ea076
commit
fde9d40098
@ -210,6 +210,7 @@ RED.nodes = (function() {
|
|||||||
|
|
||||||
function removeNode(id) {
|
function removeNode(id) {
|
||||||
var removedLinks = [];
|
var removedLinks = [];
|
||||||
|
var removedNodes = [];
|
||||||
var node;
|
var node;
|
||||||
if (id in configNodes) {
|
if (id in configNodes) {
|
||||||
node = configNodes[id];
|
node = configNodes[id];
|
||||||
@ -231,8 +232,13 @@ RED.nodes = (function() {
|
|||||||
var configNode = configNodes[node[d]];
|
var configNode = configNodes[node[d]];
|
||||||
if (configNode) {
|
if (configNode) {
|
||||||
updatedConfigNode = true;
|
updatedConfigNode = true;
|
||||||
var users = configNode.users;
|
if (configNode._def.exclusive) {
|
||||||
users.splice(users.indexOf(node),1);
|
removeNode(node[d]);
|
||||||
|
removedNodes.push(configNode);
|
||||||
|
} else {
|
||||||
|
var users = configNode.users;
|
||||||
|
users.splice(users.indexOf(node),1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +252,7 @@ RED.nodes = (function() {
|
|||||||
if (node._def.onremove) {
|
if (node._def.onremove) {
|
||||||
node._def.onremove.call(n);
|
node._def.onremove.call(n);
|
||||||
}
|
}
|
||||||
return removedLinks;
|
return {links:removedLinks,nodes:removedNodes};
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeLink(l) {
|
function removeLink(l) {
|
||||||
@ -539,6 +545,32 @@ RED.nodes = (function() {
|
|||||||
return nns;
|
return nns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compareNodes(nodeA,nodeB) {
|
||||||
|
if (nodeA.id != nodeB.id || nodeA.type != nodeB.type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var def = nodeA._def;
|
||||||
|
for (var d in def.defaults) {
|
||||||
|
if (def.defaults.hasOwnProperty(d)) {
|
||||||
|
var vA = nodeA[d];
|
||||||
|
var vB = nodeB[d];
|
||||||
|
if (typeof vA !== typeof vB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (vA === null || typeof vA === "string" || typeof vA === "number") {
|
||||||
|
if (vA !== vB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (JSON.stringify(vA) !== JSON.stringify(vB)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function importNodes(newNodesObj,createNewIds) {
|
function importNodes(newNodesObj,createNewIds) {
|
||||||
var i;
|
var i;
|
||||||
var n;
|
var n;
|
||||||
@ -607,6 +639,9 @@ RED.nodes = (function() {
|
|||||||
var workspace_map = {};
|
var workspace_map = {};
|
||||||
var new_subflows = [];
|
var new_subflows = [];
|
||||||
var subflow_map = {};
|
var subflow_map = {};
|
||||||
|
var node_map = {};
|
||||||
|
var new_nodes = [];
|
||||||
|
var new_links = [];
|
||||||
var nid;
|
var nid;
|
||||||
var def;
|
var def;
|
||||||
for (i=0;i<newNodes.length;i++) {
|
for (i=0;i<newNodes.length;i++) {
|
||||||
@ -653,7 +688,8 @@ RED.nodes = (function() {
|
|||||||
} else {
|
} else {
|
||||||
def = registry.getNodeType(n.type);
|
def = registry.getNodeType(n.type);
|
||||||
if (def && def.category == "config") {
|
if (def && def.category == "config") {
|
||||||
if (!RED.nodes.node(n.id)) {
|
var existingConfigNode = RED.nodes.node(n.id);
|
||||||
|
if (!existingConfigNode || !compareNodes(existingConfigNode,n) || existingConfigNode._def.exclusive) {
|
||||||
var configNode = {id:n.id,type:n.type,users:[]};
|
var configNode = {id:n.id,type:n.type,users:[]};
|
||||||
for (var d in def.defaults) {
|
for (var d in def.defaults) {
|
||||||
if (def.defaults.hasOwnProperty(d)) {
|
if (def.defaults.hasOwnProperty(d)) {
|
||||||
@ -662,23 +698,23 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
configNode.label = def.label;
|
configNode.label = def.label;
|
||||||
configNode._def = def;
|
configNode._def = def;
|
||||||
|
if (existingConfigNode || createNewIds) {
|
||||||
|
configNode.id = getID();
|
||||||
|
}
|
||||||
|
node_map[n.id] = configNode;
|
||||||
RED.nodes.add(configNode);
|
RED.nodes.add(configNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (defaultWorkspace == null) {
|
if (defaultWorkspace == null) {
|
||||||
defaultWorkspace = { type:"tab", id:getID(), label:"Sheet 1" };
|
defaultWorkspace = { type:"tab", id:getID(), label:RED._('workspace.defaultName',{number:1})};
|
||||||
addWorkspace(defaultWorkspace);
|
addWorkspace(defaultWorkspace);
|
||||||
RED.workspaces.add(defaultWorkspace);
|
RED.workspaces.add(defaultWorkspace);
|
||||||
new_workspaces.push(defaultWorkspace);
|
new_workspaces.push(defaultWorkspace);
|
||||||
activeWorkspace = RED.workspaces.active();
|
activeWorkspace = RED.workspaces.active();
|
||||||
}
|
}
|
||||||
|
|
||||||
var node_map = {};
|
|
||||||
var new_nodes = [];
|
|
||||||
var new_links = [];
|
|
||||||
|
|
||||||
for (i=0;i<newNodes.length;i++) {
|
for (i=0;i<newNodes.length;i++) {
|
||||||
n = newNodes[i];
|
n = newNodes[i];
|
||||||
// TODO: remove workspace in next release+1
|
// TODO: remove workspace in next release+1
|
||||||
@ -749,7 +785,15 @@ RED.nodes = (function() {
|
|||||||
node.outputs = n.outputs||node._def.outputs;
|
node.outputs = n.outputs||node._def.outputs;
|
||||||
for (var d2 in node._def.defaults) {
|
for (var d2 in node._def.defaults) {
|
||||||
if (node._def.defaults.hasOwnProperty(d2)) {
|
if (node._def.defaults.hasOwnProperty(d2)) {
|
||||||
node[d2] = n[d2];
|
if (node._def.defaults[d2].type) {
|
||||||
|
if (node_map[n[d2]]) {
|
||||||
|
node[d2] = node_map[n[d2]].id;
|
||||||
|
} else {
|
||||||
|
node[d2] = n[d2];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
node[d2] = n[d2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +518,8 @@ RED.editor = (function() {
|
|||||||
for (var d in definition.defaults) {
|
for (var d in definition.defaults) {
|
||||||
if (definition.defaults.hasOwnProperty(d)) {
|
if (definition.defaults.hasOwnProperty(d)) {
|
||||||
if (definition.defaults[d].type) {
|
if (definition.defaults[d].type) {
|
||||||
if (definition.defaults[d].exclusive) {
|
var configTypeDef = RED.nodes.getType(definition.defaults[d].type);
|
||||||
|
if (configTypeDef.exclusive) {
|
||||||
prepareConfigNodeButton(node,d,definition.defaults[d].type);
|
prepareConfigNodeButton(node,d,definition.defaults[d].type);
|
||||||
} else {
|
} else {
|
||||||
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
|
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
|
||||||
|
@ -153,10 +153,14 @@ RED.subflow = (function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var removedConfigNodes = [];
|
||||||
for (var i=0;i<removedNodes.length;i++) {
|
for (var i=0;i<removedNodes.length;i++) {
|
||||||
var rmlinks = RED.nodes.remove(removedNodes[i].id);
|
var removedEntities = RED.nodes.remove(removedNodes[i].id);
|
||||||
removedLinks = removedLinks.concat(rmlinks);
|
removedLinks = removedLinks.concat(removedEntities.links);
|
||||||
|
removedConfigNodes = removedConfigNodes.concat(removedEntities.nodes);
|
||||||
}
|
}
|
||||||
|
// TODO: this whole delete logic should be in RED.nodes.removeSubflow..
|
||||||
|
removedNodes = removedNodes.concat(removedConfigNodes);
|
||||||
|
|
||||||
var activeSubflow = getSubflow();
|
var activeSubflow = getSubflow();
|
||||||
|
|
||||||
|
@ -756,9 +756,10 @@ RED.view = (function() {
|
|||||||
if (node.x < 0) {
|
if (node.x < 0) {
|
||||||
node.x = 25
|
node.x = 25
|
||||||
}
|
}
|
||||||
var rmlinks = RED.nodes.remove(node.id);
|
var removedEntities = RED.nodes.remove(node.id);
|
||||||
removedNodes.push(node);
|
removedNodes.push(node);
|
||||||
removedLinks = removedLinks.concat(rmlinks);
|
removedNodes = removedNodes.concat(removedEntities.nodes);
|
||||||
|
removedLinks = removedLinks.concat(removedEntities.links);
|
||||||
} else {
|
} else {
|
||||||
if (node.direction === "out") {
|
if (node.direction === "out") {
|
||||||
removedSubflowOutputs.push(node);
|
removedSubflowOutputs.push(node);
|
||||||
@ -851,8 +852,21 @@ RED.view = (function() {
|
|||||||
var nns = [];
|
var nns = [];
|
||||||
for (var n=0;n<moving_set.length;n++) {
|
for (var n=0;n<moving_set.length;n++) {
|
||||||
var node = moving_set[n].n;
|
var node = moving_set[n].n;
|
||||||
|
// The only time a node.type == subflow can be selected is the
|
||||||
|
// input/output 'proxy' nodes. They cannot be copied.
|
||||||
if (node.type != "subflow") {
|
if (node.type != "subflow") {
|
||||||
|
for (var d in node._def.defaults) {
|
||||||
|
if (node._def.defaults.hasOwnProperty(d)) {
|
||||||
|
if (node._def.defaults[d].type) {
|
||||||
|
var configNode = RED.nodes.node(node[d]);
|
||||||
|
if (configNode && configNode._def.exclusive) {
|
||||||
|
nns.push(RED.nodes.convertNode(configNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
nns.push(RED.nodes.convertNode(node));
|
nns.push(RED.nodes.convertNode(node));
|
||||||
|
//TODO: if the node has an exclusive config node, it should also be copied, to ensure it remains exclusive...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clipboard = JSON.stringify(nns);
|
clipboard = JSON.stringify(nns);
|
||||||
|
@ -29,9 +29,9 @@ RED.workspaces = (function() {
|
|||||||
do {
|
do {
|
||||||
workspaceIndex += 1;
|
workspaceIndex += 1;
|
||||||
//TODO: nls of Sheet
|
//TODO: nls of Sheet
|
||||||
} while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0);
|
} while($("#workspace-tabs a[title='"+RED._('workspace.defaultName',{number:workspaceIndex})+"']").size() !== 0);
|
||||||
|
|
||||||
ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex};
|
ws = {type:"tab",id:tabId,label:RED._('workspace.defaultName',{number:workspaceIndex})};
|
||||||
RED.nodes.addWorkspace(ws);
|
RED.nodes.addWorkspace(ws);
|
||||||
workspace_tabs.addTab(ws);
|
workspace_tabs.addTab(ws);
|
||||||
workspace_tabs.activateTab(tabId);
|
workspace_tabs.activateTab(tabId);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
|
"defaultName": "Sheet __number__",
|
||||||
"renameSheet": "Rename sheet",
|
"renameSheet": "Rename sheet",
|
||||||
"confirmDelete": "Confirm delete",
|
"confirmDelete": "Confirm delete",
|
||||||
"delete": "Are you sure you want to delete '__label__'?",
|
"delete": "Are you sure you want to delete '__label__'?",
|
||||||
|
@ -160,7 +160,7 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
url: {value:"",required:true},
|
url: {value:"",required:true},
|
||||||
method: {value:"get",required:true},
|
method: {value:"get",required:true},
|
||||||
swaggerDoc: {type:"swagger-doc", exclusive:true, required:false}
|
swaggerDoc: {type:"swagger-doc", required:false}
|
||||||
},
|
},
|
||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
|
Loading…
Reference in New Issue
Block a user