2017-12-14 11:41:26 +01:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { Principal } from '../../../models/login/Principal';
|
|
|
|
import { AuthService } from '../../../services/auth/auth.service';
|
2018-03-28 15:24:47 +02:00
|
|
|
import { LanguageResolverService } from '../../../services/language-resolver/language-resolver.service';
|
2017-12-14 11:41:26 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-05-28 11:50:42 +02:00
|
|
|
selector: 'app-navigation',
|
|
|
|
templateUrl: 'navigation.component.html',
|
|
|
|
styleUrls: ['./navigation.component.css'],
|
2017-12-14 11:41:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
export class NavigationComponent {
|
2018-05-28 11:50:42 +02:00
|
|
|
invert = false;
|
|
|
|
|
|
|
|
constructor(private authentication: AuthService, private languageResolver: LanguageResolverService) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public logout(): void {
|
|
|
|
this.authentication.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return !(!this.authentication.current())
|
|
|
|
}
|
|
|
|
|
|
|
|
public isAdmin(): boolean {
|
|
|
|
if (!this.authentication.current()) { return false }
|
|
|
|
const principalRoles = this.authentication.current().appRoles;
|
|
|
|
for (let i = 0; i < principalRoles.length; i++) {
|
|
|
|
if (principalRoles[i] === Principal.AppRole.Admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalName(): string {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) { return principal.name; }
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public principalHasAvatar(): boolean {
|
|
|
|
return this.authentication.current().avatarUrl != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalAvatar(): string {
|
|
|
|
return this.authentication.current().avatarUrl;
|
|
|
|
}
|
2017-12-14 11:41:26 +01:00
|
|
|
}
|