mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-1404] Data Column enhancements for Document List (#2220)
* support 'timeAgo' format for data-column * file size column type and bug fixes * readme updates * location column type * readme fixes * update unit tests * file size pipe tests
This commit is contained in:
committed by
Mario Romano
parent
9e5b19e34c
commit
06e03ad1e9
@@ -17,7 +17,7 @@
|
||||
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { MinimalNode, MinimalNodeEntity, NodePaging } from 'alfresco-js-api';
|
||||
import { ObjectUtils } from 'ng2-alfresco-core';
|
||||
import { ObjectUtils, TimeAgoPipe } from 'ng2-alfresco-core';
|
||||
import { DataColumn, DataRow, DataSorting, DataTableAdapter } from 'ng2-alfresco-datatable';
|
||||
import { PermissionStyleModel } from './../models/permissions-style.model';
|
||||
import { DocumentListService } from './../services/document-list.service';
|
||||
@@ -27,8 +27,6 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
||||
ERR_ROW_NOT_FOUND: string = 'Row not found';
|
||||
ERR_COL_NOT_FOUND: string = 'Column not found';
|
||||
|
||||
DEFAULT_DATE_FORMAT: string = 'medium';
|
||||
|
||||
private sorting: DataSorting;
|
||||
private rows: DataRow[];
|
||||
private columns: DataColumn[];
|
||||
@@ -81,13 +79,11 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
||||
}
|
||||
|
||||
if (col.type === 'date') {
|
||||
let datePipe = new DatePipe('en-US');
|
||||
let format = col.format || this.DEFAULT_DATE_FORMAT;
|
||||
try {
|
||||
let result = datePipe.transform(value, format);
|
||||
const result = this.formatDate(col, value);
|
||||
return dataRow.cacheValue(col.key, result);
|
||||
} catch (err) {
|
||||
console.error(`Error parsing date ${value} to format ${format}`);
|
||||
console.error(`Error parsing date ${value} to format ${col.format}`);
|
||||
return 'Error';
|
||||
}
|
||||
}
|
||||
@@ -129,6 +125,21 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
||||
return dataRow.cacheValue(col.key, value);
|
||||
}
|
||||
|
||||
formatDate(col: DataColumn, value: any): string {
|
||||
if (col.type === 'date') {
|
||||
const format = col.format || 'medium';
|
||||
if (format === 'timeAgo') {
|
||||
const timeAgoPipe = new TimeAgoPipe();
|
||||
return timeAgoPipe.transform(value);
|
||||
} else {
|
||||
const datePipe = new DatePipe('en-US');
|
||||
return datePipe.transform(value, format);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
getSorting(): DataSorting {
|
||||
return this.sorting;
|
||||
}
|
||||
|
Reference in New Issue
Block a user