From 4ebf1df32a9525efef4c782b400b7a022bb8b64d Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 24 Nov 2026 13:25:00 +0100 Subject: [PATCH] choose the users organization on dashboard per default --- .../modules/dashboard/dashboard.component.ts | 13 ++++-- .../dashboard/services/dashboard.facade.ts | 44 +++++++++++++++---- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/webapp/src/app/modules/dashboard/dashboard.component.ts b/webapp/src/app/modules/dashboard/dashboard.component.ts index 9b6c8061..8380e819 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/src/app/modules/dashboard/dashboard.component.ts @@ -44,10 +44,17 @@ export class DashboardComponent implements OnInit { ngOnInit() { this.restoreTreemapNodeState(); - this.dashboard.initialize((institutionId) => { - if (institutionId === this.selectedAnalyticalInstitutionId) return; + this.dashboard.initialize((institutionId, source) => { + const changed = institutionId !== this.selectedAnalyticalInstitutionId; this.selectedAnalyticalInstitutionId = institutionId; - this.reloadAnalyticalData(); + // When the organization was auto-selected from the account (no explicit + // URL parameter), persist it so the URL reflects the current state. + if (source === 'default' && institutionId) { + this.updateDashboardPeriodUrl(); + } + if (changed) { + this.reloadAnalyticalData(); + } }); } diff --git a/webapp/src/app/modules/dashboard/services/dashboard.facade.ts b/webapp/src/app/modules/dashboard/services/dashboard.facade.ts index 6084b90f..43f2f1dc 100644 --- a/webapp/src/app/modules/dashboard/services/dashboard.facade.ts +++ b/webapp/src/app/modules/dashboard/services/dashboard.facade.ts @@ -21,6 +21,10 @@ import { TopAuthorStatistics, } from '../dashboard-statistics.service'; import { mapProjectTopicsToTreemap } from './dashboard-topic-treemap.mapper'; +import { CredentialService } from '../../../shared/services/credential.service'; + +/** Where the initially selected institution came from. */ +export type InstitutionRestoreSource = 'url' | 'default'; @Injectable() export class DashboardFacade { @@ -88,9 +92,15 @@ export class DashboardFacade { constructor( private readonly statisticsService: DashboardStatisticsService, private readonly route: ActivatedRoute, + private readonly credentials: CredentialService, ) {} - initialize(onInstitutionRestored: (institutionId: string) => void): void { + initialize( + onInstitutionRestored: ( + institutionId: string, + source: InstitutionRestoreSource, + ) => void, + ): void { this.restorePeriodState(); this.loadStatistics(); this.loadInstitutions(onInstitutionRestored); @@ -191,7 +201,10 @@ export class DashboardFacade { } private loadInstitutions( - onInstitutionRestored: (institutionId: string) => void, + onInstitutionRestored: ( + institutionId: string, + source: InstitutionRestoreSource, + ) => void, ): void { this.institutionsLoading = true; this.institutionsError = false; @@ -202,18 +215,23 @@ export class DashboardFacade { next: (institutions) => { this.institutions = institutions; const requestedInstitution = - this.route.snapshot.queryParamMap.get('institution') ?? 'all'; - const restoredInstitution = institutions.some( - (institution) => institution.id === requestedInstitution, - ) - ? requestedInstitution - : 'all'; + this.route.snapshot.queryParamMap.get('institution'); + // An explicit URL parameter wins; otherwise start with the logged-in + // person's organization (the effective institution, which follows + // impersonation) and fall back to all institutions. + const restoredInstitution = requestedInstitution + ? this.findInstitution(institutions, requestedInstitution) ?? 'all' + : this.findInstitution( + institutions, + this.credentials.effectiveInstitutionId(), + ) ?? 'all'; if (restoredInstitution !== this.selectedInstitutionId) { this.selectedInstitutionId = restoredInstitution; this.loadStatistics(); } onInstitutionRestored( restoredInstitution === 'all' ? '' : restoredInstitution, + requestedInstitution ? 'url' : 'default', ); }, error: () => { @@ -223,6 +241,16 @@ export class DashboardFacade { }); } + private findInstitution( + institutions: DashboardInstitution[], + institutionId: string | null | undefined, + ): string | undefined { + if (!institutionId) return undefined; + return institutions.some((institution) => institution.id === institutionId) + ? institutionId + : undefined; + } + private loadDfgProjectTopics( period: DashboardPeriodBounds, institutionId: string,