From 8b374681c2d9f661d29b8ec7f2fd774fc08aa276 Mon Sep 17 00:00:00 2001 From: genja Date: Thu, 12 Nov 2026 22:25:42 +0100 Subject: [PATCH] added page title service for displaying page title --- .../app/shared/services/page-title.service.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 webapp/src/app/shared/services/page-title.service.ts diff --git a/webapp/src/app/shared/services/page-title.service.ts b/webapp/src/app/shared/services/page-title.service.ts new file mode 100644 index 00000000..6e678034 --- /dev/null +++ b/webapp/src/app/shared/services/page-title.service.ts @@ -0,0 +1,71 @@ +import { Injectable, inject } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { NavigationEnd, Router } from '@angular/router'; +import { filter } from 'rxjs'; + +const APP_NAME = 'AIIS'; + +const TITLES: ReadonlyArray<{ prefix: string; title: string }> = [ + { prefix: '/person/', title: 'Person' }, + { prefix: '/persons', title: 'Personen' }, + { prefix: '/publication/', title: 'Publikation' }, + { prefix: '/publications', title: 'Publikationen' }, + { prefix: '/patent/', title: 'Patent' }, + { prefix: '/patents', title: 'Patente' }, + { prefix: '/institution/', title: 'Institution' }, + { prefix: '/institutions', title: 'Institutionen' }, + { prefix: '/topic/', title: 'Thema' }, + { prefix: '/topics', title: 'Themen' }, + { prefix: '/news/', title: 'Nachricht' }, + { prefix: '/news', title: 'Nachrichten' }, + { prefix: '/projects/', title: 'Projekt' }, + { prefix: '/projects', title: 'Projekte' }, + { prefix: '/founders/', title: 'Multiplikator' }, + { prefix: '/founders', title: 'Gründungspotenzial' }, + { prefix: '/multipliers', title: 'Multiplikatoren' }, + { prefix: '/compare', title: 'Autorenvergleich' }, + { prefix: '/bookmarks', title: 'Bookmarks' }, + { prefix: '/keywords/', title: 'Keywords' }, + { prefix: '/keywords', title: 'Keywords' }, + { prefix: '/hierarchy', title: 'Hierarchie' }, + { prefix: '/account', title: 'Mein Konto' }, + { prefix: '/accounts', title: 'Accounts' }, + { prefix: '/organizations', title: 'Organisationen' }, + { prefix: '/jobs', title: 'Jobs' }, + { prefix: '/dashboard', title: 'Dashboard' }, + { prefix: '/login', title: 'Anmelden' }, + { prefix: '/forgot-password', title: 'Passwort vergessen' }, + { prefix: '/reset-password', title: 'Passwort zurücksetzen' }, + { prefix: '/error', title: 'Fehler' }, + { prefix: '/icons', title: 'Icons' }, +]; + +@Injectable({ providedIn: 'root' }) +export class PageTitleService { + private readonly router = inject(Router); + + constructor() { + this.router.events + .pipe( + filter( + (event): event is NavigationEnd => event instanceof NavigationEnd, + ), + takeUntilDestroyed(), + ) + .subscribe((event) => this.update(event.urlAfterRedirects)); + + this.update(this.router.url); + } + + private update(url: string): void { + document.title = `${this.titleFor(url)} · ${APP_NAME}`; + } + + private titleFor(url: string): string { + const path = url.split('?')[0].split('#')[0] || '/'; + if (path === '/' || path === '') return 'Start'; + + const match = TITLES.find(({ prefix }) => path.startsWith(prefix)); + return match?.title ?? 'Übersicht'; + } +}