More performant implementation of event filter
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-12-28 15:27:31 +01:00
parent bafc56d604
commit 754408dfa3
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE

View File

@ -33,15 +33,12 @@ export class AdminComponent implements OnInit {
getEvents(): void { getEvents(): void {
this.events = []; this.events = [];
if(this.selectedCalendar === '') { if (this.selectedCalendar === '') {
return; return;
} }
this.api.getEvents(this.selectedCalendar).subscribe((events: Event[]): void => { this.api.getEvents(this.selectedCalendar).subscribe((events: Event[]): void => {
for(let event of events) { for (let event of events) {
if(!this.checkEventMeetsFilterCriteria(event)) {
continue;
}
this.events.push({ this.events.push({
...event, ...event,
startDateTime: new Date(event.startDateTime), startDateTime: new Date(event.startDateTime),
@ -49,6 +46,7 @@ export class AdminComponent implements OnInit {
createdDate: new Date(event.createdDate) createdDate: new Date(event.createdDate)
}); });
} }
this.filterEvents();
this.sortEvents(); this.sortEvents();
}); });
} }
@ -64,7 +62,7 @@ export class AdminComponent implements OnInit {
} }
getCalendarId(text: string): number { getCalendarId(text: string): number {
switch(text) { switch (text) {
case 'public': case 'public':
return 1; return 1;
case 'members': case 'members':
@ -76,6 +74,12 @@ export class AdminComponent implements OnInit {
} }
} }
filterEvents() {
this.events = this.events.filter((event) => {
return this.checkEventMeetsFilterCriteria(event);
});
}
checkEventMeetsFilterCriteria(event: Event): boolean { checkEventMeetsFilterCriteria(event: Event): boolean {
switch (this.eventFilter) { switch (this.eventFilter) {
case '': case '':
@ -105,7 +109,7 @@ export class AdminComponent implements OnInit {
} }
sortEvents(): void { sortEvents(): void {
this.events.sort((a,b) => { this.events.sort((a, b) => {
switch (this.eventSorting) { switch (this.eventSorting) {
case '': case '':
return 1; return 1;
@ -121,6 +125,6 @@ export class AdminComponent implements OnInit {
return 1; return 1;
} }
return 1; return 1;
}) });
} }
} }