2024-04-01 15:05:57 +02:00
|
|
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
2023-10-05 15:39:17 +02:00
|
|
|
import { UntypedFormGroup } from '@angular/forms';
|
2023-10-06 10:10:53 +02:00
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { Router } from '@angular/router';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { AuthService } from '../../../core/services/auth/auth.service';
|
2024-04-01 15:05:57 +02:00
|
|
|
import { Observable, Subscription, fromEvent } from 'rxjs';
|
2018-08-24 17:21:02 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-user-dialog-component',
|
|
|
|
templateUrl: 'user-dialog.component.html',
|
2019-04-30 16:14:24 +02:00
|
|
|
styleUrls: ['user-dialog.component.scss']
|
2018-08-24 17:21:02 +02:00
|
|
|
})
|
2024-04-01 15:05:57 +02:00
|
|
|
export class UserDialogComponent implements OnInit, OnDestroy {
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2023-10-05 15:39:17 +02:00
|
|
|
public formGroup: UntypedFormGroup;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2024-04-01 15:05:57 +02:00
|
|
|
resizeObservable: Observable<Event>;
|
|
|
|
resizeSubscription: Subscription;
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
constructor(
|
|
|
|
private authentication: AuthService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private router: Router,
|
2018-10-05 17:00:54 +02:00
|
|
|
public dialogRef: MatDialogRef<UserDialogComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2024-04-01 15:05:57 +02:00
|
|
|
this.resizeObservable = fromEvent(window, 'resize');
|
|
|
|
this.resizeSubscription = this.resizeObservable
|
|
|
|
.subscribe(evt =>{
|
|
|
|
this.dialogRef.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.resizeSubscription.unsubscribe();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public logout(): void {
|
|
|
|
this.dialogRef.close();
|
2023-10-11 16:53:12 +02:00
|
|
|
this.router.navigate(['/logout']);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalName(): string {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.getPrincipalName() ?? '';
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 12:42:39 +02:00
|
|
|
public getPrincipalEmail(): string {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.getUserProfileEmail() ?? '';
|
2020-07-17 12:42:39 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public principalHasAvatar(): boolean {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.getUserProfileAvatarUrl() && this.authentication.getUserProfileAvatarUrl().length > 0;
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:28:20 +01:00
|
|
|
public getDefaultAvatar(): string {
|
|
|
|
return 'assets/images/profile-placeholder.png';
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:39:33 +01:00
|
|
|
public applyFallbackAvatar(ev: Event) {
|
|
|
|
(ev.target as HTMLImageElement).src = this.getDefaultAvatar();
|
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public navigateToProfile() {
|
|
|
|
this.dialogRef.close();
|
2019-01-21 12:14:20 +01:00
|
|
|
this.router.navigate(['/profile']);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2020-07-14 11:47:57 +02:00
|
|
|
|
|
|
|
public navigateToMyDmps() {
|
|
|
|
this.dialogRef.close();
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
2018-08-24 17:21:02 +02:00
|
|
|
}
|