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

No-op and return success on enabling/disabling node by type name

This commit is contained in:
Anna Thomas 2014-12-17 13:35:57 +00:00
parent 10681f97d9
commit 66213d151d

View File

@ -142,10 +142,8 @@ module.exports = {
var info; var info;
if (!node) { if (!node) {
res.send(404); res.send(404);
} else if (!node.err && node.enabled === body.enabled) {
res.json(node);
} else { } else {
res.json(putNode(id, body.enabled)); res.json(putNode(node, body.enabled));
} }
} catch(err) { } catch(err) {
res.send(400,err.toString()); res.send(400,err.toString());
@ -169,7 +167,7 @@ module.exports = {
var matching = getMatchingNodes(mod); var matching = getMatchingNodes(mod);
if (matching.length === 1) { if (matching.length === 1) {
// One match, assume correct // One match, assume correct
res.json(putNode(matching[0].id, body.enabled)); res.json(putNode(matching[0], body.enabled));
return; return;
} else if (matching.length > 1) { } else if (matching.length > 1) {
// Multiple matches, need clarification // Multiple matches, need clarification
@ -229,24 +227,28 @@ function getMatchingNodes(node) {
return matching; return matching;
} }
function putNode(id, enabled) { function putNode(node, enabled) {
var info; var info;
if (enabled) { if (!node.err && node.enabled === enabled) {
info = redNodes.enableNode(id); info = node;
} else { } else {
info = redNodes.disableNode(id); if (enabled) {
} info = redNodes.enableNode(node.id);
} else {
if (info.enabled === enabled && !info.err) { info = redNodes.disableNode(node.id);
comms.publish("node/"+(enabled?"enabled":"disabled"),info,false); }
util.log("[red] "+(enabled?"Enabled":"Disabled")+" node types:");
for (var i=0;i<info.types.length;i++) { if (info.enabled === enabled && !info.err) {
util.log("[red] - "+info.types[i]); comms.publish("node/"+(enabled?"enabled":"disabled"),info,false);
util.log("[red] "+(enabled?"Enabled":"Disabled")+" node types:");
for (var i=0;i<info.types.length;i++) {
util.log("[red] - "+info.types[i]);
}
} else if (enabled && info.err) {
util.log("[red] Failed to enable node:");
util.log("[red] - "+info.name+" : "+info.err);
} }
} else if (enabled && info.err) {
util.log("[red] Failed to enable node:");
util.log("[red] - "+info.name+" : "+info.err);
} }
return info; return info;