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
@@ -94,8 +94,9 @@ function init(_server,_runtime) {
|
||||
});
|
||||
}
|
||||
editorApp.get("/",ensureRuntimeStarted,ui.ensureSlash,ui.editor);
|
||||
editorApp.get("/icons",needsPermission("nodes.read"),nodes.getIcons,errorHandler);
|
||||
editorApp.get("/icons/:module/:icon",ui.icon);
|
||||
editorApp.get("/icons/:scope/:module/:icon",ui.icon);
|
||||
editorApp.get("/icons/:scope/:module/:icon",ui.icon);
|
||||
theme.init(runtime);
|
||||
editorApp.use("/theme",theme.app());
|
||||
editorApp.use("/",ui.editorResources);
|
||||
|
@@ -210,9 +210,10 @@
|
||||
"editConfig": "Edit __type__ config node",
|
||||
"addNewType": "Add new __type__...",
|
||||
"nodeProperties": "node properties",
|
||||
"portLabels": "port labels",
|
||||
"portLabels": "node settings",
|
||||
"labelInputs": "Inputs",
|
||||
"labelOutputs": "Outputs",
|
||||
"settingIcon": "Icon",
|
||||
"noDefaultLabel": "none",
|
||||
"defaultLabel": "use default label",
|
||||
"errors": {
|
||||
|
@@ -208,9 +208,10 @@
|
||||
"editConfig": "__type__ ノードの設定を編集",
|
||||
"addNewType": "新規に __type__ を追加...",
|
||||
"nodeProperties": "プロパティ",
|
||||
"portLabels": "端子名",
|
||||
"portLabels": "設定",
|
||||
"labelInputs": "入力",
|
||||
"labelOutputs": "出力",
|
||||
"settingIcon": "アイコン",
|
||||
"noDefaultLabel": "なし",
|
||||
"defaultLabel": "既定の名前を使用",
|
||||
"errors": {
|
||||
|
@@ -229,6 +229,11 @@ module.exports = {
|
||||
log.audit({event: "nodes.module.set",module:mod,enabled:body.enabled,error:err.code||"unexpected_error",message:err.toString()},req);
|
||||
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
|
||||
}
|
||||
},
|
||||
|
||||
getIcons: function(req,res) {
|
||||
log.audit({event: "nodes.icons.get"},req);
|
||||
res.json(redNodes.getNodeIcons());
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -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