/** * Copyright 2013 IBM Corp. * * 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. **/ RED.nodes = (function() { var node_defs = {}; var nodes = []; var configNodes = {}; var links = []; var defaultWorkspace; var workspaces = {}; function registerType(nt,def) { node_defs[nt] = def; // TODO: too tightly coupled into palette UI RED.palette.add(nt,def); } function getID() { return (1+Math.random()*4294967295).toString(16); } function getType(type) { return node_defs[type]; } function addNode(n) { if (n._def.category == "config") { configNodes[n.id] = n; RED.sidebar.config.refresh(); } else { n.dirty = true; nodes.push(n); var updatedConfigNode = false; for (var d in n._def.defaults) { if (n._def.defaults.hasOwnProperty(d)) { var property = n._def.defaults[d]; if (property.type) { var type = getType(property.type) if (type && type.category == "config") { var configNode = configNodes[n[d]]; if (configNode) { updatedConfigNode = true; configNode.users.push(n); } } } } } if (updatedConfigNode) { RED.sidebar.config.refresh(); } } } function addLink(l) { links.push(l); } function addConfig(c) { configNodes[c.id] = c; } function getNode(id) { if (id in configNodes) { return configNodes[id]; } else { for (var n in nodes) { if (nodes[n].id == id) { return nodes[n]; } } } return null; } function removeNode(id) { var removedLinks = []; if (id in configNodes) { delete configNodes[id]; RED.sidebar.config.refresh(); } else { var node = getNode(id); if (node) { nodes.splice(nodes.indexOf(node),1); removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); }); removedLinks.map(function(l) {links.splice(links.indexOf(l), 1); }); } 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 = getType(property.type) if (type && type.category == "config") { var configNode = configNodes[node[d]]; if (configNode) { updatedConfigNode = true; var users = configNode.users; users.splice(users.indexOf(node),1); } } } } } if (updatedConfigNode) { RED.sidebar.config.refresh(); } } return removedLinks; } function removeLink(l) { var index = links.indexOf(l); if (index != -1) { links.splice(index,1); } } function refreshValidation() { for (var n=0;n 0) { var typeList = ""; var type = "type"+(unknownTypes.length > 1?"s":""); RED.notify("Imported unrecognised "+type+":"+typeList,"error",false,10000); //"DO NOT DEPLOY while in this state.
Either, add missing types to Node-RED, restart and then reload page,
or delete unknown "+n.name+", rewire as required, and then deploy.","error"); } for (i=0;iError: "+error,"error"); return null; } } return { registerType: registerType, getType: getType, convertNode: convertNode, add: addNode, addLink: addLink, remove: removeNode, removeLink: removeLink, addWorkspace: addWorkspace, removeWorkspace: removeWorkspace, workspace: getWorkspace, eachNode: function(cb) { for (var n=0;n