Add first version of admin table with basic edit capabilities

This commit is contained in:
2022-12-25 21:24:17 +01:00
parent 6822bb8a04
commit c80312de9d
12 changed files with 230 additions and 15 deletions
+14 -1
View File
@@ -1 +1,14 @@
<p>admin works!</p>
<div *ngIf="!isLoggedIn">
<p>Please log in:</p>
<input type="password" aria-label="Password" (keyup.enter)="login()" [(ngModel)]="password">
<input type="text" aria-label="Your Name" (keyup.enter)="login()" [(ngModel)]="name">
</div>
<div *ngIf="isLoggedIn">
<select [(ngModel)]="selectedCalendar" (change)="getEvents()">
<option value="" disabled selected hidden>Select calendar</option>
<option>public</option>
<option>members</option>
<option>management</option>
</select>
<app-events-table [events]="this.events"></app-events-table>
</div>
+37 -1
View File
@@ -1,4 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {ApiService} from '../../services/api.service';
import {UtilsService} from '../../services/utils.service';
import {Event} from '../../models/event';
@Component({
selector: 'app-admin',
@@ -7,10 +10,43 @@ import {Component, OnInit} from '@angular/core';
})
export class AdminComponent implements OnInit {
constructor() {
isLoggedIn: boolean = false;
events: Event[] = [];
selectedCalendar: string = '';
password: string = '';
name: string = '';
constructor(
private api: ApiService
) {
}
ngOnInit(): void {
if (UtilsService.getPasswordFromLocalStorage() !== '') {
this.isLoggedIn = true;
this.getEvents();
}
}
getEvents(): void {
if(this.selectedCalendar === '') {
return;
}
this.api.getEvents(this.selectedCalendar).subscribe((events: Event[]): void => {
events.forEach((event: Event) => {
this.events.push({
...event,
startDateTime: new Date(event.startDateTime),
endDateTime: new Date(event.endDateTime),
createdDate: new Date(event.createdDate)
})
})
})
}
login(): void {
UtilsService.saveUserInfoToLocalStorage(this.password, this.name);
this.isLoggedIn = true;
this.getEvents();
}
}