forked from eclipse-edc/DataDashboard
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: undelete title utils for header
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters