in ui-modules/utils/icon-generator/icon-generator.js [135:194]
function getIcon(entityOrTypeId, doNotAutogenerate) {
let deferred = $q.defer();
let id;
if (typeof entityOrTypeId === 'string') {
id = entityOrTypeId;
} else if (typeof entityOrTypeId === 'object') {
if (entityOrTypeId.iconUrl) {
deferred.resolve(entityOrTypeId.iconUrl);
return deferred.promise;
}
if (entityOrTypeId.links && entityOrTypeId.links.iconUrl) {
deferred.resolve(entityOrTypeId.links.iconUrl);
return deferred.promise;
}
if (entityOrTypeId.catalogItemId) {
id = entityOrTypeId.catalogItemId;
} else if (entityOrTypeId.symbolicName) {
id = entityOrTypeId.symbolicName;
} else if (entityOrTypeId.type) {
let entity = entityOrTypeId;
id = entity.type;
if (id === 'org.apache.brooklyn.entity.stock.BasicApplication' && entity.children && entity.children.length === 1) {
id = entity.children[0].catalogItemId || entity.children[0].type;
}
}
}
let icon;
if (angular.isDefined(id)) {
icon = cache.get(id);
} else {
$log.warn('No ID found for item, cannot make icon - '+entityOrTypeId, entityOrTypeId);
deferred.reject('No ID found for item, cannot make icon - '+entityOrTypeId);
return deferred.promise;
}
if (angular.isUndefined(icon)) {
let path = id.split(':');
$http({
method: 'GET',
cache: true,
url: '/v1/catalog/entities/' + path[0] + '/' + (path[1] || 'latest')
}).then((response)=> {
if (response.data.hasOwnProperty('iconUrl')) {
icon = response.data.iconUrl;
cache.put(id, icon);
} else if (doNotAutogenerate) {
icon = null;
} else {
icon = iconGenerator(id);
}
deferred.resolve(icon)
}, ()=> {
deferred.resolve(iconGenerator(id));
});
} else {
deferred.resolve(icon);
}
return deferred.promise;
}