2017-05-10 11:04:06 +02:00
|
|
|
import {Component, Inject, Optional} from '@angular/core';
|
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
NavigationEnd,
|
|
|
|
ActivatedRoute,
|
|
|
|
} from '@angular/router';
|
|
|
|
import {LoginService} from './services/login-service/login-service';
|
|
|
|
import {Title} from '@angular/platform-browser';
|
|
|
|
import {AUTH_ENABLED} from './app.tokens';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: 'app.component.html',
|
|
|
|
styleUrls: ['app.component.css']
|
|
|
|
})
|
|
|
|
export class AppComponent {
|
|
|
|
|
|
|
|
defaultTitle: string;
|
|
|
|
|
|
|
|
constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled,
|
|
|
|
private loginService: LoginService,
|
|
|
|
private activatedRoute: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private titleService: Title) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.defaultTitle = this.titleService.getTitle();
|
|
|
|
this.router.events
|
|
|
|
.filter(event => event instanceof NavigationEnd)
|
|
|
|
.subscribe(event => {
|
|
|
|
this.setBrowserTitle();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
setBrowserTitle() {
|
|
|
|
let title = this.defaultTitle;
|
|
|
|
let route = this.activatedRoute;
|
|
|
|
// firstChild gibt die Haupt-Kindroute der übergebenen Route zurück
|
|
|
|
while (route.firstChild) {
|
|
|
|
route = route.firstChild;
|
|
|
|
title = route.snapshot.data['title'] || title;
|
|
|
|
}
|
|
|
|
this.titleService.setTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
this.loginService.logout();
|
2017-05-18 14:45:00 +02:00
|
|
|
this.router.navigate(['cc-overview']);
|
2017-05-10 11:04:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|