choose the users organization on dashboard per default
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user