From 9535bfedf54e50fe2b90f54ca58075c991b35f29 Mon Sep 17 00:00:00 2001 From: genja Date: Thu, 12 Nov 2026 23:01:38 +0100 Subject: [PATCH] standartized "goBack" button --- .../researcher-network.component.html | 8 +- .../researcher-network.component.scss | 20 --- .../news-detail/news-detail.component.html | 9 -- .../news-detail/news-detail.component.scss | 23 ---- .../news-detail/news-detail.component.ts | 6 - .../patent-detail.component.html | 9 -- .../patent-detail.component.scss | 21 ---- .../patent-detail/patent-detail.component.ts | 8 -- .../modules/patents/patents.component.html | 11 -- .../app/modules/patents/patents.component.ts | 13 ++ .../bund-details/bund-details.component.ts | 3 - .../dfg-details/dfg-details.component.ts | 4 - .../publication-detail.component.html | 9 -- .../publication-detail.component.scss | 21 ---- .../publication-detail.component.ts | 16 +-- .../services/back-navigation.service.ts | 114 ++++++++++++++++++ .../ui/app-layout/app-layout.component.ts | 4 +- 17 files changed, 141 insertions(+), 158 deletions(-) create mode 100644 webapp/src/app/shared/services/back-navigation.service.ts diff --git a/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.html b/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.html index 8e02a0c3..1743f8ab 100644 --- a/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.html +++ b/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.html @@ -4,10 +4,6 @@ [subtitle]="unavailable()?.body ?? null" [titleTooltip]="unavailable() ? null : pageTooltip">
- - {{ ARROW_BACK_ICON }} - Zurück zur Multiplikatoren-Übersicht - @if (!unavailable()) {
@if (careerBucket()) { @@ -147,8 +143,8 @@

- Rang 0–100 im Vergleich zu Personen derselben Karrierestufe. - Ab 85 % wird ein Rollen-Badge vergeben. + Rang 0–100 im Vergleich zu Personen derselben Karrierestufe. Ab + 85 % wird ein Rollen-Badge vergeben.

@for (group of metricGroups(); track group.key) {
diff --git a/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.scss b/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.scss index 000a86d3..4fb68456 100644 --- a/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.scss +++ b/webapp/src/app/modules/founder-potential/researcher-network/researcher-network.component.scss @@ -3,26 +3,6 @@ min-width: 0; } -.back-link { - display: inline-flex; - align-items: center; - gap: 4px; - margin-bottom: 6px; - color: var(--sg-text-muted); - font-size: 13px; - text-decoration: none; - - mat-icon { - font-size: 18px; - width: 18px; - height: 18px; - } - - &:hover { - color: var(--sg-blue-highlight); - } -} - .meta-block { margin-top: 8px; } diff --git a/webapp/src/app/modules/news-detail/news-detail.component.html b/webapp/src/app/modules/news-detail/news-detail.component.html index 43274825..b7607dea 100644 --- a/webapp/src/app/modules/news-detail/news-detail.component.html +++ b/webapp/src/app/modules/news-detail/news-detail.component.html @@ -1,14 +1,5 @@
- - @if (loading) {
- - @if (loading) { - @if (showDetail && selectedPatent) { - - } - @if (error) {

Fehler beim Laden der Patente.

} @else if (showDetail && selectedPatent) { diff --git a/webapp/src/app/modules/patents/patents.component.ts b/webapp/src/app/modules/patents/patents.component.ts index 758f23ca..a60446e1 100644 --- a/webapp/src/app/modules/patents/patents.component.ts +++ b/webapp/src/app/modules/patents/patents.component.ts @@ -24,6 +24,7 @@ import { import { FilterCardComponent } from '../../shared/ui/filter-card/filter-card.component'; import { HELP_ICON, PATENT_ICON } from '../../shared/ui/icons'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; +import { BackNavigationService } from '../../shared/services/back-navigation.service'; type PatentSource = 'EPO' | 'USPTO'; @@ -69,6 +70,8 @@ export class PatentsComponent { private route = inject(ActivatedRoute); private patentsApi = inject(PatentsService); private destroyRef = inject(DestroyRef); + private backNavigation = inject(BackNavigationService); + private unregisterLocalBack: (() => void) | null = null; patents: PatentEntry[] = []; total = 0; @@ -92,6 +95,8 @@ export class PatentsComponent { readonly expandedClassificationKeys = new Set(); constructor() { + this.destroyRef.onDestroy(() => this.unregisterLocalBack?.()); + this.route.queryParams .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe((qp) => { @@ -181,12 +186,20 @@ export class PatentsComponent { } selectPatent(patent: PatentEntry): void { + this.unregisterLocalBack?.(); + this.unregisterLocalBack = this.backNavigation.registerLocalBack(() => + this.closeDetail(), + ); + this.selectedPatent = patent; this.showDetail = true; this.expandedClassificationKeys.clear(); } closeDetail(): void { + this.unregisterLocalBack?.(); + this.unregisterLocalBack = null; + this.showDetail = false; this.selectedPatent = null; this.expandedClassificationKeys.clear(); diff --git a/webapp/src/app/modules/projects/bund-details/bund-details.component.ts b/webapp/src/app/modules/projects/bund-details/bund-details.component.ts index ed0573df..f0e362dd 100644 --- a/webapp/src/app/modules/projects/bund-details/bund-details.component.ts +++ b/webapp/src/app/modules/projects/bund-details/bund-details.component.ts @@ -172,7 +172,4 @@ export class BundDetailsComponent implements OnInit { return 'var(--sg-text-muted)'; } } - goBack(): void { - window.history.back(); - } } diff --git a/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts b/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts index 7e66404c..3f1c6271 100644 --- a/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts +++ b/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts @@ -279,8 +279,4 @@ export class DfgDetailsComponent implements OnInit { queryParams: { search: institutionName }, }); } - - goBack(): void { - window.history.back(); - } } diff --git a/webapp/src/app/modules/publication-detail/publication-detail.component.html b/webapp/src/app/modules/publication-detail/publication-detail.component.html index 5daa523b..0303ab56 100644 --- a/webapp/src/app/modules/publication-detail/publication-detail.component.html +++ b/webapp/src/app/modules/publication-detail/publication-detail.component.html @@ -1,14 +1,5 @@
- - @if (loading) { (); @@ -130,20 +130,22 @@ export class PublicationDetailComponent implements OnInit { readonly institutionsPageSize = 5; returnUrl: string | null = null; - returnLabel = 'Alle Publikationen'; - returnAriaLabel = 'Zurück zu den Publikationen'; ngOnInit(): void { this.loading = true; const navigationState = this.location.getState() as { returnUrl?: string; - returnLabel?: string; } | null; if (navigationState?.returnUrl) { this.returnUrl = navigationState.returnUrl; - this.returnLabel = navigationState.returnLabel ?? 'Zurück'; - this.returnAriaLabel = `Zurück zu ${this.returnLabel}`; + + // The topbar back button should return to the page the user came from, + // not to an unrelated history entry. + const unregister = this.backNavigation.registerLocalBack(() => + this.navigateBack(), + ); + this.destroyRef.onDestroy(unregister); } this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({ diff --git a/webapp/src/app/shared/services/back-navigation.service.ts b/webapp/src/app/shared/services/back-navigation.service.ts new file mode 100644 index 00000000..5b3162d9 --- /dev/null +++ b/webapp/src/app/shared/services/back-navigation.service.ts @@ -0,0 +1,114 @@ +import { Location } from '@angular/common'; +import { Injectable, computed, inject, signal } from '@angular/core'; +import { Router } from '@angular/router'; + +type BackHandler = () => void; + +const ROOT_PATHS = new Set([ + '/dashboard', + '/compare', + '/multipliers', + '/founders', + '/bookmarks', + '/persons', + '/keywords', + '/hierarchy', + '/news', + '/account', + '/accounts', + '/organizations', + '/jobs', + '/publications', + '/topics', + '/projects', + '/patents', + '/institutions', + '/login', + '/forgot-password', + '/reset-password', + '/icons', + '/error', +]); + +const FALLBACKS: ReadonlyArray<{ prefix: string; target: string }> = [ + { prefix: '/person/', target: '/persons' }, + { prefix: '/publication/', target: '/publications' }, + { prefix: '/patent/', target: '/patents' }, + { prefix: '/news/', target: '/news' }, + { prefix: '/institution/', target: '/institutions' }, + { prefix: '/topic/', target: '/topics' }, + { prefix: '/projects/', target: '/projects' }, + { prefix: '/founders/', target: '/multipliers' }, + { prefix: '/keywords/', target: '/keywords' }, + { prefix: '/error', target: '/dashboard' }, +]; + +@Injectable({ providedIn: 'root' }) +export class BackNavigationService { + private readonly router = inject(Router); + private readonly location = inject(Location); + + // In-page detail views (e.g. the inline patent detail) own the back action + // while they are open. The topbar button executes the newest handler. + private readonly localHandlers = signal([]); + + readonly hasLocalHandler = computed(() => this.localHandlers().length > 0); + + /** + * Registers a back action for an in-page detail view. Returns an unregister + * function that the component calls when the view closes or is destroyed. + */ + registerLocalBack(handler: BackHandler): () => void { + this.localHandlers.update((handlers) => [...handlers, handler]); + + return () => { + this.localHandlers.update((handlers) => + handlers.filter((candidate) => candidate !== handler), + ); + }; + } + + /** True when this tab has at least one earlier in-app navigation. */ + canGoBack(): boolean { + const state = history.state as { navigationId?: number } | null; + return (state?.navigationId ?? 0) > 1; + } + + /** + * Goes back in history when that is safe, otherwise navigates to the + * section that owns the current detail page. + */ + back(fallback?: string): void { + const handlers = this.localHandlers(); + const localHandler = handlers[handlers.length - 1]; + + if (localHandler) { + localHandler(); + return; + } + + if (this.canGoBack()) { + this.location.back(); + return; + } + + void this.router.navigateByUrl( + fallback ?? this.fallbackFor(this.router.url), + ); + } + + /** Whether the current URL is a top-level section. */ + isRoot(url: string): boolean { + return ROOT_PATHS.has(this.pathOf(url)); + } + + fallbackFor(url: string): string { + const path = this.pathOf(url); + const match = FALLBACKS.find(({ prefix }) => path.startsWith(prefix)); + return match?.target ?? '/dashboard'; + } + + private pathOf(url: string): string { + return url.split('?')[0].split('#')[0] || '/'; + } +} diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts index 00cfea1d..7f47cb21 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts @@ -93,7 +93,9 @@ export class AppLayoutComponent implements OnInit, OnDestroy { private readonly currentPath = signal('/'); readonly showBack = computed( - () => !this.backNavigation.isRoot(this.currentPath()), + () => + this.backNavigation.hasLocalHandler() || + !this.backNavigation.isRoot(this.currentPath()), ); private readonly sidebarCollapsedStorageKey = 'inse.sidebar.collapsed';