mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[no-issue] error image resolver mimetype should not be part of datatable (#3415)
* move error image custom logic form datatable to documentlist * change travis * [fix-test-log] added optional function to data row interface * [no-issue] fixed datatable tests * [no-issue] fixing tests
This commit is contained in:
@@ -93,16 +93,17 @@
|
||||
<div *ngIf="!col.template" class="cell-container">
|
||||
<ng-container [ngSwitch]="col.type">
|
||||
<div *ngSwitchCase="'image'" class="cell-value">
|
||||
<mat-icon *ngIf="isIconValue(row, col); else no_iconvalue">{{ asIconValue(row, col) }}</mat-icon>
|
||||
<mat-icon *ngIf="isIconValue(row, col); else no_iconvalue">{{ asIconValue(row, col) }}
|
||||
</mat-icon>
|
||||
<ng-template #no_iconvalue>
|
||||
<mat-icon class="adf-datatable-selected"
|
||||
*ngIf="row.isSelected; else no_selected_row" svgIcon="selected">
|
||||
*ngIf="row.isSelected; else no_selected_row" svgIcon="selected">
|
||||
</mat-icon>
|
||||
<ng-template #no_selected_row>
|
||||
<img
|
||||
<img
|
||||
alt="{{ iconAltTextKey(data.getValue(row, col)) | translate }}"
|
||||
src="{{ data.getValue(row, col) }}"
|
||||
(error)="onImageLoadingError($event, row.obj.entry.content.mimeType)">
|
||||
(error)="onImageLoadingError($event, row)">
|
||||
</ng-template>
|
||||
</ng-template>
|
||||
</div>
|
||||
@@ -206,7 +207,7 @@
|
||||
<div *ngIf="loading"
|
||||
[class.adf-datatable-row]="display === 'list'"
|
||||
[class.adf-data-table-card-loading]="display === 'gallery'">
|
||||
<div class="adf-datatable-table-cell" >
|
||||
<div class="adf-datatable-table-cell">
|
||||
<ng-template *ngIf="loadingTemplate"
|
||||
ngFor [ngForOf]="[data]"
|
||||
[ngForTemplate]="loadingTemplate">
|
||||
|
@@ -29,7 +29,22 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { DataColumnListComponent } from '../../../data-column/data-column-list.component';
|
||||
import { DataColumnComponent } from '../../../data-column/data-column.component';
|
||||
|
||||
describe('DataTable', () => {
|
||||
class FakeDataRow implements DataRow {
|
||||
isDropTarget = false;
|
||||
isSelected = true;
|
||||
hasValue(key: any) {
|
||||
return true;
|
||||
}
|
||||
getValue() {
|
||||
return '1';
|
||||
}
|
||||
imageErrorResolver() {
|
||||
return './assets/images/ft_ic_miscellaneous.svg';
|
||||
}
|
||||
}
|
||||
|
||||
/*tslint:disable:ban*/
|
||||
fdescribe('DataTable', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
let dataTable: DataTableComponent;
|
||||
@@ -881,9 +896,9 @@ describe('DataTable', () => {
|
||||
src: 'missing-image'
|
||||
}
|
||||
};
|
||||
|
||||
const row = new FakeDataRow();
|
||||
dataTable.fallbackThumbnail = '<fallback>';
|
||||
dataTable.onImageLoadingError(event);
|
||||
dataTable.onImageLoadingError(event, row);
|
||||
expect(event.target.src).toBe(dataTable.fallbackThumbnail);
|
||||
});
|
||||
|
||||
@@ -894,23 +909,12 @@ describe('DataTable', () => {
|
||||
src: originalSrc
|
||||
}
|
||||
};
|
||||
|
||||
const row = new FakeDataRow();
|
||||
dataTable.fallbackThumbnail = null;
|
||||
dataTable.onImageLoadingError(event);
|
||||
dataTable.onImageLoadingError(event, row);
|
||||
expect(event.target.src).toBe('./assets/images/ft_ic_miscellaneous.svg' );
|
||||
});
|
||||
|
||||
it('should replace image source with icon if fallback is not available and mimeType is provided', () => {
|
||||
let event = <any> {
|
||||
target: {
|
||||
src: 'missing-image'
|
||||
}
|
||||
};
|
||||
|
||||
dataTable.onImageLoadingError(event, 'image/png');
|
||||
expect(event.target.src).toBe('./assets/images/ft_ic_raster_image.svg');
|
||||
});
|
||||
|
||||
it('should not get cell tooltip when row is not provided', () => {
|
||||
const col = <DataColumn> { key: 'name', type: 'text' };
|
||||
expect(dataTable.getCellTooltip(null, col)).toBeNull();
|
||||
|
@@ -27,7 +27,6 @@ import { DataRowEvent } from '../../data/data-row-event.model';
|
||||
import { DataRow } from '../../data/data-row.model';
|
||||
import { DataSorting } from '../../data/data-sorting.model';
|
||||
import { DataTableAdapter } from '../../data/datatable-adapter';
|
||||
import { ThumbnailService } from '../../../services/thumbnail.service';
|
||||
|
||||
import { ObjectDataRow } from '../../data/object-datarow.model';
|
||||
import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
|
||||
@@ -175,8 +174,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
private dataRowsChanged: Subscription;
|
||||
|
||||
constructor(private elementRef: ElementRef,
|
||||
differs: IterableDiffers,
|
||||
private thumbnailService?: ThumbnailService) {
|
||||
differs: IterableDiffers) {
|
||||
if (differs) {
|
||||
this.differ = differs.find([]).create(null);
|
||||
}
|
||||
@@ -511,15 +509,14 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
this.emitRowSelectionEvent(domEventName, row);
|
||||
}
|
||||
|
||||
onImageLoadingError(event: Event, mimeType?: string) {
|
||||
|
||||
onImageLoadingError(event: Event, row: DataRow) {
|
||||
if (event) {
|
||||
let element = <any> event.target;
|
||||
|
||||
if (this.fallbackThumbnail) {
|
||||
element.src = this.fallbackThumbnail;
|
||||
} else {
|
||||
element.src = this.thumbnailService.getMimeTypeIcon(mimeType);
|
||||
element.src = row.imageErrorResolver(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user