Skip to content
Snippets Groups Projects
Unverified Commit 837ce367 authored by Oleksii Kurinnyi's avatar Oleksii Kurinnyi Committed by GitHub
Browse files

use default icon if actual icon is not accessible (#15181)


Signed-off-by: default avatarOleksii Kurinnyi <okurinny@redhat.com>
parent d205b84c
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
'use strict'; 'use strict';
import {CheWorkspace} from '../../../../../components/api/workspace/che-workspace.factory'; import {CheWorkspace} from '../../../../../components/api/workspace/che-workspace.factory';
import {DevfileRegistry, IDevfileMetaData} from '../../../../../components/api/devfile-registry.factory'; import {DevfileRegistry, IDevfileMetaData} from '../../../../../components/api/devfile-registry.factory';
import {ImgSrcOnloadResult} from '../../../../../components/attribute/img-src/img-src.directive';
/** /**
* @description This class is handling the controller of devfile selector. * @description This class is handling the controller of devfile selector.
...@@ -21,13 +22,17 @@ export class DevfileSelectorController { ...@@ -21,13 +22,17 @@ export class DevfileSelectorController {
static $inject = ['devfileRegistry', 'cheWorkspace']; static $inject = ['devfileRegistry', 'cheWorkspace'];
private devfileRegistry: DevfileRegistry; devfiles: Array<IDevfileMetaData>;
private cheWorkspace: CheWorkspace;
private devfiles: Array<IDevfileMetaData>;
devfileOrderBy: string; devfileOrderBy: string;
onDevfileSelect: Function; onDevfileSelect: Function;
selectedDevfile: any; selectedDevfile: any;
stackName: string; stackName: string;
iconsLoaded: {
iconUrl?: boolean;
} = {};
private devfileRegistry: DevfileRegistry;
private cheWorkspace: CheWorkspace;
/** /**
* Default constructor that is using resource injection * Default constructor that is using resource injection
...@@ -68,4 +73,13 @@ export class DevfileSelectorController { ...@@ -68,4 +73,13 @@ export class DevfileSelectorController {
}); });
} }
} }
iconOnLoad(iconUrl: string, result: ImgSrcOnloadResult): void {
this.iconsLoaded[iconUrl] = result.loaded;
}
showIcon(iconUrl: string): boolean {
return !!this.iconsLoaded[iconUrl];
}
} }
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
<che-list-header-column flex="50" <che-list-header-column flex="50"
che-sort-value="devfileSelectorController.devfileOrderBy" che-sort-value="devfileSelectorController.devfileOrderBy"
che-sort-item="description" che-sort-item="description"
che-column-title="Description"></che-list-header-column> che-column-title="Description"></che-list-header-column>
<che-list-header-column flex="10" <che-list-header-column flex="10"
che-sort-value="devfileSelectorController.devfileOrderBy" che-sort-value="devfileSelectorController.devfileOrderBy"
che-sort-item="globalMemoryLimit" che-sort-item="globalMemoryLimit"
che-column-title="Required memory"></che-list-header-column> che-column-title="Required memory"></che-list-header-column>
</div> </div>
</div> </div>
</che-list-header> </che-list-header>
...@@ -42,11 +42,12 @@ ...@@ -42,11 +42,12 @@
<!-- Icon --> <!-- Icon -->
<div class="devfile-selector-icon-column" <div class="devfile-selector-icon-column"
layout="column" layout-align="center center"> layout="column" layout-align="center center">
<div ng-if="devfile.icon" class="devfile-selector-item-icon"> <div class="devfile-selector-item-icon">
<img ng-src="{{devfile.icon}}"/> <img img-src="{{devfile.icon}}"
</div> img-src-onload="devfileSelectorController.iconOnLoad(devfile.icon, $result)"
<div ng-if="!devfile.icon" class="devfile-selector-item-icon blank-icon"> ng-show="devfileSelectorController.showIcon(devfile.icon)===true">
<div class="chefont cheico-type-blank"></div> <div class="chefont cheico-type-blank"
ng-show="devfileSelectorController.showIcon(devfile.icon)===false"></div>
</div> </div>
</div> </div>
<!-- Name --> <!-- Name -->
...@@ -57,8 +58,8 @@ ...@@ -57,8 +58,8 @@
<div flex="50"> <div flex="50">
<span class="che-list-item-secondary" devfile-description="{{devfile.description}}">{{devfile.description}}</span> <span class="che-list-item-secondary" devfile-description="{{devfile.description}}">{{devfile.description}}</span>
</div> </div>
<!-- Memory --> <!-- Memory -->
<div flex="10"> <div flex="10">
<span class="che-list-item-secondary" devfile-memory="{{devfile.globalMemoryLimit}}">{{devfile.globalMemoryLimit}}</span> <span class="che-list-item-secondary" devfile-memory="{{devfile.globalMemoryLimit}}">{{devfile.globalMemoryLimit}}</span>
</div> </div>
</div> </div>
......
...@@ -11,9 +11,17 @@ ...@@ -11,9 +11,17 @@
*/ */
'use strict'; 'use strict';
export type ImgSrcOnloadResult = {
loaded: boolean;
};
/** /**
* Fetches images using the $http service. * Fetches images using the $http service.
* *
* @usage
* <img img-src="ctrl.imageSrc"
* img-src-onload="ctrl.onImageLoad($result)">
*
* @author Oleksii Kurinnyi * @author Oleksii Kurinnyi
*/ */
export class ImgSrc implements ng.IDirective { export class ImgSrc implements ng.IDirective {
...@@ -34,6 +42,13 @@ export class ImgSrc implements ng.IDirective { ...@@ -34,6 +42,13 @@ export class ImgSrc implements ng.IDirective {
} }
link($scope: ng.IScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes): void { link($scope: ng.IScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes): void {
const onload = (loaded: boolean) => {
if (!$attrs.imgSrcOnload) {
return;
}
$scope.$eval($attrs.imgSrcOnload, { $result: { loaded } });
};
$attrs.$observe('imgSrc', (url: string) => { $attrs.$observe('imgSrc', (url: string) => {
if (this.isDev) { if (this.isDev) {
url = url.replace(/https?:\/\/[^\/]+/, ''); url = url.replace(/https?:\/\/[^\/]+/, '');
...@@ -44,9 +59,12 @@ export class ImgSrc implements ng.IDirective { ...@@ -44,9 +59,12 @@ export class ImgSrc implements ng.IDirective {
url: url, url: url,
cache: 'true' cache: 'true'
}; };
this.$http(requestConfig).then((response: any) => { this.$http<string>(requestConfig).then((response: ng.IHttpResponse<string>) => {
const blob = new Blob([response.data], {type: response.headers('Content-Type')}); const blob = new Blob([response.data], {type: response.headers('Content-Type')});
$attrs.$set('src', (window.URL || (window as any).webkitURL).createObjectURL(blob)); $attrs.$set('src', (window.URL || (window as any).webkitURL).createObjectURL(blob));
onload(true);
}, () => {
onload(false);
}); });
}); });
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment