162 lines
5.7 KiB
TypeScript
162 lines
5.7 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { DashboardPeriodBounds } from './dashboard-statistics.service';
|
|
import { DashboardFilterComponent } from './components/dashboard-filter/dashboard-filter.component';
|
|
import { DashboardStatisticsGridComponent } from './components/dashboard-statistics-grid/dashboard-statistics-grid.component';
|
|
import { DashboardTopAuthorsComponent } from './components/dashboard-top-authors/dashboard-top-authors.component';
|
|
import { ProjectTopicsComponent } from './components/project-topics/project-topics.component';
|
|
import { DashboardProjectStatusComponent } from './components/dashboard-project-status/dashboard-project-status.component';
|
|
import { DashboardFieldTreemapComponent } from './components/dashboard-field-treemap/dashboard-field-treemap.component';
|
|
import { DashboardInstitutionTabsComponent } from './components/dashboard-institution-tabs/dashboard-institution-tabs.component';
|
|
import { DashboardFacade } from './services/dashboard.facade';
|
|
import { DashboardPeriodMode } from './dashboard.models';
|
|
|
|
@Component({
|
|
selector: 'dashboard',
|
|
imports: [
|
|
DashboardFilterComponent,
|
|
DashboardStatisticsGridComponent,
|
|
DashboardTopAuthorsComponent,
|
|
ProjectTopicsComponent,
|
|
DashboardProjectStatusComponent,
|
|
DashboardFieldTreemapComponent,
|
|
DashboardInstitutionTabsComponent,
|
|
],
|
|
templateUrl: './dashboard.component.html',
|
|
styleUrl: './dashboard.component.scss',
|
|
providers: [DashboardFacade],
|
|
})
|
|
export class DashboardComponent implements OnInit {
|
|
selectedAnalyticalInstitutionId = '';
|
|
selectedTopicTreemapNode?: string;
|
|
selectedDfgTopicTreemapNode?: string;
|
|
selectedEuTopicTreemapNode?: string;
|
|
selectedBundTopicTreemapNode?: string;
|
|
private topicTreemapReloadQueued = false;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
readonly dashboard: DashboardFacade,
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
this.restoreTreemapNodeState();
|
|
this.dashboard.initialize((institutionId) => {
|
|
if (institutionId === this.selectedAnalyticalInstitutionId) return;
|
|
this.selectedAnalyticalInstitutionId = institutionId;
|
|
this.reloadAnalyticalData();
|
|
});
|
|
}
|
|
|
|
setDashboardPeriodMode(mode: DashboardPeriodMode): void {
|
|
if (!this.dashboard.setPeriodMode(mode)) return;
|
|
this.updateDashboardPeriodUrl();
|
|
this.reloadPeriodData();
|
|
}
|
|
|
|
onDashboardPeriodRangeChange(): void {
|
|
this.dashboard.setCustomPeriod();
|
|
this.updateDashboardPeriodUrl();
|
|
if (this.topicTreemapReloadQueued) return;
|
|
this.topicTreemapReloadQueued = true;
|
|
setTimeout(() => {
|
|
this.topicTreemapReloadQueued = false;
|
|
this.reloadPeriodData();
|
|
});
|
|
}
|
|
|
|
onDashboardInstitutionChange(institutionId: string): void {
|
|
this.dashboard.selectInstitution(institutionId);
|
|
const analyticalInstitutionId =
|
|
institutionId === 'all' ? '' : institutionId;
|
|
const analyticalInstitutionChanged =
|
|
analyticalInstitutionId !== this.selectedAnalyticalInstitutionId;
|
|
this.selectedAnalyticalInstitutionId = analyticalInstitutionId;
|
|
this.updateDashboardPeriodUrl();
|
|
if (analyticalInstitutionChanged) {
|
|
if (analyticalInstitutionId) {
|
|
this.reloadAnalyticalData();
|
|
} else {
|
|
this.dashboard.invalidateAnalyticalData();
|
|
}
|
|
}
|
|
}
|
|
|
|
onAnalyticalInstitutionChange(institutionId: string): void {
|
|
const analyticalInstitutionChanged =
|
|
institutionId !== this.selectedAnalyticalInstitutionId;
|
|
const dashboardInstitutionChanged =
|
|
institutionId !== this.dashboard.selectedInstitutionId;
|
|
if (!analyticalInstitutionChanged && !dashboardInstitutionChanged) return;
|
|
|
|
this.selectedAnalyticalInstitutionId = institutionId;
|
|
if (dashboardInstitutionChanged) {
|
|
this.dashboard.selectInstitution(institutionId);
|
|
}
|
|
this.updateDashboardPeriodUrl();
|
|
if (analyticalInstitutionChanged) {
|
|
this.reloadAnalyticalData();
|
|
}
|
|
}
|
|
|
|
onTopicTreemapNodeChange(): void {
|
|
this.updateDashboardPeriodUrl();
|
|
}
|
|
|
|
onDfgTopicTreemapNodeChange(): void {
|
|
this.updateDashboardPeriodUrl();
|
|
}
|
|
|
|
onEuTopicTreemapNodeChange(): void {
|
|
this.updateDashboardPeriodUrl();
|
|
}
|
|
|
|
onBundTopicTreemapNodeChange(): void {
|
|
this.updateDashboardPeriodUrl();
|
|
}
|
|
|
|
private restoreTreemapNodeState(): void {
|
|
const params = this.route.snapshot.queryParamMap;
|
|
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 updateDashboardPeriodUrl(): void {
|
|
const period = this.selectedPeriodBounds();
|
|
void this.router.navigate([], {
|
|
relativeTo: this.route,
|
|
queryParams: {
|
|
period: this.dashboard.periodMode,
|
|
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.dashboard.selectedInstitutionId,
|
|
analyticalInstitution: this.selectedAnalyticalInstitutionId || null,
|
|
},
|
|
queryParamsHandling: 'merge',
|
|
replaceUrl: true,
|
|
});
|
|
}
|
|
|
|
private selectedPeriodBounds(): DashboardPeriodBounds {
|
|
return this.dashboard.periodBounds();
|
|
}
|
|
|
|
private reloadPeriodData(): void {
|
|
this.dashboard.loadStatistics();
|
|
this.reloadAnalyticalData();
|
|
}
|
|
|
|
private reloadAnalyticalData(): void {
|
|
this.dashboard.loadAnalyticalData(this.selectedAnalyticalInstitutionId);
|
|
}
|
|
}
|