#601 support for fallback thumbnails

This commit is contained in:
Denys Vuika
2016-08-25 12:49:36 +01:00
parent bec481e81e
commit 2d8d31aed4
5 changed files with 41 additions and 2 deletions

View File

@@ -47,7 +47,11 @@
[context-menu]="getContextMenuActions(row, col)">
<div *ngSwitchCase="'image'" class="cell-value">
<i *ngIf="isIconValue(row, col)" class="material-icons icon-cell">{{asIconValue(row, col)}}</i>
<img *ngIf="!isIconValue(row, col)" class="image-cell" alt="{{iconAltTextKey(data.getValue(row, col))|translate}}" src="{{data.getValue(row, col)}}">
<img *ngIf="!isIconValue(row, col)"
class="image-cell"
alt="{{iconAltTextKey(data.getValue(row, col))|translate}}"
src="{{data.getValue(row, col)}}"
(error)="onImageLoadingError($event)">
</div>
<div *ngSwitchCase="'date'" class="cell-value" [attr.data-automation-id]="'date_' + data.getValue(row, col)">
{{data.getValue(row, col)}}

View File

@@ -320,4 +320,29 @@ describe('DataTable', () => {
expect(dataTable.isColumnSorted(<DataColumn> {key: 'column_1'}, 'asc')).toBeTruthy();
expect(dataTable.isColumnSorted(<DataColumn> {key: 'column_2'}, 'desc')).toBeFalsy();
});
it('should replace image source with fallback thumbnail on error', () => {
let event = <any> {
srcElement: {
src: 'missing-image'
}
};
dataTable.fallbackThumbnail = '<fallback>';
dataTable.onImageLoadingError(event);
expect(event.srcElement.src).toBe(dataTable.fallbackThumbnail);
});
it('should replace image source only when fallback available', () => {
const originalSrc = 'missing-image';
let event = <any> {
srcElement: {
src: originalSrc
}
};
dataTable.fallbackThumbnail = null;
dataTable.onImageLoadingError(event);
expect(event.srcElement.src).toBe(originalSrc);
});
});

View File

@@ -63,6 +63,9 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
@Input()
actions: boolean = false;
@Input()
fallbackThumbnail: string;
@Output()
rowClick: EventEmitter<DataRowEvent> = new EventEmitter<DataRowEvent>();
@@ -155,6 +158,12 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
}
}
onImageLoadingError(event: Event) {
if (event && this.fallbackThumbnail) {
event.srcElement.src = this.fallbackThumbnail;
}
}
isIconValue(row: DataRow, col: DataColumn) {
if (row && col) {
let value = row.getValue(col.key);