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

Merge pull request #1987 from node-red-hitachi/fa-nonexist

Show arrow-in node when invalid font-awesome icon name was specified …
This commit is contained in:
Nick O'Leary 2018-11-30 23:13:33 +00:00 committed by GitHub
commit 2060af8a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 24 deletions

View File

@ -498,7 +498,7 @@ RED.diff = (function() {
nodeDiv.css('backgroundColor',colour); nodeDiv.css('backgroundColor',colour);
var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv); var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
RED.utils.createIconElement(icon_url, iconContainer, false, def, node); RED.utils.createIconElement(icon_url, iconContainer, false);
return nodeDiv; return nodeDiv;
} }

View File

@ -830,7 +830,7 @@ RED.editor = (function() {
var icon_url = RED.utils.getNodeIcon(node._def,node); var icon_url = RED.utils.getNodeIcon(node._def,node);
nodeDiv.css('backgroundColor',colour); nodeDiv.css('backgroundColor',colour);
var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv); var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
RED.utils.createIconElement(icon_url, iconContainer, true, node._def, node); RED.utils.createIconElement(icon_url, iconContainer, true);
iconButton.click(function(e) { iconButton.click(function(e) {
e.preventDefault(); e.preventDefault();
@ -844,7 +844,7 @@ RED.editor = (function() {
showIconPicker(iconRow,node,iconPath,function(newIcon) { showIconPicker(iconRow,node,iconPath,function(newIcon) {
$("#node-settings-icon").text(newIcon||""); $("#node-settings-icon").text(newIcon||"");
var icon_url = RED.utils.getNodeIcon(node._def,{type:node.type,icon:newIcon}); var icon_url = RED.utils.getNodeIcon(node._def,{type:node.type,icon:newIcon});
RED.utils.createIconElement(icon_url, iconContainer, true, node._def, node); RED.utils.createIconElement(icon_url, iconContainer, true);
}); });
}); });
$('<div id="node-settings-icon">').text(node.icon).appendTo(iconButton); $('<div id="node-settings-icon">').text(node.icon).appendTo(iconButton);

View File

@ -144,7 +144,7 @@ RED.palette = (function() {
function setIcon(element,sf) { function setIcon(element,sf) {
var icon_url = RED.utils.getNodeIcon(sf._def); var icon_url = RED.utils.getNodeIcon(sf._def);
var iconContainer = element.find(".palette_icon_container"); var iconContainer = element.find(".palette_icon_container");
RED.utils.createIconElement(icon_url, iconContainer, true, sf._def); RED.utils.createIconElement(icon_url, iconContainer, true);
} }
function escapeNodeType(nt) { function escapeNodeType(nt) {
@ -182,7 +182,7 @@ RED.palette = (function() {
if (def.icon) { if (def.icon) {
var icon_url = RED.utils.getNodeIcon(def); var icon_url = RED.utils.getNodeIcon(def);
var iconContainer = $('<div/>',{class:"palette_icon_container"+(def.align=="right"?" palette_icon_container_right":"")}).appendTo(d); var iconContainer = $('<div/>',{class:"palette_icon_container"+(def.align=="right"?" palette_icon_container_right":"")}).appendTo(d);
RED.utils.createIconElement(icon_url, iconContainer, true, def); RED.utils.createIconElement(icon_url, iconContainer, true);
} }
d.style.backgroundColor = RED.utils.getNodeColor(nt,def); d.style.backgroundColor = RED.utils.getNodeColor(nt,def);

View File

@ -203,7 +203,7 @@ RED.search = (function() {
nodeDiv.css('backgroundColor',colour); nodeDiv.css('backgroundColor',colour);
var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv); var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
RED.utils.createIconElement(icon_url, iconContainer, true, node._def, node); RED.utils.createIconElement(icon_url, iconContainer, true);
var contentDiv = $('<div>',{class:"red-ui-search-result-description"}).appendTo(div); var contentDiv = $('<div>',{class:"red-ui-search-result-description"}).appendTo(div);
if (node.z) { if (node.z) {

View File

@ -133,7 +133,7 @@ RED.typeSearch = (function() {
nodeDiv.css('backgroundColor',colour); nodeDiv.css('backgroundColor',colour);
var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv); var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
RED.utils.createIconElement(icon_url, iconContainer, false, def); RED.utils.createIconElement(icon_url, iconContainer, false);
if (def.inputs > 0) { if (def.inputs > 0) {
$('<div/>',{class:"red-ui-search-result-node-port"}).appendTo(nodeDiv); $('<div/>',{class:"red-ui-search-result-node-port"}).appendTo(nodeDiv);

View File

@ -782,15 +782,18 @@ RED.utils = (function() {
} }
var iconPath = getDefaultNodeIcon(def, node); var iconPath = getDefaultNodeIcon(def, node);
if (def.category === 'subflows') { if (isIconExists(iconPath)) {
if (!isIconExists(iconPath)) { if (iconPath.module === "font-awesome") {
return RED.settings.apiRootUrl+"icons/node-red/subflow.png"; return iconPath.module+"/"+iconPath.file;
} else {
return RED.settings.apiRootUrl+"icons/"+iconPath.module+"/"+iconPath.file;
} }
}
if (iconPath.module === "font-awesome") {
return iconPath.module+"/"+iconPath.file;
} else { } else {
return RED.settings.apiRootUrl+"icons/"+iconPath.module+"/"+iconPath.file; if (def.category === 'subflows') {
return RED.settings.apiRootUrl+"icons/node-red/subflow.png";
} else {
return RED.settings.apiRootUrl+"icons/node-red/arrow-in.png";
}
} }
} }
@ -904,10 +907,8 @@ RED.utils = (function() {
* @param iconUrl - Url of icon. * @param iconUrl - Url of icon.
* @param iconContainer - Icon container element with palette_icon_container class. * @param iconContainer - Icon container element with palette_icon_container class.
* @param isLarge - Whether the icon size is large. * @param isLarge - Whether the icon size is large.
* @param def - Default definition of a node.
* @param node - If the icon is a specific node instance, this parameter must be specified. If it is icon template such as an icon on the palette, this must be omitted.
*/ */
function createIconElement(iconUrl, iconContainer, isLarge, def, node) { function createIconElement(iconUrl, iconContainer, isLarge) {
// Removes the previous icon when icon was changed. // Removes the previous icon when icon was changed.
var iconElement = iconContainer.find(".palette_icon"); var iconElement = iconContainer.find(".palette_icon");
if (iconElement.length !== 0) { if (iconElement.length !== 0) {
@ -928,13 +929,8 @@ RED.utils = (function() {
faIconElement.addClass("palette_icon_fa fa fa-fw " + faLarge + iconPath.file); faIconElement.addClass("palette_icon_fa fa fa-fw " + faLarge + iconPath.file);
return; return;
} }
// If the specified name is not defined in font-awesome, show the default icon. // If the specified name is not defined in font-awesome, show arrow-in icon.
if (def) { iconUrl = RED.settings.apiRootUrl+"icons/node-red/arrow-in.png"
var iconPath = RED.utils.getDefaultNodeIcon(def, node);
iconUrl = RED.settings.apiRootUrl+"icons/"+iconPath.module+"/"+iconPath.file;
} else {
iconUrl = RED.settings.apiRootUrl+"icons/node-red/arrow-in.png"
}
} }
var imageIconElement = $('<div/>',{class:"palette_icon"}).appendTo(iconContainer); var imageIconElement = $('<div/>',{class:"palette_icon"}).appendTo(iconContainer);
imageIconElement.css("backgroundImage", "url("+iconUrl+")"); imageIconElement.css("backgroundImage", "url("+iconUrl+")");