argos/dmp-frontend/src/app/ui/navbar/user-dialog/user-dialog.component.ts

65 lines
1.6 KiB
TypeScript

import { Component, Inject, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { AuthService } from '../../../core/services/auth/auth.service';
@Component({
selector: 'app-user-dialog-component',
templateUrl: 'user-dialog.component.html',
styleUrls: ['user-dialog.component.scss']
})
export class UserDialogComponent implements OnInit {
public formGroup: UntypedFormGroup;
constructor(
private authentication: AuthService,
private router: Router,
public dialogRef: MatDialogRef<UserDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) { }
ngOnInit(): void {
}
public logout(): void {
this.dialogRef.close();
this.router.navigate(['/logout']);
}
public getPrincipalName(): string {
return this.authentication.getPrincipalName() ?? '';
}
public getPrincipalEmail(): string {
return this.authentication.getUserProfileEmail() ?? '';
}
public principalHasAvatar(): boolean {
return this.authentication.getUserProfileAvatarUrl() && this.authentication.getUserProfileAvatarUrl().length > 0;
}
public getPrincipalAvatar(): string {
return this.authentication.getUserProfileAvatarUrl();
}
public getDefaultAvatar(): string {
return 'assets/images/profile-placeholder.png';
}
public applyFallbackAvatar(ev: Event) {
(ev.target as HTMLImageElement).src = this.getDefaultAvatar();
}
public navigateToProfile() {
this.dialogRef.close();
this.router.navigate(['/profile']);
}
public navigateToMyDmps() {
this.dialogRef.close();
this.router.navigate(['/plans']);
}
}