Installing a module returns module info

Removing a module checks module exists and checks type is not in use
This commit is contained in:
Anna Thomas
2014-11-21 15:15:24 +00:00
parent 4c9d53388c
commit dd5821ee1b
4 changed files with 145 additions and 64 deletions

View File

@@ -55,20 +55,21 @@ function checkTypeInUse(id) {
var nodeInfo = registry.getNodeInfo(id);
if (!nodeInfo) {
throw new Error("Unrecognised id: "+id);
}
var inUse = {};
flows.each(function(n) {
inUse[n.type] = (inUse[n.type]||0)+1;
});
var nodesInUse = [];
nodeInfo.types.forEach(function(t) {
if (inUse[t]) {
nodesInUse.push(t);
} else {
var inUse = {};
flows.each(function(n) {
inUse[n.type] = (inUse[n.type]||0)+1;
});
var nodesInUse = [];
nodeInfo.types.forEach(function(t) {
if (inUse[t]) {
nodesInUse.push(t);
}
});
if (nodesInUse.length > 0) {
var msg = nodesInUse.join(", ");
throw new Error("Type in use: "+msg);
}
});
if (nodesInUse.length > 0) {
var msg = nodesInUse.join(", ");
throw new Error("Type in use: "+msg);
}
}
@@ -79,13 +80,16 @@ function removeNode(id) {
function removeModule(module) {
var info = registry.getNodeModuleInfo(module);
for (var i=0;i<info.nodes.length;i++) {
checkTypeInUse(info.nodes[i]);
if (!info) {
throw new Error("Unrecognised module: "+module);
} else {
for (var i=0;i<info.nodes.length;i++) {
checkTypeInUse(module+"/"+info.nodes[i]);
}
return registry.removeModule(module);
}
return registry.removeModule(module);
}
function disableNode(id) {
checkTypeInUse(id);
return registry.disableNode(id);