|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +<% if (props.auth) { -%> |
| 3 | +import { Router } from '@angular/router'; |
| 4 | + |
| 5 | +import { AuthenticationService } from '../../authentication/authentication.service'; |
| 6 | +<% } else { -%> |
| 7 | + |
| 8 | +<% } -%> |
| 9 | +import { I18nService } from '../../i18n.service'; |
| 10 | + |
| 11 | +@Component({ |
| 12 | + selector: 'app-header', |
| 13 | + templateUrl: './header.component.html', |
| 14 | + styleUrls: ['./header.component.scss'] |
| 15 | +}) |
| 16 | +export class HeaderComponent implements OnInit { |
| 17 | + |
| 18 | + menuHidden = true; |
| 19 | + langMenu: Object; |
| 20 | + userMenu: Object; |
| 21 | + |
| 22 | +<% if (props.auth) { -%> |
| 23 | + constructor(private router: Router, |
| 24 | + private authenticationService: AuthenticationService, |
| 25 | + private i18nService: I18nService) { } |
| 26 | +<% } else { -%> |
| 27 | + constructor(private i18nService: I18nService) { } |
| 28 | +<% } -%> |
| 29 | + |
| 30 | + ngOnInit() { } |
| 31 | + |
| 32 | + toggleMenu() { |
| 33 | + this.menuHidden = !this.menuHidden; |
| 34 | + } |
| 35 | + |
| 36 | + setLanguage(language: string) { |
| 37 | + this.i18nService.language = language; |
| 38 | + } |
| 39 | + |
| 40 | +<% if (props.auth) { -%> |
| 41 | + logout() { |
| 42 | + this.authenticationService.logout() |
| 43 | + .subscribe(() => this.router.navigate(['/login'], { replaceUrl: true })); |
| 44 | + } |
| 45 | + |
| 46 | +<% } -%> |
| 47 | + get currentLanguage(): string { |
| 48 | + return this.i18nService.language; |
| 49 | + } |
| 50 | + |
| 51 | + get languages(): string[] { |
| 52 | + return this.i18nService.supportedLanguages; |
| 53 | + } |
| 54 | + |
| 55 | +<% if (props.auth) { -%> |
| 56 | + get username(): string { |
| 57 | + const credentials = this.authenticationService.credentials; |
| 58 | + return credentials ? credentials.username : null; |
| 59 | + } |
| 60 | + |
| 61 | +<% } -%> |
| 62 | +} |
0 commit comments