This commit is contained in:
		
							parent
							
								
									85ffaea589
								
							
						
					
					
						commit
						1990c9a42d
					
				|  | @ -6,11 +6,21 @@ | ||||||
| 	<input id="name" type="text" aria-label="Your Name" (keyup.enter)="login()" [(ngModel)]="name"> | 	<input id="name" type="text" aria-label="Your Name" (keyup.enter)="login()" [(ngModel)]="name"> | ||||||
| </div> | </div> | ||||||
| <div *ngIf="isLoggedIn"> | <div *ngIf="isLoggedIn"> | ||||||
|  | 	<span>Logged in as {{getUserName()}}  |  </span> | ||||||
|  | 	<span>Calendar: </span> | ||||||
| 	<select [(ngModel)]="selectedCalendar" (change)="handleCalendarChange()"> | 	<select [(ngModel)]="selectedCalendar" (change)="handleCalendarChange()"> | ||||||
| 		<option value="" disabled selected hidden>Select calendar</option> | 		<option value="" disabled selected hidden>Select calendar</option> | ||||||
| 		<option>public</option> | 		<option>public</option> | ||||||
| 		<option>members</option> | 		<option>members</option> | ||||||
| 		<option>management</option> | 		<option>management</option> | ||||||
| 	</select> | 	</select> | ||||||
|  | 	<span>  |  </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> | ||||||
| 	<app-events-table [events]="this.events" [selectedCalendar]="getCalendarId(selectedCalendar)"></app-events-table> | 	<app-events-table [events]="this.events" [selectedCalendar]="getCalendarId(selectedCalendar)"></app-events-table> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
|  | @ -15,6 +15,8 @@ export class AdminComponent implements OnInit { | ||||||
| 	selectedCalendar: string = ''; | 	selectedCalendar: string = ''; | ||||||
| 	password: string = ''; | 	password: string = ''; | ||||||
| 	name: string = ''; | 	name: string = ''; | ||||||
|  | 	eventFilter: string = ''; | ||||||
|  | 
 | ||||||
| 	constructor( | 	constructor( | ||||||
| 		private api: ApiService | 		private api: ApiService | ||||||
| 	) { | 	) { | ||||||
|  | @ -28,19 +30,24 @@ export class AdminComponent implements OnInit { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	getEvents(): void { | 	getEvents(): void { | ||||||
|  | 		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 => { | ||||||
| 			events.forEach((event: Event) => { | 			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), | ||||||
| 					endDateTime: new Date(event.endDateTime), | 					endDateTime: new Date(event.endDateTime), | ||||||
| 					createdDate: new Date(event.createdDate) | 					createdDate: new Date(event.createdDate) | ||||||
| 				}) | 				}) | ||||||
| 			}) | 			} | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -51,7 +58,6 @@ export class AdminComponent implements OnInit { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	handleCalendarChange() { | 	handleCalendarChange() { | ||||||
| 		this.events = []; |  | ||||||
| 		this.getEvents(); | 		this.getEvents(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -67,4 +73,32 @@ export class AdminComponent implements OnInit { | ||||||
| 				return -1; | 				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(); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user