Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: undelete title utils for header #845

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

@richardtreier richardtreier Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now a Title Strategy, which is the native feature on how to solve this issue. This is why the class was deleted. So whatever logic you want to restore you should restore there.

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
Loading