import { AfterViewInit, Component, ElementRef, HostListener, OnInit, ViewChild, } from '@angular/core'; import { DecimalPipe } from '@angular/common'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { MatSelectModule } from '@angular/material/select'; import { MatTooltipModule } from '@angular/material/tooltip'; import { Observable, finalize } from 'rxjs'; import { ActivatedRoute, Router, RouterLink } from '@angular/router'; import { MatDialog } from '@angular/material/dialog'; import { ComponentTooltipDirective } from '../../directives/component-tooltip.directive'; import { AppAuthorTooltipComponent } from '../../shared/ui/app-author-tooltip/app-author-tooltip.component'; import { ACCOUNT_BALANCE_ICON, ACCOUNT_TREE_ICON, ARTICLE_ICON, DESCRIPTION_ICON, GROUPS_ICON, MENU_BOOK_ICON, PATENT_ICON, PUBLIC_ICON, SCIENCE_ICON, STACKED_BAR_CHART_ICON, } from '../../shared/ui/icons'; import { EuProjectStatusChartComponent } from './eu-project-status-chart/eu-project-status-chart.component'; import { YearRangeSliderComponent } from '../../shared/ui/year-range-slider/year-range-slider.component'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; import { TopicTreemapComponent } from '../../shared/ui/topic-treemap/topic-treemap.component'; import { TopicTreemapData, TopicTreemapTopicSelect, } from '../../shared/ui/topic-treemap/topic-treemap.models'; import { TopicWordCloudDialogComponent, TopicWordCloudDialogData, } from './topic-wordcloud-dialog/topic-wordcloud-dialog.component'; import { BmbfProjectStatusStatistics, BundProjectTopics, DashboardInstitution, DashboardPeriodBounds, DashboardStatisticValue, DashboardStatistics, DashboardStatisticsService, DfgProjectStatusStatistics, DfgProjectTopic, DfgProjectTopics, EuProjectStatusStatistics, EuProjectTopics, TopAuthor, TopAuthorStatistics, } from './dashboard-statistics.service'; import { institutionPersonListQueryParamsForPeriod, PersonListQueryParams, } from '../../shared/person-list-query-params'; type DashboardStatisticKey = | 'publications' | 'persons' | 'patents' | 'eu_projects' | 'bmbf_projects' | 'dfg_projects'; type TopAuthorDataset = { title: string; subtitle: string; icon: string; entries: TopAuthor[]; stripAuthorTitle?: boolean; }; type DashboardPeriodMode = | 'all_time' | 'last_10_years' | 'last_5_years' | 'custom'; @Component({ selector: 'dashboard', imports: [ DecimalPipe, MatFormFieldModule, MatIconModule, MatSelectModule, MatTooltipModule, ComponentTooltipDirective, RouterLink, LoadingComponent, EuProjectStatusChartComponent, TopicTreemapComponent, YearRangeSliderComponent, ], templateUrl: './dashboard.component.html', styleUrl: './dashboard.component.scss', }) export class DashboardComponent implements OnInit, AfterViewInit { @ViewChild('analyticalInstitutionTabList') private analyticalInstitutionTabList?: ElementRef; readonly AuthorTooltipComponent = AppAuthorTooltipComponent; readonly patentIcon = PATENT_ICON; readonly MENU_BOOK_ICON = MENU_BOOK_ICON; readonly GROUPS_ICON = GROUPS_ICON; readonly PUBLIC_ICON = PUBLIC_ICON; readonly ACCOUNT_BALANCE_ICON = ACCOUNT_BALANCE_ICON; readonly SCIENCE_ICON = SCIENCE_ICON; readonly STACKED_BAR_CHART_ICON = STACKED_BAR_CHART_ICON; readonly ACCOUNT_TREE_ICON = ACCOUNT_TREE_ICON; statistics?: Partial; statisticsLoading = false; statisticsError = false; statisticLoading: Record = { publications: false, persons: false, patents: false, eu_projects: false, bmbf_projects: false, dfg_projects: false, }; statisticErrors: Record = { publications: false, persons: false, patents: false, eu_projects: false, bmbf_projects: false, dfg_projects: false, }; private pendingStatisticRequests = 0; topAuthors?: TopAuthorStatistics; topAuthorsLoading = false; topAuthorsError = false; topicTreemap?: TopicTreemapData; topicTreemapLoading = false; topicTreemapError = false; dfgProjectTopics?: DfgProjectTopics; dfgTopicTreemap?: TopicTreemapData; dfgTopicsLoading = false; dfgTopicsError = false; euProjectTopics?: EuProjectTopics; euTopicTreemap?: TopicTreemapData; euTopicsLoading = false; euTopicsError = false; bundProjectTopics?: BundProjectTopics; bundTopicTreemap?: TopicTreemapData; bundTopicsLoading = false; bundTopicsError = false; euProjectStatuses?: EuProjectStatusStatistics; euProjectStatusesLoading = false; euProjectStatusesError = false; bmbfProjectStatuses?: BmbfProjectStatusStatistics; bmbfProjectStatusesLoading = false; bmbfProjectStatusesError = false; dfgProjectStatuses?: DfgProjectStatusStatistics; dfgProjectStatusesLoading = false; dfgProjectStatusesError = false; readonly topicTreemapMinYear = 1900; readonly topicTreemapMaxYear = new Date().getFullYear(); dashboardPeriodMode: DashboardPeriodMode = 'all_time'; dashboardFromYear = this.topicTreemapMinYear; dashboardToYear = this.topicTreemapMaxYear; dashboardInstitutions: DashboardInstitution[] = []; selectedDashboardInstitutionId = 'all'; selectedAnalyticalInstitutionId = ''; dashboardInstitutionsLoading = false; dashboardInstitutionsError = false; canScrollAnalyticalInstitutionTabsLeft = false; canScrollAnalyticalInstitutionTabsRight = false; selectedTopicTreemapNode?: string; selectedDfgTopicTreemapNode?: string; selectedEuTopicTreemapNode?: string; selectedBundTopicTreemapNode?: string; private topicTreemapReloadQueued = false; private topicTreemapRequestId = 0; private analyticalRequestId = 0; constructor( private statisticsService: DashboardStatisticsService, private route: ActivatedRoute, private router: Router, private dialog: MatDialog, ) {} ngOnInit() { this.restoreDashboardPeriodState(); this.loadDashboardInstitutions(); this.loadStatistics(); } ngAfterViewInit(): void { setTimeout(() => this.updateAnalyticalInstitutionTabScrollState()); } @HostListener('window:resize') onWindowResize(): void { this.updateAnalyticalInstitutionTabScrollState(); } private loadDashboardInstitutions(): void { this.dashboardInstitutionsLoading = true; this.dashboardInstitutionsError = false; this.statisticsService .getInstitutions() .pipe(finalize(() => (this.dashboardInstitutionsLoading = false))) .subscribe({ next: (institutions) => { this.dashboardInstitutions = institutions; setTimeout(() => this.updateAnalyticalInstitutionTabScrollState()); const requestedInstitution = this.route.snapshot.queryParamMap.get('institution') ?? 'all'; const restoredInstitution = institutions.some( (institution) => institution.id === requestedInstitution, ) ? requestedInstitution : 'all'; if (restoredInstitution !== this.selectedDashboardInstitutionId) { this.selectedDashboardInstitutionId = restoredInstitution; this.loadStatistics(); } const restoredAnalyticalInstitution = restoredInstitution === 'all' ? '' : restoredInstitution; if ( restoredAnalyticalInstitution !== this.selectedAnalyticalInstitutionId ) { this.selectedAnalyticalInstitutionId = restoredAnalyticalInstitution; this.reloadAnalyticalData(); } }, error: () => { this.dashboardInstitutions = []; this.dashboardInstitutionsError = true; }, }); } private loadStatistics(): void { this.statisticsError = false; const period = this.selectedPeriodBounds(); const institutionId = this.selectedDashboardInstitutionId; this.loadStatistic( 'publications', this.statisticsService.getPublicationCount(period, institutionId), ); this.loadStatistic( 'persons', this.statisticsService.getPersonCount(period, institutionId), ); this.loadStatistic( 'patents', this.statisticsService.getPatentCount(period, institutionId), ); this.loadStatistic( 'eu_projects', this.statisticsService.getEuProjectCount(period, institutionId), ); this.loadStatistic( 'bmbf_projects', this.statisticsService.getBmbfProjectCount(period, institutionId), ); this.loadStatistic( 'dfg_projects', this.statisticsService.getDfgProjectCount(period, institutionId), ); } isStatisticLoading(key: DashboardStatisticKey): boolean { return this.statisticLoading[key]; } topAuthorDatasets(): TopAuthorDataset[] { return [ { title: 'Publikationen', subtitle: 'Top 10 Personen mit Publikationen der ausgewählten Institution. Die Zahl zeigt die Anzahl der Publikationen der jeweiligen Person.', icon: MENU_BOOK_ICON, entries: this.topAuthors?.works ?? [], }, { title: 'EU-Projekte', subtitle: 'Top 10 Personen, die an EU-Projekten der ausgewählten Institution beteiligt sind. Die Zahl zeigt, an wie vielen EU-Projekten die jeweilige Person beteiligt ist.', icon: PUBLIC_ICON, entries: this.topAuthors?.eu_projects ?? [], }, { title: 'Patente', subtitle: 'Top 10 Personen mit Zuordnung zu Patenten der ausgewählten Institution. Die Zahl zeigt, wie vielen Patenten die jeweilige Person zugeordnet wurde.', icon: DESCRIPTION_ICON, entries: this.topAuthors?.patents ?? [], }, { title: 'DFG Projekte', subtitle: 'Top 10 Personen, die an DFG-Projekten der ausgewählten Institution beteiligt sind. Die Zahl zeigt, an wie vielen DFG-Projekten die jeweilige Person beteiligt ist.', icon: ACCOUNT_TREE_ICON, entries: this.topAuthors?.projects ?? [], stripAuthorTitle: true, }, { title: 'News', subtitle: 'Top 10 Personen der ausgewählten Institution, die in Nachrichten genannt werden. Die Zahl zeigt, in wie vielen Nachrichten die jeweilige Person vorkommt.', icon: ARTICLE_ICON, entries: this.topAuthors?.news ?? [], }, ]; } visibleTopAuthorDatasets(): TopAuthorDataset[] { const datasets = this.topAuthorDatasets(); return this.topAuthorsLoading ? datasets : datasets.filter((dataset) => dataset.entries.length > 0); } hasTopAuthorData(): boolean { return this.topAuthorDatasets().some( (dataset) => dataset.entries.length > 0, ); } hasTopicTreemapData(): boolean { return (this.topicTreemap?.fields ?? []).some( (field) => field.total > 0 || field.values.some((value) => value.count > 0), ); } hasDfgTopicData(): boolean { return (this.dfgProjectTopics?.topics.length ?? 0) > 0; } private buildDfgTopicTreemapData( projectTopics: DfgProjectTopics, ): TopicTreemapData { const fields = new Map< string, Map >(); for (const topic of projectTopics.topics) { const fieldName = topic.field?.trim() || 'Ohne Field'; const subfieldName = topic.subfield?.trim() || 'Ohne Subfield'; const subfields = fields.get(fieldName) ?? new Map(); const subfield = subfields.get(subfieldName) ?? { topics: [] }; subfield.topics.push(topic); subfields.set(subfieldName, subfield); fields.set(fieldName, subfields); } return { institution_id: projectTopics.institution_id, organization_name: projectTopics.organization_name, years: [], fields: [...fields.entries()].map(([fieldName, subfields]) => { const mappedSubfields = [...subfields.entries()].map( ([subfieldName, group]) => ({ id: `${fieldName}::${subfieldName}`, name: subfieldName, total: group.topics[0]?.subfield_project_count ?? group.topics.reduce((sum, topic) => sum + topic.project_count, 0), values: [], topics: group.topics.map((topic) => ({ id: topic.id, name: topic.name, total: topic.project_count, values: [], })), }), ); return { id: fieldName, name: fieldName, total: [...subfields.values()][0]?.topics[0]?.field_project_count ?? mappedSubfields.reduce((sum, subfield) => sum + subfield.total, 0), values: [], subfields: mappedSubfields, }; }), }; } setDashboardPeriodMode(mode: DashboardPeriodMode): void { if (mode === this.dashboardPeriodMode) return; this.dashboardPeriodMode = mode; this.applyPresetPeriod(); this.updateDashboardPeriodUrl(); this.reloadPeriodData(); } authorBarWidth(entries: TopAuthor[], count: number): number { const maximum = Math.max(...entries.map((entry) => entry.count), 1); return (count / maximum) * 100; } authorDisplayName(dataset: TopAuthorDataset, entry: TopAuthor): string { if (!dataset.stripAuthorTitle) return entry.name; return ( entry.name .replace( /^(?:(?:(?:apl\.\s*)?prof(?:essor)?\.?|priv\.-doz\.?|pd|dr\.?)\s+)+/i, '', ) .trim() || entry.name ); } authorLink(_dataset: TopAuthorDataset, entry: TopAuthor): string[] { return ['/person', entry.id!, 'overview']; } authorQueryParams( _dataset: TopAuthorDataset, _entry: TopAuthor, ): Record | null { return null; } organizationName(): string { return this.statistics?.organization_name ?? 'Ihre Organisation'; } institutionRouteId(): string { const selectedInstitutionId = this.routeableInstitutionId( this.selectedDashboardInstitutionId, ); if (selectedInstitutionId) return selectedInstitutionId; return this.routeableInstitutionId(this.dashboardInstitutions[0]?.id) ?? ''; } private routeableInstitutionId(institutionId?: string | null): string | null { const normalizedInstitutionId = institutionId ?.replace('https://openalex.org/', '') .trim(); return normalizedInstitutionId && normalizedInstitutionId !== 'all' ? normalizedInstitutionId : null; } personListQueryParams(): PersonListQueryParams { const period = this.selectedPeriodBounds(); return institutionPersonListQueryParamsForPeriod( this.institutionRouteId(), this.organizationName(), period.fromYear, period.toYear, ); } onDashboardPeriodRangeChange(): void { this.dashboardPeriodMode = 'custom'; this.topicTreemapLoading = true; this.topicTreemapError = false; this.topicTreemapRequestId += 1; this.updateDashboardPeriodUrl(); if (this.topicTreemapReloadQueued) return; this.topicTreemapReloadQueued = true; setTimeout(() => { this.topicTreemapReloadQueued = false; this.reloadPeriodData(); }); } onDashboardInstitutionChange(institutionId: string): void { this.selectedDashboardInstitutionId = institutionId; const analyticalInstitutionId = institutionId === 'all' ? '' : institutionId; const analyticalInstitutionChanged = analyticalInstitutionId !== this.selectedAnalyticalInstitutionId; this.selectedAnalyticalInstitutionId = analyticalInstitutionId; this.updateDashboardPeriodUrl(); this.loadStatistics(); if (analyticalInstitutionChanged) { if (analyticalInstitutionId) { this.reloadAnalyticalData(); } else { // Invalidate pending requests when "Alle Institutionen" is selected. this.analyticalRequestId += 1; } } } onAnalyticalInstitutionChange(institutionId: string): void { if (institutionId === this.selectedAnalyticalInstitutionId) return; this.selectedAnalyticalInstitutionId = institutionId; this.updateDashboardPeriodUrl(); this.reloadAnalyticalData(); } scrollAnalyticalInstitutionTabs(direction: -1 | 1): void { const tabList = this.analyticalInstitutionTabList?.nativeElement; if (!tabList) return; tabList.scrollBy({ left: direction * Math.floor(tabList.clientWidth * 0.75), behavior: 'smooth', }); } updateAnalyticalInstitutionTabScrollState(): void { const tabList = this.analyticalInstitutionTabList?.nativeElement; if (!tabList) { this.canScrollAnalyticalInstitutionTabsLeft = false; this.canScrollAnalyticalInstitutionTabsRight = false; return; } const maxScrollLeft = tabList.scrollWidth - tabList.clientWidth; this.canScrollAnalyticalInstitutionTabsLeft = tabList.scrollLeft > 1; this.canScrollAnalyticalInstitutionTabsRight = tabList.scrollLeft < maxScrollLeft - 1; } failedProjectStatusSources(): string { const sources = [ this.euProjectStatusesError ? 'EU' : undefined, this.bmbfProjectStatusesError ? 'Bund' : undefined, this.dfgProjectStatusesError ? 'DFG' : undefined, ].filter((source): source is string => source !== undefined); return sources.join(' und '); } onTopicTreemapNodeChange(nodeId: string | undefined): void { this.selectedTopicTreemapNode = nodeId; this.updateDashboardPeriodUrl(); } onDfgTopicTreemapNodeChange(nodeId: string | undefined): void { this.selectedDfgTopicTreemapNode = nodeId; this.updateDashboardPeriodUrl(); } onDfgTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { const dfgTopic = this.dfgProjectTopics?.topics.find( (entry) => entry.id === topic.topicId, ); if (!dfgTopic) return; this.dialog.open( TopicWordCloudDialogComponent, { width: '85vw', maxWidth: '92vw', data: { ...topic, source: 'dfg', words: dfgTopic.keywords.map((keyword) => ({ id: keyword.name, name: keyword.name, count: keyword.project_count, })), }, }, ); } onEuTopicTreemapNodeChange(nodeId: string | undefined): void { this.selectedEuTopicTreemapNode = nodeId; this.updateDashboardPeriodUrl(); } onEuTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { const euTopic = this.euProjectTopics?.topics.find( (entry) => entry.id === topic.topicId, ); if (!euTopic) return; this.dialog.open( TopicWordCloudDialogComponent, { width: '85vw', maxWidth: '92vw', data: { ...topic, source: 'eu', words: euTopic.keywords.map((keyword) => ({ id: keyword.name, name: keyword.name, count: keyword.project_count, })), }, }, ); } onBundTopicTreemapNodeChange(nodeId: string | undefined): void { this.selectedBundTopicTreemapNode = nodeId; this.updateDashboardPeriodUrl(); } onBundTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { const bundTopic = this.bundProjectTopics?.topics.find( (entry) => entry.id === topic.topicId, ); if (!bundTopic) return; this.dialog.open( TopicWordCloudDialogComponent, { width: '85vw', maxWidth: '92vw', data: { ...topic, source: 'bund', words: bundTopic.keywords.map((keyword) => ({ id: keyword.name, name: keyword.name, count: keyword.project_count, })), }, }, ); } onTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { const period = this.selectedPeriodBounds(); this.dialog.open( TopicWordCloudDialogComponent, { width: '85vw', maxWidth: '92vw', data: { ...topic, fromYear: period.fromYear, toYear: period.toYear, institutionId: this.selectedAnalyticalInstitutionId, }, }, ); } private restoreDashboardPeriodState(): void { const params = this.route.snapshot.queryParamMap; const mode = params.get('period'); if ( mode === 'all_time' || mode === 'last_10_years' || mode === 'last_5_years' || mode === 'custom' ) { this.dashboardPeriodMode = mode; } this.applyPresetPeriod(); if (this.dashboardPeriodMode !== 'all_time') { this.dashboardFromYear = this.parseDashboardYear( params.get('fromYear'), this.dashboardFromYear, ); this.dashboardToYear = this.parseDashboardYear( params.get('toYear'), this.dashboardToYear, ); } if (this.dashboardFromYear > this.dashboardToYear) { this.dashboardFromYear = this.dashboardToYear; } this.selectedTopicTreemapNode = params.get('treemapNode') ?? undefined; this.selectedDfgTopicTreemapNode = params.get('dfgTreemapNode') ?? undefined; this.selectedEuTopicTreemapNode = params.get('euTreemapNode') ?? undefined; this.selectedBundTopicTreemapNode = params.get('bundTreemapNode') ?? undefined; } private applyPresetPeriod(): void { const currentYear = this.topicTreemapMaxYear; if (this.dashboardPeriodMode === 'all_time') { this.dashboardFromYear = this.topicTreemapMinYear; this.dashboardToYear = currentYear; } else if (this.dashboardPeriodMode === 'last_10_years') { this.dashboardFromYear = currentYear - 9; this.dashboardToYear = currentYear; } else if (this.dashboardPeriodMode === 'last_5_years') { this.dashboardFromYear = currentYear - 4; this.dashboardToYear = currentYear; } } private updateDashboardPeriodUrl(): void { const period = this.selectedPeriodBounds(); void this.router.navigate([], { relativeTo: this.route, queryParams: { period: this.dashboardPeriodMode, fromYear: period.fromYear ?? null, toYear: period.toYear ?? null, treemapNode: this.selectedTopicTreemapNode ?? null, dfgTreemapNode: this.selectedDfgTopicTreemapNode ?? null, euTreemapNode: this.selectedEuTopicTreemapNode ?? null, bundTreemapNode: this.selectedBundTopicTreemapNode ?? null, institution: this.selectedDashboardInstitutionId, analyticalInstitution: this.selectedAnalyticalInstitutionId || null, }, queryParamsHandling: 'merge', replaceUrl: true, }); } private parseDashboardYear(value: string | null, fallback: number): number { const year = Number(value); return Number.isInteger(year) && year >= this.topicTreemapMinYear && year <= this.topicTreemapMaxYear ? year : fallback; } private selectedPeriodBounds(): DashboardPeriodBounds { return this.dashboardPeriodMode === 'all_time' ? {} : { fromYear: this.dashboardFromYear, toYear: this.dashboardToYear, }; } private reloadPeriodData(): void { this.loadStatistics(); this.reloadAnalyticalData(); } private reloadAnalyticalData(): void { if (!this.selectedAnalyticalInstitutionId) return; const requestId = ++this.analyticalRequestId; this.euProjectStatuses = undefined; this.bmbfProjectStatuses = undefined; this.dfgProjectStatuses = undefined; this.loadTopAuthors(requestId); this.loadTopicTreemap(requestId); this.loadDfgProjectTopics(requestId); this.loadEuProjectTopics(requestId); this.loadBundProjectTopics(requestId); this.loadEuProjectStatuses(requestId); this.loadBmbfProjectStatuses(requestId); this.loadDfgProjectStatuses(requestId); } private loadStatistic( key: DashboardStatisticKey, request: Observable, ): void { this.statisticLoading[key] = true; this.statisticErrors[key] = false; this.pendingStatisticRequests += 1; this.statisticsLoading = true; request .pipe( finalize(() => { this.statisticLoading[key] = false; this.pendingStatisticRequests -= 1; this.statisticsLoading = this.pendingStatisticRequests > 0; }), ) .subscribe({ next: (statistic) => { this.applyStatisticValue(key, statistic); }, error: () => { this.statisticErrors[key] = true; this.statisticsError = true; }, }); } private applyStatisticValue( key: DashboardStatisticKey, statistic: DashboardStatisticValue, ): void { const nextStatistics = { ...(this.statistics ?? {}), institution_id: statistic.institution_id, organization_name: statistic.organization_name, [key]: statistic.value, }; nextStatistics.projects = (nextStatistics.eu_projects ?? 0) + (nextStatistics.bmbf_projects ?? 0) + (nextStatistics.dfg_projects ?? 0); this.statistics = nextStatistics; } private loadTopAuthors(requestId = this.analyticalRequestId): void { this.topAuthorsLoading = true; this.topAuthorsError = false; this.statisticsService .getTopAuthors( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.topAuthorsLoading = false; } }), ) .subscribe({ next: (statistics) => { if (requestId === this.analyticalRequestId) { this.topAuthors = statistics; } }, error: () => { if (requestId === this.analyticalRequestId) { this.topAuthorsError = true; } }, }); } private loadDfgProjectTopics(requestId = this.analyticalRequestId): void { this.dfgTopicsLoading = true; this.dfgTopicsError = false; this.statisticsService .getDfgProjectTopics( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.dfgTopicsLoading = false; } }), ) .subscribe({ next: (topics) => { if (requestId === this.analyticalRequestId) { this.dfgProjectTopics = topics; this.dfgTopicTreemap = this.buildDfgTopicTreemapData(topics); } }, error: () => { if (requestId === this.analyticalRequestId) { this.dfgTopicsError = true; } }, }); } private loadEuProjectTopics(requestId = this.analyticalRequestId): void { this.euTopicsLoading = true; this.euTopicsError = false; this.statisticsService .getEuProjectTopics( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.euTopicsLoading = false; } }), ) .subscribe({ next: (topics) => { if (requestId === this.analyticalRequestId) { this.euProjectTopics = topics; this.euTopicTreemap = this.buildDfgTopicTreemapData(topics); } }, error: () => { if (requestId === this.analyticalRequestId) { this.euTopicsError = true; } }, }); } private loadBundProjectTopics(requestId = this.analyticalRequestId): void { this.bundTopicsLoading = true; this.bundTopicsError = false; this.statisticsService .getBundProjectTopics( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.bundTopicsLoading = false; } }), ) .subscribe({ next: (topics) => { if (requestId === this.analyticalRequestId) { this.bundProjectTopics = topics; this.bundTopicTreemap = this.buildDfgTopicTreemapData(topics); } }, error: () => { if (requestId === this.analyticalRequestId) { this.bundTopicsError = true; } }, }); } private loadEuProjectStatuses(requestId = this.analyticalRequestId): void { this.euProjectStatusesLoading = true; this.euProjectStatusesError = false; this.statisticsService .getEuProjectStatuses( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.euProjectStatusesLoading = false; } }), ) .subscribe({ next: (statuses) => { if (requestId === this.analyticalRequestId) { this.euProjectStatuses = statuses; } }, error: () => { if (requestId === this.analyticalRequestId) { this.euProjectStatusesError = true; this.euProjectStatuses = this.emptyProjectStatuses(); } }, }); } private loadBmbfProjectStatuses(requestId = this.analyticalRequestId): void { this.bmbfProjectStatusesLoading = true; this.bmbfProjectStatusesError = false; this.statisticsService .getBmbfProjectStatuses( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.bmbfProjectStatusesLoading = false; } }), ) .subscribe({ next: (statuses) => { if (requestId === this.analyticalRequestId) { this.bmbfProjectStatuses = statuses; } }, error: () => { if (requestId === this.analyticalRequestId) { this.bmbfProjectStatusesError = true; this.bmbfProjectStatuses = this.emptyProjectStatuses(); } }, }); } private loadDfgProjectStatuses(requestId = this.analyticalRequestId): void { this.dfgProjectStatusesLoading = true; this.dfgProjectStatusesError = false; this.statisticsService .getDfgProjectStatuses( this.selectedPeriodBounds(), this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if (requestId === this.analyticalRequestId) { this.dfgProjectStatusesLoading = false; } }), ) .subscribe({ next: (statuses) => { if (requestId === this.analyticalRequestId) { this.dfgProjectStatuses = statuses; } }, error: () => { if (requestId === this.analyticalRequestId) { this.dfgProjectStatusesError = true; this.dfgProjectStatuses = this.emptyProjectStatuses(); } }, }); } private emptyProjectStatuses(): EuProjectStatusStatistics { const institution = this.dashboardInstitutions.find( ({ id }) => id === this.selectedAnalyticalInstitutionId, ); return { institution_id: this.selectedAnalyticalInstitutionId, organization_name: institution?.display_name ?? '', ongoing: 0, upcoming: 0, completed: 0, }; } private loadTopicTreemap( analyticalRequestId = this.analyticalRequestId, ): void { if (this.dashboardFromYear > this.dashboardToYear) { this.topicTreemapLoading = false; this.topicTreemapError = true; return; } const treemapRequestId = ++this.topicTreemapRequestId; const period = this.selectedPeriodBounds(); this.topicTreemapLoading = true; this.topicTreemapError = false; this.statisticsService .getTopicTreemap( period.fromYear, period.toYear, this.selectedAnalyticalInstitutionId, ) .pipe( finalize(() => { if ( analyticalRequestId === this.analyticalRequestId && treemapRequestId === this.topicTreemapRequestId ) { this.topicTreemapLoading = false; } }), ) .subscribe({ next: (treemap) => { if ( analyticalRequestId === this.analyticalRequestId && treemapRequestId === this.topicTreemapRequestId ) { this.topicTreemap = treemap; } }, error: () => { if ( analyticalRequestId === this.analyticalRequestId && treemapRequestId === this.topicTreemapRequestId ) { this.topicTreemapError = true; } }, }); } }