import { Injectable } from '@angular/core' ; import { ActivatedRoute , NavigationEnd , Router } from '@angular/router' ; import { filter , map , mergeMap } from 'rxjs/operators' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { ObMasterLayoutHeaderService } from './master-layout-header/master-layout-header.service' ; import { ObMasterLayoutFooterService } from './master-layout-footer/master-layout-footer.service' ; import { ObMasterLayoutNavigationService } from './master-layout-navigation/master-layout-navigation.service' ; import { ObMasterLayoutComponentService } from './master-layout/master-layout.component.service' ; import { ObLanguageService } from '../language/language.service' ; import { ObMasterLayoutConfig } from './master-layout.config' ; @ Injectable ( { providedIn : 'root' } ) export class ObMasterLayoutService { public readonly homePageRouteChange$ : Observable < string > ; private _homePageRoute = this . config . homePageRoute ; private readonly homePageRouteChange = new BehaviorSubject < string > ( this . config . homePageRoute ) ; constructor ( private readonly router , private readonly activatedRoute , private readonly config , public readonly header , public readonly footer , public readonly navigation , public readonly layout , language ) { this . routeChange ( ) ; this . homePageRouteChange$ = this . homePageRouteChange . asObservable ( ) ; } public set homePageRoute ( homePageRoute ) { this . _homePageRoute = homePageRoute ; this . homePageRouteChange . next ( homePageRoute ) ; } public get homePageRoute ( ) : string { return this . _homePageRoute ; } private routeChange ( ) { this . router . events . pipe ( filter ( event => event instanceof NavigationEnd ) , map ( ( ) => this . activatedRoute ) , map ( route => { while ( route . firstChild ) { route = route . firstChild ; } return route ; } ) , filter ( route => route . outlet === 'primary' ) , mergeMap ( route => route . data ) ) . subscribe ( data => { const masterLayout = data . masterLayout || { } ; Object . keys ( masterLayout ) . forEach ( ( property ) => { if ( masterLayout [ property ] !== this [ property ] ) { this [ property ] = masterLayout [ property ] ; } } ) ; } ) ; } }