Skip to content

Commit

Permalink
chore: undelete title utils for header
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Sep 20, 2024
1 parent da9640a commit 8d7aa02
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/app/core/services/title-utils.service.ts
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;
}
}
3 changes: 2 additions & 1 deletion src/app/routes/connector-ui/connector-ui.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -64,7 +65,7 @@
</div>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar class="flex items-center" color="primary">
<mat-toolbar color="primary">
<button
*ngIf="isHandset$ | async"
type="button"
Expand Down
3 changes: 3 additions & 0 deletions src/app/routes/connector-ui/connector-ui.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {map, shareReplay} from 'rxjs/operators';
import {TranslateService} from '@ngx-translate/core';
import {NavItemGroup} from 'src/app/core/services/models/nav-item-group';
import {NavItemsBuilder} from 'src/app/core/services/nav-items-builder';
import {TitleUtilsService} from 'src/app/core/services/title-utils.service';
import {APP_CONFIG, AppConfig} from '../../core/config/app-config';
import {LoginPollingService} from '../../core/services/login-polling.service';

Expand All @@ -27,6 +28,7 @@ export class ConnectorUiComponent implements OnInit {
constructor(
@Inject(APP_CONFIG) public config: AppConfig,
public titleService: Title,
private titleUtilsService: TitleUtilsService,
private breakpointObserver: BreakpointObserver,
private loginPollingService: LoginPollingService,
private navItemsBuilder: NavItemsBuilder,
Expand All @@ -39,6 +41,7 @@ export class ConnectorUiComponent implements OnInit {

ngOnInit() {
this.startLoginPolling();
this.titleUtilsService.startUpdatingTitleFromRouteData('EDC Connector');
}

private startLoginPolling() {
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {TranslateModule} from '@ngx-translate/core';
import {NgChartsModule} from 'ng2-charts';
import {NgxJsonViewerModule} from 'ngx-json-viewer';
import {CustomDateAdapter} from '../core/adapters/custom-date-adapter';
import {TitleUtilsService} from '../core/services/title-utils.service';
import {AssetCardTagListComponent} from './business/asset-card-tag-list/asset-card-tag-list.component';
import {AssetDetailDialogDataService} from './business/asset-detail-dialog/asset-detail-dialog-data.service';
import {AssetDetailDialogComponent} from './business/asset-detail-dialog/asset-detail-dialog.component';
Expand Down Expand Up @@ -260,6 +261,7 @@ const MODULES = [
JsonDialogService,
PolicyExpressionRecipeService,
UrlListDialogService,
TitleUtilsService,
PolicyMultiExpressionService,
PolicyOperatorService,
PolicyVerbService,
Expand Down

0 comments on commit 8d7aa02

Please sign in to comment.