mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Merge pull request #618 from Alfresco/dev-denys-601
#601 support for fallback thumbnails
This commit is contained in:
commit
a71c1fa861
@ -47,7 +47,11 @@
|
|||||||
[context-menu]="getContextMenuActions(row, col)">
|
[context-menu]="getContextMenuActions(row, col)">
|
||||||
<div *ngSwitchCase="'image'" class="cell-value">
|
<div *ngSwitchCase="'image'" class="cell-value">
|
||||||
<i *ngIf="isIconValue(row, col)" class="material-icons icon-cell">{{asIconValue(row, col)}}</i>
|
<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>
|
||||||
<div *ngSwitchCase="'date'" class="cell-value" [attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
<div *ngSwitchCase="'date'" class="cell-value" [attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
||||||
{{data.getValue(row, col)}}
|
{{data.getValue(row, col)}}
|
||||||
|
@ -320,4 +320,29 @@ describe('DataTable', () => {
|
|||||||
expect(dataTable.isColumnSorted(<DataColumn> {key: 'column_1'}, 'asc')).toBeTruthy();
|
expect(dataTable.isColumnSorted(<DataColumn> {key: 'column_1'}, 'asc')).toBeTruthy();
|
||||||
expect(dataTable.isColumnSorted(<DataColumn> {key: 'column_2'}, 'desc')).toBeFalsy();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -63,6 +63,9 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
|
|||||||
@Input()
|
@Input()
|
||||||
actions: boolean = false;
|
actions: boolean = false;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
fallbackThumbnail: string;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
rowClick: EventEmitter<DataRowEvent> = new EventEmitter<DataRowEvent>();
|
rowClick: EventEmitter<DataRowEvent> = new EventEmitter<DataRowEvent>();
|
||||||
|
|
||||||
@ -155,6 +158,13 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onImageLoadingError(event: Event) {
|
||||||
|
if (event && this.fallbackThumbnail) {
|
||||||
|
let element = <any> event.srcElement;
|
||||||
|
element.src = this.fallbackThumbnail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isIconValue(row: DataRow, col: DataColumn) {
|
isIconValue(row: DataRow, col: DataColumn) {
|
||||||
if (row && col) {
|
if (row && col) {
|
||||||
let value = row.getValue(col.key);
|
let value = row.getValue(col.key);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
[data]="data"
|
[data]="data"
|
||||||
[actions]="contentActions"
|
[actions]="contentActions"
|
||||||
[multiselect]="multiselect"
|
[multiselect]="multiselect"
|
||||||
|
[fallbackThumbnail]="baseComponentPath + '/img/ft_ic_miscellaneous.svg'"
|
||||||
(showRowContextMenu)="onShowRowContextMenu($event)"
|
(showRowContextMenu)="onShowRowContextMenu($event)"
|
||||||
(showRowActionsMenu)="onShowRowActionsMenu($event)"
|
(showRowActionsMenu)="onShowRowActionsMenu($event)"
|
||||||
(executeRowAction)="onExecuteRowAction($event)"
|
(executeRowAction)="onExecuteRowAction($event)"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user