2013-09-05 16:02:48 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2013-09-05 16:02:48 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
2022-02-07 13:25:09 +01:00
|
|
|
|
2022-06-29 11:27:44 +02:00
|
|
|
/**
|
2022-02-07 13:25:09 +01:00
|
|
|
* An Interface to nodes and utility functions for creating/adding/deleting nodes and links
|
|
|
|
* @namespace RED.nodes
|
|
|
|
*/
|
2014-08-08 01:01:35 +02:00
|
|
|
RED.nodes = (function() {
|
2022-01-11 15:11:55 +01:00
|
|
|
var PORT_TYPE_INPUT = 1;
|
|
|
|
var PORT_TYPE_OUTPUT = 0;
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
var node_defs = {};
|
2021-02-16 21:46:41 +01:00
|
|
|
var linkTabMap = {};
|
2019-07-08 11:55:26 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
var configNodes = {};
|
|
|
|
var links = [];
|
2021-02-16 21:46:41 +01:00
|
|
|
var nodeLinks = {};
|
2013-10-25 22:34:00 +02:00
|
|
|
var defaultWorkspace;
|
|
|
|
var workspaces = {};
|
2016-05-04 16:22:30 +02:00
|
|
|
var workspacesOrder =[];
|
2014-02-25 00:35:11 +01:00
|
|
|
var subflows = {};
|
2016-10-09 23:02:24 +02:00
|
|
|
var loadedFlowVersion = null;
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2020-03-03 20:04:32 +01:00
|
|
|
var groups = {};
|
|
|
|
var groupsByZ = {};
|
2021-03-03 15:20:55 +01:00
|
|
|
|
2022-02-28 13:53:11 +01:00
|
|
|
var junctions = {};
|
|
|
|
var junctionsByZ = {};
|
|
|
|
|
2016-12-06 23:37:21 +01:00
|
|
|
var initialLoad;
|
|
|
|
|
2015-03-15 22:54:36 +01:00
|
|
|
var dirty = false;
|
2021-02-17 18:32:55 +01:00
|
|
|
|
2015-03-15 22:54:36 +01:00
|
|
|
function setDirty(d) {
|
|
|
|
dirty = d;
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("workspace:dirty",{dirty:dirty});
|
2015-03-15 22:54:36 +01:00
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2021-08-26 22:16:40 +02:00
|
|
|
// The registry holds information about all node types.
|
2014-08-28 01:35:07 +02:00
|
|
|
var registry = (function() {
|
2016-08-04 17:49:36 +02:00
|
|
|
var moduleList = {};
|
2014-08-28 01:35:07 +02:00
|
|
|
var nodeList = [];
|
|
|
|
var nodeSets = {};
|
|
|
|
var typeToId = {};
|
|
|
|
var nodeDefinitions = {};
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconSets = {};
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2017-07-26 16:46:22 +02:00
|
|
|
nodeDefinitions['tab'] = {
|
|
|
|
defaults: {
|
|
|
|
label: {value:""},
|
|
|
|
disabled: {value: false},
|
2022-09-19 22:09:00 +02:00
|
|
|
locked: {value: false},
|
2021-08-19 14:15:13 +02:00
|
|
|
info: {value: ""},
|
|
|
|
env: {value: []}
|
2017-07-26 16:46:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
var exports = {
|
2017-01-22 00:46:44 +01:00
|
|
|
setModulePendingUpdated: function(module,version) {
|
|
|
|
moduleList[module].pending_version = version;
|
|
|
|
RED.events.emit("registry:module-updated",{module:module,version:version});
|
|
|
|
},
|
2016-08-04 17:49:36 +02:00
|
|
|
getModule: function(module) {
|
|
|
|
return moduleList[module];
|
|
|
|
},
|
|
|
|
getNodeSetForType: function(nodeType) {
|
|
|
|
return exports.getNodeSet(typeToId[nodeType]);
|
|
|
|
},
|
|
|
|
getModuleList: function() {
|
|
|
|
return moduleList;
|
|
|
|
},
|
2014-08-28 01:35:07 +02:00
|
|
|
getNodeList: function() {
|
|
|
|
return nodeList;
|
|
|
|
},
|
2016-11-07 22:25:09 +01:00
|
|
|
getNodeTypes: function() {
|
|
|
|
return Object.keys(nodeDefinitions);
|
|
|
|
},
|
2014-08-28 01:35:07 +02:00
|
|
|
setNodeList: function(list) {
|
|
|
|
nodeList = [];
|
|
|
|
for(var i=0;i<list.length;i++) {
|
|
|
|
var ns = list[i];
|
|
|
|
exports.addNodeSet(ns);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addNodeSet: function(ns) {
|
2021-05-13 15:06:43 +02:00
|
|
|
if (!ns.types) {
|
|
|
|
// A node has been loaded without any types. Ignore it.
|
|
|
|
return;
|
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
ns.added = false;
|
|
|
|
nodeSets[ns.id] = ns;
|
|
|
|
for (var j=0;j<ns.types.length;j++) {
|
|
|
|
typeToId[ns.types[j]] = ns.id;
|
|
|
|
}
|
|
|
|
nodeList.push(ns);
|
2016-08-04 17:49:36 +02:00
|
|
|
|
|
|
|
moduleList[ns.module] = moduleList[ns.module] || {
|
|
|
|
name:ns.module,
|
|
|
|
version:ns.version,
|
|
|
|
local:ns.local,
|
|
|
|
sets:{}
|
|
|
|
};
|
2017-01-22 00:46:44 +01:00
|
|
|
if (ns.pending_version) {
|
|
|
|
moduleList[ns.module].pending_version = ns.pending_version;
|
|
|
|
}
|
2016-08-04 17:49:36 +02:00
|
|
|
moduleList[ns.module].sets[ns.name] = ns;
|
|
|
|
RED.events.emit("registry:node-set-added",ns);
|
2014-08-28 01:35:07 +02:00
|
|
|
},
|
|
|
|
removeNodeSet: function(id) {
|
|
|
|
var ns = nodeSets[id];
|
|
|
|
for (var j=0;j<ns.types.length;j++) {
|
|
|
|
delete typeToId[ns.types[j]];
|
|
|
|
}
|
|
|
|
delete nodeSets[id];
|
|
|
|
for (var i=0;i<nodeList.length;i++) {
|
2016-08-04 17:49:36 +02:00
|
|
|
if (nodeList[i].id === id) {
|
2014-08-28 01:35:07 +02:00
|
|
|
nodeList.splice(i,1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-05 14:39:14 +02:00
|
|
|
delete moduleList[ns.module].sets[ns.name];
|
|
|
|
if (Object.keys(moduleList[ns.module].sets).length === 0) {
|
2016-08-04 17:49:36 +02:00
|
|
|
delete moduleList[ns.module];
|
|
|
|
}
|
|
|
|
RED.events.emit("registry:node-set-removed",ns);
|
2014-08-28 01:35:07 +02:00
|
|
|
return ns;
|
|
|
|
},
|
|
|
|
getNodeSet: function(id) {
|
|
|
|
return nodeSets[id];
|
|
|
|
},
|
|
|
|
enableNodeSet: function(id) {
|
|
|
|
var ns = nodeSets[id];
|
|
|
|
ns.enabled = true;
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.emit("registry:node-set-enabled",ns);
|
2014-08-28 01:35:07 +02:00
|
|
|
},
|
|
|
|
disableNodeSet: function(id) {
|
|
|
|
var ns = nodeSets[id];
|
|
|
|
ns.enabled = false;
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.emit("registry:node-set-disabled",ns);
|
2014-08-28 01:35:07 +02:00
|
|
|
},
|
|
|
|
registerNodeType: function(nt,def) {
|
2018-06-12 13:54:32 +02:00
|
|
|
if (nt.substring(0,8) != "subflow:") {
|
2021-09-30 16:28:09 +02:00
|
|
|
if (!nodeSets[typeToId[nt]]) {
|
2021-09-30 16:39:45 +02:00
|
|
|
var error = "";
|
|
|
|
var fullType = nt;
|
|
|
|
if (RED._loadingModule) {
|
|
|
|
fullType = "["+RED._loadingModule+"] "+nt;
|
|
|
|
if (nodeSets[RED._loadingModule]) {
|
|
|
|
error = nodeSets[RED._loadingModule].err || "";
|
|
|
|
} else {
|
|
|
|
error = "Unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RED.notify(RED._("palette.event.unknownNodeRegistered",{type:fullType, error:error}), "error");
|
2021-09-30 16:28:09 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-06 23:14:00 +02:00
|
|
|
def.set = nodeSets[typeToId[nt]];
|
2014-02-25 00:35:11 +01:00
|
|
|
nodeSets[typeToId[nt]].added = true;
|
2016-08-04 17:49:36 +02:00
|
|
|
nodeSets[typeToId[nt]].enabled = true;
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2015-06-08 12:37:36 +02:00
|
|
|
var ns;
|
|
|
|
if (def.set.module === "node-red") {
|
|
|
|
ns = "node-red";
|
|
|
|
} else {
|
|
|
|
ns = def.set.id;
|
|
|
|
}
|
|
|
|
def["_"] = function() {
|
|
|
|
var args = Array.prototype.slice.call(arguments, 0);
|
2017-01-27 23:36:00 +01:00
|
|
|
var original = args[0];
|
2015-06-08 12:37:36 +02:00
|
|
|
if (args[0].indexOf(":") === -1) {
|
|
|
|
args[0] = ns+":"+args[0];
|
|
|
|
}
|
2017-01-27 23:36:00 +01:00
|
|
|
var result = RED._.apply(null,args);
|
|
|
|
if (result === args[0]) {
|
|
|
|
result = original;
|
|
|
|
}
|
|
|
|
return result;
|
2015-06-08 12:37:36 +02:00
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
// TODO: too tightly coupled into palette UI
|
|
|
|
}
|
2021-09-30 16:28:09 +02:00
|
|
|
|
|
|
|
def.type = nt;
|
|
|
|
nodeDefinitions[nt] = def;
|
|
|
|
|
|
|
|
|
2021-01-08 15:19:12 +01:00
|
|
|
if (def.defaults) {
|
|
|
|
for (var d in def.defaults) {
|
|
|
|
if (def.defaults.hasOwnProperty(d)) {
|
|
|
|
if (def.defaults[d].type) {
|
|
|
|
try {
|
|
|
|
def.defaults[d]._type = parseNodePropertyTypeString(def.defaults[d].type)
|
|
|
|
} catch(err) {
|
|
|
|
console.warn(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.emit("registry:node-type-added",nt);
|
2014-08-28 01:35:07 +02:00
|
|
|
},
|
2014-02-25 00:35:11 +01:00
|
|
|
removeNodeType: function(nt) {
|
|
|
|
if (nt.substring(0,8) != "subflow:") {
|
2015-07-01 00:42:03 +02:00
|
|
|
// NON-NLS - internal debug message
|
|
|
|
throw new Error("this api is subflow only. called with:",nt);
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
delete nodeDefinitions[nt];
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.emit("registry:node-type-removed",nt);
|
2014-02-25 00:35:11 +01:00
|
|
|
},
|
2014-08-28 01:35:07 +02:00
|
|
|
getNodeType: function(nt) {
|
|
|
|
return nodeDefinitions[nt];
|
2017-11-30 14:13:35 +01:00
|
|
|
},
|
|
|
|
setIconSets: function(sets) {
|
|
|
|
iconSets = sets;
|
2018-09-26 02:16:15 +02:00
|
|
|
iconSets["font-awesome"] = RED.nodes.fontAwesome.getIconList();
|
2017-11-30 14:13:35 +01:00
|
|
|
},
|
|
|
|
getIconSets: function() {
|
|
|
|
return iconSets;
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2014-09-24 10:57:45 +02:00
|
|
|
};
|
2014-08-28 01:35:07 +02:00
|
|
|
return exports;
|
|
|
|
})();
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2021-08-26 22:16:40 +02:00
|
|
|
// allNodes holds information about the Flow nodes.
|
|
|
|
var allNodes = (function() {
|
|
|
|
var nodes = {};
|
|
|
|
var tabMap = {};
|
|
|
|
var api = {
|
|
|
|
addTab: function(id) {
|
|
|
|
tabMap[id] = [];
|
|
|
|
},
|
|
|
|
hasTab: function(z) {
|
|
|
|
return tabMap.hasOwnProperty(z)
|
|
|
|
},
|
|
|
|
removeTab: function(id) {
|
|
|
|
delete tabMap[id];
|
|
|
|
},
|
|
|
|
addNode: function(n) {
|
|
|
|
nodes[n.id] = n;
|
|
|
|
if (tabMap.hasOwnProperty(n.z)) {
|
|
|
|
tabMap[n.z].push(n);
|
|
|
|
} else {
|
|
|
|
console.warn("Node added to unknown tab/subflow:",n);
|
|
|
|
tabMap["_"] = tabMap["_"] || [];
|
|
|
|
tabMap["_"].push(n);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeNode: function(n) {
|
|
|
|
delete nodes[n.id]
|
|
|
|
if (tabMap.hasOwnProperty(n.z)) {
|
|
|
|
var i = tabMap[n.z].indexOf(n);
|
|
|
|
if (i > -1) {
|
|
|
|
tabMap[n.z].splice(i,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hasNode: function(id) {
|
|
|
|
return nodes.hasOwnProperty(id);
|
|
|
|
},
|
|
|
|
getNode: function(id) {
|
|
|
|
return nodes[id]
|
|
|
|
},
|
|
|
|
moveNode: function(n, newZ) {
|
|
|
|
api.removeNode(n);
|
2021-10-14 10:48:35 +02:00
|
|
|
n.z = newZ;
|
|
|
|
api.addNode(n)
|
2021-08-26 22:16:40 +02:00
|
|
|
},
|
|
|
|
moveNodesForwards: function(nodes) {
|
|
|
|
var result = [];
|
|
|
|
if (!Array.isArray(nodes)) {
|
|
|
|
nodes = [nodes]
|
|
|
|
}
|
|
|
|
// Can only do this for nodes on the same tab.
|
|
|
|
// Use nodes[0] to get the z
|
|
|
|
var tabNodes = tabMap[nodes[0].z];
|
|
|
|
var toMove = new Set(nodes.filter(function(n) { return n.type !== "group" && n.type !== "subflow" }));
|
|
|
|
var moved = new Set();
|
|
|
|
for (var i = tabNodes.length-1; i >= 0; i--) {
|
|
|
|
if (toMove.size === 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var n = tabNodes[i];
|
|
|
|
if (toMove.has(n)) {
|
|
|
|
// This is a node to move.
|
|
|
|
if (i < tabNodes.length-1 && !moved.has(tabNodes[i+1])) {
|
|
|
|
// Remove from current position
|
|
|
|
tabNodes.splice(i,1);
|
|
|
|
// Add it back one position higher
|
|
|
|
tabNodes.splice(i+1,0,n);
|
|
|
|
n._reordered = true;
|
|
|
|
result.push(n);
|
|
|
|
}
|
|
|
|
toMove.delete(n);
|
|
|
|
moved.add(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.length > 0) {
|
|
|
|
RED.events.emit('nodes:reorder',{
|
|
|
|
z: nodes[0].z,
|
|
|
|
nodes: result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
moveNodesBackwards: function(nodes) {
|
|
|
|
var result = [];
|
|
|
|
if (!Array.isArray(nodes)) {
|
|
|
|
nodes = [nodes]
|
|
|
|
}
|
|
|
|
// Can only do this for nodes on the same tab.
|
|
|
|
// Use nodes[0] to get the z
|
|
|
|
var tabNodes = tabMap[nodes[0].z];
|
|
|
|
var toMove = new Set(nodes.filter(function(n) { return n.type !== "group" && n.type !== "subflow" }));
|
|
|
|
var moved = new Set();
|
|
|
|
for (var i = 0; i < tabNodes.length; i++) {
|
|
|
|
if (toMove.size === 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var n = tabNodes[i];
|
|
|
|
if (toMove.has(n)) {
|
|
|
|
// This is a node to move.
|
|
|
|
if (i > 0 && !moved.has(tabNodes[i-1])) {
|
|
|
|
// Remove from current position
|
|
|
|
tabNodes.splice(i,1);
|
|
|
|
// Add it back one position lower
|
|
|
|
tabNodes.splice(i-1,0,n);
|
|
|
|
n._reordered = true;
|
|
|
|
result.push(n);
|
|
|
|
}
|
|
|
|
toMove.delete(n);
|
|
|
|
moved.add(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.length > 0) {
|
|
|
|
RED.events.emit('nodes:reorder',{
|
|
|
|
z: nodes[0].z,
|
|
|
|
nodes: result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
moveNodesToFront: function(nodes) {
|
|
|
|
var result = [];
|
|
|
|
if (!Array.isArray(nodes)) {
|
|
|
|
nodes = [nodes]
|
|
|
|
}
|
|
|
|
// Can only do this for nodes on the same tab.
|
|
|
|
// Use nodes[0] to get the z
|
|
|
|
var tabNodes = tabMap[nodes[0].z];
|
|
|
|
var toMove = new Set(nodes.filter(function(n) { return n.type !== "group" && n.type !== "subflow" }));
|
|
|
|
var target = tabNodes.length-1;
|
|
|
|
for (var i = tabNodes.length-1; i >= 0; i--) {
|
|
|
|
if (toMove.size === 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var n = tabNodes[i];
|
|
|
|
if (toMove.has(n)) {
|
|
|
|
// This is a node to move.
|
|
|
|
if (i < target) {
|
|
|
|
// Remove from current position
|
|
|
|
tabNodes.splice(i,1);
|
|
|
|
tabNodes.splice(target,0,n);
|
|
|
|
n._reordered = true;
|
|
|
|
result.push(n);
|
|
|
|
}
|
|
|
|
target--;
|
|
|
|
toMove.delete(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.length > 0) {
|
|
|
|
RED.events.emit('nodes:reorder',{
|
|
|
|
z: nodes[0].z,
|
|
|
|
nodes: result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
moveNodesToBack: function(nodes) {
|
|
|
|
var result = [];
|
|
|
|
if (!Array.isArray(nodes)) {
|
|
|
|
nodes = [nodes]
|
|
|
|
}
|
|
|
|
// Can only do this for nodes on the same tab.
|
|
|
|
// Use nodes[0] to get the z
|
|
|
|
var tabNodes = tabMap[nodes[0].z];
|
|
|
|
var toMove = new Set(nodes.filter(function(n) { return n.type !== "group" && n.type !== "subflow" }));
|
|
|
|
var target = 0;
|
|
|
|
for (var i = 0; i < tabNodes.length; i++) {
|
|
|
|
if (toMove.size === 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var n = tabNodes[i];
|
|
|
|
if (toMove.has(n)) {
|
|
|
|
// This is a node to move.
|
|
|
|
if (i > target) {
|
|
|
|
// Remove from current position
|
|
|
|
tabNodes.splice(i,1);
|
|
|
|
// Add it back one position lower
|
|
|
|
tabNodes.splice(target,0,n);
|
|
|
|
n._reordered = true;
|
|
|
|
result.push(n);
|
|
|
|
}
|
|
|
|
target++;
|
|
|
|
toMove.delete(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.length > 0) {
|
|
|
|
RED.events.emit('nodes:reorder',{
|
|
|
|
z: nodes[0].z,
|
|
|
|
nodes: result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
getNodes: function(z) {
|
|
|
|
return tabMap[z];
|
|
|
|
},
|
|
|
|
clear: function() {
|
|
|
|
nodes = {};
|
|
|
|
tabMap = {};
|
|
|
|
},
|
|
|
|
eachNode: function(cb) {
|
|
|
|
var nodeList,i,j;
|
|
|
|
for (i in subflows) {
|
|
|
|
if (subflows.hasOwnProperty(i)) {
|
|
|
|
nodeList = tabMap[i];
|
|
|
|
for (j = 0; j < nodeList.length; j++) {
|
|
|
|
if (cb(nodeList[j]) === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < workspacesOrder.length; i++) {
|
|
|
|
nodeList = tabMap[workspacesOrder[i]];
|
|
|
|
for (j = 0; j < nodeList.length; j++) {
|
|
|
|
if (cb(nodeList[j]) === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Flow nodes that do not have a valid tab/subflow
|
|
|
|
if (tabMap["_"]) {
|
|
|
|
nodeList = tabMap["_"];
|
|
|
|
for (j = 0; j < nodeList.length; j++) {
|
|
|
|
if (cb(nodeList[j]) === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filterNodes: function(filter) {
|
|
|
|
var result = [];
|
|
|
|
var searchSet = null;
|
|
|
|
var doZFilter = false;
|
|
|
|
if (filter.hasOwnProperty("z")) {
|
|
|
|
if (tabMap.hasOwnProperty(filter.z)) {
|
|
|
|
searchSet = tabMap[filter.z];
|
|
|
|
} else {
|
|
|
|
doZFilter = true;
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 11:43:41 +02:00
|
|
|
var objectLookup = false;
|
2021-08-26 22:16:40 +02:00
|
|
|
if (searchSet === null) {
|
2021-09-29 11:43:41 +02:00
|
|
|
searchSet = Object.keys(nodes);
|
|
|
|
objectLookup = true;
|
2021-08-26 22:16:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 11:43:41 +02:00
|
|
|
|
2021-08-26 22:16:40 +02:00
|
|
|
for (var n=0;n<searchSet.length;n++) {
|
|
|
|
var node = searchSet[n];
|
2021-09-29 11:43:41 +02:00
|
|
|
if (objectLookup) {
|
|
|
|
node = nodes[node];
|
|
|
|
}
|
2021-08-26 22:16:40 +02:00
|
|
|
if (filter.hasOwnProperty("type") && node.type !== filter.type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (doZFilter && node.z !== filter.z) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result.push(node);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
getNodeOrder: function(z) {
|
|
|
|
return tabMap[z].map(function(n) { return n.id })
|
|
|
|
},
|
|
|
|
setNodeOrder: function(z, order) {
|
|
|
|
var orderMap = {};
|
|
|
|
order.forEach(function(id,i) {
|
|
|
|
orderMap[id] = i;
|
|
|
|
})
|
|
|
|
tabMap[z].sort(function(A,B) {
|
|
|
|
A._reordered = true;
|
|
|
|
B._reordered = true;
|
|
|
|
return orderMap[A.id] - orderMap[B.id];
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return api;
|
|
|
|
})()
|
|
|
|
|
2013-10-25 22:34:00 +02:00
|
|
|
function getID() {
|
2021-05-18 12:32:17 +02:00
|
|
|
var bytes = [];
|
|
|
|
for (var i=0;i<8;i++) {
|
|
|
|
bytes.push(Math.round(0xff*Math.random()).toString(16).padStart(2,'0'));
|
|
|
|
}
|
|
|
|
return bytes.join("");
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2021-01-08 15:19:12 +01:00
|
|
|
function parseNodePropertyTypeString(typeString) {
|
|
|
|
typeString = typeString.trim();
|
|
|
|
var c;
|
|
|
|
var pos = 0;
|
|
|
|
var isArray = /\[\]$/.test(typeString);
|
|
|
|
if (isArray) {
|
|
|
|
typeString = typeString.substring(0,typeString.length-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var l = typeString.length;
|
|
|
|
var inBrackets = false;
|
|
|
|
var inToken = false;
|
|
|
|
var currentToken = "";
|
|
|
|
var types = [];
|
|
|
|
while (pos < l) {
|
|
|
|
c = typeString[pos];
|
|
|
|
if (inToken) {
|
|
|
|
if (c === "|") {
|
|
|
|
types.push(currentToken.trim())
|
|
|
|
currentToken = "";
|
|
|
|
inToken = false;
|
|
|
|
} else if (c === ")") {
|
|
|
|
types.push(currentToken.trim())
|
|
|
|
currentToken = "";
|
|
|
|
inBrackets = false;
|
|
|
|
inToken = false;
|
|
|
|
} else {
|
|
|
|
currentToken += c;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (c === "(") {
|
|
|
|
if (inBrackets) {
|
|
|
|
throw new Error("Invalid character '"+c+"' at position "+pos)
|
|
|
|
}
|
|
|
|
inBrackets = true;
|
|
|
|
} else if (c !== " ") {
|
|
|
|
inToken = true;
|
|
|
|
currentToken = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
currentToken = currentToken.trim();
|
|
|
|
if (currentToken.length > 0) {
|
|
|
|
types.push(currentToken)
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
types: types,
|
|
|
|
array: isArray
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-01 11:48:48 +01:00
|
|
|
const nodeProxyHandler = {
|
|
|
|
get(node, prop) {
|
|
|
|
if (prop === '__isProxy__') {
|
|
|
|
return true
|
|
|
|
} else if (prop == '__node__') {
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
return node[prop]
|
|
|
|
},
|
|
|
|
set(node, prop, value) {
|
|
|
|
if (node.z && (RED.nodes.workspace(node.z)?.locked || RED.nodes.subflow(node.z)?.locked)) {
|
|
|
|
if (
|
|
|
|
node._def.defaults[prop] ||
|
|
|
|
prop === 'z' ||
|
|
|
|
prop === 'l' ||
|
|
|
|
prop === 'd' ||
|
2022-11-07 22:11:58 +01:00
|
|
|
(prop === 'changed' && (!!node.changed) !== (!!value)) || // jshint ignore:line
|
2022-11-01 11:48:48 +01:00
|
|
|
((prop === 'x' || prop === 'y') && !node.resize && node.type !== 'group')
|
|
|
|
) {
|
|
|
|
throw new Error(`Cannot modified property '${prop}' of locked object '${node.type}:${node.id}'`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node[prop] = value;
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2021-01-08 15:19:12 +01:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function addNode(n) {
|
2022-11-01 11:48:48 +01:00
|
|
|
let newNode
|
|
|
|
if (!n.__isProxy__) {
|
|
|
|
newNode = new Proxy(n, nodeProxyHandler)
|
|
|
|
} else {
|
|
|
|
newNode = n
|
|
|
|
}
|
|
|
|
|
2015-05-14 20:57:39 +02:00
|
|
|
if (n.type.indexOf("subflow") !== 0) {
|
2015-06-08 12:37:36 +02:00
|
|
|
n["_"] = n._def._;
|
2017-02-08 11:25:58 +01:00
|
|
|
} else {
|
2020-06-08 12:49:43 +02:00
|
|
|
var subflowId = n.type.substring(8);
|
|
|
|
var sf = RED.nodes.subflow(subflowId);
|
|
|
|
if (sf) {
|
2022-11-01 12:42:40 +01:00
|
|
|
sf.instances.push(newNode);
|
2020-06-08 12:49:43 +02:00
|
|
|
}
|
2017-02-08 11:25:58 +01:00
|
|
|
n["_"] = RED._;
|
2015-05-06 23:14:00 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
if (n._def.category == "config") {
|
|
|
|
configNodes[n.id] = n;
|
|
|
|
} else {
|
2017-01-06 15:06:30 +01:00
|
|
|
if (n.wires && (n.wires.length > n.outputs)) { n.outputs = n.wires.length; }
|
2013-09-05 16:02:48 +02:00
|
|
|
n.dirty = true;
|
2016-06-28 15:57:48 +02:00
|
|
|
updateConfigNodeUsers(n);
|
2014-02-25 00:35:11 +01:00
|
|
|
if (n._def.category == "subflows" && typeof n.i === "undefined") {
|
|
|
|
var nextId = 0;
|
|
|
|
RED.nodes.eachNode(function(node) {
|
|
|
|
nextId = Math.max(nextId,node.i||0);
|
|
|
|
});
|
|
|
|
n.i = nextId+1;
|
|
|
|
}
|
2022-11-01 11:48:48 +01:00
|
|
|
allNodes.addNode(newNode);
|
2021-02-16 21:46:41 +01:00
|
|
|
if (!nodeLinks[n.id]) {
|
|
|
|
nodeLinks[n.id] = {in:[],out:[]};
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2022-11-01 11:48:48 +01:00
|
|
|
RED.events.emit('nodes:add',newNode);
|
|
|
|
return newNode
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
function addLink(l) {
|
2022-02-14 21:35:47 +01:00
|
|
|
if (nodeLinks[l.source.id]) {
|
|
|
|
const isUnique = nodeLinks[l.source.id].out.every(function(link) {
|
|
|
|
return link.sourcePort !== l.sourcePort || link.target.id !== l.target.id
|
|
|
|
})
|
|
|
|
if (!isUnique) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
links.push(l);
|
2021-02-16 21:46:41 +01:00
|
|
|
if (l.source) {
|
|
|
|
// Possible the node hasn't been added yet
|
|
|
|
if (!nodeLinks[l.source.id]) {
|
|
|
|
nodeLinks[l.source.id] = {in:[],out:[]};
|
|
|
|
}
|
|
|
|
nodeLinks[l.source.id].out.push(l);
|
|
|
|
}
|
|
|
|
if (l.target) {
|
|
|
|
if (!nodeLinks[l.target.id]) {
|
|
|
|
nodeLinks[l.target.id] = {in:[],out:[]};
|
|
|
|
}
|
|
|
|
nodeLinks[l.target.id].in.push(l);
|
|
|
|
}
|
|
|
|
if (l.source.z === l.target.z && linkTabMap[l.source.z]) {
|
|
|
|
linkTabMap[l.source.z].push(l);
|
|
|
|
}
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("links:add",l);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function getNode(id) {
|
|
|
|
if (id in configNodes) {
|
|
|
|
return configNodes[id];
|
|
|
|
}
|
2021-08-26 22:16:40 +02:00
|
|
|
return allNodes.getNode(id);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function removeNode(id) {
|
|
|
|
var removedLinks = [];
|
2015-07-08 23:12:52 +02:00
|
|
|
var removedNodes = [];
|
2015-03-04 14:18:59 +01:00
|
|
|
var node;
|
2013-09-05 16:02:48 +02:00
|
|
|
if (id in configNodes) {
|
2015-03-04 14:18:59 +01:00
|
|
|
node = configNodes[id];
|
2013-09-05 16:02:48 +02:00
|
|
|
delete configNodes[id];
|
2016-05-30 00:51:20 +02:00
|
|
|
RED.events.emit('nodes:remove',node);
|
2015-09-23 23:49:48 +02:00
|
|
|
RED.workspaces.refresh();
|
2021-08-26 22:16:40 +02:00
|
|
|
} else if (allNodes.hasNode(id)) {
|
|
|
|
node = allNodes.getNode(id);
|
|
|
|
allNodes.removeNode(node);
|
2021-02-16 21:46:41 +01:00
|
|
|
delete nodeLinks[id];
|
2020-09-16 12:42:22 +02:00
|
|
|
removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); });
|
|
|
|
removedLinks.forEach(removeLink);
|
|
|
|
var updatedConfigNode = false;
|
|
|
|
for (var d in node._def.defaults) {
|
|
|
|
if (node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
var property = node._def.defaults[d];
|
|
|
|
if (property.type) {
|
|
|
|
var type = registry.getNodeType(property.type);
|
|
|
|
if (type && type.category == "config") {
|
|
|
|
var configNode = configNodes[node[d]];
|
|
|
|
if (configNode) {
|
|
|
|
updatedConfigNode = true;
|
|
|
|
if (configNode._def.exclusive) {
|
|
|
|
removeNode(node[d]);
|
|
|
|
removedNodes.push(configNode);
|
|
|
|
} else {
|
|
|
|
var users = configNode.users;
|
|
|
|
users.splice(users.indexOf(node),1);
|
2021-07-01 21:52:13 +02:00
|
|
|
RED.events.emit('nodes:change',configNode)
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2014-01-25 23:31:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
}
|
2020-06-08 12:49:43 +02:00
|
|
|
|
2020-09-16 12:42:22 +02:00
|
|
|
if (node.type.indexOf("subflow:") === 0) {
|
|
|
|
var subflowId = node.type.substring(8);
|
|
|
|
var sf = RED.nodes.subflow(subflowId);
|
|
|
|
if (sf) {
|
|
|
|
sf.instances.splice(sf.instances.indexOf(node),1);
|
2020-06-08 12:49:43 +02:00
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
}
|
2020-06-08 12:49:43 +02:00
|
|
|
|
2020-09-16 12:42:22 +02:00
|
|
|
if (updatedConfigNode) {
|
|
|
|
RED.workspaces.refresh();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (node._def.oneditdelete) {
|
|
|
|
node._def.oneditdelete.call(node);
|
2018-01-23 22:28:58 +01:00
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditdelete",node.id,node.type,err.toString());
|
2014-01-25 23:31:43 +01:00
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
RED.events.emit('nodes:remove',node);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2020-06-08 12:49:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 23:49:48 +02:00
|
|
|
if (node && node._def.onremove) {
|
2018-01-23 22:28:58 +01:00
|
|
|
// Deprecated: never documented but used by some early nodes
|
|
|
|
console.log("Deprecated API warning: node type ",node.type," has an onremove function - should be oneditremove - please report");
|
2015-03-04 14:18:59 +01:00
|
|
|
node._def.onremove.call(n);
|
|
|
|
}
|
2015-07-08 23:12:52 +02:00
|
|
|
return {links:removedLinks,nodes:removedNodes};
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2021-08-26 22:16:40 +02:00
|
|
|
function moveNodesForwards(nodes) {
|
|
|
|
return allNodes.moveNodesForwards(nodes);
|
|
|
|
}
|
|
|
|
function moveNodesBackwards(nodes) {
|
|
|
|
return allNodes.moveNodesBackwards(nodes);
|
|
|
|
}
|
|
|
|
function moveNodesToFront(nodes) {
|
|
|
|
return allNodes.moveNodesToFront(nodes);
|
|
|
|
}
|
|
|
|
function moveNodesToBack(nodes) {
|
|
|
|
return allNodes.moveNodesToBack(nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNodeOrder(z) {
|
|
|
|
return allNodes.getNodeOrder(z);
|
|
|
|
}
|
|
|
|
function setNodeOrder(z, order) {
|
|
|
|
allNodes.setNodeOrder(z,order);
|
|
|
|
}
|
|
|
|
|
2019-07-26 16:06:56 +02:00
|
|
|
function moveNodeToTab(node, z) {
|
2020-03-14 01:17:16 +01:00
|
|
|
if (node.type === "group") {
|
|
|
|
moveGroupToTab(node,z);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-13 01:47:41 +02:00
|
|
|
if (node.type === "junction") {
|
|
|
|
moveJunctionToTab(node,z);
|
|
|
|
return;
|
|
|
|
}
|
2021-10-14 10:48:35 +02:00
|
|
|
var oldZ = node.z;
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.moveNode(node,z);
|
2021-03-10 01:03:52 +01:00
|
|
|
var nl = nodeLinks[node.id];
|
|
|
|
if (nl) {
|
2021-03-10 22:31:05 +01:00
|
|
|
nl.in.forEach(function(l) {
|
2021-10-14 10:48:35 +02:00
|
|
|
var idx = linkTabMap[oldZ].indexOf(l);
|
2021-03-10 01:03:52 +01:00
|
|
|
if (idx != -1) {
|
2021-10-14 10:48:35 +02:00
|
|
|
linkTabMap[oldZ].splice(idx, 1);
|
2021-03-10 01:03:52 +01:00
|
|
|
}
|
|
|
|
if ((l.source.z === z) && linkTabMap[z]) {
|
|
|
|
linkTabMap[z].push(l);
|
|
|
|
}
|
|
|
|
});
|
2021-03-10 22:31:05 +01:00
|
|
|
nl.out.forEach(function(l) {
|
2021-10-14 10:48:35 +02:00
|
|
|
var idx = linkTabMap[oldZ].indexOf(l);
|
2021-03-10 01:03:52 +01:00
|
|
|
if (idx != -1) {
|
2021-10-14 10:48:35 +02:00
|
|
|
linkTabMap[oldZ].splice(idx, 1);
|
2021-03-10 01:03:52 +01:00
|
|
|
}
|
|
|
|
if ((l.target.z === z) && linkTabMap[z]) {
|
|
|
|
linkTabMap[z].push(l);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("nodes:change",node);
|
2019-07-26 16:06:56 +02:00
|
|
|
}
|
2020-03-14 01:17:16 +01:00
|
|
|
function moveGroupToTab(group, z) {
|
|
|
|
var index = groupsByZ[group.z].indexOf(group);
|
|
|
|
groupsByZ[group.z].splice(index,1);
|
|
|
|
groupsByZ[z] = groupsByZ[z] || [];
|
|
|
|
groupsByZ[z].push(group);
|
|
|
|
group.z = z;
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("groups:change",group);
|
2020-03-14 01:17:16 +01:00
|
|
|
}
|
2019-09-24 22:04:33 +02:00
|
|
|
|
2022-06-13 01:47:41 +02:00
|
|
|
function moveJunctionToTab(junction, z) {
|
|
|
|
var index = junctionsByZ[junction.z].indexOf(junction);
|
2022-06-14 09:49:14 +02:00
|
|
|
junctionsByZ[junction.z].splice(index,1);
|
2022-06-13 01:47:41 +02:00
|
|
|
junctionsByZ[z] = junctionsByZ[z] || [];
|
|
|
|
junctionsByZ[z].push(junction);
|
|
|
|
|
|
|
|
var oldZ = junction.z;
|
2022-06-14 09:49:14 +02:00
|
|
|
junction.z = z;
|
|
|
|
|
2022-06-13 01:47:41 +02:00
|
|
|
var nl = nodeLinks[junction.id];
|
|
|
|
if (nl) {
|
|
|
|
nl.in.forEach(function(l) {
|
|
|
|
var idx = linkTabMap[oldZ].indexOf(l);
|
|
|
|
if (idx != -1) {
|
|
|
|
linkTabMap[oldZ].splice(idx, 1);
|
|
|
|
}
|
|
|
|
if ((l.source.z === z) && linkTabMap[z]) {
|
|
|
|
linkTabMap[z].push(l);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
nl.out.forEach(function(l) {
|
|
|
|
var idx = linkTabMap[oldZ].indexOf(l);
|
|
|
|
if (idx != -1) {
|
|
|
|
linkTabMap[oldZ].splice(idx, 1);
|
|
|
|
}
|
|
|
|
if ((l.target.z === z) && linkTabMap[z]) {
|
|
|
|
linkTabMap[z].push(l);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
RED.events.emit("junctions:change",junction);
|
|
|
|
}
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function removeLink(l) {
|
|
|
|
var index = links.indexOf(l);
|
|
|
|
if (index != -1) {
|
|
|
|
links.splice(index,1);
|
2021-02-27 22:57:27 +01:00
|
|
|
if (l.source && nodeLinks[l.source.id]) {
|
2021-02-16 21:46:41 +01:00
|
|
|
var sIndex = nodeLinks[l.source.id].out.indexOf(l)
|
|
|
|
if (sIndex !== -1) {
|
|
|
|
nodeLinks[l.source.id].out.splice(sIndex,1)
|
|
|
|
}
|
|
|
|
}
|
2021-02-27 22:57:27 +01:00
|
|
|
if (l.target && nodeLinks[l.target.id]) {
|
2021-02-16 21:46:41 +01:00
|
|
|
var tIndex = nodeLinks[l.target.id].in.indexOf(l)
|
|
|
|
if (tIndex !== -1) {
|
|
|
|
nodeLinks[l.target.id].in.splice(tIndex,1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (l.source.z === l.target.z && linkTabMap[l.source.z]) {
|
|
|
|
index = linkTabMap[l.source.z].indexOf(l);
|
|
|
|
if (index !== -1) {
|
|
|
|
linkTabMap[l.source.z].splice(index,1)
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("links:remove",l);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2018-10-27 00:08:58 +02:00
|
|
|
function addWorkspace(ws,targetIndex) {
|
2013-10-25 22:34:00 +02:00
|
|
|
workspaces[ws.id] = ws;
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.addTab(ws.id);
|
2021-02-16 21:46:41 +01:00
|
|
|
linkTabMap[ws.id] = [];
|
2019-07-08 11:55:26 +02:00
|
|
|
|
2017-07-26 16:46:22 +02:00
|
|
|
ws._def = RED.nodes.getType('tab');
|
2018-10-27 00:08:58 +02:00
|
|
|
if (targetIndex === undefined) {
|
|
|
|
workspacesOrder.push(ws.id);
|
|
|
|
} else {
|
|
|
|
workspacesOrder.splice(targetIndex,0,ws.id);
|
|
|
|
}
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit('flows:add',ws);
|
2020-04-27 11:49:54 +02:00
|
|
|
if (targetIndex !== undefined) {
|
|
|
|
RED.events.emit('flows:reorder',workspacesOrder)
|
|
|
|
}
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2013-10-26 23:29:24 +02:00
|
|
|
function getWorkspace(id) {
|
|
|
|
return workspaces[id];
|
|
|
|
}
|
|
|
|
function removeWorkspace(id) {
|
2020-04-20 22:30:03 +02:00
|
|
|
var ws = workspaces[id];
|
2013-10-26 23:29:24 +02:00
|
|
|
var removedNodes = [];
|
|
|
|
var removedLinks = [];
|
2020-03-14 00:01:01 +01:00
|
|
|
var removedGroups = [];
|
2022-02-28 13:53:11 +01:00
|
|
|
var removedJunctions = [];
|
2020-04-20 22:30:03 +02:00
|
|
|
if (ws) {
|
|
|
|
delete workspaces[id];
|
2021-02-16 21:46:41 +01:00
|
|
|
delete linkTabMap[id];
|
2020-04-20 22:30:03 +02:00
|
|
|
workspacesOrder.splice(workspacesOrder.indexOf(id),1);
|
2020-06-03 15:23:26 +02:00
|
|
|
var i;
|
2020-04-20 22:30:03 +02:00
|
|
|
var node;
|
2021-08-26 22:16:40 +02:00
|
|
|
|
|
|
|
if (allNodes.hasTab(id)) {
|
2022-08-01 21:54:05 +02:00
|
|
|
removedNodes = allNodes.getNodes(id).slice()
|
2015-09-23 23:49:48 +02:00
|
|
|
}
|
2021-08-26 22:16:40 +02:00
|
|
|
for (i in configNodes) {
|
2020-06-03 15:23:26 +02:00
|
|
|
if (configNodes.hasOwnProperty(i)) {
|
|
|
|
node = configNodes[i];
|
2020-04-20 22:30:03 +02:00
|
|
|
if (node.z == id) {
|
|
|
|
removedNodes.push(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 21:54:05 +02:00
|
|
|
removedJunctions = RED.nodes.junctions(id)
|
2020-03-14 00:01:01 +01:00
|
|
|
|
2020-06-03 15:23:26 +02:00
|
|
|
for (i=0;i<removedNodes.length;i++) {
|
|
|
|
var result = removeNode(removedNodes[i].id);
|
2020-04-20 22:30:03 +02:00
|
|
|
removedLinks = removedLinks.concat(result.links);
|
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
for (i=0;i<removedJunctions.length;i++) {
|
|
|
|
var result = removeJunction(removedJunctions[i])
|
|
|
|
removedLinks = removedLinks.concat(result.links)
|
|
|
|
}
|
2020-06-03 15:23:26 +02:00
|
|
|
|
|
|
|
// Must get 'removedGroups' in the right order.
|
|
|
|
// - start with the top-most groups
|
|
|
|
// - then recurse into them
|
|
|
|
removedGroups = (groupsByZ[id] || []).filter(function(g) { return !g.g; });
|
|
|
|
for (i=0;i<removedGroups.length;i++) {
|
|
|
|
removedGroups[i].nodes.forEach(function(n) {
|
|
|
|
if (n.type === "group") {
|
|
|
|
removedGroups.push(n);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Now remove them in the reverse order
|
|
|
|
for (i=removedGroups.length-1; i>=0; i--) {
|
|
|
|
removeGroup(removedGroups[i]);
|
|
|
|
}
|
2021-11-25 05:26:52 +01:00
|
|
|
allNodes.removeTab(id);
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit('flows:remove',ws);
|
2013-10-26 23:29:24 +02:00
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
return {nodes:removedNodes,links:removedLinks, groups: removedGroups, junctions: removedJunctions};
|
2013-10-26 23:29:24 +02:00
|
|
|
}
|
2013-12-11 23:22:33 +01:00
|
|
|
|
2015-03-28 23:12:18 +01:00
|
|
|
function addSubflow(sf, createNewIds) {
|
|
|
|
if (createNewIds) {
|
|
|
|
var subflowNames = Object.keys(subflows).map(function(sfid) {
|
|
|
|
return subflows[sfid].name;
|
|
|
|
});
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2015-03-28 23:12:18 +01:00
|
|
|
subflowNames.sort();
|
|
|
|
var copyNumber = 1;
|
|
|
|
var subflowName = sf.name;
|
|
|
|
subflowNames.forEach(function(name) {
|
|
|
|
if (subflowName == name) {
|
|
|
|
copyNumber++;
|
|
|
|
subflowName = sf.name+" ("+copyNumber+")";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sf.name = subflowName;
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
subflows[sf.id] = sf;
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.addTab(sf.id);
|
2021-02-16 21:46:41 +01:00
|
|
|
linkTabMap[sf.id] = [];
|
2019-07-08 11:55:26 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
RED.nodes.registerType("subflow:"+sf.id, {
|
2019-01-26 15:15:20 +01:00
|
|
|
defaults:{
|
|
|
|
name:{value:""},
|
|
|
|
env:{value:[]}
|
|
|
|
},
|
2019-06-21 13:36:20 +02:00
|
|
|
icon: function() { return sf.icon||"subflow.svg" },
|
2018-06-12 13:54:32 +02:00
|
|
|
category: sf.category || "subflows",
|
2014-02-25 00:35:11 +01:00
|
|
|
inputs: sf.in.length,
|
|
|
|
outputs: sf.out.length,
|
2019-09-23 11:19:41 +02:00
|
|
|
color: sf.color || "#DDAA99",
|
2014-02-25 00:35:11 +01:00
|
|
|
label: function() { return this.name||RED.nodes.subflow(sf.id).name },
|
2019-05-15 14:54:29 +02:00
|
|
|
labelStyle: function() { return this.name?"red-ui-flow-node-label-italic":""; },
|
2015-06-29 17:12:18 +02:00
|
|
|
paletteLabel: function() { return RED.nodes.subflow(sf.id).name },
|
2017-02-08 11:25:58 +01:00
|
|
|
inputLabels: function(i) { return sf.inputLabels?sf.inputLabels[i]:null },
|
|
|
|
outputLabels: function(i) { return sf.outputLabels?sf.outputLabels[i]:null },
|
2019-11-01 15:14:48 +01:00
|
|
|
oneditprepare: function() {
|
2021-09-02 11:33:43 +02:00
|
|
|
if (this.type !== 'subflow') {
|
2021-09-02 17:14:35 +02:00
|
|
|
// A subflow instance node
|
2021-09-02 11:33:43 +02:00
|
|
|
RED.subflow.buildEditForm("subflow",this);
|
2021-09-02 17:14:35 +02:00
|
|
|
} else {
|
|
|
|
// A subflow template node
|
|
|
|
RED.subflow.buildEditForm("subflow-template", this);
|
2021-09-02 11:33:43 +02:00
|
|
|
}
|
2019-11-01 15:14:48 +01:00
|
|
|
},
|
2019-02-04 18:20:13 +01:00
|
|
|
oneditresize: function(size) {
|
2021-09-02 11:33:43 +02:00
|
|
|
if (this.type === 'subflow') {
|
|
|
|
$("#node-input-env-container").editableList('height',size.height - 80);
|
|
|
|
}
|
2019-02-04 18:20:13 +01:00
|
|
|
},
|
2015-06-29 17:12:18 +02:00
|
|
|
set:{
|
|
|
|
module: "node-red"
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
});
|
2020-06-08 12:49:43 +02:00
|
|
|
sf.instances = [];
|
2017-02-08 11:25:58 +01:00
|
|
|
sf._def = RED.nodes.getType("subflow:"+sf.id);
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("subflows:add",sf);
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
function getSubflow(id) {
|
|
|
|
return subflows[id];
|
|
|
|
}
|
|
|
|
function removeSubflow(sf) {
|
2020-04-20 22:30:03 +02:00
|
|
|
if (subflows[sf.id]) {
|
|
|
|
delete subflows[sf.id];
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.removeTab(sf.id);
|
2020-04-20 22:30:03 +02:00
|
|
|
registry.removeNodeType("subflow:"+sf.id);
|
|
|
|
RED.events.emit("subflows:remove",sf);
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
function subflowContains(sfid,nodeid) {
|
2021-08-26 22:16:40 +02:00
|
|
|
var sfNodes = allNodes.getNodes(sfid);
|
|
|
|
for (var i = 0; i<sfNodes.length; i++) {
|
|
|
|
var node = sfNodes[i];
|
|
|
|
var m = /^subflow:(.+)$/.exec(node.type);
|
|
|
|
if (m) {
|
|
|
|
if (m[1] === nodeid) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
var result = subflowContains(m[1],nodeid);
|
|
|
|
if (result) {
|
|
|
|
return true;
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2021-02-17 18:32:55 +01:00
|
|
|
function getAllDownstreamNodes(node) {
|
2021-03-03 15:20:55 +01:00
|
|
|
return getAllFlowNodes(node,'down').filter(function(n) { return n !== node });
|
2021-02-17 18:32:55 +01:00
|
|
|
}
|
|
|
|
function getAllUpstreamNodes(node) {
|
2021-03-03 15:20:55 +01:00
|
|
|
return getAllFlowNodes(node,'up').filter(function(n) { return n !== node });
|
2021-02-17 18:32:55 +01:00
|
|
|
}
|
|
|
|
function getAllFlowNodes(node, direction) {
|
|
|
|
var selection = RED.view.selection();
|
|
|
|
var visited = new Set();
|
|
|
|
var nodes = [node];
|
2021-03-03 15:20:55 +01:00
|
|
|
var initialNode = true;
|
2021-02-17 18:32:55 +01:00
|
|
|
while(nodes.length > 0) {
|
|
|
|
var n = nodes.shift();
|
|
|
|
visited.add(n);
|
|
|
|
var links = [];
|
2021-03-03 15:20:55 +01:00
|
|
|
if (!initialNode || !direction || (initialNode && direction === 'up')) {
|
2021-02-17 18:32:55 +01:00
|
|
|
links = links.concat(nodeLinks[n.id].in);
|
|
|
|
}
|
2021-03-03 15:20:55 +01:00
|
|
|
if (!initialNode || !direction || (initialNode && direction === 'down')) {
|
2021-02-17 18:32:55 +01:00
|
|
|
links = links.concat(nodeLinks[n.id].out);
|
|
|
|
}
|
2021-03-03 15:20:55 +01:00
|
|
|
initialNode = false;
|
2021-02-17 18:32:55 +01:00
|
|
|
links.forEach(function(l) {
|
|
|
|
if (!visited.has(l.source)) {
|
|
|
|
nodes.push(l.source);
|
|
|
|
}
|
|
|
|
if (!visited.has(l.target)) {
|
|
|
|
nodes.push(l.target);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2021-02-17 18:32:55 +01:00
|
|
|
})
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2021-02-17 18:32:55 +01:00
|
|
|
return Array.from(visited);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2021-02-17 18:32:55 +01:00
|
|
|
|
2021-09-02 17:14:35 +02:00
|
|
|
function convertWorkspace(n,opts) {
|
|
|
|
var exportCreds = true;
|
|
|
|
if (opts) {
|
|
|
|
if (opts.hasOwnProperty("credentials")) {
|
|
|
|
exportCreds = opts.credentials;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 22:58:14 +02:00
|
|
|
var node = {};
|
|
|
|
node.id = n.id;
|
|
|
|
node.type = n.type;
|
|
|
|
for (var d in n._def.defaults) {
|
|
|
|
if (n._def.defaults.hasOwnProperty(d)) {
|
2022-09-19 22:09:00 +02:00
|
|
|
if (d === 'locked' && !n.locked) {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-29 22:58:14 +02:00
|
|
|
node[d] = n[d];
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 17:14:35 +02:00
|
|
|
if (exportCreds) {
|
|
|
|
var credentialSet = {};
|
|
|
|
if (n.credentials) {
|
|
|
|
for (var tabCred in n.credentials) {
|
|
|
|
if (n.credentials.hasOwnProperty(tabCred)) {
|
|
|
|
if (!n.credentials._ ||
|
|
|
|
n.credentials["has_"+tabCred] != n.credentials._["has_"+tabCred] ||
|
|
|
|
(n.credentials["has_"+tabCred] && n.credentials[tabCred])) {
|
|
|
|
credentialSet[tabCred] = n.credentials[tabCred];
|
|
|
|
}
|
2021-08-30 01:00:58 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-02 17:14:35 +02:00
|
|
|
if (Object.keys(credentialSet).length > 0) {
|
|
|
|
node.credentials = credentialSet;
|
|
|
|
}
|
2021-08-30 01:00:58 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-29 22:58:14 +02:00
|
|
|
return node;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
/**
|
2013-12-08 22:55:34 +01:00
|
|
|
* Converts a node to an exportable JSON Object
|
2013-09-05 16:02:48 +02:00
|
|
|
**/
|
2021-06-04 14:53:01 +02:00
|
|
|
function convertNode(n, opts) {
|
|
|
|
var exportCreds = true;
|
|
|
|
var exportDimensions = false;
|
|
|
|
if (opts === false) {
|
|
|
|
exportCreds = false;
|
|
|
|
} else if (typeof opts === "object") {
|
|
|
|
if (opts.hasOwnProperty("credentials")) {
|
|
|
|
exportCreds = opts.credentials;
|
|
|
|
}
|
|
|
|
if (opts.hasOwnProperty("dimensions")) {
|
|
|
|
exportDimensions = opts.dimensions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 22:34:52 +02:00
|
|
|
if (n.type === 'tab') {
|
2021-09-02 17:14:35 +02:00
|
|
|
return convertWorkspace(n, { credentials: exportCreds });
|
2016-10-11 22:34:52 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
var node = {};
|
|
|
|
node.id = n.id;
|
|
|
|
node.type = n.type;
|
2015-09-23 23:49:48 +02:00
|
|
|
node.z = n.z;
|
2020-10-19 14:24:04 +02:00
|
|
|
if (node.z === 0 || node.z === "") {
|
|
|
|
delete node.z;
|
|
|
|
}
|
2019-06-14 23:12:47 +02:00
|
|
|
if (n.d === true) {
|
|
|
|
node.d = true;
|
|
|
|
}
|
2020-03-09 12:14:18 +01:00
|
|
|
if (n.g) {
|
|
|
|
node.g = n.g;
|
|
|
|
}
|
2014-10-30 22:41:42 +01:00
|
|
|
if (node.type == "unknown") {
|
|
|
|
for (var p in n._orig) {
|
|
|
|
if (n._orig.hasOwnProperty(p)) {
|
|
|
|
node[p] = n._orig[p];
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2014-10-30 22:41:42 +01:00
|
|
|
} else {
|
|
|
|
for (var d in n._def.defaults) {
|
|
|
|
if (n._def.defaults.hasOwnProperty(d)) {
|
|
|
|
node[d] = n[d];
|
|
|
|
}
|
|
|
|
}
|
2019-11-01 15:14:48 +01:00
|
|
|
if (exportCreds) {
|
2014-11-23 23:25:09 +01:00
|
|
|
var credentialSet = {};
|
2021-08-30 01:00:58 +02:00
|
|
|
if ((/^subflow:/.test(node.type) ||
|
|
|
|
(node.type === "group")) &&
|
|
|
|
n.credentials) {
|
|
|
|
// A subflow instance/group node can have arbitrary creds
|
2019-11-01 15:14:48 +01:00
|
|
|
for (var sfCred in n.credentials) {
|
|
|
|
if (n.credentials.hasOwnProperty(sfCred)) {
|
2016-09-30 15:15:04 +02:00
|
|
|
if (!n.credentials._ ||
|
2019-11-01 15:14:48 +01:00
|
|
|
n.credentials["has_"+sfCred] != n.credentials._["has_"+sfCred] ||
|
|
|
|
(n.credentials["has_"+sfCred] && n.credentials[sfCred])) {
|
|
|
|
credentialSet[sfCred] = n.credentials[sfCred];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (n.credentials) {
|
|
|
|
node.credentials = {};
|
|
|
|
// All other nodes have a well-defined list of possible credentials
|
|
|
|
for (var cred in n._def.credentials) {
|
|
|
|
if (n._def.credentials.hasOwnProperty(cred)) {
|
|
|
|
if (n._def.credentials[cred].type == 'password') {
|
|
|
|
if (!n.credentials._ ||
|
|
|
|
n.credentials["has_"+cred] != n.credentials._["has_"+cred] ||
|
|
|
|
(n.credentials["has_"+cred] && n.credentials[cred])) {
|
|
|
|
credentialSet[cred] = n.credentials[cred];
|
|
|
|
}
|
|
|
|
} else if (n.credentials[cred] != null && (!n.credentials._ || n.credentials[cred] != n.credentials._[cred])) {
|
2014-11-23 23:25:09 +01:00
|
|
|
credentialSet[cred] = n.credentials[cred];
|
|
|
|
}
|
2014-10-30 22:41:42 +01:00
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-23 23:25:09 +01:00
|
|
|
if (Object.keys(credentialSet).length > 0) {
|
|
|
|
node.credentials = credentialSet;
|
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
2014-06-24 12:13:19 +02:00
|
|
|
}
|
2020-03-09 12:14:18 +01:00
|
|
|
if (n.type === "group") {
|
2020-03-26 16:27:34 +01:00
|
|
|
node.x = n.x;
|
|
|
|
node.y = n.y;
|
|
|
|
node.w = n.w;
|
|
|
|
node.h = n.h;
|
2020-07-07 19:22:45 +02:00
|
|
|
// In 1.1.0, we have seen an instance of this array containing `undefined`
|
|
|
|
// Until we know how that can happen, add a filter here to remove them
|
|
|
|
node.nodes = node.nodes.filter(function(n) { return !!n }).map(function(n) { return n.id });
|
2020-03-09 12:14:18 +01:00
|
|
|
}
|
2021-10-28 13:14:34 +02:00
|
|
|
if (n.type === "tab" || n.type === "group") {
|
|
|
|
if (node.env && node.env.length === 0) {
|
|
|
|
delete node.env;
|
|
|
|
}
|
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
if (n._def.category != "config" || n.type === 'junction') {
|
2013-09-05 16:02:48 +02:00
|
|
|
node.x = n.x;
|
|
|
|
node.y = n.y;
|
2021-06-04 14:53:01 +02:00
|
|
|
if (exportDimensions) {
|
|
|
|
if (!n.hasOwnProperty('w')) {
|
|
|
|
// This node has not yet been drawn in the view. So we need
|
|
|
|
// to explicitly calculate its dimensions. Store the result
|
|
|
|
// on the node as if it had been drawn will save us doing
|
|
|
|
// it again
|
|
|
|
var dimensions = RED.view.calculateNodeDimensions(n);
|
|
|
|
n.w = dimensions[0];
|
|
|
|
n.h = dimensions[1];
|
|
|
|
}
|
|
|
|
node.w = n.w;
|
|
|
|
node.h = n.h;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
node.wires = [];
|
|
|
|
for(var i=0;i<n.outputs;i++) {
|
|
|
|
node.wires.push([]);
|
|
|
|
}
|
|
|
|
var wires = links.filter(function(d){return d.source === n;});
|
2014-08-08 01:01:35 +02:00
|
|
|
for (var j=0;j<wires.length;j++) {
|
|
|
|
var w = wires[j];
|
2014-02-25 00:35:11 +01:00
|
|
|
if (w.target.type != "subflow") {
|
2018-05-17 12:27:28 +02:00
|
|
|
if (w.sourcePort < node.wires.length) {
|
|
|
|
node.wires[w.sourcePort].push(w.target.id);
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
|
|
|
|
if (n.inputs > 0 && n.inputLabels && !/^\s*$/.test(n.inputLabels.join(""))) {
|
|
|
|
node.inputLabels = n.inputLabels.slice();
|
|
|
|
}
|
|
|
|
if (n.outputs > 0 && n.outputLabels && !/^\s*$/.test(n.outputLabels.join(""))) {
|
|
|
|
node.outputLabels = n.outputLabels.slice();
|
|
|
|
}
|
2018-02-01 23:28:05 +01:00
|
|
|
if ((!n._def.defaults || !n._def.defaults.hasOwnProperty("icon")) && n.icon) {
|
2017-11-30 14:13:35 +01:00
|
|
|
var defIcon = RED.utils.getDefaultNodeIcon(n._def, n);
|
|
|
|
if (n.icon !== defIcon.module+"/"+defIcon.file) {
|
|
|
|
node.icon = n.icon;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 17:25:11 +02:00
|
|
|
if ((!n._def.defaults || !n._def.defaults.hasOwnProperty("l")) && n.hasOwnProperty('l')) {
|
2021-09-29 11:43:41 +02:00
|
|
|
var showLabel = n._def.hasOwnProperty("showLabel")?n._def.showLabel:true;
|
|
|
|
if (showLabel != n.l) {
|
2018-10-08 17:25:11 +02:00
|
|
|
node.l = n.l;
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 11:54:24 +02:00
|
|
|
}
|
|
|
|
if (n.info) {
|
|
|
|
node.info = n.info;
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2021-06-04 14:53:01 +02:00
|
|
|
function convertSubflow(n, opts) {
|
|
|
|
var exportCreds = true;
|
|
|
|
var exportDimensions = false;
|
|
|
|
if (opts === false) {
|
|
|
|
exportCreds = false;
|
|
|
|
} else if (typeof opts === "object") {
|
|
|
|
if (opts.hasOwnProperty("credentials")) {
|
|
|
|
exportCreds = opts.credentials;
|
|
|
|
}
|
|
|
|
if (opts.hasOwnProperty("dimensions")) {
|
|
|
|
exportDimensions = opts.dimensions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
var node = {};
|
|
|
|
node.id = n.id;
|
|
|
|
node.type = n.type;
|
|
|
|
node.name = n.name;
|
2015-10-23 23:14:21 +02:00
|
|
|
node.info = n.info;
|
2018-06-12 13:54:32 +02:00
|
|
|
node.category = n.category;
|
2014-02-25 00:35:11 +01:00
|
|
|
node.in = [];
|
|
|
|
node.out = [];
|
2019-01-26 15:15:20 +01:00
|
|
|
node.env = n.env;
|
2020-11-19 15:28:50 +01:00
|
|
|
node.meta = n.meta;
|
2019-11-01 15:14:48 +01:00
|
|
|
|
|
|
|
if (exportCreds) {
|
|
|
|
var credentialSet = {};
|
|
|
|
// A subflow node can have arbitrary creds
|
|
|
|
for (var sfCred in n.credentials) {
|
|
|
|
if (n.credentials.hasOwnProperty(sfCred)) {
|
|
|
|
if (!n.credentials._ ||
|
|
|
|
n.credentials["has_"+sfCred] != n.credentials._["has_"+sfCred] ||
|
|
|
|
(n.credentials["has_"+sfCred] && n.credentials[sfCred])) {
|
|
|
|
credentialSet[sfCred] = n.credentials[sfCred];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Object.keys(credentialSet).length > 0) {
|
|
|
|
node.credentials = credentialSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:52:08 +02:00
|
|
|
node.color = n.color;
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
n.in.forEach(function(p) {
|
|
|
|
var nIn = {x:p.x,y:p.y,wires:[]};
|
|
|
|
var wires = links.filter(function(d) { return d.source === p });
|
|
|
|
for (var i=0;i<wires.length;i++) {
|
|
|
|
var w = wires[i];
|
2015-01-08 23:34:26 +01:00
|
|
|
if (w.target.type != "subflow") {
|
2014-02-25 00:35:11 +01:00
|
|
|
nIn.wires.push({id:w.target.id})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node.in.push(nIn);
|
|
|
|
});
|
|
|
|
n.out.forEach(function(p,c) {
|
|
|
|
var nOut = {x:p.x,y:p.y,wires:[]};
|
|
|
|
var wires = links.filter(function(d) { return d.target === p });
|
|
|
|
for (i=0;i<wires.length;i++) {
|
|
|
|
if (wires[i].source.type != "subflow") {
|
|
|
|
nOut.wires.push({id:wires[i].source.id,port:wires[i].sourcePort})
|
|
|
|
} else {
|
|
|
|
nOut.wires.push({id:n.id,port:0})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node.out.push(nOut);
|
|
|
|
});
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2017-02-08 11:25:58 +01:00
|
|
|
if (node.in.length > 0 && n.inputLabels && !/^\s*$/.test(n.inputLabels.join(""))) {
|
|
|
|
node.inputLabels = n.inputLabels.slice();
|
|
|
|
}
|
|
|
|
if (node.out.length > 0 && n.outputLabels && !/^\s*$/.test(n.outputLabels.join(""))) {
|
|
|
|
node.outputLabels = n.outputLabels.slice();
|
|
|
|
}
|
2018-03-14 05:51:50 +01:00
|
|
|
if (n.icon) {
|
2019-06-21 13:36:20 +02:00
|
|
|
if (n.icon !== "node-red/subflow.svg") {
|
2018-03-14 05:51:50 +01:00
|
|
|
node.icon = n.icon;
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 00:44:50 +01:00
|
|
|
if (n.status) {
|
|
|
|
node.status = {x: n.status.x, y: n.status.y, wires:[]};
|
|
|
|
links.forEach(function(d) {
|
|
|
|
if (d.target === n.status) {
|
|
|
|
if (d.source.type != "subflow") {
|
|
|
|
node.status.wires.push({id:d.source.id, port:d.sourcePort})
|
|
|
|
} else {
|
|
|
|
node.status.wires.push({id:n.id, port:0})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
return node;
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
|
|
|
|
function createExportableSubflow(id) {
|
|
|
|
var sf = getSubflow(id);
|
2021-08-26 22:16:40 +02:00
|
|
|
var nodeSet;
|
|
|
|
var sfNodes = allNodes.getNodes(sf.id);
|
|
|
|
if (sfNodes) {
|
|
|
|
nodeSet = sfNodes.slice();
|
|
|
|
nodeSet.unshift(sf);
|
|
|
|
} else {
|
|
|
|
nodeSet = [sf];
|
2020-09-16 12:42:22 +02:00
|
|
|
}
|
|
|
|
return createExportableNodeSet(nodeSet);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
/**
|
|
|
|
* Converts the current node selection to an exportable JSON Object
|
|
|
|
**/
|
2020-03-26 19:01:57 +01:00
|
|
|
function createExportableNodeSet(set, exportedIds, exportedSubflows, exportedConfigNodes) {
|
2013-09-05 16:02:48 +02:00
|
|
|
var nns = [];
|
2020-03-26 19:01:57 +01:00
|
|
|
|
|
|
|
exportedIds = exportedIds || {};
|
|
|
|
set = set.filter(function(n) {
|
|
|
|
if (exportedIds[n.id]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
exportedIds[n.id] = true;
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
|
2017-06-26 11:07:44 +02:00
|
|
|
exportedConfigNodes = exportedConfigNodes || {};
|
|
|
|
exportedSubflows = exportedSubflows || {};
|
2014-08-08 01:01:35 +02:00
|
|
|
for (var n=0;n<set.length;n++) {
|
2015-03-13 00:38:37 +01:00
|
|
|
var node = set[n];
|
2014-02-25 00:35:11 +01:00
|
|
|
if (node.type.substring(0,8) == "subflow:") {
|
|
|
|
var subflowId = node.type.substring(8);
|
|
|
|
if (!exportedSubflows[subflowId]) {
|
|
|
|
exportedSubflows[subflowId] = true;
|
|
|
|
var subflow = getSubflow(subflowId);
|
2021-08-26 22:16:40 +02:00
|
|
|
var subflowSet = allNodes.getNodes(subflowId).slice();
|
|
|
|
subflowSet.unshift(subflow);
|
|
|
|
|
2021-01-29 03:05:15 +01:00
|
|
|
RED.nodes.eachConfig(function(n) {
|
|
|
|
if (n.z == subflowId) {
|
|
|
|
subflowSet.push(n);
|
2021-01-29 11:16:40 +01:00
|
|
|
exportedConfigNodes[n.id] = true;
|
2021-01-29 03:05:15 +01:00
|
|
|
}
|
|
|
|
});
|
2022-08-01 21:54:05 +02:00
|
|
|
|
|
|
|
subflowSet = subflowSet.concat(RED.nodes.junctions(subflowId))
|
|
|
|
subflowSet = subflowSet.concat(RED.nodes.groups(subflowId))
|
|
|
|
|
2020-03-26 19:01:57 +01:00
|
|
|
var exportableSubflow = createExportableNodeSet(subflowSet, exportedIds, exportedSubflows, exportedConfigNodes);
|
2014-02-25 00:35:11 +01:00
|
|
|
nns = exportableSubflow.concat(nns);
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 19:01:57 +01:00
|
|
|
if (node.type !== "subflow") {
|
2021-01-29 11:16:40 +01:00
|
|
|
var convertedNode = RED.nodes.convertNode(node);
|
|
|
|
for (var d in node._def.defaults) {
|
|
|
|
if (node._def.defaults[d].type) {
|
|
|
|
var nodeList = node[d];
|
|
|
|
if (!Array.isArray(nodeList)) {
|
|
|
|
nodeList = [nodeList];
|
|
|
|
}
|
|
|
|
nodeList = nodeList.filter(function(id) {
|
|
|
|
if (id in configNodes) {
|
|
|
|
var confNode = configNodes[id];
|
|
|
|
if (confNode._def.exportable !== false) {
|
|
|
|
if (!(id in exportedConfigNodes)) {
|
|
|
|
exportedConfigNodes[id] = true;
|
|
|
|
set.push(confNode);
|
2021-01-08 15:19:12 +01:00
|
|
|
}
|
2021-03-17 16:11:35 +01:00
|
|
|
return true;
|
2021-01-08 15:19:12 +01:00
|
|
|
}
|
2021-01-29 11:16:40 +01:00
|
|
|
return false;
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2021-01-29 11:16:40 +01:00
|
|
|
return true;
|
|
|
|
})
|
|
|
|
if (nodeList.length === 0) {
|
|
|
|
convertedNode[d] = Array.isArray(node[d])?[]:""
|
|
|
|
} else {
|
|
|
|
convertedNode[d] = Array.isArray(node[d])?nodeList:nodeList[0]
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 11:16:40 +01:00
|
|
|
nns.push(convertedNode);
|
2020-03-26 19:01:57 +01:00
|
|
|
if (node.type === "group") {
|
|
|
|
nns = nns.concat(createExportableNodeSet(node.nodes, exportedIds, exportedSubflows, exportedConfigNodes));
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
} else {
|
|
|
|
var convertedSubflow = convertSubflow(node);
|
|
|
|
nns.push(convertedSubflow);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nns;
|
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2021-06-04 14:53:01 +02:00
|
|
|
// Create the Flow JSON for the current configuration
|
|
|
|
// opts.credentials (whether to include (known) credentials) - default: true
|
|
|
|
// opts.dimensions (whether to include node dimensions) - default: false
|
|
|
|
function createCompleteNodeSet(opts) {
|
2013-09-05 16:02:48 +02:00
|
|
|
var nns = [];
|
2014-08-08 01:01:35 +02:00
|
|
|
var i;
|
2016-05-04 16:22:30 +02:00
|
|
|
for (i=0;i<workspacesOrder.length;i++) {
|
|
|
|
if (workspaces[workspacesOrder[i]].type == "tab") {
|
2021-09-02 17:14:35 +02:00
|
|
|
nns.push(convertWorkspace(workspaces[workspacesOrder[i]], opts));
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i in subflows) {
|
|
|
|
if (subflows.hasOwnProperty(i)) {
|
2021-06-04 14:53:01 +02:00
|
|
|
nns.push(convertSubflow(subflows[i], opts));
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2020-03-09 12:14:18 +01:00
|
|
|
for (i in groups) {
|
|
|
|
if (groups.hasOwnProperty(i)) {
|
2021-06-04 14:53:01 +02:00
|
|
|
nns.push(convertNode(groups[i], opts));
|
2020-03-09 12:14:18 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
for (i in junctions) {
|
|
|
|
if (junctions.hasOwnProperty(i)) {
|
|
|
|
nns.push(convertNode(junctions[i], opts));
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
for (i in configNodes) {
|
|
|
|
if (configNodes.hasOwnProperty(i)) {
|
2021-06-04 14:53:01 +02:00
|
|
|
nns.push(convertNode(configNodes[i], opts));
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2021-08-26 22:16:40 +02:00
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
nns.push(convertNode(n, opts));
|
|
|
|
})
|
2013-09-05 16:02:48 +02:00
|
|
|
return nns;
|
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2016-09-24 23:20:28 +02:00
|
|
|
function checkForMatchingSubflow(subflow,subflowNodes) {
|
2018-10-27 00:07:48 +02:00
|
|
|
subflowNodes = subflowNodes || [];
|
2016-09-24 23:20:28 +02:00
|
|
|
var i;
|
|
|
|
var match = null;
|
2018-10-27 00:07:48 +02:00
|
|
|
RED.nodes.eachSubflow(function(sf) {
|
|
|
|
if (sf.name != subflow.name ||
|
|
|
|
sf.info != subflow.info ||
|
|
|
|
sf.in.length != subflow.in.length ||
|
|
|
|
sf.out.length != subflow.out.length) {
|
2016-09-24 23:20:28 +02:00
|
|
|
return;
|
2018-10-27 00:07:48 +02:00
|
|
|
}
|
|
|
|
var sfNodes = RED.nodes.filterNodes({z:sf.id});
|
|
|
|
if (sfNodes.length != subflowNodes.length) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-24 23:20:28 +02:00
|
|
|
|
2018-10-27 00:07:48 +02:00
|
|
|
var subflowNodeSet = [subflow].concat(subflowNodes);
|
|
|
|
var sfNodeSet = [sf].concat(sfNodes);
|
2016-09-24 23:20:28 +02:00
|
|
|
|
2018-10-27 00:07:48 +02:00
|
|
|
var exportableSubflowNodes = JSON.stringify(subflowNodeSet);
|
|
|
|
var exportableSFNodes = JSON.stringify(createExportableNodeSet(sfNodeSet));
|
|
|
|
var nodeMap = {};
|
|
|
|
for (i=0;i<sfNodes.length;i++) {
|
|
|
|
exportableSubflowNodes = exportableSubflowNodes.replace(new RegExp("\""+subflowNodes[i].id+"\"","g"),'"'+sfNodes[i].id+'"');
|
|
|
|
}
|
|
|
|
exportableSubflowNodes = exportableSubflowNodes.replace(new RegExp("\""+subflow.id+"\"","g"),'"'+sf.id+'"');
|
2016-09-24 23:20:28 +02:00
|
|
|
|
2018-10-27 00:07:48 +02:00
|
|
|
if (exportableSubflowNodes !== exportableSFNodes) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-24 23:20:28 +02:00
|
|
|
|
2018-10-27 00:07:48 +02:00
|
|
|
match = sf;
|
|
|
|
return false;
|
|
|
|
});
|
2016-09-24 23:20:28 +02:00
|
|
|
return match;
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
function compareNodes(nodeA,nodeB,idMustMatch) {
|
|
|
|
if (idMustMatch && nodeA.id != nodeB.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (nodeA.type != nodeB.type) {
|
2015-07-08 23:12:52 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
|
|
|
|
function identifyImportConflicts(importedNodes) {
|
|
|
|
var imported = {
|
|
|
|
tabs: {},
|
|
|
|
subflows: {},
|
|
|
|
groups: {},
|
2022-02-28 13:53:11 +01:00
|
|
|
junctions: {},
|
2020-09-16 12:42:22 +02:00
|
|
|
configs: {},
|
|
|
|
nodes: {},
|
|
|
|
all: [],
|
|
|
|
conflicted: {},
|
|
|
|
zMap: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
importedNodes.forEach(function(n) {
|
|
|
|
imported.all.push(n);
|
|
|
|
if (n.type === "tab") {
|
|
|
|
imported.tabs[n.id] = n;
|
|
|
|
} else if (n.type === "subflow") {
|
|
|
|
imported.subflows[n.id] = n;
|
|
|
|
} else if (n.type === "group") {
|
|
|
|
imported.groups[n.id] = n;
|
2022-02-28 13:53:11 +01:00
|
|
|
} else if (n.type === "junction") {
|
|
|
|
imported.junctions[n.id] = n;
|
2020-09-16 12:42:22 +02:00
|
|
|
} else if (n.hasOwnProperty("x") && n.hasOwnProperty("y")) {
|
|
|
|
imported.nodes[n.id] = n;
|
|
|
|
} else {
|
|
|
|
imported.configs[n.id] = n;
|
|
|
|
}
|
|
|
|
var nodeZ = n.z || "__global__";
|
|
|
|
imported.zMap[nodeZ] = imported.zMap[nodeZ] || [];
|
|
|
|
imported.zMap[nodeZ].push(n)
|
2022-02-28 13:53:11 +01:00
|
|
|
if (allNodes.hasNode(n.id) || configNodes[n.id] || workspaces[n.id] || subflows[n.id] || groups[n.id] || junctions[n.id]) {
|
2020-09-16 12:42:22 +02:00
|
|
|
imported.conflicted[n.id] = n;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return imported;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace the provided nodes.
|
|
|
|
* This must contain complete Subflow defs or complete Flow Tabs.
|
|
|
|
* It does not replace an individual node in the middle of a flow.
|
|
|
|
*/
|
|
|
|
function replaceNodes(newNodes) {
|
|
|
|
var zMap = {};
|
|
|
|
var newSubflows = {};
|
|
|
|
var newConfigNodes = {};
|
|
|
|
var removedNodes = [];
|
|
|
|
// Figure out what we're being asked to replace - subflows/configNodes
|
|
|
|
// TODO: config nodes
|
|
|
|
newNodes.forEach(function(n) {
|
|
|
|
if (n.type === "subflow") {
|
|
|
|
newSubflows[n.id] = n;
|
|
|
|
} else if (!n.hasOwnProperty('x') && !n.hasOwnProperty('y')) {
|
|
|
|
newConfigNodes[n.id] = n;
|
|
|
|
}
|
|
|
|
if (n.z) {
|
|
|
|
zMap[n.z] = zMap[n.z] || [];
|
|
|
|
zMap[n.z].push(n);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Filter out config nodes inside a subflow def that is being replaced
|
|
|
|
var configNodeIds = Object.keys(newConfigNodes);
|
|
|
|
configNodeIds.forEach(function(id) {
|
|
|
|
var n = newConfigNodes[id];
|
|
|
|
if (newSubflows[n.z]) {
|
|
|
|
// This config node is in a subflow to be replaced.
|
|
|
|
// - remove from the list as it'll get handled with the subflow
|
|
|
|
delete newConfigNodes[id];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Rebuild the list of ids
|
|
|
|
configNodeIds = Object.keys(newConfigNodes);
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Replace subflow definitions
|
|
|
|
//
|
|
|
|
// For each of the subflows to be replaced:
|
|
|
|
var newSubflowIds = Object.keys(newSubflows);
|
|
|
|
newSubflowIds.forEach(function(id) {
|
|
|
|
var n = newSubflows[id];
|
|
|
|
// Get a snapshot of the existing subflow definition
|
|
|
|
removedNodes = removedNodes.concat(createExportableSubflow(id));
|
|
|
|
// Remove the old subflow definition - but leave the instances in place
|
|
|
|
var removalResult = RED.subflow.removeSubflow(n.id, true);
|
|
|
|
// Create the list of nodes for the new subflow def
|
|
|
|
var subflowNodes = [n].concat(zMap[n.id]);
|
|
|
|
// Import the new subflow - no clashes should occur as we've removed
|
|
|
|
// the old version
|
|
|
|
var result = importNodes(subflowNodes);
|
|
|
|
newSubflows[id] = getSubflow(id);
|
|
|
|
})
|
|
|
|
|
|
|
|
// Having replaced the subflow definitions, now need to update the
|
|
|
|
// instance nodes.
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (/^subflow:/.test(n.type)) {
|
|
|
|
var sfId = n.type.substring(8);
|
|
|
|
if (newSubflows[sfId]) {
|
|
|
|
// This is an instance of one of the replaced subflows
|
|
|
|
// - update the new def's instances array to include this one
|
|
|
|
newSubflows[sfId].instances.push(n);
|
|
|
|
// - update the instance's _def to point to the new def
|
|
|
|
n._def = RED.nodes.getType(n.type);
|
|
|
|
// - set all the flags so the view refreshes properly
|
|
|
|
n.dirty = true;
|
|
|
|
n.changed = true;
|
|
|
|
n._colorChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-09-18 21:56:16 +02:00
|
|
|
|
|
|
|
newSubflowIds.forEach(function(id) {
|
|
|
|
var n = newSubflows[id];
|
|
|
|
RED.events.emit("subflows:change",n);
|
|
|
|
})
|
2020-09-16 12:42:22 +02:00
|
|
|
// Just in case the imported subflow changed color.
|
|
|
|
RED.utils.clearNodeColorCache();
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Replace config nodes
|
|
|
|
//
|
|
|
|
configNodeIds.forEach(function(id) {
|
|
|
|
removedNodes = removedNodes.concat(convertNode(getNode(id)));
|
|
|
|
removeNode(id);
|
|
|
|
importNodes([newConfigNodes[id]])
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
removedNodes: removedNodes
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:31:33 +02:00
|
|
|
/**
|
|
|
|
* Options:
|
|
|
|
* - generateIds - whether to replace all node ids
|
|
|
|
* - addFlow - whether to import nodes to a new tab
|
2022-06-28 17:22:24 +02:00
|
|
|
* - reimport - if node has a .z property, dont overwrite it
|
|
|
|
* Only applicible when `generateIds` is false
|
2020-09-16 12:42:22 +02:00
|
|
|
* - importMap - how to resolve any conflicts.
|
|
|
|
* - id:import - import as-is
|
|
|
|
* - id:copy - import with new id
|
|
|
|
* - id:replace - import over the top of existing
|
2020-09-03 19:31:33 +02:00
|
|
|
*/
|
|
|
|
function importNodes(newNodesObj,options) { // createNewIds,createMissingWorkspace) {
|
2022-06-28 17:22:24 +02:00
|
|
|
const defOpts = { generateIds: false, addFlow: false, reimport: false, importMap: {} }
|
|
|
|
options = Object.assign({}, defOpts, options)
|
2022-06-30 16:17:49 +02:00
|
|
|
options.importMap = options.importMap || {}
|
2022-06-28 17:22:24 +02:00
|
|
|
const createNewIds = options.generateIds;
|
|
|
|
const reimport = (!createNewIds && !!options.reimport)
|
|
|
|
const createMissingWorkspace = options.addFlow;
|
2015-03-14 23:53:31 +01:00
|
|
|
var i;
|
|
|
|
var n;
|
|
|
|
var newNodes;
|
2016-09-24 23:20:28 +02:00
|
|
|
var nodeZmap = {};
|
2020-09-03 19:31:33 +02:00
|
|
|
var recoveryWorkspace;
|
2015-03-14 23:53:31 +01:00
|
|
|
if (typeof newNodesObj === "string") {
|
|
|
|
if (newNodesObj === "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2013-09-05 16:02:48 +02:00
|
|
|
newNodes = JSON.parse(newNodesObj);
|
2015-03-14 23:53:31 +01:00
|
|
|
} catch(err) {
|
2015-07-01 00:42:03 +02:00
|
|
|
var e = new Error(RED._("clipboard.invalidFlow",{message:err.message}));
|
2015-03-14 23:53:31 +01:00
|
|
|
e.code = "NODE_RED";
|
|
|
|
throw e;
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
} else {
|
|
|
|
newNodes = newNodesObj;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
if (!$.isArray(newNodes)) {
|
|
|
|
newNodes = [newNodes];
|
|
|
|
}
|
2019-03-15 20:02:24 +01:00
|
|
|
|
|
|
|
// Scan for any duplicate nodes and remove them. This is a temporary
|
|
|
|
// fix to help resolve corrupted flows caused by 0.20.0 where multiple
|
|
|
|
// copies of the flow would get loaded at the same time.
|
|
|
|
// If the user hit deploy they would have saved those duplicates.
|
|
|
|
var seenIds = {};
|
2020-09-16 12:42:22 +02:00
|
|
|
var existingNodes = [];
|
|
|
|
var nodesToReplace = [];
|
|
|
|
|
2019-03-15 20:02:24 +01:00
|
|
|
newNodes = newNodes.filter(function(n) {
|
2020-09-16 12:42:22 +02:00
|
|
|
var id = n.id;
|
2019-03-15 20:02:24 +01:00
|
|
|
if (seenIds[n.id]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
seenIds[n.id] = true;
|
2020-09-16 12:42:22 +02:00
|
|
|
|
|
|
|
if (!options.generateIds) {
|
|
|
|
if (!options.importMap[id]) {
|
|
|
|
// No conflict resolution for this node
|
2022-02-28 13:53:11 +01:00
|
|
|
var existing = allNodes.getNode(id) || configNodes[id] || workspaces[id] || subflows[id] || groups[id] || junctions[id];
|
2020-11-02 22:13:52 +01:00
|
|
|
if (existing) {
|
|
|
|
existingNodes.push({existing:existing, imported:n});
|
2020-09-16 12:42:22 +02:00
|
|
|
}
|
|
|
|
} else if (options.importMap[id] === "replace") {
|
|
|
|
nodesToReplace.push(n);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:02:24 +01:00
|
|
|
return true;
|
|
|
|
})
|
|
|
|
|
2020-09-16 12:42:22 +02:00
|
|
|
if (existingNodes.length > 0) {
|
2020-11-02 22:13:52 +01:00
|
|
|
var errorMessage = RED._("clipboard.importDuplicate",{count:existingNodes.length});
|
|
|
|
var nodeList = $("<ul>");
|
|
|
|
var existingNodesCount = Math.min(5,existingNodes.length);
|
|
|
|
for (var i=0;i<existingNodesCount;i++) {
|
|
|
|
var conflict = existingNodes[i];
|
|
|
|
$("<li>").text(
|
|
|
|
conflict.existing.id+
|
|
|
|
" [ "+conflict.existing.type+ ((conflict.imported.type !== conflict.existing.type)?" | "+conflict.imported.type:"")+" ]").appendTo(nodeList)
|
|
|
|
}
|
|
|
|
if (existingNodesCount !== existingNodes.length) {
|
|
|
|
$("<li>").text(RED._("deploy.confirm.plusNMore",{count:existingNodes.length-existingNodesCount})).appendTo(nodeList)
|
|
|
|
}
|
|
|
|
var wrapper = $("<p>").append(nodeList);
|
|
|
|
|
|
|
|
var existingNodesError = new Error(errorMessage+wrapper.html());
|
2020-09-16 12:42:22 +02:00
|
|
|
existingNodesError.code = "import_conflict";
|
|
|
|
existingNodesError.importConfig = identifyImportConflicts(newNodes);
|
|
|
|
throw existingNodesError;
|
|
|
|
}
|
|
|
|
var removedNodes;
|
|
|
|
if (nodesToReplace.length > 0) {
|
|
|
|
var replaceResult = replaceNodes(nodesToReplace);
|
|
|
|
removedNodes = replaceResult.removedNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-22 14:46:11 +01:00
|
|
|
var isInitialLoad = false;
|
2016-12-06 23:37:21 +01:00
|
|
|
if (!initialLoad) {
|
2018-01-22 14:46:11 +01:00
|
|
|
isInitialLoad = true;
|
2016-12-06 23:37:21 +01:00
|
|
|
initialLoad = JSON.parse(JSON.stringify(newNodes));
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
var unknownTypes = [];
|
|
|
|
for (i=0;i<newNodes.length;i++) {
|
|
|
|
n = newNodes[i];
|
2020-09-16 12:42:22 +02:00
|
|
|
var id = n.id;
|
2015-03-14 23:53:31 +01:00
|
|
|
// TODO: remove workspace in next release+1
|
2015-06-29 17:12:18 +02:00
|
|
|
if (n.type != "workspace" &&
|
|
|
|
n.type != "tab" &&
|
2015-03-14 23:53:31 +01:00
|
|
|
n.type != "subflow" &&
|
2020-03-09 12:14:18 +01:00
|
|
|
n.type != "group" &&
|
2022-02-28 13:53:11 +01:00
|
|
|
n.type != 'junction' &&
|
2015-03-14 23:53:31 +01:00
|
|
|
!registry.getNodeType(n.type) &&
|
2015-03-19 23:56:59 +01:00
|
|
|
n.type.substring(0,8) != "subflow:" &&
|
|
|
|
unknownTypes.indexOf(n.type)==-1) {
|
2015-03-14 23:53:31 +01:00
|
|
|
unknownTypes.push(n.type);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2016-09-24 23:20:28 +02:00
|
|
|
if (n.z) {
|
|
|
|
nodeZmap[n.z] = nodeZmap[n.z] || [];
|
|
|
|
nodeZmap[n.z].push(n);
|
2020-10-21 11:36:47 +02:00
|
|
|
} else if (isInitialLoad && n.hasOwnProperty('x') && n.hasOwnProperty('y') && !n.z) {
|
2020-09-03 19:31:33 +02:00
|
|
|
// Hit the rare issue where node z values get set to 0.
|
|
|
|
// Repair the flow - but we really need to track that down.
|
|
|
|
if (!recoveryWorkspace) {
|
2020-09-03 21:24:50 +02:00
|
|
|
recoveryWorkspace = {
|
|
|
|
id: RED.nodes.id(),
|
|
|
|
type: "tab",
|
|
|
|
disabled: false,
|
|
|
|
label: RED._("clipboard.recoveredNodes"),
|
2021-08-19 14:15:13 +02:00
|
|
|
info: RED._("clipboard.recoveredNodesInfo"),
|
|
|
|
env: []
|
2020-09-03 21:24:50 +02:00
|
|
|
}
|
|
|
|
addWorkspace(recoveryWorkspace);
|
|
|
|
RED.workspaces.add(recoveryWorkspace);
|
2020-09-03 19:31:33 +02:00
|
|
|
nodeZmap[recoveryWorkspace.id] = [];
|
|
|
|
}
|
|
|
|
n.z = recoveryWorkspace.id;
|
|
|
|
nodeZmap[recoveryWorkspace.id].push(n);
|
2016-09-24 23:20:28 +02:00
|
|
|
}
|
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2018-01-22 14:46:11 +01:00
|
|
|
if (!isInitialLoad && unknownTypes.length > 0) {
|
2020-09-21 15:00:01 +02:00
|
|
|
var typeList = $("<ul>");
|
|
|
|
unknownTypes.forEach(function(t) {
|
|
|
|
$("<li>").text(t).appendTo(typeList);
|
|
|
|
})
|
|
|
|
typeList = typeList[0].outerHTML;
|
2018-04-16 14:23:36 +02:00
|
|
|
RED.notify("<p>"+RED._("clipboard.importUnrecognised",{count:unknownTypes.length})+"</p>"+typeList,"error",false,10000);
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2013-12-12 16:51:15 +01:00
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
var activeWorkspace = RED.workspaces.active();
|
2017-01-01 01:18:39 +01:00
|
|
|
//TODO: check the z of the subflow instance and check _that_ if it exists
|
2015-03-14 23:53:31 +01:00
|
|
|
var activeSubflow = getSubflow(activeWorkspace);
|
2017-01-01 01:18:39 +01:00
|
|
|
for (i=0;i<newNodes.length;i++) {
|
|
|
|
var m = /^subflow:(.+)$/.exec(newNodes[i].type);
|
|
|
|
if (m) {
|
|
|
|
var subflowId = m[1];
|
2019-10-16 13:59:01 +02:00
|
|
|
var parent = getSubflow(activeWorkspace);
|
2017-01-01 01:18:39 +01:00
|
|
|
if (parent) {
|
2015-03-14 23:53:31 +01:00
|
|
|
var err;
|
2017-01-01 01:18:39 +01:00
|
|
|
if (subflowId === parent.id) {
|
2015-07-01 00:42:03 +02:00
|
|
|
err = new Error(RED._("notification.errors.cannotAddSubflowToItself"));
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2017-01-01 01:18:39 +01:00
|
|
|
if (subflowContains(subflowId,parent.id)) {
|
2015-07-01 00:42:03 +02:00
|
|
|
err = new Error(RED._("notification.errors.cannotAddCircularReference"));
|
2014-09-08 11:53:18 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
if (err) {
|
|
|
|
// TODO: standardise error codes
|
|
|
|
err.code = "NODE_RED";
|
|
|
|
throw err;
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
var new_workspaces = [];
|
|
|
|
var workspace_map = {};
|
|
|
|
var new_subflows = [];
|
|
|
|
var subflow_map = {};
|
2020-07-07 19:22:45 +02:00
|
|
|
var subflow_denylist = {};
|
2015-07-08 23:12:52 +02:00
|
|
|
var node_map = {};
|
|
|
|
var new_nodes = [];
|
|
|
|
var new_links = [];
|
2020-03-09 12:14:18 +01:00
|
|
|
var new_groups = [];
|
2022-02-28 13:53:11 +01:00
|
|
|
var new_junctions = [];
|
2020-08-04 21:59:51 +02:00
|
|
|
var new_group_set = new Set();
|
2015-03-14 23:53:31 +01:00
|
|
|
var nid;
|
|
|
|
var def;
|
2016-04-19 22:41:26 +02:00
|
|
|
var configNode;
|
2016-09-23 23:02:12 +02:00
|
|
|
var missingWorkspace = null;
|
2016-09-30 15:15:04 +02:00
|
|
|
var d;
|
2016-04-19 22:41:26 +02:00
|
|
|
|
2020-09-03 19:31:33 +02:00
|
|
|
if (recoveryWorkspace) {
|
|
|
|
new_workspaces.push(recoveryWorkspace);
|
|
|
|
}
|
|
|
|
|
2016-04-19 22:41:26 +02:00
|
|
|
// Find all tabs and subflow templates
|
2015-03-14 23:53:31 +01:00
|
|
|
for (i=0;i<newNodes.length;i++) {
|
|
|
|
n = newNodes[i];
|
|
|
|
// TODO: remove workspace in next release+1
|
|
|
|
if (n.type === "workspace" || n.type === "tab") {
|
|
|
|
if (n.type === "workspace") {
|
|
|
|
n.type = "tab";
|
|
|
|
}
|
|
|
|
if (defaultWorkspace == null) {
|
|
|
|
defaultWorkspace = n;
|
|
|
|
}
|
2020-10-19 13:53:03 +02:00
|
|
|
if (activeWorkspace === 0) {
|
|
|
|
activeWorkspace = n.id;
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2015-03-14 23:53:31 +01:00
|
|
|
nid = getID();
|
|
|
|
workspace_map[n.id] = nid;
|
|
|
|
n.id = nid;
|
2021-04-28 21:54:31 +02:00
|
|
|
} else {
|
|
|
|
workspace_map[n.id] = n.id;
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
addWorkspace(n);
|
|
|
|
RED.workspaces.add(n);
|
|
|
|
new_workspaces.push(n);
|
|
|
|
} else if (n.type === "subflow") {
|
2020-09-16 12:42:22 +02:00
|
|
|
var matchingSubflow;
|
|
|
|
if (!options.importMap[n.id]) {
|
|
|
|
matchingSubflow = checkForMatchingSubflow(n,nodeZmap[n.id]);
|
|
|
|
}
|
2016-09-24 23:20:28 +02:00
|
|
|
if (matchingSubflow) {
|
2020-07-07 19:22:45 +02:00
|
|
|
subflow_denylist[n.id] = matchingSubflow;
|
2016-09-24 23:20:28 +02:00
|
|
|
} else {
|
|
|
|
subflow_map[n.id] = n;
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2016-09-24 23:20:28 +02:00
|
|
|
nid = getID();
|
|
|
|
n.id = nid;
|
|
|
|
}
|
|
|
|
// TODO: handle createNewIds - map old to new subflow ids
|
|
|
|
n.in.forEach(function(input,i) {
|
|
|
|
input.type = "subflow";
|
|
|
|
input.direction = "in";
|
|
|
|
input.z = n.id;
|
|
|
|
input.i = i;
|
|
|
|
input.id = getID();
|
|
|
|
});
|
|
|
|
n.out.forEach(function(output,i) {
|
|
|
|
output.type = "subflow";
|
|
|
|
output.direction = "out";
|
|
|
|
output.z = n.id;
|
|
|
|
output.i = i;
|
|
|
|
output.id = getID();
|
|
|
|
});
|
2019-02-02 00:44:50 +01:00
|
|
|
if (n.status) {
|
|
|
|
n.status.type = "subflow";
|
|
|
|
n.status.direction = "status";
|
|
|
|
n.status.z = n.id;
|
|
|
|
n.status.id = getID();
|
|
|
|
}
|
2016-09-24 23:20:28 +02:00
|
|
|
new_subflows.push(n);
|
2020-09-16 12:42:22 +02:00
|
|
|
addSubflow(n,createNewIds || options.importMap[n.id] === "copy");
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2016-04-19 22:41:26 +02:00
|
|
|
|
|
|
|
// Add a tab if there isn't one there already
|
2015-03-14 23:53:31 +01:00
|
|
|
if (defaultWorkspace == null) {
|
2021-08-19 14:15:13 +02:00
|
|
|
defaultWorkspace = { type:"tab", id:getID(), disabled: false, info:"", label:RED._('workspace.defaultName',{number:1}), env:[]};
|
2015-03-14 23:53:31 +01:00
|
|
|
addWorkspace(defaultWorkspace);
|
|
|
|
RED.workspaces.add(defaultWorkspace);
|
|
|
|
new_workspaces.push(defaultWorkspace);
|
|
|
|
activeWorkspace = RED.workspaces.active();
|
|
|
|
}
|
2013-12-08 22:55:34 +01:00
|
|
|
|
2016-04-19 22:41:26 +02:00
|
|
|
// Find all config nodes and add them
|
2015-09-25 18:43:28 +02:00
|
|
|
for (i=0;i<newNodes.length;i++) {
|
|
|
|
n = newNodes[i];
|
|
|
|
def = registry.getNodeType(n.type);
|
|
|
|
if (def && def.category == "config") {
|
|
|
|
var existingConfigNode = null;
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2015-09-25 18:43:28 +02:00
|
|
|
if (n.z) {
|
2020-07-07 19:22:45 +02:00
|
|
|
if (subflow_denylist[n.z]) {
|
2016-09-24 23:20:28 +02:00
|
|
|
continue;
|
|
|
|
} else if (subflow_map[n.z]) {
|
2015-09-25 18:43:28 +02:00
|
|
|
n.z = subflow_map[n.z].id;
|
|
|
|
} else {
|
|
|
|
n.z = workspace_map[n.z];
|
|
|
|
if (!workspaces[n.z]) {
|
2016-09-23 23:02:12 +02:00
|
|
|
if (createMissingWorkspace) {
|
|
|
|
if (missingWorkspace === null) {
|
|
|
|
missingWorkspace = RED.workspaces.add(null,true);
|
|
|
|
new_workspaces.push(missingWorkspace);
|
|
|
|
}
|
|
|
|
n.z = missingWorkspace.id;
|
|
|
|
} else {
|
|
|
|
n.z = activeWorkspace;
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
if (options.importMap[n.id] !== "copy") {
|
|
|
|
existingConfigNode = RED.nodes.node(n.id);
|
|
|
|
if (existingConfigNode) {
|
|
|
|
if (n.z && existingConfigNode.z !== n.z) {
|
|
|
|
existingConfigNode = null;
|
|
|
|
// Check the config nodes on n.z
|
|
|
|
for (var cn in configNodes) {
|
|
|
|
if (configNodes.hasOwnProperty(cn)) {
|
|
|
|
if (configNodes[cn].z === n.z && compareNodes(configNodes[cn],n,false)) {
|
|
|
|
existingConfigNode = configNodes[cn];
|
|
|
|
node_map[n.id] = configNodes[cn];
|
|
|
|
break;
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 15:10:32 +01:00
|
|
|
} else {
|
2022-10-16 23:38:11 +02:00
|
|
|
const keepNodesCurrentZ = reimport && n.z && (RED.workspaces.contains(n.z) || RED.nodes.subflow(n.z))
|
2022-06-28 17:22:24 +02:00
|
|
|
if (!keepNodesCurrentZ && n.z && !workspace_map[n.z] && !subflow_map[n.z]) {
|
2020-11-18 00:07:43 +01:00
|
|
|
n.z = activeWorkspace;
|
2020-11-14 15:10:32 +01:00
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 14:34:41 +01:00
|
|
|
if (!existingConfigNode || existingConfigNode._def.exclusive) { //} || !compareNodes(existingConfigNode,n,true) || existingConfigNode.z !== n.z) {
|
2018-09-14 11:54:24 +02:00
|
|
|
configNode = {
|
|
|
|
id:n.id,
|
|
|
|
z:n.z,
|
|
|
|
type:n.type,
|
|
|
|
info: n.info,
|
|
|
|
users:[],
|
|
|
|
_config:{}
|
|
|
|
};
|
2020-10-19 14:24:04 +02:00
|
|
|
if (!n.z) {
|
|
|
|
delete configNode.z;
|
|
|
|
}
|
2019-06-17 23:46:34 +02:00
|
|
|
if (n.hasOwnProperty('d')) {
|
|
|
|
configNode.d = n.d;
|
|
|
|
}
|
2016-09-30 15:15:04 +02:00
|
|
|
for (d in def.defaults) {
|
2015-09-25 18:43:28 +02:00
|
|
|
if (def.defaults.hasOwnProperty(d)) {
|
|
|
|
configNode[d] = n[d];
|
2016-10-09 23:02:24 +02:00
|
|
|
configNode._config[d] = JSON.stringify(n[d]);
|
2015-09-25 18:43:28 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-30 15:15:04 +02:00
|
|
|
if (def.hasOwnProperty('credentials') && n.hasOwnProperty('credentials')) {
|
|
|
|
configNode.credentials = {};
|
|
|
|
for (d in def.credentials) {
|
|
|
|
if (def.credentials.hasOwnProperty(d) && n.credentials.hasOwnProperty(d)) {
|
|
|
|
configNode.credentials[d] = n.credentials[d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
configNode.label = def.label;
|
|
|
|
configNode._def = def;
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2015-09-25 18:43:28 +02:00
|
|
|
configNode.id = getID();
|
|
|
|
}
|
|
|
|
node_map[n.id] = configNode;
|
|
|
|
new_nodes.push(configNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-19 22:41:26 +02:00
|
|
|
// Find regular flow nodes and subflow instances
|
2015-03-14 23:53:31 +01:00
|
|
|
for (i=0;i<newNodes.length;i++) {
|
|
|
|
n = newNodes[i];
|
|
|
|
// TODO: remove workspace in next release+1
|
|
|
|
if (n.type !== "workspace" && n.type !== "tab" && n.type !== "subflow") {
|
|
|
|
def = registry.getNodeType(n.type);
|
|
|
|
if (!def || def.category != "config") {
|
2017-02-06 14:23:42 +01:00
|
|
|
var node = {
|
2018-11-13 14:29:48 +01:00
|
|
|
x:parseFloat(n.x || 0),
|
|
|
|
y:parseFloat(n.y || 0),
|
2017-02-06 14:23:42 +01:00
|
|
|
z:n.z,
|
|
|
|
type:0,
|
2018-08-06 14:39:37 +02:00
|
|
|
info: n.info,
|
2017-02-06 14:23:42 +01:00
|
|
|
changed:false,
|
|
|
|
_config:{}
|
2020-03-09 12:14:18 +01:00
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
if (n.type !== "group" && n.type !== 'junction') {
|
2020-03-09 12:14:18 +01:00
|
|
|
node.wires = n.wires||[];
|
|
|
|
node.inputLabels = n.inputLabels;
|
|
|
|
node.outputLabels = n.outputLabels;
|
|
|
|
node.icon = n.icon;
|
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
if (n.type === 'junction') {
|
|
|
|
node.wires = n.wires||[];
|
|
|
|
}
|
2018-10-08 17:25:11 +02:00
|
|
|
if (n.hasOwnProperty('l')) {
|
|
|
|
node.l = n.l;
|
|
|
|
}
|
2019-06-14 23:12:47 +02:00
|
|
|
if (n.hasOwnProperty('d')) {
|
|
|
|
node.d = n.d;
|
|
|
|
}
|
2020-03-09 12:14:18 +01:00
|
|
|
if (n.hasOwnProperty('g')) {
|
|
|
|
node.g = n.g;
|
|
|
|
}
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2020-07-07 19:22:45 +02:00
|
|
|
if (subflow_denylist[n.z]) {
|
2016-09-24 23:20:28 +02:00
|
|
|
continue;
|
|
|
|
} else if (subflow_map[node.z]) {
|
2015-03-14 23:53:31 +01:00
|
|
|
node.z = subflow_map[node.z].id;
|
2013-10-25 22:34:00 +02:00
|
|
|
} else {
|
2015-03-14 23:53:31 +01:00
|
|
|
node.z = workspace_map[node.z];
|
|
|
|
if (!workspaces[node.z]) {
|
2016-09-23 23:02:12 +02:00
|
|
|
if (createMissingWorkspace) {
|
|
|
|
if (missingWorkspace === null) {
|
|
|
|
missingWorkspace = RED.workspaces.add(null,true);
|
|
|
|
new_workspaces.push(missingWorkspace);
|
|
|
|
}
|
|
|
|
node.z = missingWorkspace.id;
|
|
|
|
} else {
|
|
|
|
node.z = activeWorkspace;
|
|
|
|
}
|
2013-10-25 22:34:00 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
node.id = getID();
|
|
|
|
} else {
|
|
|
|
node.id = n.id;
|
2022-10-16 23:38:11 +02:00
|
|
|
const keepNodesCurrentZ = reimport && node.z && (RED.workspaces.contains(node.z) || RED.nodes.subflow(node.z))
|
2022-06-28 17:22:24 +02:00
|
|
|
if (!keepNodesCurrentZ && (node.z == null || (!workspace_map[node.z] && !subflow_map[node.z]))) {
|
2016-09-23 23:02:12 +02:00
|
|
|
if (createMissingWorkspace) {
|
|
|
|
if (missingWorkspace === null) {
|
|
|
|
missingWorkspace = RED.workspaces.add(null,true);
|
|
|
|
new_workspaces.push(missingWorkspace);
|
|
|
|
}
|
|
|
|
node.z = missingWorkspace.id;
|
|
|
|
} else {
|
|
|
|
node.z = activeWorkspace;
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
node.type = n.type;
|
|
|
|
node._def = def;
|
2020-03-09 12:14:18 +01:00
|
|
|
if (node.type === "group") {
|
|
|
|
node._def = RED.group.def;
|
|
|
|
for (d in node._def.defaults) {
|
|
|
|
if (node._def.defaults.hasOwnProperty(d) && d !== 'inputs' && d !== 'outputs') {
|
|
|
|
node[d] = n[d];
|
|
|
|
node._config[d] = JSON.stringify(n[d]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node._config.x = node.x;
|
|
|
|
node._config.y = node.y;
|
|
|
|
} else if (n.type.substring(0,7) === "subflow") {
|
2015-03-14 23:53:31 +01:00
|
|
|
var parentId = n.type.split(":")[1];
|
2020-07-07 19:22:45 +02:00
|
|
|
var subflow = subflow_denylist[parentId]||subflow_map[parentId]||getSubflow(parentId);
|
2020-09-16 12:42:22 +02:00
|
|
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
2015-03-14 23:53:31 +01:00
|
|
|
parentId = subflow.id;
|
|
|
|
node.type = "subflow:"+parentId;
|
|
|
|
node._def = registry.getNodeType(node.type);
|
|
|
|
delete node.i;
|
|
|
|
}
|
|
|
|
node.name = n.name;
|
|
|
|
node.outputs = subflow.out.length;
|
|
|
|
node.inputs = subflow.in.length;
|
2019-01-26 15:15:20 +01:00
|
|
|
node.env = n.env;
|
2022-02-28 13:53:11 +01:00
|
|
|
} else if (n.type === 'junction') {
|
|
|
|
node._def = {defaults:{}}
|
|
|
|
node._config.x = node.x
|
|
|
|
node._config.y = node.y
|
|
|
|
node.inputs = 1
|
|
|
|
node.outputs = 1
|
|
|
|
node.w = 0;
|
|
|
|
node.h = 0;
|
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
} else {
|
|
|
|
if (!node._def) {
|
|
|
|
if (node.x && node.y) {
|
|
|
|
node._def = {
|
|
|
|
color:"#fee",
|
|
|
|
defaults: {},
|
|
|
|
label: "unknown: "+n.type,
|
2019-05-15 14:54:29 +02:00
|
|
|
labelStyle: "red-ui-flow-node-label-italic",
|
2020-04-06 16:39:48 +02:00
|
|
|
outputs: n.outputs|| (n.wires && n.wires.length) || 0,
|
2015-05-26 15:34:15 +02:00
|
|
|
set: registry.getNodeSet("node-red/unknown")
|
2014-10-30 22:41:42 +01:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
} else {
|
|
|
|
node._def = {
|
2015-05-26 15:34:15 +02:00
|
|
|
category:"config",
|
|
|
|
set: registry.getNodeSet("node-red/unknown")
|
2015-03-14 23:53:31 +01:00
|
|
|
};
|
|
|
|
node.users = [];
|
2018-04-16 12:20:03 +02:00
|
|
|
// This is a config node, so delete the default
|
|
|
|
// non-config node properties
|
|
|
|
delete node.x;
|
|
|
|
delete node.y;
|
|
|
|
delete node.wires;
|
|
|
|
delete node.inputLabels;
|
|
|
|
delete node.outputLabels;
|
2020-10-19 13:53:03 +02:00
|
|
|
if (!n.z) {
|
|
|
|
delete node.z;
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
var orig = {};
|
|
|
|
for (var p in n) {
|
|
|
|
if (n.hasOwnProperty(p) && p!="x" && p!="y" && p!="z" && p!="id" && p!="wires") {
|
|
|
|
orig[p] = n[p];
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
node._orig = orig;
|
|
|
|
node.name = n.type;
|
|
|
|
node.type = "unknown";
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-10-30 22:41:42 +01:00
|
|
|
if (node._def.category != "config") {
|
2018-05-24 21:25:26 +02:00
|
|
|
if (n.hasOwnProperty('inputs')) {
|
|
|
|
node.inputs = n.inputs;
|
|
|
|
node._config.inputs = JSON.stringify(n.inputs);
|
|
|
|
} else {
|
|
|
|
node.inputs = node._def.inputs;
|
|
|
|
}
|
|
|
|
if (n.hasOwnProperty('outputs')) {
|
|
|
|
node.outputs = n.outputs;
|
|
|
|
node._config.outputs = JSON.stringify(n.outputs);
|
|
|
|
} else {
|
|
|
|
node.outputs = node._def.outputs;
|
|
|
|
}
|
2018-04-16 14:23:36 +02:00
|
|
|
if (node.hasOwnProperty('wires') && node.wires.length > node.outputs) {
|
2018-05-24 21:25:26 +02:00
|
|
|
if (!node._def.defaults.hasOwnProperty("outputs") || !isNaN(parseInt(n.outputs))) {
|
|
|
|
// If 'wires' is longer than outputs, clip wires
|
|
|
|
console.log("Warning: node.wires longer than node.outputs - trimming wires:",node.id," wires:",node.wires.length," outputs:",node.outputs);
|
|
|
|
node.wires = node.wires.slice(0,node.outputs);
|
|
|
|
} else {
|
|
|
|
// The node declares outputs in its defaults, but has not got a valid value
|
|
|
|
// Defer to the length of the wires array
|
|
|
|
node.outputs = node.wires.length;
|
|
|
|
}
|
2018-04-16 14:23:36 +02:00
|
|
|
}
|
2016-09-30 15:15:04 +02:00
|
|
|
for (d in node._def.defaults) {
|
2018-05-24 21:25:26 +02:00
|
|
|
if (node._def.defaults.hasOwnProperty(d) && d !== 'inputs' && d !== 'outputs') {
|
2016-09-30 15:15:04 +02:00
|
|
|
node[d] = n[d];
|
2016-10-09 23:02:24 +02:00
|
|
|
node._config[d] = JSON.stringify(n[d]);
|
2016-09-30 15:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-09 23:02:24 +02:00
|
|
|
node._config.x = node.x;
|
|
|
|
node._config.y = node.y;
|
2016-09-30 15:15:04 +02:00
|
|
|
if (node._def.hasOwnProperty('credentials') && n.hasOwnProperty('credentials')) {
|
|
|
|
node.credentials = {};
|
|
|
|
for (d in node._def.credentials) {
|
|
|
|
if (node._def.credentials.hasOwnProperty(d) && n.credentials.hasOwnProperty(d)) {
|
|
|
|
node.credentials[d] = n.credentials[d];
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 22:41:42 +01:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
node_map[n.id] = node;
|
2018-04-16 12:20:03 +02:00
|
|
|
// If an 'unknown' config node, it will not have been caught by the
|
|
|
|
// proper config node handling, so needs adding to new_nodes here
|
2022-02-28 13:53:11 +01:00
|
|
|
if (node.type === 'junction') {
|
|
|
|
new_junctions.push(node)
|
|
|
|
} else if (node.type === "unknown" || node._def.category !== "config") {
|
2015-03-14 23:53:31 +01:00
|
|
|
new_nodes.push(node);
|
2020-03-09 12:14:18 +01:00
|
|
|
} else if (node.type === "group") {
|
|
|
|
new_groups.push(node);
|
2020-08-04 21:59:51 +02:00
|
|
|
new_group_set.add(node.id);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2016-05-17 10:39:18 +02:00
|
|
|
|
2016-04-19 22:41:26 +02:00
|
|
|
// Remap all wires and config node references
|
2022-02-28 13:53:11 +01:00
|
|
|
for (i=0;i<new_nodes.length+new_junctions.length;i++) {
|
|
|
|
if (i<new_nodes.length) {
|
|
|
|
n = new_nodes[i];
|
|
|
|
} else {
|
|
|
|
n = new_junctions[i - new_nodes.length]
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
if (n.wires) {
|
|
|
|
for (var w1=0;w1<n.wires.length;w1++) {
|
2022-03-09 11:39:47 +01:00
|
|
|
var wires = (Array.isArray(n.wires[w1]))?n.wires[w1]:[n.wires[w1]];
|
2015-09-25 18:43:28 +02:00
|
|
|
for (var w2=0;w2<wires.length;w2++) {
|
2017-01-13 15:16:12 +01:00
|
|
|
if (node_map.hasOwnProperty(wires[w2])) {
|
2017-01-19 14:24:21 +01:00
|
|
|
if (n.z === node_map[wires[w2]].z) {
|
|
|
|
var link = {source:n,sourcePort:w1,target:node_map[wires[w2]]};
|
|
|
|
addLink(link);
|
|
|
|
new_links.push(link);
|
|
|
|
} else {
|
|
|
|
console.log("Warning: dropping link that crosses tabs:",n.id,"->",node_map[wires[w2]].id);
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 18:43:28 +02:00
|
|
|
delete n.wires;
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2020-03-09 12:14:18 +01:00
|
|
|
if (n.g && node_map[n.g]) {
|
|
|
|
n.g = node_map[n.g].id;
|
|
|
|
} else {
|
|
|
|
delete n.g
|
|
|
|
}
|
2016-04-19 22:41:26 +02:00
|
|
|
for (var d3 in n._def.defaults) {
|
|
|
|
if (n._def.defaults.hasOwnProperty(d3)) {
|
2021-01-08 15:19:12 +01:00
|
|
|
if (n._def.defaults[d3].type) {
|
|
|
|
var nodeList = n[d3];
|
|
|
|
if (!Array.isArray(nodeList)) {
|
|
|
|
nodeList = [nodeList];
|
2016-04-19 22:41:26 +02:00
|
|
|
}
|
2021-01-08 15:19:12 +01:00
|
|
|
nodeList = nodeList.map(function(id) {
|
|
|
|
var node = node_map[id];
|
|
|
|
if (node) {
|
|
|
|
if (node._def.category === 'config') {
|
|
|
|
if (node.users.indexOf(n) === -1) {
|
|
|
|
node.users.push(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node.id;
|
2016-05-17 10:39:18 +02:00
|
|
|
}
|
2021-01-08 15:19:12 +01:00
|
|
|
return id;
|
|
|
|
})
|
|
|
|
n[d3] = Array.isArray(n[d3])?nodeList:nodeList[0];
|
2016-04-19 22:41:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 00:51:08 +02:00
|
|
|
// If importing into a subflow, ensure an outbound-link doesn't
|
|
|
|
// get added
|
|
|
|
if (activeSubflow && /^link /.test(n.type) && n.links) {
|
|
|
|
n.links = n.links.filter(function(id) {
|
|
|
|
var otherNode = RED.nodes.node(id);
|
|
|
|
return (otherNode && otherNode.z === activeWorkspace)
|
|
|
|
});
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
for (i=0;i<new_subflows.length;i++) {
|
|
|
|
n = new_subflows[i];
|
|
|
|
n.in.forEach(function(input) {
|
|
|
|
input.wires.forEach(function(wire) {
|
|
|
|
var link = {source:input, sourcePort:0, target:node_map[wire.id]};
|
|
|
|
addLink(link);
|
|
|
|
new_links.push(link);
|
2014-02-25 00:35:11 +01:00
|
|
|
});
|
2015-03-14 23:53:31 +01:00
|
|
|
delete input.wires;
|
|
|
|
});
|
|
|
|
n.out.forEach(function(output) {
|
|
|
|
output.wires.forEach(function(wire) {
|
|
|
|
var link;
|
2015-03-19 23:56:59 +01:00
|
|
|
if (subflow_map[wire.id] && subflow_map[wire.id].id == n.id) {
|
2015-03-14 23:53:31 +01:00
|
|
|
link = {source:n.in[wire.port], sourcePort:wire.port,target:output};
|
|
|
|
} else {
|
2015-03-19 23:56:59 +01:00
|
|
|
link = {source:node_map[wire.id]||subflow_map[wire.id], sourcePort:wire.port,target:output};
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
addLink(link);
|
|
|
|
new_links.push(link);
|
2014-02-25 00:35:11 +01:00
|
|
|
});
|
2015-03-14 23:53:31 +01:00
|
|
|
delete output.wires;
|
|
|
|
});
|
2019-02-02 00:44:50 +01:00
|
|
|
if (n.status) {
|
|
|
|
n.status.wires.forEach(function(wire) {
|
|
|
|
var link;
|
|
|
|
if (subflow_map[wire.id] && subflow_map[wire.id].id == n.id) {
|
|
|
|
link = {source:n.in[wire.port], sourcePort:wire.port,target:n.status};
|
|
|
|
} else {
|
|
|
|
link = {source:node_map[wire.id]||subflow_map[wire.id], sourcePort:wire.port,target:n.status};
|
|
|
|
}
|
|
|
|
addLink(link);
|
|
|
|
new_links.push(link);
|
|
|
|
});
|
|
|
|
delete n.status.wires;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2020-07-06 16:59:50 +02:00
|
|
|
// Order the groups to ensure they are outer-most to inner-most
|
|
|
|
var groupDepthMap = {};
|
2020-03-09 12:14:18 +01:00
|
|
|
for (i=0;i<new_groups.length;i++) {
|
|
|
|
n = new_groups[i];
|
2020-08-04 21:59:51 +02:00
|
|
|
|
|
|
|
if (n.g && !new_group_set.has(n.g)) {
|
2020-03-09 12:14:18 +01:00
|
|
|
delete n.g;
|
|
|
|
}
|
2020-07-06 16:59:50 +02:00
|
|
|
if (!n.g) {
|
|
|
|
groupDepthMap[n.id] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var changedDepth;
|
|
|
|
do {
|
|
|
|
changedDepth = false;
|
|
|
|
for (i=0;i<new_groups.length;i++) {
|
|
|
|
n = new_groups[i];
|
|
|
|
if (n.g) {
|
|
|
|
if (groupDepthMap[n.id] !== groupDepthMap[n.g] + 1) {
|
|
|
|
groupDepthMap[n.id] = groupDepthMap[n.g] + 1;
|
|
|
|
changedDepth = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(changedDepth);
|
|
|
|
|
|
|
|
new_groups.sort(function(A,B) {
|
|
|
|
return groupDepthMap[A.id] - groupDepthMap[B.id];
|
|
|
|
});
|
|
|
|
for (i=0;i<new_groups.length;i++) {
|
2022-11-01 11:48:48 +01:00
|
|
|
new_groups[i] = addGroup(new_groups[i]);
|
|
|
|
node_map[new_groups[i].id] = new_groups[i]
|
2020-05-19 12:28:38 +02:00
|
|
|
}
|
2020-07-06 16:59:50 +02:00
|
|
|
|
2022-02-28 13:53:11 +01:00
|
|
|
for (i=0;i<new_junctions.length;i++) {
|
2022-11-01 11:48:48 +01:00
|
|
|
new_junctions[i] = addJunction(new_junctions[i]);
|
|
|
|
node_map[new_junctions[i].id] = new_junctions[i]
|
2022-02-28 13:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-19 12:28:38 +02:00
|
|
|
// Now the nodes have been fully updated, add them.
|
|
|
|
for (i=0;i<new_nodes.length;i++) {
|
2022-11-01 11:48:48 +01:00
|
|
|
new_nodes[i] = addNode(new_nodes[i])
|
|
|
|
node_map[new_nodes[i].id] = new_nodes[i]
|
2020-06-04 18:06:29 +02:00
|
|
|
}
|
2022-11-01 11:48:48 +01:00
|
|
|
|
2020-06-04 18:06:29 +02:00
|
|
|
// Finally validate them all.
|
|
|
|
// This has to be done after everything is added so that any checks for
|
|
|
|
// dependent config nodes will pass
|
|
|
|
for (i=0;i<new_nodes.length;i++) {
|
|
|
|
var node = new_nodes[i];
|
2020-05-19 12:28:38 +02:00
|
|
|
RED.editor.validateNode(node);
|
2020-03-09 12:14:18 +01:00
|
|
|
}
|
2022-11-01 11:48:48 +01:00
|
|
|
const lookupNode = (id) => {
|
|
|
|
const mappedNode = node_map[id]
|
|
|
|
if (!mappedNode) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if (mappedNode.__isProxy__) {
|
|
|
|
return mappedNode
|
|
|
|
} else {
|
|
|
|
return node_map[mappedNode.id]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update groups to reference proxy node objects
|
|
|
|
for (i=0;i<new_groups.length;i++) {
|
|
|
|
n = new_groups[i];
|
|
|
|
// bypass the proxy in case the flow is locked
|
|
|
|
n.__node__.nodes = n.nodes.map(lookupNode)
|
|
|
|
// Just in case the group references a node that doesn't exist for some reason
|
|
|
|
n.__node__.nodes = n.nodes.filter(function(v) {
|
|
|
|
if (v) {
|
|
|
|
// Repair any nodes that have forgotten they are in this group
|
|
|
|
if (v.g !== n.id) {
|
|
|
|
v.g = n.id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !!v
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update links to use proxy node objects
|
|
|
|
for (i=0;i<new_links.length;i++) {
|
|
|
|
new_links[i].source = lookupNode(new_links[i].source.id) || new_links[i].source
|
|
|
|
new_links[i].target = lookupNode(new_links[i].target.id) || new_links[i].target
|
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2015-09-23 23:49:48 +02:00
|
|
|
RED.workspaces.refresh();
|
2020-09-03 19:31:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (recoveryWorkspace) {
|
|
|
|
var notification = RED.notify(RED._("clipboard.recoveredNodesNotification",{flowName:RED._("clipboard.recoveredNodes")}),{
|
|
|
|
type:"warning",
|
|
|
|
fixed:true,
|
|
|
|
buttons: [
|
|
|
|
{text: RED._("common.label.close"), click: function() { notification.close() }}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-16 12:42:22 +02:00
|
|
|
return {
|
|
|
|
nodes:new_nodes,
|
|
|
|
links:new_links,
|
|
|
|
groups:new_groups,
|
2022-02-28 13:53:11 +01:00
|
|
|
junctions: new_junctions,
|
2020-09-16 12:42:22 +02:00
|
|
|
workspaces:new_workspaces,
|
|
|
|
subflows:new_subflows,
|
|
|
|
missingWorkspace: missingWorkspace,
|
|
|
|
removedNodes: removedNodes
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2015-03-19 23:56:59 +01:00
|
|
|
// TODO: supports filter.z|type
|
2015-03-16 00:31:38 +01:00
|
|
|
function filterNodes(filter) {
|
2021-08-26 22:16:40 +02:00
|
|
|
return allNodes.filterNodes(filter);
|
2015-03-16 00:31:38 +01:00
|
|
|
}
|
2021-08-26 22:16:40 +02:00
|
|
|
|
2015-03-16 00:31:38 +01:00
|
|
|
function filterLinks(filter) {
|
|
|
|
var result = [];
|
2021-02-16 21:46:41 +01:00
|
|
|
var candidateLinks = [];
|
|
|
|
var hasCandidates = false;
|
|
|
|
var filterSZ = filter.source && filter.source.z;
|
|
|
|
var filterTZ = filter.target && filter.target.z;
|
|
|
|
var filterZ;
|
|
|
|
if (filterSZ || filterTZ) {
|
|
|
|
if (filterSZ === filterTZ) {
|
|
|
|
filterZ = filterSZ;
|
|
|
|
} else {
|
|
|
|
filterZ = (filterSZ === undefined)?filterTZ:filterSZ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filterZ) {
|
|
|
|
candidateLinks = linkTabMap[filterZ] || [];
|
|
|
|
hasCandidates = true;
|
|
|
|
} else if (filter.source && filter.source.hasOwnProperty("id")) {
|
|
|
|
if (nodeLinks[filter.source.id]) {
|
|
|
|
hasCandidates = true;
|
|
|
|
candidateLinks = candidateLinks.concat(nodeLinks[filter.source.id].out)
|
|
|
|
}
|
|
|
|
} else if (filter.target && filter.target.hasOwnProperty("id")) {
|
|
|
|
if (nodeLinks[filter.target.id]) {
|
|
|
|
hasCandidates = true;
|
|
|
|
candidateLinks = candidateLinks.concat(nodeLinks[filter.target.id].in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasCandidates) {
|
|
|
|
candidateLinks = links;
|
|
|
|
}
|
|
|
|
for (var n=0;n<candidateLinks.length;n++) {
|
|
|
|
var link = candidateLinks[n];
|
2015-03-16 00:31:38 +01:00
|
|
|
if (filter.source) {
|
2015-04-22 23:53:21 +02:00
|
|
|
if (filter.source.hasOwnProperty("id") && link.source.id !== filter.source.id) {
|
2015-03-16 00:31:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-22 23:53:21 +02:00
|
|
|
if (filter.source.hasOwnProperty("z") && link.source.z !== filter.source.z) {
|
2015-03-16 00:31:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filter.target) {
|
2015-04-22 23:53:21 +02:00
|
|
|
if (filter.target.hasOwnProperty("id") && link.target.id !== filter.target.id) {
|
2015-03-16 00:31:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-22 23:53:21 +02:00
|
|
|
if (filter.target.hasOwnProperty("z") && link.target.z !== filter.target.z) {
|
2015-03-16 00:31:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 23:53:21 +02:00
|
|
|
if (filter.hasOwnProperty("sourcePort") && link.sourcePort !== filter.sourcePort) {
|
2015-03-16 00:41:16 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-03-16 00:31:38 +01:00
|
|
|
result.push(link);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2016-06-28 15:57:48 +02:00
|
|
|
// Update any config nodes referenced by the provided node to ensure their 'users' list is correct
|
|
|
|
function updateConfigNodeUsers(n) {
|
|
|
|
for (var d in n._def.defaults) {
|
|
|
|
if (n._def.defaults.hasOwnProperty(d)) {
|
|
|
|
var property = n._def.defaults[d];
|
|
|
|
if (property.type) {
|
|
|
|
var type = registry.getNodeType(property.type);
|
|
|
|
if (type && type.category == "config") {
|
|
|
|
var configNode = configNodes[n[d]];
|
|
|
|
if (configNode) {
|
|
|
|
if (configNode.users.indexOf(n) === -1) {
|
|
|
|
configNode.users.push(n);
|
2021-07-01 21:52:13 +02:00
|
|
|
RED.events.emit('nodes:change',configNode)
|
2016-06-28 15:57:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-09 23:02:24 +02:00
|
|
|
function flowVersion(version) {
|
|
|
|
if (version !== undefined) {
|
|
|
|
loadedFlowVersion = version;
|
|
|
|
} else {
|
|
|
|
return loadedFlowVersion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
function clear() {
|
|
|
|
links = [];
|
2021-02-16 21:46:41 +01:00
|
|
|
linkTabMap = {};
|
|
|
|
nodeLinks = {};
|
2017-01-01 01:18:39 +01:00
|
|
|
configNodes = {};
|
|
|
|
workspacesOrder = [];
|
2020-03-13 12:27:13 +01:00
|
|
|
groups = {};
|
|
|
|
groupsByZ = {};
|
2022-05-05 17:56:28 +02:00
|
|
|
junctions = {};
|
|
|
|
junctionsByZ = {};
|
2020-03-13 12:27:13 +01:00
|
|
|
|
2022-12-03 22:44:33 +01:00
|
|
|
var workspaceIds = Object.keys(workspaces);
|
|
|
|
// Ensure all workspaces are unlocked so we don't get any edit-protection
|
|
|
|
// preventing removal
|
|
|
|
workspaceIds.forEach(function(id) {
|
|
|
|
workspaces[id].locked = false
|
|
|
|
});
|
|
|
|
|
2017-01-01 01:18:39 +01:00
|
|
|
var subflowIds = Object.keys(subflows);
|
|
|
|
subflowIds.forEach(function(id) {
|
|
|
|
RED.subflow.removeSubflow(id)
|
|
|
|
});
|
|
|
|
workspaceIds.forEach(function(id) {
|
|
|
|
RED.workspaces.remove(workspaces[id]);
|
|
|
|
});
|
|
|
|
defaultWorkspace = null;
|
2018-01-22 14:46:11 +01:00
|
|
|
initialLoad = null;
|
2020-10-12 12:20:44 +02:00
|
|
|
workspaces = {};
|
|
|
|
|
2021-10-14 12:07:49 +02:00
|
|
|
allNodes.clear();
|
|
|
|
|
2017-09-20 11:30:07 +02:00
|
|
|
RED.nodes.dirty(false);
|
2020-06-05 17:56:12 +02:00
|
|
|
RED.view.redraw(true, true);
|
2017-01-01 01:18:39 +01:00
|
|
|
RED.palette.refresh();
|
|
|
|
RED.workspaces.refresh();
|
|
|
|
RED.sidebar.config.refresh();
|
2017-09-20 11:30:07 +02:00
|
|
|
RED.sidebar.info.refresh();
|
2017-01-01 01:18:39 +01:00
|
|
|
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("workspace:clear");
|
2017-01-01 01:18:39 +01:00
|
|
|
}
|
|
|
|
|
2020-03-03 20:04:32 +01:00
|
|
|
function addGroup(group) {
|
2022-11-01 11:48:48 +01:00
|
|
|
if (!group.__isProxy__) {
|
|
|
|
group = new Proxy(group, nodeProxyHandler)
|
|
|
|
}
|
2020-03-03 20:04:32 +01:00
|
|
|
groupsByZ[group.z] = groupsByZ[group.z] || [];
|
|
|
|
groupsByZ[group.z].push(group);
|
|
|
|
groups[group.id] = group;
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("groups:add",group);
|
2022-11-01 11:48:48 +01:00
|
|
|
return group
|
2020-03-03 20:04:32 +01:00
|
|
|
}
|
2020-03-05 11:43:28 +01:00
|
|
|
function removeGroup(group) {
|
|
|
|
var i = groupsByZ[group.z].indexOf(group);
|
|
|
|
groupsByZ[group.z].splice(i,1);
|
2020-06-03 15:23:26 +02:00
|
|
|
if (groupsByZ[group.z].length === 0) {
|
|
|
|
delete groupsByZ[group.z];
|
|
|
|
}
|
2020-03-05 23:49:31 +01:00
|
|
|
if (group.g) {
|
|
|
|
if (groups[group.g]) {
|
|
|
|
var index = groups[group.g].nodes.indexOf(group);
|
|
|
|
groups[group.g].nodes.splice(index,1);
|
|
|
|
}
|
|
|
|
}
|
2020-03-24 15:05:09 +01:00
|
|
|
RED.group.markDirty(group);
|
2020-03-05 23:49:31 +01:00
|
|
|
|
2020-03-05 11:43:28 +01:00
|
|
|
delete groups[group.id];
|
2020-04-20 22:30:03 +02:00
|
|
|
RED.events.emit("groups:remove",group);
|
2020-03-05 11:43:28 +01:00
|
|
|
}
|
2020-03-03 20:04:32 +01:00
|
|
|
|
2022-02-28 13:53:11 +01:00
|
|
|
function addJunction(junction) {
|
2022-11-01 11:48:48 +01:00
|
|
|
if (!junction.__isProxy__) {
|
|
|
|
junction = new Proxy(junction, nodeProxyHandler)
|
|
|
|
}
|
2022-02-28 13:53:11 +01:00
|
|
|
junctionsByZ[junction.z] = junctionsByZ[junction.z] || []
|
|
|
|
junctionsByZ[junction.z].push(junction)
|
|
|
|
junctions[junction.id] = junction;
|
|
|
|
if (!nodeLinks[junction.id]) {
|
|
|
|
nodeLinks[junction.id] = {in:[],out:[]};
|
|
|
|
}
|
|
|
|
RED.events.emit("junctions:add", junction)
|
2022-11-01 11:48:48 +01:00
|
|
|
return junction
|
2022-02-28 13:53:11 +01:00
|
|
|
}
|
|
|
|
function removeJunction(junction) {
|
|
|
|
var i = junctionsByZ[junction.z].indexOf(junction)
|
|
|
|
junctionsByZ[junction.z].splice(i, 1)
|
|
|
|
if (junctionsByZ[junction.z].length === 0) {
|
|
|
|
delete junctionsByZ[junction.z]
|
|
|
|
}
|
|
|
|
delete junctions[junction.id]
|
|
|
|
delete nodeLinks[junction.id];
|
|
|
|
RED.events.emit("junctions:remove", junction)
|
|
|
|
|
|
|
|
var removedLinks = links.filter(function(l) { return (l.source === junction) || (l.target === junction); });
|
|
|
|
removedLinks.forEach(removeLink);
|
|
|
|
return { links: removedLinks }
|
|
|
|
}
|
|
|
|
|
2021-01-07 16:34:27 +01:00
|
|
|
function getNodeHelp(type) {
|
|
|
|
var helpContent = "";
|
|
|
|
var helpElement = $("script[data-help-name='"+type+"']");
|
|
|
|
if (helpElement) {
|
|
|
|
helpContent = helpElement.html();
|
|
|
|
var helpType = helpElement.attr("type");
|
|
|
|
if (helpType === "text/markdown") {
|
|
|
|
helpContent = RED.utils.renderMarkdown(helpContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return helpContent;
|
|
|
|
}
|
2020-03-03 20:04:32 +01:00
|
|
|
|
2022-01-11 15:11:55 +01:00
|
|
|
function getNodeIslands(nodes) {
|
|
|
|
var selectedNodes = new Set(nodes);
|
|
|
|
// Maps node => island index
|
|
|
|
var nodeToIslandIndex = new Map();
|
|
|
|
// Maps island index => [nodes in island]
|
|
|
|
var islandIndexToNodes = new Map();
|
|
|
|
var internalLinks = new Set();
|
|
|
|
nodes.forEach((node, index) => {
|
|
|
|
nodeToIslandIndex.set(node,index);
|
|
|
|
islandIndexToNodes.set(index, [node]);
|
|
|
|
var inboundLinks = RED.nodes.getNodeLinks(node, PORT_TYPE_INPUT);
|
|
|
|
var outboundLinks = RED.nodes.getNodeLinks(node, PORT_TYPE_OUTPUT);
|
|
|
|
inboundLinks.forEach(l => {
|
|
|
|
if (selectedNodes.has(l.source)) {
|
|
|
|
internalLinks.add(l)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
outboundLinks.forEach(l => {
|
|
|
|
if (selectedNodes.has(l.target)) {
|
|
|
|
internalLinks.add(l)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
internalLinks.forEach(l => {
|
|
|
|
let source = l.source;
|
|
|
|
let target = l.target;
|
|
|
|
if (nodeToIslandIndex.get(source) !== nodeToIslandIndex.get(target)) {
|
|
|
|
let sourceIsland = nodeToIslandIndex.get(source);
|
|
|
|
let islandToMove = nodeToIslandIndex.get(target);
|
|
|
|
let nodesToMove = islandIndexToNodes.get(islandToMove);
|
|
|
|
nodesToMove.forEach(n => {
|
|
|
|
nodeToIslandIndex.set(n,sourceIsland);
|
|
|
|
islandIndexToNodes.get(sourceIsland).push(n);
|
|
|
|
})
|
|
|
|
islandIndexToNodes.delete(islandToMove);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const result = [];
|
|
|
|
islandIndexToNodes.forEach((nodes,index) => {
|
|
|
|
result.push(nodes);
|
|
|
|
})
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function detachNodes(nodes) {
|
|
|
|
let allSelectedNodes = [];
|
|
|
|
nodes.forEach(node => {
|
|
|
|
if (node.type === 'group') {
|
|
|
|
let groupNodes = RED.group.getNodes(node,true,true);
|
|
|
|
allSelectedNodes = allSelectedNodes.concat(groupNodes);
|
|
|
|
} else {
|
|
|
|
allSelectedNodes.push(node);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (allSelectedNodes.length > 0 ) {
|
|
|
|
const nodeIslands = RED.nodes.getNodeIslands(allSelectedNodes);
|
|
|
|
let removedLinks = [];
|
|
|
|
let newLinks = [];
|
|
|
|
let createdLinkIds = new Set();
|
|
|
|
|
|
|
|
nodeIslands.forEach(nodes => {
|
|
|
|
let selectedNodes = new Set(nodes);
|
|
|
|
let allInboundLinks = [];
|
|
|
|
let allOutboundLinks = [];
|
|
|
|
// Identify links that enter or exit this island of nodes
|
|
|
|
nodes.forEach(node => {
|
|
|
|
var inboundLinks = RED.nodes.getNodeLinks(node, PORT_TYPE_INPUT);
|
|
|
|
var outboundLinks = RED.nodes.getNodeLinks(node, PORT_TYPE_OUTPUT);
|
|
|
|
inboundLinks.forEach(l => {
|
|
|
|
if (!selectedNodes.has(l.source)) {
|
|
|
|
allInboundLinks.push(l)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
outboundLinks.forEach(l => {
|
|
|
|
if (!selectedNodes.has(l.target)) {
|
|
|
|
allOutboundLinks.push(l)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Identify the links to restore
|
|
|
|
allInboundLinks.forEach(inLink => {
|
|
|
|
// For Each inbound link,
|
|
|
|
// - get source node.
|
|
|
|
// - trace through to all outbound links
|
|
|
|
let sourceNode = inLink.source;
|
|
|
|
let targetNodes = new Set();
|
|
|
|
let visited = new Set();
|
|
|
|
let stack = [inLink.target];
|
|
|
|
while (stack.length > 0) {
|
|
|
|
let node = stack.pop(stack);
|
|
|
|
visited.add(node)
|
|
|
|
let links = RED.nodes.getNodeLinks(node, PORT_TYPE_OUTPUT);
|
|
|
|
links.forEach(l => {
|
|
|
|
if (visited.has(l.target)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
visited.add(l.target);
|
|
|
|
if (selectedNodes.has(l.target)) {
|
|
|
|
// internal link
|
|
|
|
stack.push(l.target)
|
|
|
|
} else {
|
|
|
|
targetNodes.add(l.target)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
targetNodes.forEach(target => {
|
|
|
|
let linkId = `${sourceNode.id}[${inLink.sourcePort}] -> ${target.id}`
|
|
|
|
if (!createdLinkIds.has(linkId)) {
|
|
|
|
createdLinkIds.add(linkId);
|
|
|
|
let link = {
|
|
|
|
source: sourceNode,
|
|
|
|
sourcePort: inLink.sourcePort,
|
|
|
|
target: target
|
|
|
|
}
|
|
|
|
let existingLinks = RED.nodes.filterLinks(link)
|
|
|
|
if (existingLinks.length === 0) {
|
|
|
|
newLinks.push(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// 2. delete all those links
|
|
|
|
allInboundLinks.forEach(l => { RED.nodes.removeLink(l); removedLinks.push(l)})
|
|
|
|
allOutboundLinks.forEach(l => { RED.nodes.removeLink(l); removedLinks.push(l)})
|
|
|
|
})
|
|
|
|
|
|
|
|
newLinks.forEach(l => RED.nodes.addLink(l));
|
|
|
|
return {
|
|
|
|
newLinks,
|
|
|
|
removedLinks
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
return {
|
2017-07-08 18:29:41 +02:00
|
|
|
init: function() {
|
|
|
|
RED.events.on("registry:node-type-added",function(type) {
|
|
|
|
var def = registry.getNodeType(type);
|
|
|
|
var replaced = false;
|
2019-01-17 23:35:58 +01:00
|
|
|
var replaceNodes = {};
|
2017-07-08 18:29:41 +02:00
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type === "unknown" && n.name === type) {
|
2019-01-17 23:35:58 +01:00
|
|
|
replaceNodes[n.id] = n;
|
2017-07-08 18:29:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.nodes.eachConfig(function(n) {
|
|
|
|
if (n.type === "unknown" && n.name === type) {
|
2019-01-17 23:35:58 +01:00
|
|
|
replaceNodes[n.id] = n;
|
2017-07-08 18:29:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-26 01:51:41 +02:00
|
|
|
const nodeGroupMap = {}
|
2019-01-17 23:35:58 +01:00
|
|
|
var replaceNodeIds = Object.keys(replaceNodes);
|
|
|
|
if (replaceNodeIds.length > 0) {
|
2017-07-08 18:29:41 +02:00
|
|
|
var reimportList = [];
|
2019-01-17 23:35:58 +01:00
|
|
|
replaceNodeIds.forEach(function(id) {
|
|
|
|
var n = replaceNodes[id];
|
2017-07-08 18:29:41 +02:00
|
|
|
if (configNodes.hasOwnProperty(n.id)) {
|
|
|
|
delete configNodes[n.id];
|
|
|
|
} else {
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.removeNode(n);
|
2017-07-08 18:29:41 +02:00
|
|
|
}
|
2022-10-16 23:38:11 +02:00
|
|
|
if (n.g) {
|
|
|
|
// reimporting a node *without* including its group object
|
|
|
|
// will cause the g property to be cleared. Cache it
|
|
|
|
// here so we can restore it
|
|
|
|
nodeGroupMap[n.id] = n.g
|
|
|
|
}
|
2017-07-08 18:29:41 +02:00
|
|
|
reimportList.push(convertNode(n));
|
2020-07-10 21:00:18 +02:00
|
|
|
RED.events.emit('nodes:remove',n);
|
2017-07-08 18:29:41 +02:00
|
|
|
});
|
2019-01-17 23:35:58 +01:00
|
|
|
|
|
|
|
// Remove any links between nodes that are going to be reimported.
|
|
|
|
// This prevents a duplicate link from being added.
|
|
|
|
var removeLinks = [];
|
|
|
|
RED.nodes.eachLink(function(l) {
|
|
|
|
if (replaceNodes.hasOwnProperty(l.source.id) && replaceNodes.hasOwnProperty(l.target.id)) {
|
|
|
|
removeLinks.push(l);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
removeLinks.forEach(removeLink);
|
|
|
|
|
2020-03-31 16:58:51 +02:00
|
|
|
// Force the redraw to be synchronous so the view updates
|
|
|
|
// *now* and removes the unknown node
|
|
|
|
RED.view.redraw(true, true);
|
2022-06-28 17:22:24 +02:00
|
|
|
var result = importNodes(reimportList,{generateIds:false, reimport: true});
|
2017-07-08 18:29:41 +02:00
|
|
|
var newNodeMap = {};
|
2020-09-16 12:42:22 +02:00
|
|
|
result.nodes.forEach(function(n) {
|
2017-07-08 18:29:41 +02:00
|
|
|
newNodeMap[n.id] = n;
|
2022-10-16 23:38:11 +02:00
|
|
|
if (nodeGroupMap[n.id]) {
|
|
|
|
// This node is in a group - need to substitute the
|
|
|
|
// node reference inside the group
|
|
|
|
n.g = nodeGroupMap[n.id]
|
|
|
|
const group = RED.nodes.group(n.g)
|
|
|
|
if (group) {
|
|
|
|
var index = group.nodes.findIndex(gn => gn.id === n.id)
|
|
|
|
if (index > -1) {
|
|
|
|
group.nodes[index] = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:29:41 +02:00
|
|
|
});
|
|
|
|
RED.nodes.eachLink(function(l) {
|
|
|
|
if (newNodeMap.hasOwnProperty(l.source.id)) {
|
|
|
|
l.source = newNodeMap[l.source.id];
|
|
|
|
}
|
|
|
|
if (newNodeMap.hasOwnProperty(l.target.id)) {
|
|
|
|
l.target = newNodeMap[l.target.id];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.view.redraw(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2014-08-28 01:35:07 +02:00
|
|
|
registry:registry,
|
|
|
|
setNodeList: registry.setNodeList,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
getNodeSet: registry.getNodeSet,
|
|
|
|
addNodeSet: registry.addNodeSet,
|
|
|
|
removeNodeSet: registry.removeNodeSet,
|
|
|
|
enableNodeSet: registry.enableNodeSet,
|
|
|
|
disableNodeSet: registry.disableNodeSet,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2017-11-30 14:13:35 +01:00
|
|
|
setIconSets: registry.setIconSets,
|
|
|
|
getIconSets: registry.getIconSets,
|
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
registerType: registry.registerNodeType,
|
|
|
|
getType: registry.getNodeType,
|
2021-01-07 16:34:27 +01:00
|
|
|
getNodeHelp: getNodeHelp,
|
2013-09-05 16:02:48 +02:00
|
|
|
convertNode: convertNode,
|
|
|
|
add: addNode,
|
|
|
|
remove: removeNode,
|
2017-01-01 01:18:39 +01:00
|
|
|
clear: clear,
|
2022-01-11 15:11:55 +01:00
|
|
|
detachNodes: detachNodes,
|
2021-08-26 22:16:40 +02:00
|
|
|
moveNodesForwards: moveNodesForwards,
|
|
|
|
moveNodesBackwards: moveNodesBackwards,
|
|
|
|
moveNodesToFront: moveNodesToFront,
|
|
|
|
moveNodesToBack: moveNodesToBack,
|
|
|
|
getNodeOrder: getNodeOrder,
|
|
|
|
setNodeOrder: setNodeOrder,
|
|
|
|
|
2019-07-26 16:06:56 +02:00
|
|
|
moveNodeToTab: moveNodeToTab,
|
2019-09-24 22:04:33 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
addLink: addLink,
|
2013-09-05 16:02:48 +02:00
|
|
|
removeLink: removeLink,
|
2022-01-04 00:27:25 +01:00
|
|
|
getNodeLinks: function(id, portType) {
|
2022-01-11 01:16:24 +01:00
|
|
|
if (typeof id !== 'string') {
|
|
|
|
id = id.id;
|
|
|
|
}
|
2022-01-04 00:27:25 +01:00
|
|
|
if (nodeLinks[id]) {
|
|
|
|
if (portType === 1) {
|
|
|
|
// Return cloned arrays so they can be safely modified by caller
|
|
|
|
return [].concat(nodeLinks[id].in)
|
|
|
|
} else {
|
|
|
|
return [].concat(nodeLinks[id].out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
2013-10-25 22:34:00 +02:00
|
|
|
addWorkspace: addWorkspace,
|
2013-10-26 23:29:24 +02:00
|
|
|
removeWorkspace: removeWorkspace,
|
2022-11-01 11:35:57 +01:00
|
|
|
getWorkspaceOrder: function() { return [...workspacesOrder] },
|
2016-05-04 16:22:30 +02:00
|
|
|
setWorkspaceOrder: function(order) { workspacesOrder = order; },
|
2013-10-26 23:29:24 +02:00
|
|
|
workspace: getWorkspace,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
addSubflow: addSubflow,
|
|
|
|
removeSubflow: removeSubflow,
|
|
|
|
subflow: getSubflow,
|
|
|
|
subflowContains: subflowContains,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2020-03-03 20:04:32 +01:00
|
|
|
addGroup: addGroup,
|
2020-03-05 11:43:28 +01:00
|
|
|
removeGroup: removeGroup,
|
2020-03-03 20:04:32 +01:00
|
|
|
group: function(id) { return groups[id] },
|
2021-08-26 22:16:40 +02:00
|
|
|
groups: function(z) { return groupsByZ[z]?groupsByZ[z].slice():[] },
|
2020-03-03 20:04:32 +01:00
|
|
|
|
2022-02-28 13:53:11 +01:00
|
|
|
addJunction: addJunction,
|
|
|
|
removeJunction: removeJunction,
|
|
|
|
junction: function(id) { return junctions[id] },
|
|
|
|
junctions: function(z) { return junctionsByZ[z]?junctionsByZ[z].slice():[] },
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
eachNode: function(cb) {
|
2021-08-26 22:16:40 +02:00
|
|
|
allNodes.eachNode(cb);
|
2013-09-05 16:02:48 +02:00
|
|
|
},
|
|
|
|
eachLink: function(cb) {
|
2014-08-08 01:01:35 +02:00
|
|
|
for (var l=0;l<links.length;l++) {
|
2018-10-27 00:07:48 +02:00
|
|
|
if (cb(links[l]) === false) {
|
|
|
|
break;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
eachConfig: function(cb) {
|
|
|
|
for (var id in configNodes) {
|
2014-08-08 01:01:35 +02:00
|
|
|
if (configNodes.hasOwnProperty(id)) {
|
2018-10-27 00:07:48 +02:00
|
|
|
if (cb(configNodes[id]) === false) {
|
|
|
|
break;
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
},
|
2014-02-25 00:35:11 +01:00
|
|
|
eachSubflow: function(cb) {
|
|
|
|
for (var id in subflows) {
|
|
|
|
if (subflows.hasOwnProperty(id)) {
|
2018-10-27 00:07:48 +02:00
|
|
|
if (cb(subflows[id]) === false) {
|
|
|
|
break;
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-09-23 23:49:48 +02:00
|
|
|
eachWorkspace: function(cb) {
|
2016-05-04 16:22:30 +02:00
|
|
|
for (var i=0;i<workspacesOrder.length;i++) {
|
2018-10-27 00:07:48 +02:00
|
|
|
if (cb(workspaces[workspacesOrder[i]]) === false) {
|
|
|
|
break;
|
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
}
|
|
|
|
},
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
node: getNode,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2016-10-09 23:02:24 +02:00
|
|
|
version: flowVersion,
|
2016-12-06 23:37:21 +01:00
|
|
|
originalFlow: function(flow) {
|
|
|
|
if (flow === undefined) {
|
|
|
|
return initialLoad;
|
|
|
|
} else {
|
|
|
|
initialLoad = flow;
|
|
|
|
}
|
|
|
|
},
|
2016-10-09 23:02:24 +02:00
|
|
|
|
2015-03-16 00:31:38 +01:00
|
|
|
filterNodes: filterNodes,
|
|
|
|
filterLinks: filterLinks,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
import: importNodes,
|
2015-06-29 17:12:18 +02:00
|
|
|
|
2020-09-16 12:42:22 +02:00
|
|
|
identifyImportConflicts: identifyImportConflicts,
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
getAllFlowNodes: getAllFlowNodes,
|
2021-02-17 18:32:55 +01:00
|
|
|
getAllUpstreamNodes: getAllUpstreamNodes,
|
|
|
|
getAllDownstreamNodes: getAllDownstreamNodes,
|
2022-01-11 15:11:55 +01:00
|
|
|
getNodeIslands: getNodeIslands,
|
2013-09-05 16:02:48 +02:00
|
|
|
createExportableNodeSet: createExportableNodeSet,
|
|
|
|
createCompleteNodeSet: createCompleteNodeSet,
|
2016-06-28 15:57:48 +02:00
|
|
|
updateConfigNodeUsers: updateConfigNodeUsers,
|
2013-10-25 22:34:00 +02:00
|
|
|
id: getID,
|
2015-03-15 22:54:36 +01:00
|
|
|
dirty: function(d) {
|
|
|
|
if (d == null) {
|
|
|
|
return dirty;
|
|
|
|
} else {
|
|
|
|
setDirty(d);
|
|
|
|
}
|
2015-03-16 00:31:38 +01:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
};
|
2014-08-08 01:01:35 +02:00
|
|
|
})();
|