diff --git a/webapp/src/app/directives/component-tooltip.directive.ts b/webapp/src/app/directives/component-tooltip.directive.ts index daccfa52..2f9e8735 100644 --- a/webapp/src/app/directives/component-tooltip.directive.ts +++ b/webapp/src/app/directives/component-tooltip.directive.ts @@ -45,6 +45,7 @@ export class ComponentTooltipDirective implements OnDestroy { private componentRef: ComponentRef | null = null; private showTimeout?: ReturnType; private hideTimeout?: ReturnType; + private dismissTimeout?: ReturnType; private isOverHost = false; private isOverOverlay = false; @@ -84,6 +85,24 @@ export class ComponentTooltipDirective implements OnDestroy { this.scheduleHide(); } + @HostListener('click') + onHostClick(): void { + this.scheduleDismiss(); + } + + private scheduleDismiss(): void { + clearTimeout(this.dismissTimeout); + this.dismissTimeout = setTimeout(() => this.dismiss()); + } + + private dismiss(): void { + clearTimeout(this.showTimeout); + clearTimeout(this.hideTimeout); + this.isOverHost = false; + this.isOverOverlay = false; + this.hide(); + } + private scheduleHide(): void { this.hideTimeout = setTimeout(() => { if (!this.isOverHost && !this.isOverOverlay) { @@ -155,6 +174,7 @@ export class ComponentTooltipDirective implements OnDestroy { overlayElement.addEventListener('mouseenter', this.onOverlayEnter); overlayElement.addEventListener('mouseleave', this.onOverlayLeave); + overlayElement.addEventListener('click', this.onOverlayClick, true); } private applyMaxWidth( @@ -179,11 +199,16 @@ export class ComponentTooltipDirective implements OnDestroy { this.scheduleHide(); }; + private readonly onOverlayClick = (): void => { + this.scheduleDismiss(); + }; + private hide(): void { if (this.overlayRef) { const overlayElement = this.overlayRef.overlayElement; overlayElement.removeEventListener('mouseenter', this.onOverlayEnter); overlayElement.removeEventListener('mouseleave', this.onOverlayLeave); + overlayElement.removeEventListener('click', this.onOverlayClick, true); this.overlayRef.detach(); } this.componentRef = null; @@ -192,6 +217,7 @@ export class ComponentTooltipDirective implements OnDestroy { ngOnDestroy(): void { clearTimeout(this.showTimeout); clearTimeout(this.hideTimeout); + clearTimeout(this.dismissTimeout); this.overlayRef?.dispose(); } } diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.html b/webapp/src/app/modules/person-interesting/person-interesting.component.html index 87a7ed5e..5ac0ea97 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.html +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.html @@ -44,6 +44,9 @@ [color]="tag.color" [disabled]="!tag.id" [active]="isTagActive(tag)" + [secondaryActionLabel]="tagAction(tag)?.label ?? null" + [secondaryActionLink]="tagAction(tag)?.link ?? null" + [secondaryActionQueryParams]="tagAction(tag)?.queryParams ?? null" countIcon="article" descriptionTooltipTarget="button" (chipClick)="onTagClick(tag)"> diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.ts b/webapp/src/app/modules/person-interesting/person-interesting.component.ts index ad3307bf..dc1fc4d3 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.ts +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.ts @@ -14,6 +14,7 @@ import { CommonModule } from '@angular/common'; import { ActivatedRoute, Router } from '@angular/router'; import { TopicCount } from '../../api'; +import { workQueryParamKeys } from '../../resolvers/work-page.resolver'; import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component'; import { TopicLegendComponent } from '../../shared/ui/topic-legend/topic-legend.component'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; @@ -45,6 +46,12 @@ interface InterestTag { domainDescription: string; } +interface InterestTagAction { + label: string; + link: unknown[]; + queryParams: Record; +} + const MAX_TAGS = 5; @Component({ @@ -69,6 +76,10 @@ export class PersonInterestingComponent implements OnInit { readonly topics = input(null); readonly loading = input(false); + + readonly personPublicationsLink = input(null); + readonly personName = input(''); + readonly legendExpanded = signal(false); readonly activeLegendFieldIds = signal>(new Set()); readonly activeLegendSubfieldIds = signal>(new Set()); @@ -142,6 +153,36 @@ export class PersonInterestingComponent implements OnInit { }); } + private readonly tagActions = computed(() => { + const actions = new Map(); + const link = this.personPublicationsLink(); + + if (!link) { + return actions; + } + + const person = this.personName() || 'dieser Person'; + + for (const tag of this.tags()) { + if (!tag.id) continue; + + actions.set(tag.id, { + label: `Publikationen von ${person}`, + link, + queryParams: { + [workQueryParamKeys.page]: 0, + [workQueryParamKeys.topicId]: tag.id, + }, + }); + } + + return actions; + }); + + tagAction(tag: InterestTag): InterestTagAction | null { + return this.tagActions().get(tag.id) ?? null; + } + onTagClick(tag: InterestTag): void { if (!tag.id) return; this.tagClick.emit({ diff --git a/webapp/src/app/modules/person/person.component.html b/webapp/src/app/modules/person/person.component.html index 1fd0a34b..40abbf6b 100644 --- a/webapp/src/app/modules/person/person.component.html +++ b/webapp/src/app/modules/person/person.component.html @@ -130,6 +130,8 @@ @if (this.links()) { diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index f32588d1..afd17359 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -5,6 +5,7 @@ import { inject, signal, DestroyRef, + ElementRef, input, viewChild, } from '@angular/core'; @@ -18,11 +19,20 @@ import { MatTabsModule } from '@angular/material/tabs'; import { MatTooltipModule } from '@angular/material/tooltip'; import { ActivatedRoute, + NavigationEnd, Router, RouterModule, RouterOutlet, } from '@angular/router'; -import { of, switchMap, finalize, map, catchError, combineLatest } from 'rxjs'; +import { + of, + switchMap, + finalize, + map, + catchError, + combineLatest, + filter, +} from 'rxjs'; import { PersonInterestingComponent } from '../person-interesting/person-interesting.component'; import { CountryFlagComponent } from '../../shared/ui/country-flag/country-flag.component'; @@ -82,11 +92,28 @@ export class PersonComponent { () => this.navBar()?.activeLink() ?? null, ); + private readonly tabPanelElement = viewChild('tabPanel', { + read: ElementRef, + }); + + private publicationFilterKey: string | null = null; + constructor() { this.bookmarkService .load() .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe(); + + this.router.events + .pipe( + filter( + (event): event is NavigationEnd => event instanceof NavigationEnd, + ), + takeUntilDestroyed(this.destroyRef), + ) + .subscribe((event) => + this.scrollToPanelOnFilterChange(event.urlAfterRedirects), + ); } readonly params = toSignal(this.activatedRoute.paramMap); @@ -169,6 +196,13 @@ export class PersonComponent { readonly displayName = computed( () => this.person()?.display_name ?? 'Unbekannte Person', ); + + readonly personName = computed(() => this.person()?.display_name ?? ''); + + readonly personPublicationsLink = computed(() => { + const authorId = this.authorId(); + return authorId ? ['/person', authorId, 'publications'] : null; + }); readonly initials = computed(() => this.buildInitials(this.displayName())); readonly primaryAffiliation = computed( () => this.person()?.affiliations?.[0] ?? null, @@ -368,6 +402,46 @@ export class PersonComponent { }); } + private scrollToPanelOnFilterChange(url: string): void { + const { queryParams } = this.router.parseUrl(url); + const filterKey = [workQueryParamKeys.topicId, workQueryParamKeys.years] + .map((key) => { + const value = queryParams[key]; + return Array.isArray(value) ? value.join(',') : (value ?? ''); + }) + .join('|'); + + const previousFilterKey = this.publicationFilterKey; + this.publicationFilterKey = filterKey; + + const hasFilter = filterKey !== '|'; + const isFirstNavigation = previousFilterKey === null; + + if (isFirstNavigation || !hasFilter || filterKey === previousFilterKey) { + return; + } + + this.scrollPanelIntoView(); + } + + private scrollPanelIntoView(): void { + const scrollToPanel = (): void => { + this.tabPanelElement()?.nativeElement.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + }; + + requestAnimationFrame(scrollToPanel); + + setTimeout(() => { + const panel = this.tabPanelElement(); + if (panel && panel.nativeElement.getBoundingClientRect().top > 8) { + scrollToPanel(); + } + }, 400); + } + private getId(key: string): string | null { const ids = this.person()?.ids as Record | undefined; if (!ids) {