mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
allow a node's icon to be set dynamically (#1490)
* create a proto type * Fixed some problems after reviewing
This commit is contained in:
committed by
Nick O'Leary
parent
cc88ebd2b9
commit
6d2389945b
@@ -148,6 +148,7 @@ module.exports = {
|
||||
getNodeConfigs: registry.getNodeConfigs,
|
||||
getNodeConfig: registry.getNodeConfig,
|
||||
getNodeIconPath: registry.getNodeIconPath,
|
||||
getNodeIcons: registry.getNodeIcons,
|
||||
getNodeExampleFlows: library.getExampleFlows,
|
||||
getNodeExampleFlowPath: library.getExampleFlowPath,
|
||||
|
||||
|
@@ -71,6 +71,7 @@ module.exports = {
|
||||
getNodeConfigs: registry.getAllNodeConfigs,
|
||||
getNodeConfig: registry.getNodeConfig,
|
||||
getNodeIconPath: registry.getNodeIconPath,
|
||||
getNodeIcons: registry.getNodeIcons,
|
||||
|
||||
enableNode: enableNodeSet,
|
||||
disableNode: registry.disableNodeSet,
|
||||
|
@@ -24,6 +24,7 @@ var i18n;
|
||||
|
||||
var settings;
|
||||
var disableNodePathScan = false;
|
||||
var iconFileExtensions = [".png", ".gif"];
|
||||
|
||||
function init(runtime) {
|
||||
settings = runtime.settings;
|
||||
@@ -104,7 +105,8 @@ function getLocalNodeFiles(dir) {
|
||||
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
|
||||
result = result.concat(getLocalNodeFiles(path.join(dir,fn)));
|
||||
} else if (fn === "icons") {
|
||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn)});
|
||||
var iconList = scanIconDir(path.join(dir,fn));
|
||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn),icons:iconList});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -197,7 +199,8 @@ function getModuleNodeFiles(module) {
|
||||
if (iconDirs.indexOf(iconDir) == -1) {
|
||||
try {
|
||||
fs.statSync(iconDir);
|
||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir});
|
||||
var iconList = scanIconDir(iconDir);
|
||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir,icons:iconList});
|
||||
iconDirs.push(iconDir);
|
||||
} catch(err) {
|
||||
}
|
||||
@@ -218,6 +221,10 @@ function getNodeFiles(disableNodePathScan) {
|
||||
// Find all of the nodes to load
|
||||
var nodeFiles = [];
|
||||
|
||||
var dir = path.resolve(__dirname + '/../../../../public/icons');
|
||||
var iconList = scanIconDir(dir);
|
||||
events.emit("node-icon-dir",{name:'node-red',path:dir,icons:iconList});
|
||||
|
||||
if (settings.coreNodesDir) {
|
||||
nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
|
||||
var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
|
||||
@@ -302,6 +309,20 @@ function getModuleFiles(module) {
|
||||
return nodeList;
|
||||
}
|
||||
|
||||
function scanIconDir(dir) {
|
||||
var iconList = [];
|
||||
try {
|
||||
var files = fs.readdirSync(dir);
|
||||
files.forEach(function(file) {
|
||||
var stats = fs.statSync(path.join(dir, file));
|
||||
if (stats.isFile() && iconFileExtensions.indexOf(path.extname(file)) !== -1) {
|
||||
iconList.push(file);
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
}
|
||||
return iconList;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
|
@@ -579,6 +579,25 @@ var defaultIcon = path.resolve(__dirname + '/../../../../public/icons/arrow-in.p
|
||||
function nodeIconDir(dir) {
|
||||
icon_paths[dir.name] = icon_paths[dir.name] || [];
|
||||
icon_paths[dir.name].push(path.resolve(dir.path));
|
||||
|
||||
if (dir.icons) {
|
||||
if (!moduleConfigs[dir.name]) {
|
||||
moduleConfigs[dir.name] = {
|
||||
name: dir.name,
|
||||
nodes: {},
|
||||
icons: []
|
||||
};
|
||||
}
|
||||
var module = moduleConfigs[dir.name];
|
||||
if (module.icons === undefined) {
|
||||
module.icons = [];
|
||||
}
|
||||
dir.icons.forEach(function(icon) {
|
||||
if (module.icons.indexOf(icon) === -1) {
|
||||
module.icons.push(icon);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getNodeIconPath(module,icon) {
|
||||
@@ -607,6 +626,20 @@ function getNodeIconPath(module,icon) {
|
||||
}
|
||||
}
|
||||
|
||||
function getNodeIcons() {
|
||||
var iconList = {};
|
||||
|
||||
for (var module in moduleConfigs) {
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
if (moduleConfigs[module].icons) {
|
||||
iconList[module] = moduleConfigs[module].icons;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return iconList;
|
||||
}
|
||||
|
||||
var registry = module.exports = {
|
||||
init: init,
|
||||
load: load,
|
||||
@@ -629,6 +662,7 @@ var registry = module.exports = {
|
||||
getModuleInfo: getModuleInfo,
|
||||
|
||||
getNodeIconPath: getNodeIconPath,
|
||||
getNodeIcons: getNodeIcons,
|
||||
/**
|
||||
* Gets all of the node template configs
|
||||
* @return all of the node templates in a single string
|
||||
|
Reference in New Issue
Block a user