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

Add "Unknown node" type to core.

Relates to Issue #5
not the best/complete solution - but a start.
This commit is contained in:
Dave C-J 2013-12-08 21:55:34 +00:00
parent 3984b6b702
commit ac884bfdf3
3 changed files with 97 additions and 28 deletions

View File

@ -0,0 +1,49 @@
<!--
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.
-->
<script type="text/x-red" data-template-name="unknown">
<div class="form-tips">This node is currently unknown to Node-RED. <i>DO NOT Deploy while in this state or the flow file may well be trashed...</i>. Usually this can be resolved by installing the npm module that this node relies on. To do this - stop Node-RED and restart. Look at the errors shown for one that matches this missing node. Stop Node-RED again and type <b>npm install {missing module name}</b>. Restart Node-RED, and hopefully this will have resolved it.</div>
</script>
<script type="text/x-red" data-help-name="unknown">
<p>This node is currently unknown to Node-RED.</p>
<p><i>DO NOT Deploy while in this state or the flow file may well be trashed...</i></p>
<p>Usually this can be resolved by installing the npm module that this node relies on. To do this, stop Node-RED and restart.</p>
<p>Look at the errors shown in the console for one that matches the name of this missing node.</p>
<p>Stop Node-RED again and type <b>npm install {missing module name}</b>. Restart Node-RED, and hopefully this will have resolved it.</p>
<p>If not then you will need to obtain that Node-RED module from somewhere... ask the author of the flow where they got it from.</p>
<p>(hopefully soon we will have a central repository where all nodes can be registered. work in progress.)</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('unknown',{
category: 'unknown',
color:"#C00000",
defaults: {
name: {value:""},
foo: {value:"",required:true}
},
inputs:1,
outputs:1,
icon: "",
label: function() {
return this.name||"unknown";
},
labelStyle: function() {
return "node_label_white";
}
});
</script>

View File

@ -0,0 +1,22 @@
/**
* 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.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
function UnknownNode(n) {
RED.nodes.createNode(this,n);
}
RED.nodes.registerType("unknown",UnknownNode);

View File

@ -14,31 +14,28 @@
* limitations under the License. * limitations under the License.
**/ **/
RED.nodes = function() { RED.nodes = function() {
var node_defs = {}; var node_defs = {};
var nodes = []; var nodes = [];
var configNodes = {}; var configNodes = {};
var links = []; var links = [];
var defaultWorkspace; var defaultWorkspace;
var workspaces = {}; var workspaces = {};
function registerType(nt,def) { function registerType(nt,def) {
node_defs[nt] = def; node_defs[nt] = def;
// TODO: too tightly coupled into palette UI // TODO: too tightly coupled into palette UI
RED.palette.add(nt,def); RED.palette.add(nt,def);
} }
function getID() { function getID() {
return (1+Math.random()*4294967295).toString(16); return (1+Math.random()*4294967295).toString(16);
} }
function getType(type) { function getType(type) {
return node_defs[type]; return node_defs[type];
} }
function addNode(n) { function addNode(n) {
if (n._def.category == "config") { if (n._def.category == "config") {
configNodes[n.id] = n; configNodes[n.id] = n;
@ -53,7 +50,7 @@ RED.nodes = function() {
function addConfig(c) { function addConfig(c) {
configNodes[c.id] = c; configNodes[c.id] = c;
} }
function getNode(id) { function getNode(id) {
if (id in configNodes) { if (id in configNodes) {
return configNodes[id]; return configNodes[id];
@ -66,7 +63,7 @@ RED.nodes = function() {
} }
return null; return null;
} }
function removeNode(id) { function removeNode(id) {
var removedLinks = []; var removedLinks = [];
if (id in configNodes) { if (id in configNodes) {
@ -81,20 +78,20 @@ RED.nodes = function() {
} }
return removedLinks; return removedLinks;
} }
function removeLink(l) { function removeLink(l) {
var index = links.indexOf(l); var index = links.indexOf(l);
if (index != -1) { if (index != -1) {
links.splice(index,1); links.splice(index,1);
} }
} }
function refreshValidation() { function refreshValidation() {
for (var n in nodes) { for (var n in nodes) {
RED.editor.validateNode(nodes[n]); RED.editor.validateNode(nodes[n]);
} }
} }
function addWorkspace(ws) { function addWorkspace(ws) {
workspaces[ws.id] = ws; workspaces[ws.id] = ws;
} }
@ -136,9 +133,9 @@ RED.nodes = function() {
} }
return nns; return nns;
} }
/** /**
* Converts a node to an exportable JSON Object * Converts a node to an exportable JSON Object
**/ **/
function convertNode(n) { function convertNode(n) {
var node = {}; var node = {};
@ -151,7 +148,7 @@ RED.nodes = function() {
node.x = n.x; node.x = n.x;
node.y = n.y; node.y = n.y;
node.z = n.z; node.z = n.z;
node.wires = []; node.wires = [];
for(var i=0;i<n.outputs;i++) { for(var i=0;i<n.outputs;i++) {
node.wires.push([]); node.wires.push([]);
@ -164,7 +161,7 @@ RED.nodes = function() {
} }
return node; return node;
} }
/** /**
* Converts the current node selection to an exportable JSON Object * Converts the current node selection to an exportable JSON Object
**/ **/
@ -193,7 +190,7 @@ RED.nodes = function() {
} }
return nns; return nns;
} }
//TODO: rename this (createCompleteNodeSet) //TODO: rename this (createCompleteNodeSet)
function createCompleteNodeSet() { function createCompleteNodeSet() {
var nns = []; var nns = [];
@ -209,7 +206,7 @@ RED.nodes = function() {
} }
return nns; return nns;
} }
function importNodes(newNodesObj,createNewIds) { function importNodes(newNodesObj,createNewIds) {
try { try {
var newNodes; var newNodes;
@ -230,8 +227,10 @@ RED.nodes = function() {
// TODO: remove workspace in next release+1 // TODO: remove workspace in next release+1
if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) { if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) {
// TODO: get this UI thing out of here! (see below as well) // TODO: get this UI thing out of here! (see below as well)
RED.notify("<strong>Failed to import nodes</strong>: unrecognised type '"+n.type+"'","error"); RED.notify("<strong>Failed to import node</strong>: unrecognised type '"+n.type+"'<br/>DO NOT DEPLOY while in this state.<br/>Either, add missing types to Node-RED, restart and then reload page,<br/>or delete unknown ( "+n.type+" ), rewire as required, and then deploy.","error","true");
return null; //return null; //
n.name = "( "+n.type+" )"; // DCJ - mod to make it load, but will lose all "self knowledge".
n.type = "unknown"; //
} }
} }
for (var i in newNodes) { for (var i in newNodes) {
@ -253,11 +252,11 @@ RED.nodes = function() {
addWorkspace(defaultWorkspace); addWorkspace(defaultWorkspace);
RED.view.addWorkspace(defaultWorkspace); RED.view.addWorkspace(defaultWorkspace);
} }
var node_map = {}; var node_map = {};
var new_nodes = []; var new_nodes = [];
var new_links = []; var new_links = [];
for (var i in newNodes) { for (var i in newNodes) {
var n = newNodes[i]; var n = newNodes[i];
// TODO: remove workspace in next release+1 // TODO: remove workspace in next release+1
@ -296,7 +295,7 @@ RED.nodes = function() {
} }
} }
node.outputs = n.outputs||node._def.outputs; node.outputs = n.outputs||node._def.outputs;
for (var d in node._def.defaults) { for (var d in node._def.defaults) {
node[d] = n[d]; node[d] = n[d];
if (node._def.defaults[d].type) { if (node._def.defaults[d].type) {
@ -306,7 +305,7 @@ RED.nodes = function() {
} }
} }
} }
addNode(node); addNode(node);
RED.editor.validateNode(node); RED.editor.validateNode(node);
node_map[n.id] = node; node_map[n.id] = node;
@ -336,7 +335,7 @@ RED.nodes = function() {
} }
} }
return { return {
registerType: registerType, registerType: registerType,
getType: getType, getType: getType,
@ -373,5 +372,4 @@ RED.nodes = function() {
nodes: nodes, // TODO: exposed for d3 vis nodes: nodes, // TODO: exposed for d3 vis
links: links // TODO: exposed for d3 vis links: links // TODO: exposed for d3 vis
}; };
}(); }();