Claude init file + div. improvements
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {ApiService} from '../../services/api.service';
|
||||
import {UtilsService} from '../../services/utils.service';
|
||||
import {Event} from '../../models/event';
|
||||
@@ -10,7 +12,9 @@ import {User} from '../../models/user';
|
||||
templateUrl: './admin.component.html',
|
||||
styleUrls: ['./admin.component.css']
|
||||
})
|
||||
export class AdminComponent implements OnInit {
|
||||
export class AdminComponent implements OnInit, OnDestroy {
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
isLoggedIn: boolean = false;
|
||||
events: Event[] = [];
|
||||
@@ -32,7 +36,7 @@ export class AdminComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
if (UtilsService.getSessionInfoFromLocalStorage().sessionId !== -1) {
|
||||
this.api.checkSession(UtilsService.getSessionInfoFromLocalStorage()).subscribe((user: User) => {
|
||||
this.api.checkSession(UtilsService.getSessionInfoFromLocalStorage()).pipe(takeUntil(this.destroy$)).subscribe((user: User) => {
|
||||
if(user.userId != null && user.userId !== -1) {
|
||||
this.isLoggedIn = true;
|
||||
this.name = user.fullName;
|
||||
@@ -43,6 +47,11 @@ export class AdminComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
getEvents(): void {
|
||||
this.events = [];
|
||||
|
||||
@@ -50,7 +59,7 @@ export class AdminComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
this.api.getEvents(this.selectedCalendar).subscribe((events: Event[]): void => {
|
||||
this.api.getEvents(this.selectedCalendar).pipe(takeUntil(this.destroy$)).subscribe((events: Event[]): void => {
|
||||
for (let event of events) {
|
||||
if(event.status !== 'DELETED') {
|
||||
this.events.push({
|
||||
@@ -119,6 +128,7 @@ export class AdminComponent implements OnInit {
|
||||
dayOnlyDate.setFullYear(date.getFullYear());
|
||||
dayOnlyDate.setMonth(date.getMonth());
|
||||
dayOnlyDate.setDate(date.getDate());
|
||||
dayOnlyDate.setHours(0, 0, 0, 0);
|
||||
|
||||
return dayOnlyDate;
|
||||
}
|
||||
@@ -147,39 +157,39 @@ export class AdminComponent implements OnInit {
|
||||
}
|
||||
|
||||
login(): void {
|
||||
this.api.login(this.email, this.password).subscribe((session: Session): void => {
|
||||
this.api.login(this.email, this.password).pipe(takeUntil(this.destroy$)).subscribe((session: Session): void => {
|
||||
if(session.sessionId != null && session.sessionId !== -1) {
|
||||
UtilsService.saveSessionInfoToLocalStorage(session.sessionId, session.sessionKey);
|
||||
|
||||
// Get user info
|
||||
this.api.checkSession(UtilsService.getSessionInfoFromLocalStorage()).subscribe((user: User) => {
|
||||
this.api.checkSession(UtilsService.getSessionInfoFromLocalStorage()).pipe(takeUntil(this.destroy$)).subscribe((user: User) => {
|
||||
if(user.userId != null && user.userId !== -1) {
|
||||
this.isLoggedIn = true;
|
||||
this.name = user.fullName;
|
||||
this.isActive = user.isActive;
|
||||
this.getEvents();
|
||||
} else {
|
||||
confirm('Login unsuccessful. Please check if you provided the correct username and password.');
|
||||
alert('Login unsuccessful. Please check if you provided the correct username and password.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}, (error) => {
|
||||
confirm('Login unsuccessful. Reported problem from server: ' + error.error.message);
|
||||
alert('Login unsuccessful. Reported problem from server: ' + error?.error?.message);
|
||||
});
|
||||
}
|
||||
|
||||
register(): void {
|
||||
this.api.register(this.registerEmail, this.name, this.registerPassword).subscribe((session: Session): void => {
|
||||
this.api.register(this.registerEmail, this.name, this.registerPassword).pipe(takeUntil(this.destroy$)).subscribe((session: Session): void => {
|
||||
if(session.sessionId != null && session.sessionId !== -1) {
|
||||
UtilsService.saveSessionInfoToLocalStorage(session.sessionId, session.sessionKey);
|
||||
this.isLoggedIn = true;
|
||||
this.getEvents();
|
||||
confirm('An email was sent to your Nachklang address. Please click the link in the email to activate your account. You can\'t use this application before the activation.');
|
||||
alert('An email was sent to your Nachklang address. Please click the link in the email to activate your account. You can\'t use this application before the activation.');
|
||||
} else {
|
||||
confirm('Regisistration unsuccessful. Please contact Patrick.');
|
||||
alert('Registration unsuccessful. Please contact Patrick.');
|
||||
}
|
||||
}, (error) => {
|
||||
confirm('Login unsuccessful. Reported problem from server: ' + error.error.message);
|
||||
alert('Registration unsuccessful. Reported problem from server: ' + error?.error?.message);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user