mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Enable npm nodes to provide custom icons
This commit is contained in:
		@@ -88,8 +88,16 @@ function loadNode(nodeDir, nodeFn, nodeLabel) {
 | 
				
			|||||||
function loadNodesFromModule(moduleDir,pkg) {
 | 
					function loadNodesFromModule(moduleDir,pkg) {
 | 
				
			||||||
    var nodes = pkg['node-red'].nodes||{};
 | 
					    var nodes = pkg['node-red'].nodes||{};
 | 
				
			||||||
    var promises = [];
 | 
					    var promises = [];
 | 
				
			||||||
 | 
					    var iconDirs = [];
 | 
				
			||||||
    for (var n in nodes) {
 | 
					    for (var n in nodes) {
 | 
				
			||||||
        promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
 | 
					        promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
 | 
				
			||||||
 | 
					        var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
 | 
				
			||||||
 | 
					        if (iconDirs.indexOf(iconDir) == -1) {
 | 
				
			||||||
 | 
					            if (fs.existsSync(iconDir)) {
 | 
				
			||||||
 | 
					                events.emit("node-icon-dir",iconDir);
 | 
				
			||||||
 | 
					                iconDirs.push(iconDir);
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return promises;
 | 
					    return promises;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								red/ui.js
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								red/ui.js
									
									
									
									
									
								
							@@ -41,15 +41,24 @@ function setupUI(settings) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    var iconCache = {};
 | 
				
			||||||
 | 
					    //TODO: create a default icon
 | 
				
			||||||
 | 
					    var defaultIcon = path.resolve(__dirname + '/../public/icons/arrow-in.png');
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    app.get("/icons/:icon",function(req,res) {
 | 
					    app.get("/icons/:icon",function(req,res) {
 | 
				
			||||||
        for (var p in icon_paths) {
 | 
					        if (iconCache[req.params.icon]) {
 | 
				
			||||||
            if (fs.existsSync(icon_paths[p]+'/'+req.params.icon)) {
 | 
					            res.sendfile(iconCache[req.params.icon]);
 | 
				
			||||||
                res.sendfile(icon_paths[p]+'/'+req.params.icon);
 | 
					        } else { 
 | 
				
			||||||
                return;
 | 
					            for (var p in icon_paths) {
 | 
				
			||||||
 | 
					                var iconPath = path.join(icon_paths[p],req.params.icon);
 | 
				
			||||||
 | 
					                if (fs.existsSync(iconPath)) {
 | 
				
			||||||
 | 
					                    res.sendfile(iconPath);
 | 
				
			||||||
 | 
					                    iconCache[req.params.icon] = iconPath;
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            res.sendfile(defaultIcon);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //TODO: create a default icon
 | 
					 | 
				
			||||||
        res.sendfile(path.resolve(__dirname + '/../public/icons/arrow-in.png'));
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    app.get("/settings", function(req,res) {
 | 
					    app.get("/settings", function(req,res) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user