67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { sample } from 'rxjs/operators';
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
import { Principal } from '../../../models/login/Principal';
|
|
import { AuthService } from '../../../services/auth/auth.service';
|
|
import { LanguageResolverService } from '../../../services/language-resolver/language-resolver.service';
|
|
|
|
@Component({
|
|
selector: 'app-navigation',
|
|
templateUrl: 'navigation.component.html',
|
|
styleUrls: ['./navigation.component.css'],
|
|
})
|
|
|
|
export class NavigationComponent {
|
|
invert = false;
|
|
|
|
constructor(private authentication: AuthService, private languageResolver: LanguageResolverService) {
|
|
|
|
}
|
|
|
|
public logout(): void {
|
|
this.authentication.logout();
|
|
}
|
|
|
|
public isAuthenticated(): boolean {
|
|
return !(!this.authentication.current())
|
|
}
|
|
|
|
@Input()
|
|
sidenavOpen = false;
|
|
|
|
@Output()
|
|
sidenavOpenChanges = new EventEmitter();
|
|
|
|
events: string[] = [];
|
|
opened: boolean;
|
|
|
|
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;
|
|
}
|
|
|
|
onSideNavClick() {
|
|
this.sidenavOpen = !this.sidenavOpen;
|
|
this.sidenavOpenChanges.emit(this.sidenavOpen);
|
|
}
|
|
}
|