| /******************************************************************************** |
| * Copyright (c) 2015-2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ********************************************************************************/ |
| |
| import { Component, OnInit } from '@angular/core'; |
| import {DialogModule} from 'primeng/primeng'; |
| import { TranslateService } from '@ngx-translate/core'; |
| |
| import {SelectItem} from 'primeng/api'; |
| import { User, Role } from './authentication/authentication.service'; |
| import { AuthenticationService } from './authentication/authentication.service'; |
| |
| @Component({ |
| selector: 'app-root', |
| templateUrl: './app.component.html' |
| }) |
| export class AppComponent implements OnInit { |
| |
| readonly TtlLogout = 'Logout'; |
| readonly TtlAbout = 'About'; |
| readonly TtlLanguage = 'Language'; |
| |
| languages = <SelectItem[]> [ |
| { label: 'English', value: 'en' }, |
| { label: 'Deutsch', value: 'de' }, |
| ]; |
| |
| selectedLanguage = 'en'; |
| |
| links = [ |
| { name: 'Administration', path: '/administration', roles: [ Role.Admin ] } |
| ]; |
| displayAboutDialog = false; |
| user: User = null; |
| rolesTooltip: string; |
| |
| constructor(private translate: TranslateService, private authService: AuthenticationService) { |
| } |
| |
| ngOnInit() { |
| this.translate.langs = this.languages.map(i => i.value); |
| let browserLang = this.translate.getBrowserLang(); |
| if (this.translate.langs.findIndex(l => l === browserLang) > -1) { |
| this.selectedLanguage = browserLang; |
| } |
| this.translate.setDefaultLang(this.selectedLanguage); |
| this.translate.use(this.selectedLanguage); |
| this.authService.getLoginUser().subscribe(value => { |
| this.user = value; |
| this.rolesTooltip = value.roles.join(', '); |
| }) |
| } |
| |
| selectLanguage($event: any) { |
| this.translate.use(this.selectedLanguage); |
| } |
| |
| showAboutDialog() { |
| this.displayAboutDialog = true; |
| } |
| } |