Add sorting options
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-12-28 15:00:56 +01:00
parent 1990c9a42d
commit 8fa2b8cb5f
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
2 changed files with 33 additions and 4 deletions

View File

@ -17,10 +17,17 @@
<span>&nbsp; | &nbsp;</span>
<span>Filter: </span>
<select [(ngModel)]="eventFilter" (change)="getEvents()">
<option value="" disabled selected hidden>Select filter</option>
<option value="all">All Events</option>
<option value="future">Future Events only</option>
<option value="past">Past Events only</option>
</select>
<span>&nbsp; | &nbsp;</span>
<span>Sorting: </span>
<select [(ngModel)]="eventSorting" (change)="sortEvents()">
<option value="start_asc">Start Date - Ascending</option>
<option value="start_desc">Start Date - Descending</option>
<option value="created_asc">Created Date - Ascending</option>
<option value="created_desc">Created Date - Descending</option>
</select>
<app-events-table [events]="this.events" [selectedCalendar]="getCalendarId(selectedCalendar)"></app-events-table>
</div>

View File

@ -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;
})
}
}