Preserve unknown node type properties across deploys

Closes #5
This commit is contained in:
Nick O'Leary 2014-10-30 21:41:42 +00:00
parent 7419f62a20
commit dfc79e3122
2 changed files with 62 additions and 34 deletions

View File

@ -16,13 +16,15 @@
<script type="text/x-red" data-template-name="unknown"> <script type="text/x-red" data-template-name="unknown">
<div class="form-tips"><p>This node is a type unknown to your installation of Node-RED.</p> <div class="form-tips"><p>This node is a type unknown to your installation of Node-RED.</p>
<p><i>If you deploy with the node in this state, it will lose all of its configuration.</i></p> <p><i>If you deploy with the node in this state, it's configuration will be preserved, but
the flow will not start until the missing type is installed.</i></p>
<p>See the Info side bar for more help</p></div> <p>See the Info side bar for more help</p></div>
</script> </script>
<script type="text/x-red" data-help-name="unknown"> <script type="text/x-red" data-help-name="unknown">
<p>This node is a type unknown to your installation of Node-RED.</p> <p>This node is a type unknown to your installation of Node-RED.</p>
<p><i>If you deploy with the node in this state, it will lose all of its configuration.</i></p> <p><i>If you deploy with the node in this state, it's configuration will be preserved, but
the flow will not start until the missing type is installed.</i></p>
<p>It is possible this node type is already installed, but is missing a dependency. Check the Node-RED start-up log for <p>It is possible this node type is already installed, but is missing a dependency. Check the Node-RED start-up log for
any error messages associated with the missing node type. Use <b>npm install &lt;module&gt;</b> to install any missing modules any error messages associated with the missing node type. Use <b>npm install &lt;module&gt;</b> to install any missing modules
and restart Node-RED and reimport the nodes.</p> and restart Node-RED and reimport the nodes.</p>

View File

@ -330,17 +330,25 @@ RED.nodes = (function() {
var node = {}; var node = {};
node.id = n.id; node.id = n.id;
node.type = n.type; node.type = n.type;
for (var d in n._def.defaults) { if (node.type == "unknown") {
if (n._def.defaults.hasOwnProperty(d)) { for (var p in n._orig) {
node[d] = n[d]; if (n._orig.hasOwnProperty(p)) {
node[p] = n._orig[p];
}
} }
} } else {
if(exportCreds && n.credentials) { for (var d in n._def.defaults) {
node.credentials = {}; if (n._def.defaults.hasOwnProperty(d)) {
for (var cred in n._def.credentials) { node[d] = n[d];
if (n._def.credentials.hasOwnProperty(cred)) { }
if (n.credentials[cred] != null) { }
node.credentials[cred] = n.credentials[cred]; if(exportCreds && n.credentials) {
node.credentials = {};
for (var cred in n._def.credentials) {
if (n._def.credentials.hasOwnProperty(cred)) {
if (n.credentials[cred] != null) {
node.credentials[cred] = n.credentials[cred];
}
} }
} }
} }
@ -503,16 +511,15 @@ RED.nodes = (function() {
!registry.getNodeType(n.type) && !registry.getNodeType(n.type) &&
n.type.substring(0,8) != "subflow:") { n.type.substring(0,8) != "subflow:") {
// TODO: get this UI thing out of here! (see below as well) // TODO: get this UI thing out of here! (see below as well)
n.name = n.type;
n.type = "unknown"; if (unknownTypes.indexOf(n.type)==-1) {
if (unknownTypes.indexOf(n.name)==-1) { unknownTypes.push(n.type);
unknownTypes.push(n.name);
}
if (n.x == null && n.y == null) {
// config node - remove it
newNodes.splice(i,1);
i--;
} }
//if (n.x == null && n.y == null) {
// // config node - remove it
// newNodes.splice(i,1);
// i--;
//}
} }
} }
if (unknownTypes.length > 0) { if (unknownTypes.length > 0) {
@ -653,27 +660,46 @@ RED.nodes = (function() {
node.inputs = subflow.in.length; node.inputs = subflow.in.length;
} else { } else {
if (!node._def) { if (!node._def) {
node._def = { if (node.x && node.y) {
color:"#fee", node._def = {
defaults: {}, color:"#fee",
label: "unknown: "+n.type, defaults: {},
labelStyle: "node_label_italic", label: "unknown: "+n.type,
outputs: n.outputs||n.wires.length labelStyle: "node_label_italic",
outputs: n.outputs||n.wires.length
}
} else {
node._def = {
category:"config"
};
node.users = [];
} }
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];
}
}
node._orig = orig;
node.name = n.type;
node.type = "unknown";
} }
node.inputs = n.inputs||node._def.inputs; if (node._def.category != "config") {
node.outputs = n.outputs||node._def.outputs; node.inputs = n.inputs||node._def.inputs;
node.outputs = n.outputs||node._def.outputs;
for (var d2 in node._def.defaults) { for (var d2 in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(d2)) { if (node._def.defaults.hasOwnProperty(d2)) {
node[d2] = n[d2]; node[d2] = n[d2];
}
} }
} }
} }
addNode(node); addNode(node);
RED.editor.validateNode(node); RED.editor.validateNode(node);
node_map[n.id] = node; node_map[n.id] = node;
new_nodes.push(node); if (node._def.category != "config") {
new_nodes.push(node);
}
} }
} }
} }