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

Replaced hex id with 'module/set' id

This commit is contained in:
Anna Thomas 2014-11-20 10:06:18 +00:00
parent 50fddf474b
commit 591b5f3f91

View File

@ -95,7 +95,6 @@ var registry = (function() {
nodeList = []; nodeList = [];
nodeConfigCache = null; nodeConfigCache = null;
}, },
addNodeSet: function(id,set) { addNodeSet: function(id,set) {
if (!set.err) { if (!set.err) {
set.types.forEach(function(t) { set.types.forEach(function(t) {
@ -103,10 +102,8 @@ var registry = (function() {
}); });
} }
if (set.module) {
nodeModules[set.module] = nodeModules[set.module]||{nodes:[]}; nodeModules[set.module] = nodeModules[set.module]||{nodes:[]};
nodeModules[set.module].nodes.push(id); nodeModules[set.module].nodes.push(set.name);
}
nodeConfigs[id] = set; nodeConfigs[id] = set;
nodeList.push(id); nodeList.push(id);
@ -141,7 +138,7 @@ var registry = (function() {
} }
var infoList = []; var infoList = [];
for (var i=0;i<nodes.nodes.length;i++) { for (var i=0;i<nodes.nodes.length;i++) {
infoList.push(registry.removeNode(nodes.nodes[i])); infoList.push(registry.removeNode(module+"/"+nodes.nodes[i]));
} }
delete nodeModules[module]; delete nodeModules[module];
saveNodeList(); saveNodeList();
@ -174,7 +171,7 @@ var registry = (function() {
nodes: [] nodes: []
}; };
for (var i = 0; i < nodes.length; ++i) { for (var i = 0; i < nodes.length; ++i) {
m.nodes.push(filterNodeInfo(nodeConfigs[nodes[i]])); m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
} }
list.push(m); list.push(m);
} }
@ -188,7 +185,7 @@ var registry = (function() {
nodes: [] nodes: []
}; };
for (var i = 0; i < nodes.length; ++i) { for (var i = 0; i < nodes.length; ++i) {
m.nodes.push(filterNodeInfo(nodeConfigs[nodes[i]])); m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
} }
return m; return m;
}, },
@ -475,14 +472,7 @@ function loadNodesFromModule(moduleDir,pkg) {
* } * }
*/ */
function loadNodeConfig(file,module,name) { function loadNodeConfig(file,module,name) {
var id = crypto.createHash('sha1').update(module+":"+name).digest("hex"); var id = module + "/" + name;
var existingInfo = registry.getNodeInfo(id);
if (existingInfo) {
// For a brief period, id for modules were calculated incorrectly.
// To prevent false-duplicates, this removes the old id entry
registry.removeNode(id);
registry.saveNodeList();
}
var info = registry.getNodeInfo(id); var info = registry.getNodeInfo(id);
var isEnabled = true; var isEnabled = true;
@ -496,14 +486,14 @@ function loadNodeConfig(file,module,name) {
var node = { var node = {
id: id, id: id,
module: module,
name: name,
file: file, file: file,
template: file.replace(/\.js$/,".html"), template: file.replace(/\.js$/,".html"),
enabled: isEnabled, enabled: isEnabled,
loaded:false loaded:false
}; };
node.name = module+":"+name;
node.module = module;
try { try {
var content = fs.readFileSync(node.template,'utf8'); var content = fs.readFileSync(node.template,'utf8');
@ -673,7 +663,7 @@ function addNode(file) {
} }
var nodes = []; var nodes = [];
try { try {
nodes.push(loadNodeConfig(file)); nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,"")));
} catch(err) { } catch(err) {
return when.reject(err); return when.reject(err);
} }