diff --git a/webapp/src/app/custom-directives/sk-text.directive.ts b/webapp/src/app/custom-directives/sk-text.directive.ts index 07ef9d17..b5406088 100644 --- a/webapp/src/app/custom-directives/sk-text.directive.ts +++ b/webapp/src/app/custom-directives/sk-text.directive.ts @@ -8,7 +8,7 @@ import { effect, inject, } from '@angular/core'; -import { ResolverStateService } from '../../app/shared/services/resolver-state.service'; +import { NavigationStateService } from '../../app/shared/services/navigation-state.service'; @Directive({ selector: 'span, [skText]', @@ -19,11 +19,11 @@ export class SkTextDirective implements OnChanges { private readonly el = inject(ElementRef); private readonly renderer = inject(Renderer2); - private readonly resolverStateService = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); constructor() { effect(() => { - const loading = this.skText || this.resolverStateService.isResolving(); + const loading = this.skText || this.navigationState.isResolving(); if (loading) { this.showSkeleton(); @@ -38,7 +38,7 @@ export class SkTextDirective implements OnChanges { return; } - if (this.skText || this.resolverStateService.isResolving()) { + if (this.skText || this.navigationState.isResolving()) { this.showSkeleton(); } else { this.hideSkeleton(); diff --git a/webapp/src/app/modules/institutions/institutions.component.ts b/webapp/src/app/modules/institutions/institutions.component.ts index 3edccef3..2893df89 100644 --- a/webapp/src/app/modules/institutions/institutions.component.ts +++ b/webapp/src/app/modules/institutions/institutions.component.ts @@ -14,7 +14,7 @@ import { FilterObserver } from '../../shared/ui/selected-filters/selected-filter import { AppInstitutionCardComponent } from '../../shared/ui/app-institution-card/app-institution-card.component'; import { SEARCH_ICON } from '../../shared/ui/icons'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; -import { ResolverStateService } from '../../shared/services/resolver-state.service'; +import { NavigationStateService } from '../../shared/services/navigation-state.service'; @Component({ selector: 'app-institutions', @@ -33,9 +33,9 @@ import { ResolverStateService } from '../../shared/services/resolver-state.servi export class InstitutionsComponent { institutionPage = input.required(); - private readonly resolverState = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); readonly loading = computed(() => - this.resolverState.isResolvingInside('/institutions'), + this.navigationState.isResolvingInside('/institutions'), ); observers: FilterObserver[] = [ diff --git a/webapp/src/app/modules/person-list/person-list.component.html b/webapp/src/app/modules/person-list/person-list.component.html index 794239ed..5e6a2764 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -114,6 +114,8 @@ } + +
{{ resultRange() @@ -151,11 +153,15 @@ Sortiert nach Publikationen und Zitierungen-->
- @if (getPersons().length) { + @if (loading) { + + } @else if (getPersons().length) {
@for (person of getPersons(); track person.id) { - this.resolverStateService.isResolvingInside('/persons'), + this.navigationState.isResolvingInside('/persons'), ); persons: CustomAuthor[] = []; total = 0; @@ -600,6 +603,13 @@ export class PersonListComponent { return `${start}-${end} von ${this.total} Personen`; } + /** Announced to screen readers whenever a new result set is rendered. */ + get resultAnnouncement(): string { + if (this.loading) return ''; + if (!this.total) return 'Keine Personen gefunden'; + return this.resultRange(); + } + // Bookmarks toggleBookmark(person: CustomAuthor): void { this.bookmarkService diff --git a/webapp/src/app/modules/person-news/person-news.component.ts b/webapp/src/app/modules/person-news/person-news.component.ts index 998f5e83..feea573d 100644 --- a/webapp/src/app/modules/person-news/person-news.component.ts +++ b/webapp/src/app/modules/person-news/person-news.component.ts @@ -9,7 +9,7 @@ import { import { ActivatedRoute } from '@angular/router'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { ResolverStateService } from '../../shared/services/resolver-state.service'; +import { NavigationStateService } from '../../shared/services/navigation-state.service'; import { NewsArticle, NewsPage } from '../../resolvers/person-news.resolver'; import { CardSearchComponent, @@ -27,7 +27,7 @@ import { SelectorOption } from '../../shared/ui/query-param-selector/query-param export class PersonNewsComponent implements OnInit { private readonly destroyRef = inject(DestroyRef); private readonly route = inject(ActivatedRoute); - private readonly resolverStateService = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); readonly sortingDirectionOptions: SelectorOption[] = [ { value: 'desc', display_name: 'Neueste zuerst' }, @@ -40,7 +40,7 @@ export class PersonNewsComponent implements OnInit { private currentSize = 10; get loading(): boolean { - return this.resolverStateService.isResolving(); + return this.navigationState.isResolving(); } readonly page = computed(() => ({ diff --git a/webapp/src/app/modules/projects/projects.component.ts b/webapp/src/app/modules/projects/projects.component.ts index c611597e..cf2e4d99 100644 --- a/webapp/src/app/modules/projects/projects.component.ts +++ b/webapp/src/app/modules/projects/projects.component.ts @@ -16,7 +16,7 @@ import { FilterObserver } from '../../shared/ui/selected-filters/selected-filter import { FilterCardComponent } from '../../shared/ui/filter-card/filter-card.component'; import { SEARCH_ICON } from '../../shared/ui/icons'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; -import { ResolverStateService } from '../../shared/services/resolver-state.service'; +import { NavigationStateService } from '../../shared/services/navigation-state.service'; @Component({ selector: 'app-projects', @@ -37,9 +37,9 @@ import { ResolverStateService } from '../../shared/services/resolver-state.servi export class ProjectsComponent { fundingProjectPage = input.required(); - private readonly resolverState = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); readonly loading = computed(() => - this.resolverState.isResolvingInside('/projects'), + this.navigationState.isResolvingInside('/projects'), ); page = computed(() => ({ diff --git a/webapp/src/app/modules/publications/publications.component.ts b/webapp/src/app/modules/publications/publications.component.ts index 42969dbe..c3495e9e 100644 --- a/webapp/src/app/modules/publications/publications.component.ts +++ b/webapp/src/app/modules/publications/publications.component.ts @@ -19,7 +19,7 @@ import { PublicationFilterComponent } from '../../shared/ui/publication-filters/ import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component'; import { workQueryParamKeys } from '../../resolvers/work-page.resolver'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; -import { ResolverStateService } from '../../shared/services/resolver-state.service'; +import { NavigationStateService } from '../../shared/services/navigation-state.service'; @Component({ selector: 'app-publications', @@ -35,10 +35,10 @@ import { ResolverStateService } from '../../shared/services/resolver-state.servi export class PublicationsComponent { private readonly route = inject(ActivatedRoute); private readonly router = inject(Router); - private readonly resolverState = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); readonly loading = computed(() => - this.resolverState.isResolvingInside('/publications'), + this.navigationState.isResolvingInside('/publications'), ); workPage = input.required(); diff --git a/webapp/src/app/modules/topics/topics.component.ts b/webapp/src/app/modules/topics/topics.component.ts index f3c24c64..a68f6bcc 100644 --- a/webapp/src/app/modules/topics/topics.component.ts +++ b/webapp/src/app/modules/topics/topics.component.ts @@ -10,7 +10,7 @@ import { topicQueryParamKeys } from '../../resolvers/topic-page.resolver'; import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component'; import { SEARCH_ICON } from '../../shared/ui/icons'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; -import { ResolverStateService } from '../../shared/services/resolver-state.service'; +import { NavigationStateService } from '../../shared/services/navigation-state.service'; @Component({ selector: 'app-topics', @@ -21,9 +21,9 @@ import { ResolverStateService } from '../../shared/services/resolver-state.servi export class TopicsComponent { topicPage = input.required(); - private readonly resolverState = inject(ResolverStateService); + private readonly navigationState = inject(NavigationStateService); readonly loading = computed(() => - this.resolverState.isResolvingInside('/topics'), + this.navigationState.isResolvingInside('/topics'), ); observers: FilterObserver[] = [ diff --git a/webapp/src/app/shared/services/navigation-focus.service.ts b/webapp/src/app/shared/services/navigation-focus.service.ts new file mode 100644 index 00000000..c8f4b943 --- /dev/null +++ b/webapp/src/app/shared/services/navigation-focus.service.ts @@ -0,0 +1,55 @@ +import { inject, Injectable } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { NavigationEnd, Router } from '@angular/router'; +import { filter } from 'rxjs'; +import { navigationSectionFor, pathOf } from './navigation-sections'; + +/** + * Moves keyboard and screen-reader focus to the new page heading after a + * navigation between sections. In-section updates (tabs, filters, pagination) + * keep the focus where the user left it. + */ +@Injectable({ providedIn: 'root' }) +export class NavigationFocusService { + private readonly router = inject(Router); + private lastPath: string | null = null; + + constructor() { + this.router.events + .pipe( + filter( + (event): event is NavigationEnd => event instanceof NavigationEnd, + ), + takeUntilDestroyed(), + ) + .subscribe((event) => { + const path = pathOf(event.urlAfterRedirects); + const previousPath = this.lastPath; + this.lastPath = path; + + // Skip the initial load and in-section updates. + if (previousPath === null) return; + const fromSection = navigationSectionFor(previousPath); + const toSection = navigationSectionFor(path); + if (fromSection?.id === toSection?.id) return; + + this.focusPageHeading(); + }); + } + + private focusPageHeading(): void { + // Wait for the activated component's view to be in the DOM. + requestAnimationFrame(() => { + const main = document.querySelector('main'); + const heading = main?.querySelector('h1') ?? null; + const target = heading ?? main; + if (!target) return; + + if (!target.hasAttribute('tabindex')) { + target.setAttribute('tabindex', '-1'); + } + // The scroll service owns the scroll position; focusing must not move it. + target.focus({ preventScroll: true }); + }); + } +} diff --git a/webapp/src/app/shared/services/navigation-sections.ts b/webapp/src/app/shared/services/navigation-sections.ts new file mode 100644 index 00000000..3948ca5f --- /dev/null +++ b/webapp/src/app/shared/services/navigation-sections.ts @@ -0,0 +1,331 @@ +import { + ACCOUNT_CIRCLE_ICON, + BOOKMARKS_ICON, + DASHBOARD_ICON, + FOUNDER_ICON, + HIERARCHY_ICON, + INSTITUTION_ICON, + JOBS_ICON, + KEYWORDS_ICON, + NEWS_ICON, + ORGANIZATIONS_ICON, + PATENT_ICON, + PERSONS_ICON, + PERSON_ICON, + PROJECT_ICON, + PUBLICATION_ICON, + TOPIC_ICON, +} from '../ui/icons'; + +/** + * Shape of the page skeleton for a navigation target. The variants mirror the + * actual page layouts: card grids, data tables, master-detail pages, KPI + * dashboards, tree charts, forms and graphs. + */ +export type PageSkeletonVariant = + | 'cards' + | 'cards-plain' + | 'cards-sidebar' + | 'table' + | 'table-stats' + | 'detail' + | 'detail-table' + | 'detail-chart' + | 'dashboard' + | 'comparison' + | 'tree' + | 'form' + | 'graph'; + +export interface NavigationSection { + /** Stable identifier, used to detect navigations that stay inside a section. */ + id: string; + /** + * URL prefix. A trailing slash means "any path below this prefix" and is + * used for detail routes that share their list's prefix (e.g. `/news/:id`). + */ + prefix: string; + label: string; + /** Announced and shown while the section's resolvers run. */ + loadingText: string; + icon: string; + skeleton: PageSkeletonVariant; +} + +/** + * Central map of the app's sections. Used for the navigation skeleton and to + * tell "from outside" navigations (show a skeleton) apart from in-section + * updates such as filters and pagination (keep the current content). + */ +export const NAVIGATION_SECTIONS: readonly NavigationSection[] = [ + { + // Person list: card grid on the left, filter sidebar on the right. + id: 'persons', + prefix: '/persons', + label: 'Personen', + loadingText: 'Personen werden geladen …', + icon: PERSONS_ICON, + skeleton: 'cards-sidebar', + }, + { + // Person detail: hero, tabs, timeline/wordcloud on the overview tab. + id: 'person', + prefix: '/person', + label: 'Person', + loadingText: 'Personendaten werden geladen …', + icon: PERSON_ICON, + skeleton: 'detail-chart', + }, + { + id: 'publications', + prefix: '/publications', + label: 'Publikationen', + loadingText: 'Publikationen werden geladen …', + icon: PUBLICATION_ICON, + skeleton: 'cards', + }, + { + id: 'publication', + prefix: '/publication', + label: 'Publikation', + loadingText: 'Publikationsdaten werden geladen …', + icon: PUBLICATION_ICON, + skeleton: 'detail', + }, + { + id: 'project-detail', + prefix: '/projects/dfg/', + label: 'Projekt', + loadingText: 'Projektdaten werden geladen …', + icon: PROJECT_ICON, + skeleton: 'detail', + }, + { + id: 'project-detail', + prefix: '/projects/bund/', + label: 'Projekt', + loadingText: 'Projektdaten werden geladen …', + icon: PROJECT_ICON, + skeleton: 'detail', + }, + { + id: 'project-detail', + prefix: '/projects/eu/', + label: 'Projekt', + loadingText: 'Projektdaten werden geladen …', + icon: PROJECT_ICON, + skeleton: 'detail', + }, + { + // Project list uses app-card-search, not a table. + id: 'projects', + prefix: '/projects', + label: 'Projekte', + loadingText: 'Projekte werden geladen …', + icon: PROJECT_ICON, + skeleton: 'cards', + }, + { + id: 'institutions', + prefix: '/institutions', + label: 'Institutionen', + loadingText: 'Institutionen werden geladen …', + icon: INSTITUTION_ICON, + skeleton: 'cards', + }, + { + // Institution detail tabs default to a publication table. + id: 'institution', + prefix: '/institution', + label: 'Institution', + loadingText: 'Institutionsdaten werden geladen …', + icon: INSTITUTION_ICON, + skeleton: 'detail-table', + }, + { + // Patent list uses app-card-search; clicking a card opens a detail panel. + id: 'patents', + prefix: '/patents', + label: 'Patente', + loadingText: 'Patente werden geladen …', + icon: PATENT_ICON, + skeleton: 'cards', + }, + { + id: 'patent', + prefix: '/patent', + label: 'Patent', + loadingText: 'Patentdaten werden geladen …', + icon: PATENT_ICON, + skeleton: 'detail', + }, + { + id: 'news-detail', + prefix: '/news/', + label: 'Nachricht', + loadingText: 'Nachricht wird geladen …', + icon: NEWS_ICON, + skeleton: 'detail', + }, + { + id: 'news', + prefix: '/news', + label: 'Nachrichten', + loadingText: 'Nachrichten werden geladen …', + icon: NEWS_ICON, + skeleton: 'cards', + }, + { + // Topic list uses app-card-search, not a table. + id: 'topics', + prefix: '/topics', + label: 'Themen', + loadingText: 'Themen werden geladen …', + icon: TOPIC_ICON, + skeleton: 'cards', + }, + { + // Topic detail tabs default to a publication table. + id: 'topic', + prefix: '/topic', + label: 'Thema', + loadingText: 'Themendaten werden geladen …', + icon: TOPIC_ICON, + skeleton: 'detail-table', + }, + { + id: 'hierarchy', + prefix: '/hierarchy', + label: 'Hierarchie', + loadingText: 'Hierarchie wird geladen …', + icon: HIERARCHY_ICON, + skeleton: 'tree', + }, + { + // KPI tiles plus several ECharts panels. + id: 'dashboard', + prefix: '/dashboard', + label: 'Dashboard', + loadingText: 'Dashboard wird geladen …', + icon: DASHBOARD_ICON, + skeleton: 'dashboard', + }, + { + id: 'multipliers', + prefix: '/multipliers', + label: 'Multiplikatoren', + loadingText: 'Multiplikatoren werden geladen …', + icon: FOUNDER_ICON, + skeleton: 'table', + }, + { + // KPI cards above a data table with expandable rows. + id: 'founders', + prefix: '/founders', + label: 'Gründungspotenzial', + loadingText: 'Gründungspotenzial wird geladen …', + icon: FOUNDER_ICON, + skeleton: 'table-stats', + }, + { + id: 'collaboration-network', + prefix: '/collaboration-network', + label: 'Forschungsnetzwerk', + loadingText: 'Forschungsnetzwerk wird geladen …', + icon: PERSON_ICON, + skeleton: 'graph', + }, + { + // Bookmarks are just a card grid, without search/sort/pagination. + id: 'bookmarks', + prefix: '/bookmarks', + label: 'Bookmarks', + loadingText: 'Bookmarks werden geladen …', + icon: BOOKMARKS_ICON, + skeleton: 'cards-plain', + }, + { + // Two statistic tables, charts and a research-profile panel. + id: 'compare', + prefix: '/compare', + label: 'Autorenvergleich', + loadingText: 'Autorenvergleich wird geladen …', + icon: PERSON_ICON, + skeleton: 'comparison', + }, + { + // Keyword extraction form with a four-column chip matrix. + id: 'keywords-results', + prefix: '/keywords/search-results', + label: 'Keyword-Suche', + loadingText: 'Ergebnisse werden geladen …', + icon: KEYWORDS_ICON, + skeleton: 'table', + }, + { + id: 'keywords', + prefix: '/keywords', + label: 'Keywords', + loadingText: 'Keywords werden geladen …', + icon: KEYWORDS_ICON, + skeleton: 'form', + }, + { + id: 'accounts', + prefix: '/accounts', + label: 'Accounts', + loadingText: 'Accounts werden geladen …', + icon: ACCOUNT_CIRCLE_ICON, + skeleton: 'table', + }, + { + id: 'account', + prefix: '/account', + label: 'Mein Konto', + loadingText: 'Kontodaten werden geladen …', + icon: ACCOUNT_CIRCLE_ICON, + skeleton: 'detail', + }, + { + id: 'organizations', + prefix: '/organizations', + label: 'Organisationen', + loadingText: 'Organisationen werden geladen …', + icon: ORGANIZATIONS_ICON, + skeleton: 'table', + }, + { + // Health status cards above a data table. + id: 'jobs', + prefix: '/jobs', + label: 'Jobs', + loadingText: 'Jobs werden geladen …', + icon: JOBS_ICON, + skeleton: 'table-stats', + }, +]; + +// Longest prefix first so `/persons` wins over `/person`. +const SECTIONS_BY_LENGTH = [...NAVIGATION_SECTIONS].sort( + (a, b) => b.prefix.length - a.prefix.length, +); + +/** Resolve the section for a router URL (query string and hash are ignored). */ +export function navigationSectionFor( + url: string | null | undefined, +): NavigationSection | null { + if (!url) return null; + const path = pathOf(url); + return SECTIONS_BY_LENGTH.find((section) => matchesPrefix(path, section.prefix)) ?? null; +} + +function matchesPrefix(path: string, prefix: string): boolean { + return prefix.endsWith('/') + ? path.startsWith(prefix) + : path === prefix || path.startsWith(`${prefix}/`); +} + +/** Path part of a router URL. */ +export function pathOf(url: string): string { + return url.split('?')[0].split('#')[0] || '/'; +} diff --git a/webapp/src/app/shared/services/navigation-state.service.ts b/webapp/src/app/shared/services/navigation-state.service.ts new file mode 100644 index 00000000..5aaaec95 --- /dev/null +++ b/webapp/src/app/shared/services/navigation-state.service.ts @@ -0,0 +1,111 @@ +import { computed, inject, Injectable, signal } from '@angular/core'; +import { + ActivatedRouteSnapshot, + NavigationCancel, + NavigationEnd, + NavigationError, + ResolveStart, + Router, + RouterStateSnapshot, +} from '@angular/router'; +import { + NavigationSection, + navigationSectionFor, + pathOf, +} from './navigation-sections'; + +export interface NavigationTarget { + /** URL the router is navigating to (including query string). */ + url: string; + /** Section of the target URL, if it is one of the known sections. */ + section: NavigationSection | null; + /** URL the user is coming from, captured when resolving starts. */ + fromUrl: string | null; + /** Section of the origin URL. */ + fromSection: NavigationSection | null; + /** True when the navigation switches to a different section. */ + external: boolean; +} + +/** + * Central navigation state for the whole app. + * + * Resolvers run between `ResolveStart` and `NavigationEnd`; while they do, the + * layout shows a section skeleton for navigations that come from outside a + * section. In-section updates (filters, pagination, tabs) keep the current + * content on screen and only clear when the navigation finishes. + */ +@Injectable({ providedIn: 'root' }) +export class NavigationStateService { + private readonly router = inject(Router); + private readonly currentTarget = signal(null); + + readonly target = this.currentTarget.asReadonly(); + readonly isResolving = computed(() => this.currentTarget() !== null); + + /** Section whose skeleton should be shown, or null to keep the content. */ + readonly skeleton = computed(() => { + const target = this.currentTarget(); + return target?.external ? target.section : null; + }); + + constructor() { + this.router.events.subscribe((event) => { + if (event instanceof ResolveStart) { + // Angular emits ResolveStart for every activation, even when no + // resolver is configured. Without resolvers there is nothing to wait + // for, so showing a skeleton would only cause a flash. + if (!hasResolvers(event.state)) return; + + const fromUrl = this.router.url; + const section = navigationSectionFor(event.url); + const fromSection = navigationSectionFor(fromUrl); + this.currentTarget.set({ + url: event.url, + section, + fromUrl, + fromSection, + external: section?.id !== fromSection?.id, + }); + return; + } + + if ( + event instanceof NavigationEnd || + event instanceof NavigationCancel || + event instanceof NavigationError + ) { + this.currentTarget.set(null); + } + }); + } + + /** True while resolving a URL that starts with `path` from outside `path`. */ + isResolvingFromOutside(path: string): boolean { + const target = this.currentTarget(); + if (!target || !matchesPath(target.url, path)) return false; + return !matchesPath(target.fromUrl, path); + } + + /** True while resolving a URL that stays inside `path`. */ + isResolvingInside(path: string): boolean { + const target = this.currentTarget(); + if (!target || !matchesPath(target.url, path)) return false; + return matchesPath(target.fromUrl, path); + } +} + +function matchesPath(url: string | null, prefix: string): boolean { + if (!url) return false; + const path = pathOf(url); + return path === prefix || path.startsWith(`${prefix}/`); +} + +function hasResolvers(state: RouterStateSnapshot): boolean { + let route: ActivatedRouteSnapshot | null = state.root; + while (route) { + if (Object.keys(route.routeConfig?.resolve ?? {}).length > 0) return true; + route = route.firstChild; + } + return false; +} diff --git a/webapp/src/app/shared/services/resolver-state.service.ts b/webapp/src/app/shared/services/resolver-state.service.ts deleted file mode 100644 index f6eb2052..00000000 --- a/webapp/src/app/shared/services/resolver-state.service.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Injectable, signal, inject, computed } from '@angular/core'; -import { Router, RouterEvent, ActivatedRoute } from '@angular/router'; -import { toSignal } from '@angular/core/rxjs-interop'; -import { ResolveEnd, ResolveStart } from '@angular/router'; -import { - NavigationEnd, - NavigationError, - NavigationCancel, -} from '@angular/router'; -@Injectable({ providedIn: 'root' }) -export class ResolverStateService { - private readonly router = inject(Router); - - readonly resolvingUrl = signal(null); - readonly previousUrl = signal(null); - - readonly isResolving = computed(() => this.resolvingUrl() !== null); - - constructor() { - this.router.events.subscribe((event) => { - if (event instanceof ResolveStart) { - this.previousUrl.set(this.router.url); // capture current before it changes - this.resolvingUrl.set(event.url); - } - - if ( - event instanceof NavigationEnd || - event instanceof NavigationCancel || - event instanceof NavigationError - ) { - this.resolvingUrl.set(null); - } - }); - } - - isResolvingFromOutside(path: string) { - const from = this.previousUrl(); - const to = this.resolvingUrl(); - if (!to?.startsWith(path)) return false; - return !from?.startsWith(path); // came from outside - } - - isResolvingInside(path: string) { - const from = this.previousUrl(); - const to = this.resolvingUrl(); - if (to?.startsWith(path) && from?.startsWith(path)) return true; - return false; - } -} diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.html b/webapp/src/app/shared/ui/app-layout/app-layout.component.html index b41ef3df..7f6c0b1b 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.html +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.html @@ -56,62 +56,13 @@ } -
+
- @if (resolverState.isResolvingFromOutside('/persons')) { - - } @else if (resolverState.isResolvingFromOutside('/person')) { - - } @else if (resolverState.isResolvingFromOutside('/publications')) { - - } @else if (resolverState.isResolvingFromOutside('/projects')) { - - } @else if (resolverState.isResolvingFromOutside('/institutions')) { - - } @else if (resolverState.isResolvingFromOutside('/patents')) { - - } @else if (resolverState.isResolvingFromOutside('/news')) { - - } @else if (resolverState.isResolvingFromOutside('/topics')) { - - } @else if (resolverState.isResolvingFromOutside('/hierarchy')) { - + @if (navigationState.skeleton(); as skeleton) { + } @else { } 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 7f47cb21..7a5400e1 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 @@ -25,24 +25,16 @@ import { AppMenuComponent } from '../app-menu/app-menu.component'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CredentialService } from '../../services/credential.service'; import { AppSearchbarComponent } from '../app-searchbar/app-searchbar.component'; -import { ResolverStateService } from '../../services/resolver-state.service'; +import { NavigationStateService } from '../../services/navigation-state.service'; +import { NavigationFocusService } from '../../services/navigation-focus.service'; import { BackNavigationService } from '../../services/back-navigation.service'; import { PageTitleService } from '../../services/page-title.service'; import { RouteScrollService } from '../../services/route-scroll.service'; -import { LoadingComponent } from '../loading/loading.component'; +import { PageSkeletonComponent } from '../page-skeleton/page-skeleton.component'; import { ARROW_BACK_ICON, - INSTITUTION_ICON, MENU_ICON, - NEWS_ICON, - PATENT_ICON, - PERSONS_ICON, - PERSON_ICON, - PROJECT_ICON, - PUBLICATION_ICON, SWITCH_ACCOUNT_ICON, - TOPIC_ICON, - HIERARCHY_ICON, } from '../icons'; @Component({ @@ -56,7 +48,7 @@ import { AppMenuComponent, MatTooltipModule, AppSearchbarComponent, - LoadingComponent, + PageSkeletonComponent, ], templateUrl: './app-layout.component.html', styleUrl: './app-layout.component.scss', @@ -66,28 +58,21 @@ export class AppLayoutComponent implements OnInit, OnDestroy { readonly SWITCH_ACCOUNT_ICON = SWITCH_ACCOUNT_ICON; readonly MENU_ICON = MENU_ICON; readonly ARROW_BACK_ICON = ARROW_BACK_ICON; - readonly PERSONS_ICON = PERSONS_ICON; - readonly PERSON_ICON = PERSON_ICON; - readonly PUBLICATION_ICON = PUBLICATION_ICON; - readonly PROJECT_ICON = PROJECT_ICON; - readonly INSTITUTION_ICON = INSTITUTION_ICON; - readonly PATENT_ICON = PATENT_ICON; - readonly NEWS_ICON = NEWS_ICON; - readonly HIERARCHY_ICON = HIERARCHY_ICON; - readonly TOPIC_ICON = TOPIC_ICON; @ViewChild(MatDrawer, { static: false }) drawer?: MatDrawer; mediaQuery: MediaQueryList; - protected resolverState = inject(ResolverStateService); + protected navigationState = inject(NavigationStateService); mediaQueryListener: () => void; private readonly destroyRef = inject(DestroyRef); private readonly backNavigation = inject(BackNavigationService); private readonly scrollService = inject(RouteScrollService); - // Instantiated for its router subscription; keeps document.title in sync. + // Instantiated for their router subscriptions; keeps document.title in sync + // and moves focus to the new page heading after navigation. private readonly pageTitle = inject(PageTitleService); + private readonly navigationFocus = inject(NavigationFocusService); private readonly contentScroller = viewChild>('contentScroller'); private readonly currentPath = signal('/'); diff --git a/webapp/src/app/shared/ui/card-search/card-search.component.html b/webapp/src/app/shared/ui/card-search/card-search.component.html index 72c99f8b..4074a201 100644 --- a/webapp/src/app/shared/ui/card-search/card-search.component.html +++ b/webapp/src/app/shared/ui/card-search/card-search.component.html @@ -31,6 +31,7 @@ @let pageValue = page();
+ @if (loading()) {
(); sortingDirectionQueryParamKey = input('sorting_order'); sortingDirectionLabel = input('Sortierreihenfolge'); + + /** Announced to screen readers whenever a new result set is rendered. */ + readonly resultAnnouncement = computed(() => { + if (this.loading()) return ''; + const total = this.page().total ?? 0; + if (total === 0) return 'Keine Ergebnisse'; + return total === 1 ? '1 Ergebnis' : `${total} Ergebnisse`; + }); } diff --git a/webapp/src/app/shared/ui/live-region/live-region.component.ts b/webapp/src/app/shared/ui/live-region/live-region.component.ts new file mode 100644 index 00000000..14d2e6a7 --- /dev/null +++ b/webapp/src/app/shared/ui/live-region/live-region.component.ts @@ -0,0 +1,33 @@ +import { Component, effect, input, signal } from '@angular/core'; + +/** + * Visually hidden live region. Screen readers announce text changes, while + * sighted users see the normal result count elsewhere on the page. + * + * The text is applied in the next frame so that the region is already part of + * the accessibility tree when its content changes. Screen readers then treat + * it as an update and announce it, including on the first render. + */ +@Component({ + selector: 'app-live-region', + template: `{{ announcement() }}`, +}) +export class LiveRegionComponent { + readonly text = input(''); + + private readonly pending = signal(''); + readonly announcement = this.pending.asReadonly(); + + constructor() { + effect((onCleanup) => { + const text = this.text(); + const handle = requestAnimationFrame(() => this.pending.set(text)); + onCleanup(() => cancelAnimationFrame(handle)); + }); + } +} diff --git a/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.html b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.html new file mode 100644 index 00000000..e32a73bf --- /dev/null +++ b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.html @@ -0,0 +1,316 @@ +
+ @if (!compact()) { +
+ + {{ label() }} +
+ + + } + + +
+ + + +
+ + + +
+
+ + +
+
+ + + +
+ +
+
+ + +
+ @for (card of [1, 2, 3, 4, 5, 6]; track card) { +
+ + + + +
+ } +
+
+ + +
+
+ +
+ @for (row of [1, 2, 3, 4, 5, 6, 7]; track row) { +
+ +
+ } +
+
+ +
+
+ + +
+ +
+ + +
+ @for (chip of [1, 2, 3]; track chip) { + + } +
+
+
+
+ + +
+ @for (tab of [1, 2, 3, 4]; track tab) { + + } +
+
+ + +
+ +
+ @for (height of [45, 68, 52, 88, 61, 76, 48, 70]; track $index) { + + } +
+
+
diff --git a/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.scss b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.scss new file mode 100644 index 00000000..cf45d7c9 --- /dev/null +++ b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.scss @@ -0,0 +1,522 @@ +:host { + display: block; + width: 100%; + min-width: 0; +} + +.page-skeleton { + display: flex; + flex-direction: column; + gap: 14px; + padding: clamp(8px, 1.4vw, 18px); + + &--compact { + gap: 0; + padding: 0; + + .page-skeleton__body { + margin-top: 0; + } + } +} + +.page-skeleton__status { + display: flex; + align-items: center; + gap: 8px; + color: var(--sg-text-soft); + font-size: 13px; + + mat-icon { + flex: none; + width: 18px; + height: 18px; + font-size: 18px; + } +} + +.page-skeleton__header { + display: flex; + flex-direction: column; + gap: 8px; +} + +.page-skeleton__body { + display: flex; + flex-direction: column; + gap: 14px; + margin-top: 4px; +} + +/* Shimmer bars ------------------------------------------------------------ */ +.sk-bar { + display: block; + flex: none; + height: 12px; + border-radius: 6px; + background: linear-gradient( + 90deg, + var(--sg-skeleton-base) 25%, + var(--sg-skeleton-highlight) 50%, + var(--sg-skeleton-base) 75% + ); + background-size: 600px 100%; + animation: page-skeleton-shimmer 1.6s infinite linear; + + &--eyebrow { + width: 180px; + max-width: 40%; + height: 9px; + } + + &--title { + width: 360px; + max-width: 60%; + height: 26px; + } + + &--subtitle { + width: 520px; + max-width: 80%; + } + + &--section-title { + width: 220px; + max-width: 50%; + height: 18px; + } + + &--card-title { + width: 60%; + height: 16px; + } + + &--short { + width: 45%; + } + + &--search { + width: min(360px, 40%); + height: 36px; + border-radius: 18px; + } + + &--select, + &--field { + width: 180px; + max-width: 30%; + height: 36px; + border-radius: 8px; + } + + &--toolbar { + width: 220px; + max-width: 35%; + height: 14px; + } + + &--filter { + width: 100%; + height: 14px; + } + + &--button { + width: 140px; + height: 34px; + border-radius: 8px; + background: color-mix(in srgb, var(--sg-primary, #345) 25%, transparent); + } + + &--chip { + width: 86px; + height: 24px; + border-radius: 12px; + } + + &--tab { + width: 110px; + height: 30px; + } + + &--accordion { + width: 100%; + height: 40px; + border-radius: 8px; + } + + &--kpi-label { + width: 70%; + height: 9px; + } + + &--kpi-value { + width: 50%; + height: 22px; + } + + &--pagination { + width: 280px; + max-width: 60%; + height: 24px; + } +} + +/* Search/filter/toolbar rows of list pages -------------------------------- */ +.sk-filters, +.sk-toolbar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px; +} + +.sk-toolbar { + justify-content: space-between; +} + +.sk-chips { + display: flex; + flex-wrap: wrap; + gap: 8px; +} + +.sk-pagination { + display: flex; + justify-content: flex-end; +} + +/* Card grids -------------------------------------------------------------- */ +.sk-cards { + display: grid; + grid-template-columns: repeat( + auto-fill, + minmax(var(--sk-card-min-width, 260px), 1fr) + ); + gap: 16px; +} + +.sk-card { + display: flex; + min-height: 130px; + flex-direction: column; + gap: 10px; + padding: 18px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); +} + +/* Person list: grid plus filter sidebar ----------------------------------- */ +.sk-split { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); + gap: 20px; + + &__main { + min-width: 0; + } +} + +/* Tables ------------------------------------------------------------------ */ +.sk-table { + display: flex; + flex-direction: column; + overflow: hidden; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); + + &--compact .sk-table__row { + grid-template-columns: 2fr 1fr 0.6fr; + padding: 10px 14px; + } + + &--two-col .sk-table__row { + grid-template-columns: 1fr 2fr; + } +} + +.sk-compare-tables { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 16px; +} + +.sk-table__row { + display: grid; + grid-template-columns: 2fr 1fr 1fr 0.6fr; + gap: 16px; + padding: 14px 18px; + + & + & { + border-top: 1px solid var(--sg-border); + } + + &--head { + background: var(--sg-surface-soft); + } +} + +/* Detail pages: hero, tabs, main + aside ---------------------------------- */ +.sk-hero { + display: flex; + align-items: flex-start; + gap: 18px; + padding: 18px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); + + &__copy { + display: flex; + flex: 1; + min-width: 0; + flex-direction: column; + gap: 10px; + } +} + +.sk-avatar { + flex: none; + width: 64px; + height: 64px; + border-radius: 50%; + background: var(--sg-skeleton-base); + animation: page-skeleton-pulse 1.6s infinite ease-in-out; +} + +.sk-tabs { + display: flex; + gap: 18px; + padding-bottom: 8px; + border-bottom: 1px solid var(--sg-border); +} + +.sk-detail { + display: grid; + grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); + gap: 20px; +} + +.sk-panel { + display: flex; + flex-direction: column; + gap: 12px; + padding: 18px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); + + .sk-table { + margin-top: 4px; + } +} + +/* Dashboard: KPI tiles + chart panels ------------------------------------- */ +.sk-kpis { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); + gap: 12px; + + &--many { + grid-template-columns: repeat(4, minmax(0, 1fr)); + } +} + +.sk-kpi { + display: flex; + min-height: 78px; + flex-direction: column; + justify-content: center; + gap: 10px; + padding: 14px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); +} + +.sk-chart-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); + gap: 16px; +} + +.sk-chart { + display: flex; + height: 170px; + align-items: flex-end; + gap: 10px; + padding: 12px 4px 0; + + &__axis { + align-self: stretch; + width: 1px; + background: var(--sg-border); + } + + &__bars { + display: flex; + height: 100%; + flex: 1; + align-items: flex-end; + justify-content: space-around; + gap: 8px; + border-bottom: 1px solid var(--sg-border); + } + + &__bar { + width: min(32px, 8%); + border-radius: 4px 4px 0 0; + background: var(--sg-skeleton-base); + animation: page-skeleton-pulse 1.6s infinite ease-in-out; + } +} + +/* Hierarchy tree ---------------------------------------------------------- */ +.sk-accordion { + display: flex; + flex-direction: column; + gap: 8px; +} + +.sk-tree { + gap: 14px; + + &__node { + display: block; + width: min(320px, 70%); + height: 16px; + border-radius: 8px; + background: linear-gradient( + 90deg, + var(--sg-skeleton-base) 25%, + var(--sg-skeleton-highlight) 50%, + var(--sg-skeleton-base) 75% + ); + background-size: 600px 100%; + animation: page-skeleton-shimmer 1.6s infinite linear; + + &::before { + display: inline-block; + width: 8px; + height: 8px; + margin-right: 10px; + border-radius: 2px; + background: var(--sg-border-strong); + content: ''; + vertical-align: middle; + } + } +} + +/* Keyword form and chip matrix -------------------------------------------- */ +.sk-form { + display: flex; + flex-direction: column; + gap: 12px; + padding: 18px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); +} + +.sk-matrix { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 10px; + padding: 18px; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); +} + +/* Collaboration network --------------------------------------------------- */ +.sk-graph { + position: relative; + height: min(52vh, 420px); + min-height: 240px; + overflow: hidden; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-surface-muted); + + &__node { + position: absolute; + width: 18px; + height: 18px; + margin: -9px 0 0 -9px; + border-radius: 50%; + background: var(--sg-skeleton-base); + animation: page-skeleton-pulse 1.6s infinite ease-in-out; + + &--center { + top: 50%; + left: 50%; + width: 30px; + height: 30px; + margin: -15px 0 0 -15px; + } + } +} + +@keyframes page-skeleton-shimmer { + from { + background-position: -600px 0; + } + + to { + background-position: 600px 0; + } +} + +@keyframes page-skeleton-pulse { + 0%, + 100% { + opacity: 0.55; + } + + 50% { + opacity: 1; + } +} + +@media (max-width: 900px) { + .sk-detail, + .sk-split { + grid-template-columns: 1fr; + } + + .sk-kpis--many { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + .sk-compare-tables { + grid-template-columns: 1fr; + } + + .sk-matrix { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + .sk-table:not(.sk-table--two-col) .sk-table__row { + grid-template-columns: 2fr 1fr 0.6fr; + + .sk-bar:last-child { + display: none; + } + } +} + +@media (prefers-reduced-motion: reduce) { + .sk-bar, + .sk-tree__node { + animation: none; + background: var(--sg-skeleton-base); + } + + .sk-avatar, + .sk-chart__bar, + .sk-graph__node { + animation: none; + } +} diff --git a/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.ts b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.ts new file mode 100644 index 00000000..0cbaa0a3 --- /dev/null +++ b/webapp/src/app/shared/ui/page-skeleton/page-skeleton.component.ts @@ -0,0 +1,38 @@ +import { NgTemplateOutlet } from '@angular/common'; +import { Component, input } from '@angular/core'; +import { MatIconModule } from '@angular/material/icon'; +import { PageSkeletonVariant } from '../../services/navigation-sections'; + +/** Fixed node positions for the network graph placeholder. */ +const GRAPH_NODES = [ + { x: 18, y: 26 }, + { x: 38, y: 14 }, + { x: 73, y: 20 }, + { x: 85, y: 52 }, + { x: 62, y: 78 }, + { x: 26, y: 72 }, + { x: 10, y: 52 }, +]; + +/** + * Generic page placeholder shown while route resolvers run. Its variants + * mirror the page layouts (card grids, tables, detail pages, dashboards, + * trees, forms and graphs) so the loaded page does not shift the layout. + */ +@Component({ + selector: 'app-page-skeleton', + imports: [MatIconModule, NgTemplateOutlet], + templateUrl: './page-skeleton.component.html', + styleUrl: './page-skeleton.component.scss', +}) +export class PageSkeletonComponent { + readonly label = input('Inhalte werden geladen …'); + readonly icon = input('hourglass_empty'); + readonly variant = input('table'); + /** Render only the body, e.g. inside an existing page's results panel. */ + readonly compact = input(false); + /** Minimum card width, so the placeholder grid matches the real grid. */ + readonly cardMinWidth = input(260); + + readonly nodes = GRAPH_NODES; +} diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index c5f9c45c..1b73fcf2 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -750,3 +750,24 @@ html.dark-theme { flex-shrink: 0; transition: transform 0.3s ease; } + +/* Screen-reader-only content (result announcements, see LiveRegionComponent). */ +.visually-hidden { + position: absolute !important; + width: 1px !important; + height: 1px !important; + margin: -1px !important; + padding: 0 !important; + overflow: hidden !important; + clip: rect(0 0 0 0) !important; + clip-path: inset(50%) !important; + white-space: nowrap !important; + border: 0 !important; +} + +/* Focus targets set by NavigationFocusService: no visible ring on the page + frame itself, the heading is announced by screen readers instead. */ +main[tabindex='-1']:focus, +main [tabindex='-1']:focus { + outline: none; +}