From 8fa2b8cb5f582ad8766f2ecd2296e1b567134bb0 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Wed, 28 Dec 2022 15:00:56 +0100 Subject: [PATCH] Add sorting options --- src/app/pages/admin/admin.component.html | 9 +++++++- src/app/pages/admin/admin.component.ts | 28 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/app/pages/admin/admin.component.html b/src/app/pages/admin/admin.component.html index b038023..4f0bd67 100644 --- a/src/app/pages/admin/admin.component.html +++ b/src/app/pages/admin/admin.component.html @@ -17,10 +17,17 @@   |   Filter: +   |   + Sorting: + diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index 2990e21..372287b 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -15,7 +15,8 @@ export class AdminComponent implements OnInit { selectedCalendar: string = ''; password: string = ''; name: string = ''; - eventFilter: string = ''; + eventFilter: string = 'all'; + eventSorting: string = 'start_asc'; constructor( private api: ApiService @@ -46,9 +47,10 @@ export class AdminComponent implements OnInit { startDateTime: new Date(event.startDateTime), endDateTime: new Date(event.endDateTime), createdDate: new Date(event.createdDate) - }) + }); } - }) + this.sortEvents(); + }); } login(): void { @@ -101,4 +103,24 @@ export class AdminComponent implements OnInit { getUserName(): string { return UtilsService.getNameFromLocalStorage(); } + + sortEvents(): void { + this.events.sort((a,b) => { + switch (this.eventSorting) { + case '': + return 1; + case 'start_asc': + return a.startDateTime > b.startDateTime ? 1 : -1; + case 'start_desc': + return a.startDateTime > b.startDateTime ? -1 : 1; + case 'created_asc': + return a.createdDate > b.createdDate ? 1 : -1; + case 'created_desc': + return a.createdDate > b.createdDate ? -1 : 1; + default: + return 1; + } + return 1; + }) + } }