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:
parent
3984b6b702
commit
ac884bfdf3
49
nodes/core/core/98-unknown.html
Normal file
49
nodes/core/core/98-unknown.html
Normal 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>
|
22
nodes/core/core/98-unknown.js
Normal file
22
nodes/core/core/98-unknown.js
Normal 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);
|
@ -14,31 +14,28 @@
|
||||
* 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
|
||||
// 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;
|
||||
@ -53,7 +50,7 @@ RED.nodes = function() {
|
||||
function addConfig(c) {
|
||||
configNodes[c.id] = c;
|
||||
}
|
||||
|
||||
|
||||
function getNode(id) {
|
||||
if (id in configNodes) {
|
||||
return configNodes[id];
|
||||
@ -66,7 +63,7 @@ RED.nodes = function() {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function removeNode(id) {
|
||||
var removedLinks = [];
|
||||
if (id in configNodes) {
|
||||
@ -81,20 +78,20 @@ RED.nodes = function() {
|
||||
}
|
||||
return removedLinks;
|
||||
}
|
||||
|
||||
|
||||
function removeLink(l) {
|
||||
var index = links.indexOf(l);
|
||||
if (index != -1) {
|
||||
links.splice(index,1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function refreshValidation() {
|
||||
for (var n in nodes) {
|
||||
RED.editor.validateNode(nodes[n]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addWorkspace(ws) {
|
||||
workspaces[ws.id] = ws;
|
||||
}
|
||||
@ -136,9 +133,9 @@ RED.nodes = function() {
|
||||
}
|
||||
return nns;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a node to an exportable JSON Object
|
||||
* Converts a node to an exportable JSON Object
|
||||
**/
|
||||
function convertNode(n) {
|
||||
var node = {};
|
||||
@ -151,7 +148,7 @@ RED.nodes = function() {
|
||||
node.x = n.x;
|
||||
node.y = n.y;
|
||||
node.z = n.z;
|
||||
|
||||
|
||||
node.wires = [];
|
||||
for(var i=0;i<n.outputs;i++) {
|
||||
node.wires.push([]);
|
||||
@ -164,7 +161,7 @@ RED.nodes = function() {
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts the current node selection to an exportable JSON Object
|
||||
**/
|
||||
@ -193,7 +190,7 @@ RED.nodes = function() {
|
||||
}
|
||||
return nns;
|
||||
}
|
||||
|
||||
|
||||
//TODO: rename this (createCompleteNodeSet)
|
||||
function createCompleteNodeSet() {
|
||||
var nns = [];
|
||||
@ -209,7 +206,7 @@ RED.nodes = function() {
|
||||
}
|
||||
return nns;
|
||||
}
|
||||
|
||||
|
||||
function importNodes(newNodesObj,createNewIds) {
|
||||
try {
|
||||
var newNodes;
|
||||
@ -230,8 +227,10 @@ RED.nodes = function() {
|
||||
// TODO: remove workspace in next release+1
|
||||
if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) {
|
||||
// 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");
|
||||
return null;
|
||||
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; //
|
||||
n.name = "( "+n.type+" )"; // DCJ - mod to make it load, but will lose all "self knowledge".
|
||||
n.type = "unknown"; //
|
||||
}
|
||||
}
|
||||
for (var i in newNodes) {
|
||||
@ -253,11 +252,11 @@ RED.nodes = function() {
|
||||
addWorkspace(defaultWorkspace);
|
||||
RED.view.addWorkspace(defaultWorkspace);
|
||||
}
|
||||
|
||||
|
||||
var node_map = {};
|
||||
var new_nodes = [];
|
||||
var new_links = [];
|
||||
|
||||
|
||||
for (var i in newNodes) {
|
||||
var n = newNodes[i];
|
||||
// TODO: remove workspace in next release+1
|
||||
@ -296,7 +295,7 @@ RED.nodes = function() {
|
||||
}
|
||||
}
|
||||
node.outputs = n.outputs||node._def.outputs;
|
||||
|
||||
|
||||
for (var d in node._def.defaults) {
|
||||
node[d] = n[d];
|
||||
if (node._def.defaults[d].type) {
|
||||
@ -306,7 +305,7 @@ RED.nodes = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addNode(node);
|
||||
RED.editor.validateNode(node);
|
||||
node_map[n.id] = node;
|
||||
@ -336,7 +335,7 @@ RED.nodes = function() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
registerType: registerType,
|
||||
getType: getType,
|
||||
@ -373,5 +372,4 @@ RED.nodes = function() {
|
||||
nodes: nodes, // TODO: exposed for d3 vis
|
||||
links: links // TODO: exposed for d3 vis
|
||||
};
|
||||
|
||||
}();
|
||||
|
Loading…
Reference in New Issue
Block a user