Add institution filtering

This commit is contained in:
spsaefan
2026-08-15 22:45:24 +02:00
parent fbcee778d2
commit 82fa2e816b
2 changed files with 219 additions and 61 deletions
@@ -175,28 +175,31 @@ export class DashboardStatisticsService {
getEuProjectStatuses(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<EuProjectStatusStatistics> {
return this.httpClient.get<EuProjectStatusStatistics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/eu/status`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
getBmbfProjectStatuses(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<BmbfProjectStatusStatistics> {
return this.httpClient.get<BmbfProjectStatusStatistics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/bmbf/status`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
getDfgProjectStatuses(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<DfgProjectStatusStatistics> {
return this.httpClient.get<DfgProjectStatusStatistics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/dfg/status`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
@@ -222,39 +225,43 @@ export class DashboardStatisticsService {
getDfgProjectTopics(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<DfgProjectTopics> {
return this.httpClient.get<DfgProjectTopics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/dfg/topics`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
getEuProjectTopics(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<EuProjectTopics> {
return this.httpClient.get<EuProjectTopics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/eu/topics`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
getBundProjectTopics(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<BundProjectTopics> {
return this.httpClient.get<BundProjectTopics>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/bund/topics`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
);
}
getTopAuthors(
period: DashboardPeriodBounds = {},
institutionId = 'all',
): Observable<TopAuthorStatistics> {
const analysis = (source: string) =>
this.httpClient
.get<TopAuthorAnalysis>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/top-authors/${source}`,
{ params: this.periodParams(period) },
{ params: this.analyticalParams(period, institutionId) },
)
.pipe(catchError(() => of(null)));
@@ -288,8 +295,11 @@ export class DashboardStatisticsService {
getTopicTreemap(
fromYear?: number,
toYear?: number,
institutionId = 'all',
): Observable<TopicTreemapData> {
const params: Record<string, number> = {};
const params: Record<string, string | number> = {
institution_id: institutionId,
};
if (fromYear !== undefined) params['from_year'] = fromYear;
if (toYear !== undefined) params['to_year'] = toYear;
@@ -303,8 +313,12 @@ export class DashboardStatisticsService {
topicId: string,
fromYear?: number,
toYear?: number,
institutionId = 'all',
): Observable<TopicWordCloud> {
const params: Record<string, string | number> = { topicId };
const params: Record<string, string | number> = {
topicId,
institution_id: institutionId,
};
if (fromYear !== undefined) params['from_year'] = fromYear;
if (toYear !== undefined) params['to_year'] = toYear;
return this.httpClient.get<TopicWordCloud>(
@@ -329,4 +343,14 @@ export class DashboardStatisticsService {
institution_id: institutionId,
};
}
private analyticalParams(
period: DashboardPeriodBounds,
institutionId: string,
): Record<string, string | number> {
return {
...this.periodParams(period),
institution_id: institutionId,
};
}
}
@@ -135,6 +135,7 @@ export class DashboardComponent implements OnInit {
dashboardToYear = this.topicTreemapMaxYear;
dashboardInstitutions: DashboardInstitution[] = [];
selectedDashboardInstitutionId = 'all';
selectedAnalyticalInstitutionId = 'all';
dashboardInstitutionsLoading = false;
dashboardInstitutionsError = false;
selectedTopicTreemapNode?: string;
@@ -143,6 +144,7 @@ export class DashboardComponent implements OnInit {
selectedBundTopicTreemapNode?: string;
private topicTreemapReloadQueued = false;
private topicTreemapRequestId = 0;
private analyticalRequestId = 0;
constructor(
private statisticsService: DashboardStatisticsService,
@@ -185,6 +187,20 @@ export class DashboardComponent implements OnInit {
this.selectedDashboardInstitutionId = restoredInstitution;
this.loadStatistics();
}
const requestedAnalyticalInstitution =
this.route.snapshot.queryParamMap.get('analyticalInstitution') ??
'all';
const restoredAnalyticalInstitution = institutions.some(
(institution) => institution.id === requestedAnalyticalInstitution,
)
? requestedAnalyticalInstitution
: 'all';
if (
restoredAnalyticalInstitution !== this.selectedAnalyticalInstitutionId
) {
this.selectedAnalyticalInstitutionId = restoredAnalyticalInstitution;
this.reloadAnalyticalData();
}
},
error: () => {
this.dashboardInstitutions = [];
@@ -416,6 +432,13 @@ export class DashboardComponent implements OnInit {
this.loadStatistics();
}
onAnalyticalInstitutionChange(institutionId: string): void {
if (institutionId === this.selectedAnalyticalInstitutionId) return;
this.selectedAnalyticalInstitutionId = institutionId;
this.updateDashboardPeriodUrl();
this.reloadAnalyticalData();
}
onTopicTreemapNodeChange(nodeId: string | undefined): void {
this.selectedTopicTreemapNode = nodeId;
this.updateDashboardPeriodUrl();
@@ -519,6 +542,7 @@ export class DashboardComponent implements OnInit {
...topic,
fromYear: period.fromYear,
toYear: period.toYear,
institutionId: this.selectedAnalyticalInstitutionId,
},
},
);
@@ -585,6 +609,7 @@ export class DashboardComponent implements OnInit {
euTreemapNode: this.selectedEuTopicTreemapNode ?? null,
bundTreemapNode: this.selectedBundTopicTreemapNode ?? null,
institution: this.selectedDashboardInstitutionId,
analyticalInstitution: this.selectedAnalyticalInstitutionId,
},
queryParamsHandling: 'merge',
replaceUrl: true,
@@ -611,14 +636,19 @@ export class DashboardComponent implements OnInit {
private reloadPeriodData(): void {
this.loadStatistics();
this.loadTopAuthors();
this.loadTopicTreemap();
this.loadDfgProjectTopics();
this.loadEuProjectTopics();
this.loadBundProjectTopics();
this.loadEuProjectStatuses();
this.loadBmbfProjectStatuses();
this.loadDfgProjectStatuses();
this.reloadAnalyticalData();
}
private reloadAnalyticalData(): void {
const requestId = ++this.analyticalRequestId;
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(
@@ -666,149 +696,253 @@ export class DashboardComponent implements OnInit {
this.statistics = nextStatistics;
}
private loadTopAuthors(): void {
private loadTopAuthors(requestId = this.analyticalRequestId): void {
this.topAuthorsLoading = true;
this.topAuthorsError = false;
this.statisticsService
.getTopAuthors(this.selectedPeriodBounds())
.pipe(finalize(() => (this.topAuthorsLoading = false)))
.getTopAuthors(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.topAuthorsLoading = false;
}
}),
)
.subscribe({
next: (statistics) => {
this.topAuthors = statistics;
if (requestId === this.analyticalRequestId) {
this.topAuthors = statistics;
}
},
error: () => {
this.topAuthorsError = true;
if (requestId === this.analyticalRequestId) {
this.topAuthorsError = true;
}
},
});
}
private loadDfgProjectTopics(): void {
private loadDfgProjectTopics(requestId = this.analyticalRequestId): void {
this.dfgTopicsLoading = true;
this.dfgTopicsError = false;
this.statisticsService
.getDfgProjectTopics(this.selectedPeriodBounds())
.pipe(finalize(() => (this.dfgTopicsLoading = false)))
.getDfgProjectTopics(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.dfgTopicsLoading = false;
}
}),
)
.subscribe({
next: (topics) => {
this.dfgProjectTopics = topics;
this.dfgTopicTreemap = this.buildDfgTopicTreemapData(topics);
if (requestId === this.analyticalRequestId) {
this.dfgProjectTopics = topics;
this.dfgTopicTreemap = this.buildDfgTopicTreemapData(topics);
}
},
error: () => {
this.dfgTopicsError = true;
if (requestId === this.analyticalRequestId) {
this.dfgTopicsError = true;
}
},
});
}
private loadEuProjectTopics(): void {
private loadEuProjectTopics(requestId = this.analyticalRequestId): void {
this.euTopicsLoading = true;
this.euTopicsError = false;
this.statisticsService
.getEuProjectTopics(this.selectedPeriodBounds())
.pipe(finalize(() => (this.euTopicsLoading = false)))
.getEuProjectTopics(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.euTopicsLoading = false;
}
}),
)
.subscribe({
next: (topics) => {
this.euProjectTopics = topics;
this.euTopicTreemap = this.buildDfgTopicTreemapData(topics);
if (requestId === this.analyticalRequestId) {
this.euProjectTopics = topics;
this.euTopicTreemap = this.buildDfgTopicTreemapData(topics);
}
},
error: () => {
this.euTopicsError = true;
if (requestId === this.analyticalRequestId) {
this.euTopicsError = true;
}
},
});
}
private loadBundProjectTopics(): void {
private loadBundProjectTopics(requestId = this.analyticalRequestId): void {
this.bundTopicsLoading = true;
this.bundTopicsError = false;
this.statisticsService
.getBundProjectTopics(this.selectedPeriodBounds())
.pipe(finalize(() => (this.bundTopicsLoading = false)))
.getBundProjectTopics(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.bundTopicsLoading = false;
}
}),
)
.subscribe({
next: (topics) => {
this.bundProjectTopics = topics;
this.bundTopicTreemap = this.buildDfgTopicTreemapData(topics);
if (requestId === this.analyticalRequestId) {
this.bundProjectTopics = topics;
this.bundTopicTreemap = this.buildDfgTopicTreemapData(topics);
}
},
error: () => {
this.bundTopicsError = true;
if (requestId === this.analyticalRequestId) {
this.bundTopicsError = true;
}
},
});
}
private loadEuProjectStatuses(): void {
private loadEuProjectStatuses(requestId = this.analyticalRequestId): void {
this.euProjectStatusesLoading = true;
this.euProjectStatusesError = false;
this.statisticsService
.getEuProjectStatuses(this.selectedPeriodBounds())
.pipe(finalize(() => (this.euProjectStatusesLoading = false)))
.getEuProjectStatuses(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.euProjectStatusesLoading = false;
}
}),
)
.subscribe({
next: (statuses) => {
this.euProjectStatuses = statuses;
if (requestId === this.analyticalRequestId) {
this.euProjectStatuses = statuses;
}
},
error: () => {
this.euProjectStatusesError = true;
if (requestId === this.analyticalRequestId) {
this.euProjectStatusesError = true;
}
},
});
}
private loadBmbfProjectStatuses(): void {
private loadBmbfProjectStatuses(requestId = this.analyticalRequestId): void {
this.bmbfProjectStatusesLoading = true;
this.bmbfProjectStatusesError = false;
this.statisticsService
.getBmbfProjectStatuses(this.selectedPeriodBounds())
.pipe(finalize(() => (this.bmbfProjectStatusesLoading = false)))
.getBmbfProjectStatuses(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.bmbfProjectStatusesLoading = false;
}
}),
)
.subscribe({
next: (statuses) => {
this.bmbfProjectStatuses = statuses;
if (requestId === this.analyticalRequestId) {
this.bmbfProjectStatuses = statuses;
}
},
error: () => {
this.bmbfProjectStatusesError = true;
if (requestId === this.analyticalRequestId) {
this.bmbfProjectStatusesError = true;
}
},
});
}
private loadDfgProjectStatuses(): void {
private loadDfgProjectStatuses(requestId = this.analyticalRequestId): void {
this.dfgProjectStatusesLoading = true;
this.dfgProjectStatusesError = false;
this.statisticsService
.getDfgProjectStatuses(this.selectedPeriodBounds())
.pipe(finalize(() => (this.dfgProjectStatusesLoading = false)))
.getDfgProjectStatuses(
this.selectedPeriodBounds(),
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.analyticalRequestId) {
this.dfgProjectStatusesLoading = false;
}
}),
)
.subscribe({
next: (statuses) => {
this.dfgProjectStatuses = statuses;
if (requestId === this.analyticalRequestId) {
this.dfgProjectStatuses = statuses;
}
},
error: () => {
this.dfgProjectStatusesError = true;
if (requestId === this.analyticalRequestId) {
this.dfgProjectStatusesError = true;
}
},
});
}
private loadTopicTreemap(): void {
private loadTopicTreemap(analyticalRequestId = this.analyticalRequestId): void {
if (this.dashboardFromYear > this.dashboardToYear) {
this.topicTreemapLoading = false;
this.topicTreemapError = true;
return;
}
const requestId = ++this.topicTreemapRequestId;
const treemapRequestId = ++this.topicTreemapRequestId;
const period = this.selectedPeriodBounds();
this.topicTreemapLoading = true;
this.topicTreemapError = false;
this.statisticsService
.getTopicTreemap(period.fromYear, period.toYear)
.getTopicTreemap(
period.fromYear,
period.toYear,
this.selectedAnalyticalInstitutionId,
)
.pipe(
finalize(() => {
if (requestId === this.topicTreemapRequestId) {
if (
analyticalRequestId === this.analyticalRequestId &&
treemapRequestId === this.topicTreemapRequestId
) {
this.topicTreemapLoading = false;
}
}),
)
.subscribe({
next: (treemap) => {
if (requestId === this.topicTreemapRequestId) {
if (
analyticalRequestId === this.analyticalRequestId &&
treemapRequestId === this.topicTreemapRequestId
) {
this.topicTreemap = treemap;
}
},
error: () => {
if (requestId === this.topicTreemapRequestId) {
if (
analyticalRequestId === this.analyticalRequestId &&
treemapRequestId === this.topicTreemapRequestId
) {
this.topicTreemapError = true;
}
},