2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2018-08-24 17:21:02 +02:00
|
|
|
import { FormGroup } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { Router } from '@angular/router';
|
2020-04-27 15:21:03 +02:00
|
|
|
import { Principal } from '../../../../core/model/auth/principal';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
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
|
|
|
})
|
|
|
|
export class UserDialogComponent implements OnInit {
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public formGroup: FormGroup;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
}
|
|
|
|
|
|
|
|
public logout(): void {
|
|
|
|
this.dialogRef.close();
|
|
|
|
this.authentication.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalName(): string {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) { return principal.name; }
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public principalHasAvatar(): boolean {
|
2019-11-22 17:28:20 +01:00
|
|
|
return this.authentication.current() && this.authentication.current().avatarUrl != null && this.authentication.current().avatarUrl.length > 0;
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalAvatar(): string {
|
|
|
|
return this.authentication.current() && this.authentication.current().avatarUrl;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|