[SI-1836(US), SI-2714, SI-2713] - Add last modification date below the table
Signed-off-by: dtheinert <dietmar.theinert@pta.de>
diff --git a/projects/grid-failure-information-table-app/src/app/app.component.html b/projects/grid-failure-information-table-app/src/app/app.component.html
index d573aec..58d06c1 100644
--- a/projects/grid-failure-information-table-app/src/app/app.component.html
+++ b/projects/grid-failure-information-table-app/src/app/app.component.html
@@ -23,3 +23,4 @@
>
</ag-grid-angular>
<app-spinner [isRunning]="!(gridFailures)"></app-spinner>
+<div id="grid-failure-information-table-app-lastChange">Letzte Änderung: {{lastModDate}}</div>
diff --git a/projects/grid-failure-information-table-app/src/app/app.component.spec.ts b/projects/grid-failure-information-table-app/src/app/app.component.spec.ts
index c0c0e99..a9d8473 100644
--- a/projects/grid-failure-information-table-app/src/app/app.component.spec.ts
+++ b/projects/grid-failure-information-table-app/src/app/app.component.spec.ts
@@ -22,10 +22,13 @@
beforeEach(() => {
service = {
- loadGridFailureData: () => of(true)
+ loadGridFailureData: () => of(true),
} as any;
- gridFailureMapListAll = [new GridFailure({ postcode: '007' }), new GridFailure({ postcode: '4711' }), new GridFailure({ postcode: '0815' })];
- component = new TableComponent(service);
+ gridFailureMapListAll = [
+ new GridFailure({ postcode: '007', modDate: '2020-08-13T13:35:44.808Z' }),
+ new GridFailure({ postcode: '4711', modDate: '2020-08-14T13:35:44.808Z' }),
+ new GridFailure({ postcode: '0815', modDate: '2019-08-13T13:35:44.808Z' })];
+ component = new TableComponent(service, null);
(component as any)._gridFailuresAll = gridFailureMapListAll;
component.gridFailures = gridFailureMapListAll.map(i => Object.assign(i));
});
@@ -44,6 +47,7 @@
let sortModel;
let params = { api: { setSortModel: sortModel = {} } };
component['_gridApi'] = params.api;
+ component['_datePipe'] = {transform: () => '18.09.2020 / 10:17'} as any;
const spy: any = spyOn(component['_gridApi'], 'setSortModel');
component.onGridReady(params);
expect(spy).toHaveBeenCalled();
@@ -59,4 +63,9 @@
expect(component.gridFailures.length).toEqual(1);
expect(component.gridFailures[0].postcode).toEqual('007');
});
+
+ it('should get the last modDate of the GridFailure array after "_getLastModeDate"', () => {
+ const lastTimeStamp = (component as any)._getLastModeDate();
+ expect(lastTimeStamp).toEqual(1597412144808); // == '2020-08-14T13:35:44.808Z'
+ });
});
diff --git a/projects/grid-failure-information-table-app/src/app/app.component.ts b/projects/grid-failure-information-table-app/src/app/app.component.ts
index 927f011..ef48275 100644
--- a/projects/grid-failure-information-table-app/src/app/app.component.ts
+++ b/projects/grid-failure-information-table-app/src/app/app.component.ts
@@ -17,6 +17,7 @@
import { GridOptions } from 'ag-grid-community';
import { Globals } from '@grid-failure-information-app/shared/constants/globals';
import { Subscription } from 'rxjs';
+import { DatePipe } from '@angular/common';
@Component({
selector: 'app-root',
@@ -30,12 +31,13 @@
public gridOptions: GridOptions;
public noRowsTemplate: string;
public gridFailures: GridFailure[];
+ public lastModDate: string;
private _gridApi;
private _gridFailuresAll: GridFailure[];
private _subscription: Subscription;
- constructor(private _appTableService: AppTableService) {
+ constructor(private _appTableService: AppTableService, private _datePipe: DatePipe) {
this.defaultColDef = {
sortable: true,
suppressMovable: true,
@@ -62,9 +64,16 @@
this._gridApi = params.api;
const sortModel = [{ colId: 'failureBegin', sort: 'desc' }];
this._gridApi.setSortModel(sortModel);
+ this.lastModDate = this._datePipe.transform(this._getLastModeDate(), Globals.DATE_TIME_FORMAT);
}
ngOnDestroy(): void {
this._subscription.unsubscribe();
}
+
+ private _getLastModeDate(): number{
+ let modeDates:number[] = this.gridFailures.map(gf => Date.parse(gf.modDate));
+ modeDates = modeDates.sort((a,b) => b-a); // sort timestamps descending
+ return modeDates[0];
+ }
}
diff --git a/projects/grid-failure-information-table-app/src/app/app.module.ts b/projects/grid-failure-information-table-app/src/app/app.module.ts
index e2c2e1f..656322a 100644
--- a/projects/grid-failure-information-table-app/src/app/app.module.ts
+++ b/projects/grid-failure-information-table-app/src/app/app.module.ts
@@ -18,8 +18,9 @@
import { HttpClientModule } from '@angular/common/http';
import { AgGridModule } from 'ag-grid-angular';
import { PublicApiModule } from '@grid-failure-information-app/app/public-api.module';
+import { DatePipe } from '@angular/common';
-const providers =[AppTableService];
+const providers =[AppTableService, DatePipe];
@NgModule({
declarations: [TableComponent],