import {of as observableOf, Observable } from 'rxjs'; import {switchMap, filter, map } from 'rxjs/operators'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { environment } from '../environments/environment'; import { AuthService } from './core/services/auth/auth.service'; import { CultureService } from './core/services/culture/culture-service'; import { BreadCrumbResolverService } from './ui/misc/breadcrumb/service/breadcrumb.service'; import { Title } from '@angular/platform-browser'; declare const gapi: any; declare var $: any; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { hasBreadCrumb = observableOf(false); sideNavOpen = false; helpContentEnabled = environment.HelpService.Enabled; constructor( private router: Router, private route: ActivatedRoute, private authentication: AuthService, private translate: TranslateService, private breadCrumbResolverService: BreadCrumbResolverService, private titleService: Title, private language: TranslateService, private cultureService: CultureService ) { this.initializeServices(); } onActivate(event: any) { this.breadCrumbResolverService.push(event); } onDeactivate(event: any) { //this.breadCrumbResolverService.clear() } ngOnInit() { this.hasBreadCrumb = this.router.events.pipe( filter(event => event instanceof NavigationEnd), map(() => this.route), map(route => route.firstChild), switchMap(route => route.data), map(data => data['breadcrumb']),); const appTitle = this.titleService.getTitle(); this.router .events.pipe( filter(event => event instanceof NavigationEnd), map(() => { let child = this.route.firstChild; while (child.firstChild) { child = child.firstChild; } if (child.snapshot.data['title']) { return child.snapshot.data['title']; } return appTitle; }) ).subscribe((ttl: string) => { if (ttl.length > 0) { this.language.get(ttl).subscribe((translated: string) => { this.language.get('GENERAL.TITLES.PREFIX').subscribe( (titlePrefix: string) => { this.titleService.setTitle(titlePrefix + translated); }); }); } else { this.language.get('GENERAL.TITLES.GENERAL').subscribe((translated: string) => { this.titleService.setTitle(translated); }); } }); } login() { //redirect to login page this.router.navigate(['/login'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } }); } logout() { } public isAuthenticated(): boolean { return !(!this.authentication.current()); } goToDMPs() { this.router.navigate(['/plans'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } }); } goToGrants() { this.router.navigate(['/grants'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } }); } initializeServices() { this.translate.setDefaultLang('en'); this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(environment.defaultCulture); } }