#7: Adding filters
Jenkins Production Deployment

This commit is contained in:
2022-12-28 14:10:39 +01:00
parent 85ffaea589
commit 1990c9a42d
2 changed files with 47 additions and 3 deletions
+37 -3
View File
@@ -15,6 +15,8 @@ export class AdminComponent implements OnInit {
selectedCalendar: string = '';
password: string = '';
name: string = '';
eventFilter: string = '';
constructor(
private api: ApiService
) {
@@ -28,19 +30,24 @@ export class AdminComponent implements OnInit {
}
getEvents(): void {
this.events = [];
if(this.selectedCalendar === '') {
return;
}
this.api.getEvents(this.selectedCalendar).subscribe((events: Event[]): void => {
events.forEach((event: Event) => {
for(let event of events) {
if(!this.checkEventMeetsFilterCriteria(event)) {
continue;
}
this.events.push({
...event,
startDateTime: new Date(event.startDateTime),
endDateTime: new Date(event.endDateTime),
createdDate: new Date(event.createdDate)
})
})
}
})
}
@@ -51,7 +58,6 @@ export class AdminComponent implements OnInit {
}
handleCalendarChange() {
this.events = [];
this.getEvents();
}
@@ -67,4 +73,32 @@ export class AdminComponent implements OnInit {
return -1;
}
}
checkEventMeetsFilterCriteria(event: Event): boolean {
switch (this.eventFilter) {
case '':
return true;
case 'all':
return true;
case 'future':
return this.reduceToDay(new Date(event.endDateTime)) >= this.reduceToDay(new Date());
case 'past':
return this.reduceToDay(new Date(event.endDateTime)) < this.reduceToDay(new Date());
default:
return true;
}
}
reduceToDay(date: Date): Date {
let dayOnlyDate: Date = new Date();
dayOnlyDate.setFullYear(date.getFullYear());
dayOnlyDate.setMonth(date.getMonth());
dayOnlyDate.setDate(date.getDate());
return dayOnlyDate;
}
getUserName(): string {
return UtilsService.getNameFromLocalStorage();
}
}