diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.spec.ts b/webapp/src/app/modules/person-interesting/person-interesting.component.spec.ts index 0a056035..c20e79de 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.spec.ts +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { provideRouter } from '@angular/router'; import { PersonInterestingComponent } from './person-interesting.component'; @@ -9,6 +10,7 @@ describe('PersonInterestingComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [PersonInterestingComponent], + providers: [provideRouter([])], }).compileComponents(); fixture = TestBed.createComponent(PersonInterestingComponent); 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 1a695ead..122cda7e 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.ts +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.ts @@ -1,7 +1,18 @@ -import { Component, input, computed, output, signal } from '@angular/core'; +import { + Component, + DestroyRef, + OnInit, + computed, + inject, + input, + output, + signal, +} from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CommonModule } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; import { TopicCount } from '../../api'; import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component'; @@ -42,7 +53,14 @@ const MAX_LEGEND_GROUPS = 3; templateUrl: './person-interesting.component.html', styleUrl: './person-interesting.component.scss', }) -export class PersonInterestingComponent { +export class PersonInterestingComponent implements OnInit { + private static readonly legendExpandedQueryParam = + 'interesting_legend_expanded'; + + private readonly route = inject(ActivatedRoute); + private readonly router = inject(Router); + private readonly destroyRef = inject(DestroyRef); + readonly topics = input(null); readonly legendExpanded = signal(false); @@ -132,12 +150,58 @@ export class PersonInterestingComponent { .reduce((count, group) => count + group.items.length, 0), ); + ngOnInit(): void { + this.route.queryParamMap + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe((queryParams) => { + this.legendExpanded.set( + this.parseBooleanQueryParam( + queryParams.get( + PersonInterestingComponent.legendExpandedQueryParam, + ), + false, + ), + ); + }); + } + onTagClick(tag: InterestTag): void { if (!tag.id) return; this.tagClick.emit({ id: tag.id, name: tag.label }); } toggleLegend(): void { - this.legendExpanded.update((expanded) => !expanded); + const expanded = !this.legendExpanded(); + this.legendExpanded.set(expanded); + + void this.router.navigate([], { + relativeTo: this.route, + queryParams: { + [PersonInterestingComponent.legendExpandedQueryParam]: expanded + ? 'true' + : null, + }, + queryParamsHandling: 'merge', + replaceUrl: true, + }); + } + + private parseBooleanQueryParam( + value: string | null, + fallback: boolean, + ): boolean { + if (value === null) { + return fallback; + } + + if (value === 'true' || value === '1') { + return true; + } + + if (value === 'false' || value === '0') { + return false; + } + + return fallback; } } diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts index 268dc074..60fb616f 100644 --- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts +++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts @@ -112,12 +112,16 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked { @Input() viewMode: TimelineViewMode = 'years'; @Input() startYear: number | undefined; @Input() endYear: number | undefined; + @Input() subfieldLegendVisible = true; + @Input() subfieldLegendExpanded = false; @Output() viewModeChange = new EventEmitter(); @Output() yearRangeChange = new EventEmitter(); @Output() topicSelect = new EventEmitter(); @Output() yearSelect = new EventEmitter(); @Output() loadEarlierYears = new EventEmitter(); + @Output() subfieldLegendVisibleChange = new EventEmitter(); + @Output() subfieldLegendExpandedChange = new EventEmitter(); timelineViewMode: TimelineViewMode = 'years'; @@ -125,8 +129,6 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked { maxYear = 0; selectedStartYear = 0; selectedEndYear = 0; - subfieldLegendVisible = true; - subfieldLegendExpanded = false; private readonly columnWidth = 240; private readonly displayedTopicLimit = 3; @@ -146,12 +148,10 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked { this.timelineViewMode = this.isTimelineViewMode(this.viewMode) ? this.viewMode : 'years'; - this.subfieldLegendExpanded = false; } if (changes['elements']) { this.initializeYearBounds(); - this.subfieldLegendExpanded = false; } if (changes['elements'] || changes['startYear'] || changes['endYear']) { @@ -443,10 +443,12 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked { toggleSubfieldLegend(): void { this.subfieldLegendExpanded = !this.subfieldLegendExpanded; + this.subfieldLegendExpandedChange.emit(this.subfieldLegendExpanded); } toggleSubfieldLegendVisibility(): void { this.subfieldLegendVisible = !this.subfieldLegendVisible; + this.subfieldLegendVisibleChange.emit(this.subfieldLegendVisible); } trackByLegendGroup(_: number, group: TopicFieldLegendGroup): string { diff --git a/webapp/src/app/modules/person-overview/person-overview.component.html b/webapp/src/app/modules/person-overview/person-overview.component.html index 31ac9ae8..ae891993 100644 --- a/webapp/src/app/modules/person-overview/person-overview.component.html +++ b/webapp/src/app/modules/person-overview/person-overview.component.html @@ -9,8 +9,12 @@ [viewMode]="timelineViewMode" [startYear]="timelineStartYear" [endYear]="timelineEndYear" + [subfieldLegendVisible]="timelineLegendVisible" + [subfieldLegendExpanded]="timelineLegendExpanded" (viewModeChange)="onTimelineViewModeChange($event)" (yearRangeChange)="onTimelineYearRangeChange($event)" + (subfieldLegendVisibleChange)="onTimelineLegendVisibleChange($event)" + (subfieldLegendExpandedChange)="onTimelineLegendExpandedChange($event)" (topicSelect)="onTimelineTopicSelect($event)" (yearSelect)="onTimelineYearSelect($event)" (loadEarlierYears)="onTimelineLoadEarlierYears()"> diff --git a/webapp/src/app/modules/person-overview/person-overview.component.ts b/webapp/src/app/modules/person-overview/person-overview.component.ts index 97fb8c8b..fa76ba7e 100644 --- a/webapp/src/app/modules/person-overview/person-overview.component.ts +++ b/webapp/src/app/modules/person-overview/person-overview.component.ts @@ -28,6 +28,10 @@ export class PersonOverviewComponent implements OnInit { private static readonly timelineViewQueryParam = 'timeline_view'; private static readonly timelineStartYearQueryParam = 'timeline_start_year'; private static readonly timelineEndYearQueryParam = 'timeline_end_year'; + private static readonly timelineLegendVisibleQueryParam = + 'timeline_legend_visible'; + private static readonly timelineLegendExpandedQueryParam = + 'timeline_legend_expanded'; private static readonly timelineTopicCountLimit = 4; private static readonly initialTimelineTargetPublications = 250; @@ -49,6 +53,8 @@ export class PersonOverviewComponent implements OnInit { timelineViewMode: TimelineViewMode = 'years'; timelineStartYear: number | undefined; timelineEndYear: number | undefined; + timelineLegendVisible = true; + timelineLegendExpanded = false; wordCloudOptions: EChartsOption | null = null; loadingWordCloud = false; @@ -84,6 +90,18 @@ export class PersonOverviewComponent implements OnInit { this.timelineEndYear = this.parseOptionalYear( queryParams.get(PersonOverviewComponent.timelineEndYearQueryParam), ); + this.timelineLegendVisible = this.parseBooleanQueryParam( + queryParams.get( + PersonOverviewComponent.timelineLegendVisibleQueryParam, + ), + true, + ); + this.timelineLegendExpanded = this.parseBooleanQueryParam( + queryParams.get( + PersonOverviewComponent.timelineLegendExpandedQueryParam, + ), + false, + ); }); } @@ -112,6 +130,32 @@ export class PersonOverviewComponent implements OnInit { ); } + onTimelineLegendVisibleChange(visible: boolean): void { + this.timelineLegendVisible = visible; + + this.updateTimelineQueryParams( + { + [PersonOverviewComponent.timelineLegendVisibleQueryParam]: visible + ? null + : 'false', + }, + true, + ); + } + + onTimelineLegendExpandedChange(expanded: boolean): void { + this.timelineLegendExpanded = expanded; + + this.updateTimelineQueryParams( + { + [PersonOverviewComponent.timelineLegendExpandedQueryParam]: expanded + ? 'true' + : null, + }, + true, + ); + } + onTimelineTopicSelect(selection: TimelineTopicSelection): void { if (!selection.topic.id) { return; @@ -499,8 +543,27 @@ export class PersonOverviewComponent implements OnInit { return year; } + private parseBooleanQueryParam( + value: string | null, + fallback: boolean, + ): boolean { + if (value === null) { + return fallback; + } + + if (value === 'true' || value === '1') { + return true; + } + + if (value === 'false' || value === '0') { + return false; + } + + return fallback; + } + private updateTimelineQueryParams( - queryParams: Record, + queryParams: Record, replaceUrl: boolean, ): void { void this.router.navigate([], {