diff --git a/src/app/core/services/title-utils.service.ts b/src/app/core/services/title-utils.service.ts new file mode 100644 index 00000000..ef372f79 --- /dev/null +++ b/src/app/core/services/title-utils.service.ts @@ -0,0 +1,52 @@ +import {Injectable} from '@angular/core'; +import {Title} from '@angular/platform-browser'; +import { + ActivatedRoute, + ActivatedRouteSnapshot, + NavigationEnd, + Router, +} from '@angular/router'; +import {concat, of} from 'rxjs'; +import {filter, map, shareReplay} from 'rxjs/operators'; + +@Injectable() +export class TitleUtilsService { + routeData$ = this.routeDone$().pipe( + map(() => this.getRouteDataRecursively()), + shareReplay(1), + ); + + title$ = this.routeData$.pipe(map((data) => data.title)); + + constructor( + private router: Router, + private titleService: Title, + private activatedRoute: ActivatedRoute, + ) {} + + startUpdatingTitleFromRouteData(defaultTitle: string) { + this.title$.subscribe((title) => { + let fullTitle = title ?? defaultTitle; + this.titleService.setTitle(fullTitle); + }); + } + + private routeDone$() { + return concat( + of({}), + this.router.events.pipe( + filter((event) => event instanceof NavigationEnd), + ), + ); + } + + private getRouteDataRecursively(): any { + let snapshot: ActivatedRouteSnapshot | null = this.activatedRoute.snapshot; + let data = {}; + while (snapshot) { + data = {...data, ...snapshot.data}; + snapshot = snapshot.firstChild; + } + return data; + } +} diff --git a/src/app/routes/connector-ui/connector-ui.component.html b/src/app/routes/connector-ui/connector-ui.component.html index 756cf3f9..0e22dd89 100644 --- a/src/app/routes/connector-ui/connector-ui.component.html +++ b/src/app/routes/connector-ui/connector-ui.component.html @@ -3,6 +3,7 @@ class="sidenav" #drawer fixedInViewport + [disableClose]="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'" [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="(isHandset$ | async) === false"> @@ -64,7 +65,7 @@ - +