2018-06-29 10:29:43 +02:00
|
|
|
import { sample } from 'rxjs/operators';
|
2018-07-11 15:47:36 +02:00
|
|
|
import { Component, EventEmitter, Input, Output, ElementRef } from '@angular/core';
|
2017-12-14 11:41:26 +01:00
|
|
|
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';
|
2018-07-11 15:47:36 +02:00
|
|
|
import { MatSidenav } from '@angular/material';
|
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())
|
|
|
|
}
|
|
|
|
|
2018-06-29 10:29:43 +02:00
|
|
|
@Input()
|
2018-07-11 15:47:36 +02:00
|
|
|
sideNav: MatSidenav;
|
2018-06-29 10:29:43 +02:00
|
|
|
|
|
|
|
@Output()
|
|
|
|
sidenavOpenChanges = new EventEmitter();
|
|
|
|
|
|
|
|
events: string[] = [];
|
|
|
|
opened: boolean;
|
|
|
|
|
2018-05-28 11:50:42 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-06-29 10:29:43 +02:00
|
|
|
|
|
|
|
onSideNavClick() {
|
2018-07-11 15:47:36 +02:00
|
|
|
this.sideNav.toggle();
|
2018-06-29 10:29:43 +02:00
|
|
|
}
|
2017-12-14 11:41:26 +01:00
|
|
|
}
|