Update dependencies and configure the app for angular material and flex layout. Fixes #44
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
|
|
import { Title } from '@angular/platform-browser';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { merge } from 'rxjs';
|
|
import { filter, map, mergeMap } from 'rxjs/operators';
|
|
|
|
import { environment } from '../environments/environment';
|
|
import { Logger, I18nService } from '../app/core';
|
|
const log = new Logger('App');
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss']
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
constructor(private router: Router,
|
|
private activatedRoute: ActivatedRoute,
|
|
private titleService: Title,
|
|
private translateService: TranslateService,
|
|
private i18nService: I18nService) { }
|
|
|
|
ngOnInit() {
|
|
// Setup logger
|
|
if (environment.production) {
|
|
Logger.enableProductionMode();
|
|
}
|
|
|
|
log.debug('init');
|
|
|
|
|
|
// Setup translations
|
|
this.i18nService.init(environment.defaultLanguage, environment.supportedLanguages);
|
|
|
|
const onNavigationEnd = this.router.events.pipe(filter(event => event instanceof NavigationEnd));
|
|
|
|
// Change page title on navigation or language change, based on route data
|
|
merge(this.translateService.onLangChange, onNavigationEnd)
|
|
.pipe(
|
|
map(() => {
|
|
let route = this.activatedRoute;
|
|
while (route.firstChild) {
|
|
route = route.firstChild;
|
|
}
|
|
return route;
|
|
}),
|
|
filter(route => route.outlet === 'primary'),
|
|
mergeMap(route => route.data)
|
|
)
|
|
.subscribe(event => {
|
|
const title = event['title'];
|
|
if (title) {
|
|
this.titleService.setTitle(this.translateService.instant(title));
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|