diff --git a/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.html b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.html new file mode 100644 index 00000000..8c817037 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.html @@ -0,0 +1,30 @@ +@if (shouldDisplay()) { +
+
+
+

Field Treemap

+

Publikationen Ihrer Organisation nach Field.

+
+
+ + @if (loading()) { +
+ +
+ } @else if (error()) { +

+ Die Field-Treemap konnte nicht geladen werden. +

+ } @else { + + } +
+} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.scss new file mode 100644 index 00000000..2914a772 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.scss @@ -0,0 +1,45 @@ +:host { + display: block; +} + +.field-treemap-section { + margin-bottom: 2.5rem; + padding: 1.25rem; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-card-bg); +} + +.field-treemap-header { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 1rem; + margin-bottom: 1rem; + + hgroup, + h2, + p { + margin: 0; + } + + p { + margin-top: 0.35rem; + color: var(--sg-text-muted); + } + + @media (max-width: 820px) { + align-items: flex-start; + flex-direction: column; + } +} + +.field-treemap-loading { + display: grid; + min-height: 25rem; + place-items: center; +} + +.statistics-error { + color: var(--sg-error); +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.ts new file mode 100644 index 00000000..56e79e03 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-field-treemap/dashboard-field-treemap.component.ts @@ -0,0 +1,61 @@ +import { Component, computed, inject, input, model } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { ACCOUNT_TREE_ICON } from '../../../../shared/ui/icons'; +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 { DashboardPeriodMode } from '../../dashboard.models'; +import { + TopicWordCloudDialogComponent, + TopicWordCloudDialogData, +} from '../topic-wordcloud-dialog/topic-wordcloud-dialog.component'; + +@Component({ + selector: 'app-dashboard-field-treemap', + imports: [LoadingComponent, TopicTreemapComponent], + templateUrl: './dashboard-field-treemap.component.html', + styleUrl: './dashboard-field-treemap.component.scss', +}) +export class DashboardFieldTreemapComponent { + readonly treemap = input(); + readonly loading = input(false); + readonly error = input(false); + readonly selectedNodeId = model(); + readonly periodMode = input.required(); + readonly fromYear = input.required(); + readonly toYear = input.required(); + readonly institutionId = input.required(); + + readonly loadingIcon = ACCOUNT_TREE_ICON; + readonly hasData = computed(() => + (this.treemap()?.fields ?? []).some( + (field) => + field.total > 0 || field.values.some((value) => value.count > 0), + ), + ); + readonly shouldDisplay = computed( + () => this.loading() || this.error() || this.hasData(), + ); + + private readonly dialog = inject(MatDialog); + + openTopic(topic: TopicTreemapTopicSelect): void { + const hasCustomPeriod = this.periodMode() !== 'all_time'; + this.dialog.open( + TopicWordCloudDialogComponent, + { + width: '85vw', + maxWidth: '92vw', + data: { + ...topic, + fromYear: hasCustomPeriod ? this.fromYear() : undefined, + toYear: hasCustomPeriod ? this.toYear() : undefined, + institutionId: this.institutionId(), + }, + }, + ); + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.html b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.html new file mode 100644 index 00000000..ffc848d8 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.html @@ -0,0 +1,53 @@ +
+ +
+ + + +
+
+ +
+ + +
+ + + Institution + + Alle Institutionen + @for (institution of institutions(); track institution.id) { + + {{ institution.display_name }} + + } + + +
diff --git a/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.scss new file mode 100644 index 00000000..1fab83ed --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.scss @@ -0,0 +1,58 @@ +:host { + display: block; +} + +.dashboard-period-filter { + display: flex; + align-items: center; + gap: 1rem; + margin-bottom: 1.5rem; + flex-wrap: wrap; +} + +.dashboard-period-presets { + display: inline-flex; + overflow: hidden; + flex: 0 0 auto; + border: 1px solid var(--sg-border); + border-radius: 6px; + background: var(--sg-surface); + + button { + padding: 0.55rem 0.8rem; + border: 0; + border-right: 1px solid var(--sg-border); + background: transparent; + color: var(--sg-text); + cursor: pointer; + font: inherit; + + &.active { + background: var(--sg-blue-highlight); + color: var(--sg-card-bg); + } + } + + button:last-child { + border-right: 0; + } +} + +.dashboard-period-slider { + width: 280px; + max-width: 100%; +} + +.dashboard-institution-filter { + width: 280px; + max-width: 100%; + margin-left: auto; +} + +@media (max-width: 720px) { + .dashboard-institution-filter, + .dashboard-period-slider { + width: 100%; + margin-left: 0; + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.ts new file mode 100644 index 00000000..d8d56f75 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-filter/dashboard-filter.component.ts @@ -0,0 +1,42 @@ +import { Component, input, model, output } from '@angular/core'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatSelectModule } from '@angular/material/select'; +import { YearRangeSliderComponent } from '../../../../shared/ui/year-range-slider/year-range-slider.component'; +import { DashboardInstitution } from '../../dashboard-statistics.service'; +import { DashboardPeriodMode } from '../../dashboard.models'; +import { FilterCardComponent } from '../../../../shared/ui/filter-card/filter-card.component'; + +@Component({ + selector: 'app-dashboard-filter', + imports: [MatFormFieldModule, MatSelectModule, YearRangeSliderComponent, FilterCardComponent], + templateUrl: './dashboard-filter.component.html', + styleUrl: './dashboard-filter.component.scss', +}) +export class DashboardFilterComponent { + readonly periodMode = input.required(); + readonly minYear = input.required(); + readonly maxYear = input.required(); + readonly startYear = model.required(); + readonly endYear = model.required(); + readonly institutions = input([]); + readonly institutionsLoading = input(false); + readonly selectedInstitutionId = input('all'); + + readonly periodModeSelected = output(); + readonly periodRangeChanged = output(); + readonly institutionSelected = output(); + + selectPeriodMode(mode: DashboardPeriodMode): void { + this.periodModeSelected.emit(mode); + } + + updateStartYear(year: number): void { + this.startYear.set(year); + this.periodRangeChanged.emit(); + } + + updateEndYear(year: number): void { + this.endYear.set(year); + this.periodRangeChanged.emit(); + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.html b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.html new file mode 100644 index 00000000..5bac0ad8 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.html @@ -0,0 +1,48 @@ +
+
+ + +
+ @for (institution of institutions(); track institution.id) { + + } +
+ + +
+ + @if (error()) { +

+ Die Institutionen konnten nicht geladen werden. +

+ } +
diff --git a/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.scss new file mode 100644 index 00000000..e7a6e9a2 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.scss @@ -0,0 +1,115 @@ +:host { + display: block; +} + +.dashboard-institution-tabs { + margin: -0.25rem 0 2rem; +} + +.dashboard-institution-tab-bar { + display: grid; + grid-template-columns: 40px minmax(0, 1fr) 40px; + align-items: stretch; + border-bottom: 1px solid var(--sg-border); +} + +.dashboard-institution-tab-arrow { + display: grid; + width: 40px; + height: 48px; + padding: 0; + place-items: center; + border: 0; + background: transparent; + color: var(--sg-text-muted); + cursor: pointer; + transition: + color 0.15s ease, + background-color 0.15s ease, + opacity 0.15s ease; + + &:hover:not(:disabled) { + background: var(--sg-option-hover); + color: var(--sg-text); + } + + &:focus-visible { + outline-offset: -3px; + } + + &:disabled { + cursor: default; + } + + &.is-hidden { + visibility: hidden; + opacity: 0; + } +} + +.dashboard-institution-tab-list { + display: flex; + overflow-x: auto; + overflow-y: hidden; + border-bottom: 0; + background: transparent; + scrollbar-width: none; + + &::-webkit-scrollbar { + display: none; + } + + button { + position: relative; + flex: 0 0 auto; + min-width: 120px; + height: 48px; + padding: 0 16px; + border: 0; + border-radius: 0; + background: transparent; + color: var(--sg-text-muted); + cursor: pointer; + font: inherit; + font-size: 14px; + font-weight: 600; + line-height: 48px; + text-align: center; + white-space: nowrap; + transition: + color 0.15s ease, + background-color 0.15s ease; + + &::after { + position: absolute; + right: 0; + bottom: 0; + left: 0; + border-top: 3px solid transparent; + background: transparent; + content: ''; + } + + &:hover { + background: var(--sg-option-hover); + color: var(--sg-text); + } + + &:focus-visible { + outline: 3px solid var(--sg-card-hover-border); + outline-offset: -3px; + } + + &.active { + color: var(--sg-blue-highlight); + + &::after { + border-top-color: var(--sg-blue-highlight); + } + } + } +} + +.statistics-error { + color: var(--sg-error); +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.ts new file mode 100644 index 00000000..e7763b66 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-institution-tabs/dashboard-institution-tabs.component.ts @@ -0,0 +1,74 @@ +import { + AfterViewInit, + Component, + ElementRef, + HostListener, + OnChanges, + ViewChild, + input, + output, +} from '@angular/core'; +import { MatIconModule } from '@angular/material/icon'; +import { DashboardInstitution } from '../../dashboard-statistics.service'; + +@Component({ + selector: 'app-dashboard-institution-tabs', + imports: [MatIconModule], + templateUrl: './dashboard-institution-tabs.component.html', + styleUrl: './dashboard-institution-tabs.component.scss', +}) +export class DashboardInstitutionTabsComponent + implements AfterViewInit, OnChanges +{ + @ViewChild('tabList') private tabList?: ElementRef; + + readonly institutions = input([]); + readonly selectedInstitutionId = input(''); + readonly error = input(false); + readonly institutionSelected = output(); + + canScrollLeft = false; + canScrollRight = false; + + ngAfterViewInit(): void { + setTimeout(() => this.updateScrollState()); + } + + ngOnChanges(): void { + setTimeout(() => this.updateScrollState()); + } + + @HostListener('window:resize') + onWindowResize(): void { + this.updateScrollState(); + } + + selectInstitution(institutionId: string): void { + if (institutionId !== this.selectedInstitutionId()) { + this.institutionSelected.emit(institutionId); + } + } + + scroll(direction: -1 | 1): void { + const tabList = this.tabList?.nativeElement; + if (!tabList) return; + + tabList.scrollBy({ + left: direction * Math.floor(tabList.clientWidth * 0.75), + behavior: 'smooth', + }); + } + + updateScrollState(): void { + const tabList = this.tabList?.nativeElement; + if (!tabList) { + this.canScrollLeft = false; + this.canScrollRight = false; + return; + } + + const maxScrollLeft = tabList.scrollWidth - tabList.clientWidth; + this.canScrollLeft = tabList.scrollLeft > 1; + this.canScrollRight = tabList.scrollLeft < maxScrollLeft - 1; + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.html b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.html new file mode 100644 index 00000000..192873ac --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.html @@ -0,0 +1,45 @@ +@if (shouldDisplay()) { +
+
+
+

Projektstatus nach Fördergeber

+

+ Laufende, kommende und abgeschlossene EU-, Bund- und DFG-Projekte + Ihrer Organisation. +

+
+ @if (statusData(); as statuses) { +
+ EU: {{ total(statuses.eu) | number }} + Bund: {{ total(statuses.bund) | number }} + DFG: {{ total(statuses.dfg) | number }} +
+ } +
+ + @if (loading()) { +
+ +
+ } @else if (allFailed()) { +

+ Der Status der EU-, Bund- und DFG-Projekte konnte nicht geladen werden. +

+ } @else if (statusData(); as statuses) { + @if (failedSources()) { +

+ Projektstatusdaten für {{ failedSources() }} konnten nicht geladen + werden. Die übrigen Daten werden weiterhin angezeigt. +

+ } + + } +
+} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.scss new file mode 100644 index 00000000..b6d9dcb4 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.scss @@ -0,0 +1,59 @@ +:host { + display: block; +} + +.project-status-section { + margin-bottom: 2.5rem; + padding: 1.25rem; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-card-bg); +} + +.project-status-header { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 1rem; + margin-bottom: 1rem; + + h2, + p { + margin: 0; + } + + p { + margin-top: 0.35rem; + color: var(--sg-text-muted); + } + + @media (max-width: 820px) { + align-items: flex-start; + flex-direction: column; + } +} + +.project-status-loading { + display: grid; + min-height: 15rem; + place-items: center; +} + +.project-status-summary { + display: flex; + flex: 0 0 auto; + gap: 0.5rem; + + span { + padding: 0.35rem 0.65rem; + border-radius: 999px; + background: var(--sg-surface-muted); + color: var(--sg-text-muted); + font-size: 0.9rem; + font-weight: 600; + } +} + +.statistics-error { + color: var(--sg-error); +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.ts new file mode 100644 index 00000000..3f172b39 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-project-status/dashboard-project-status.component.ts @@ -0,0 +1,69 @@ +import { DecimalPipe } from '@angular/common'; +import { Component, computed, input } from '@angular/core'; +import { STACKED_BAR_CHART_ICON } from '../../../../shared/ui/icons'; +import { LoadingComponent } from '../../../../shared/ui/loading/loading.component'; +import { + BmbfProjectStatusStatistics, + DfgProjectStatusStatistics, + EuProjectStatusStatistics, +} from '../../dashboard-statistics.service'; +import { EuProjectStatusChartComponent } from '../eu-project-status-chart/eu-project-status-chart.component'; + +@Component({ + selector: 'app-dashboard-project-status', + imports: [DecimalPipe, EuProjectStatusChartComponent, LoadingComponent], + templateUrl: './dashboard-project-status.component.html', + styleUrl: './dashboard-project-status.component.scss', +}) +export class DashboardProjectStatusComponent { + readonly active = input(false); + readonly euStatuses = input(); + readonly bundStatuses = input(); + readonly dfgStatuses = input(); + readonly euLoading = input(false); + readonly bundLoading = input(false); + readonly dfgLoading = input(false); + readonly euError = input(false); + readonly bundError = input(false); + readonly dfgError = input(false); + + readonly loadingIcon = STACKED_BAR_CHART_ICON; + readonly loading = computed( + () => this.euLoading() || this.bundLoading() || this.dfgLoading(), + ); + readonly allFailed = computed( + () => this.euError() && this.bundError() && this.dfgError(), + ); + readonly failedSources = computed(() => + [ + this.euError() ? 'EU' : undefined, + this.bundError() ? 'Bund' : undefined, + this.dfgError() ? 'DFG' : undefined, + ] + .filter((source): source is string => source !== undefined) + .join(' und '), + ); + readonly statusData = computed(() => { + const eu = this.euStatuses(); + const bund = this.bundStatuses(); + const dfg = this.dfgStatuses(); + return eu && bund && dfg ? { eu, bund, dfg } : undefined; + }); + readonly shouldDisplay = computed( + () => + this.active() && + (this.loading() || + this.euError() || + this.bundError() || + this.dfgError() || + Boolean(this.statusData())), + ); + + total(statuses: { + ongoing: number; + upcoming: number; + completed: number; + }): number { + return statuses.ongoing + statuses.upcoming + statuses.completed; + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.html b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.html new file mode 100644 index 00000000..e7407bf5 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.html @@ -0,0 +1,18 @@ + +
+ {{ icon() }} +
+
+ {{ label() }} + {{ loading() ? '…' : ((value() | number) ?? '–') }} +
+
diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.scss new file mode 100644 index 00000000..37852979 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.scss @@ -0,0 +1,76 @@ +:host { + display: block; +} + +.statistics-card { + display: flex; + align-items: center; + gap: 1rem; + min-height: 120px; + padding: 1.25rem; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-card-bg); + box-shadow: var(--sg-shadow-sm); + color: inherit; + text-decoration: none; + transition: + border-color 160ms ease, + box-shadow 160ms ease, + transform 160ms ease; + + &:hover { + border-color: var(--sg-card-hover-border); + box-shadow: var(--sg-shadow-md); + transform: translateY(-2px); + } + + &:focus-visible { + outline: 3px solid var(--sg-card-hover-border); + outline-offset: 3px; + } + + &.disabled { + pointer-events: none; + } + + span { + display: block; + color: var(--sg-text-muted); + } + + strong { + display: block; + margin: 0.2rem 0; + color: var(--sg-text); + font-size: clamp(1.7rem, 3vw, 2.3rem); + line-height: 1.1; + } +} + +.statistics-icon { + display: grid; + flex: 0 0 52px; + width: 52px; + height: 52px; + place-items: center; + border-radius: 12px; + background: var(--sg-primary-soft); + color: var(--sg-blue-highlight); + + &--persons { + background: var(--sg-success-soft); + color: var(--sg-success); + } + + &--patents { + background: var(--sg-error-soft); + color: var(--sg-error); + } + + &--bund-projects, + &--dfg-projects { + background: var(--sg-warning-soft); + color: var(--sg-warning); + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.ts new file mode 100644 index 00000000..c7d6f4ac --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistic-card/dashboard-statistic-card.component.ts @@ -0,0 +1,32 @@ +import { DecimalPipe } from '@angular/common'; +import { Component, input } from '@angular/core'; +import { MatIconModule } from '@angular/material/icon'; +import { MatTooltipModule } from '@angular/material/tooltip'; +import { Params, RouterLink, UrlTree } from '@angular/router'; + +export type DashboardStatisticCardVariant = + | 'publications' + | 'persons' + | 'patents' + | 'eu-projects' + | 'bund-projects' + | 'dfg-projects'; + +@Component({ + selector: 'app-dashboard-statistic-card', + imports: [DecimalPipe, MatIconModule, MatTooltipModule, RouterLink], + templateUrl: './dashboard-statistic-card.component.html', + styleUrl: './dashboard-statistic-card.component.scss', +}) +export class DashboardStatisticCardComponent { + readonly label = input.required(); + readonly value = input(); + readonly loading = input(false); + readonly icon = input.required(); + readonly variant = input.required(); + readonly link = input.required(); + readonly queryParams = input(null); + readonly ariaLabel = input.required(); + readonly tooltip = input.required(); + readonly disabled = input(false); +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.html b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.html new file mode 100644 index 00000000..d1f27c4a --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.html @@ -0,0 +1,67 @@ +
+ + + + + + + + + + + +
diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.scss new file mode 100644 index 00000000..30d3169a --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.scss @@ -0,0 +1,6 @@ +.statistics-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); + gap: 1rem; + margin-bottom: 2rem; +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.ts new file mode 100644 index 00000000..6f23540b --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-statistics-grid/dashboard-statistics-grid.component.ts @@ -0,0 +1,76 @@ +import { Component, computed, input } from '@angular/core'; +import { + ACCOUNT_BALANCE_ICON, + GROUPS_ICON, + MENU_BOOK_ICON, + PATENT_ICON, + PUBLIC_ICON, + SCIENCE_ICON, +} from '../../../../shared/ui/icons'; +import { institutionPersonListQueryParamsForPeriod } from '../../../../shared/person-list-query-params'; +import { + DashboardInstitution, + DashboardStatistics, +} from '../../dashboard-statistics.service'; +import { + DashboardPeriodMode, + DashboardStatisticKey, +} from '../../dashboard.models'; +import { DashboardStatisticCardComponent } from '../dashboard-statistic-card/dashboard-statistic-card.component'; + +@Component({ + selector: 'app-dashboard-statistics-grid', + imports: [DashboardStatisticCardComponent], + templateUrl: './dashboard-statistics-grid.component.html', + styleUrl: './dashboard-statistics-grid.component.scss', +}) +export class DashboardStatisticsGridComponent { + readonly statistics = input>(); + readonly loading = input.required< + Readonly> + >(); + readonly institutions = input([]); + readonly selectedInstitutionId = input('all'); + readonly periodMode = input.required(); + readonly fromYear = input.required(); + readonly toYear = input.required(); + + readonly MENU_BOOK_ICON = MENU_BOOK_ICON; + readonly GROUPS_ICON = GROUPS_ICON; + readonly PATENT_ICON = PATENT_ICON; + readonly PUBLIC_ICON = PUBLIC_ICON; + readonly ACCOUNT_BALANCE_ICON = ACCOUNT_BALANCE_ICON; + readonly SCIENCE_ICON = SCIENCE_ICON; + + readonly organizationName = computed( + () => this.statistics()?.organization_name ?? 'Ihre Organisation', + ); + + readonly institutionRouteId = computed(() => { + const selectedInstitutionId = this.routeableInstitutionId( + this.selectedInstitutionId(), + ); + if (selectedInstitutionId) return selectedInstitutionId; + + return this.routeableInstitutionId(this.institutions()[0]?.id) ?? ''; + }); + + readonly personListQueryParams = computed(() => + institutionPersonListQueryParamsForPeriod( + this.institutionRouteId(), + this.organizationName(), + this.periodMode() === 'all_time' ? undefined : this.fromYear(), + this.periodMode() === 'all_time' ? undefined : this.toYear(), + ), + ); + + private routeableInstitutionId(institutionId?: string | null): string | null { + const normalizedInstitutionId = institutionId + ?.replace('https://openalex.org/', '') + .trim(); + + return normalizedInstitutionId && normalizedInstitutionId !== 'all' + ? normalizedInstitutionId + : null; + } +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.html b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.html new file mode 100644 index 00000000..62cb6c8f --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.html @@ -0,0 +1,25 @@ +@if (shouldDisplay()) { +
+
+
+

Top 10 Personen

+

+ Nach Anzahl der Works, DFG-Projekte, Patente und News Ihrer + Organisation. +

+
+
+ + @if (error()) { +

+ Die Autorenstatistiken konnten nicht geladen werden. +

+ } @else { +
+ @for (dataset of visibleDatasets(); track dataset.title) { + + } +
+ } +
+} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.scss b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.scss new file mode 100644 index 00000000..0ad78169 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.scss @@ -0,0 +1,49 @@ +:host { + display: block; +} + +.top-authors-section { + margin-bottom: 2.5rem; +} + +.top-authors-header { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 1rem; + margin-bottom: 1rem; + + hgroup, + h2, + p { + margin: 0; + } + + p { + margin-top: 0.35rem; + color: var(--sg-text-muted); + } + + @media (max-width: 720px) { + align-items: flex-start; + flex-direction: column; + } +} + +.top-authors-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1rem; + + &.loading { + opacity: 0.65; + } + + @media (max-width: 900px) { + grid-template-columns: 1fr; + } +} + +.statistics-error { + color: var(--sg-error); +} diff --git a/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.ts b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.ts new file mode 100644 index 00000000..9c6ae5dc --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/dashboard-top-authors/dashboard-top-authors.component.ts @@ -0,0 +1,77 @@ +import { Component, computed, input } from '@angular/core'; +import { + ACCOUNT_TREE_ICON, + ARTICLE_ICON, + DESCRIPTION_ICON, + MENU_BOOK_ICON, + PUBLIC_ICON, +} from '../../../../shared/ui/icons'; +import { TopAuthorStatistics } from '../../dashboard-statistics.service'; +import { + TopAuthorChartComponent, + TopAuthorDataset, +} from '../top-author-chart/top-author-chart.component'; + +@Component({ + selector: 'app-dashboard-top-authors', + imports: [TopAuthorChartComponent], + templateUrl: './dashboard-top-authors.component.html', + styleUrl: './dashboard-top-authors.component.scss', +}) +export class DashboardTopAuthorsComponent { + readonly statistics = input(); + readonly loading = input(false); + readonly error = input(false); + + readonly datasets = computed(() => [ + { + 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.statistics()?.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.statistics()?.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.statistics()?.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.statistics()?.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.statistics()?.news ?? [], + }, + ]); + + readonly visibleDatasets = computed(() => + this.loading() + ? this.datasets() + : this.datasets().filter((dataset) => dataset.entries.length > 0), + ); + + readonly shouldDisplay = computed( + () => + this.loading() || + this.error() || + this.datasets().some((dataset) => dataset.entries.length > 0), + ); +} diff --git a/webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.html b/webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.html similarity index 100% rename from webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.html rename to webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.html diff --git a/webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.scss b/webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.scss similarity index 100% rename from webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.scss rename to webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.scss diff --git a/webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.ts b/webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.ts similarity index 95% rename from webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.ts rename to webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.ts index 0d65be22..a6bd55ef 100644 --- a/webapp/src/app/modules/dashboard/dfg-topic-donut/dfg-topic-donut.component.ts +++ b/webapp/src/app/modules/dashboard/components/dfg-topic-donut/dfg-topic-donut.component.ts @@ -1,9 +1,9 @@ import { Component, Input, OnChanges, effect, inject } from '@angular/core'; import { EChartsOption } from 'echarts'; import { NgxEchartsDirective } from 'ngx-echarts'; -import { ChartThemeService } from '../../../shared/services/chart-theme.service'; +import { ChartThemeService } from '../../../../shared/services/chart-theme.service'; -import { DfgProjectTopic } from '../dashboard-statistics.service'; +import { DfgProjectTopic } from '../../dashboard-statistics.service'; @Component({ selector: 'app-dfg-topic-donut', diff --git a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.html b/webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.html similarity index 100% rename from webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.html rename to webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.html diff --git a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.scss b/webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.scss similarity index 100% rename from webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.scss rename to webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.scss diff --git a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts b/webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.ts similarity index 96% rename from webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts rename to webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.ts index e3ac317e..9cd8d82f 100644 --- a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts +++ b/webapp/src/app/modules/dashboard/components/eu-project-status-chart/eu-project-status-chart.component.ts @@ -1,13 +1,13 @@ import { Component, Input, OnChanges, effect, inject } from '@angular/core'; import { EChartsOption } from 'echarts'; import { NgxEchartsDirective } from 'ngx-echarts'; -import { ChartThemeService } from '../../../shared/services/chart-theme.service'; +import { ChartThemeService } from '../../../../shared/services/chart-theme.service'; import { BmbfProjectStatusStatistics, DfgProjectStatusStatistics, EuProjectStatusStatistics, -} from '../dashboard-statistics.service'; +} from '../../dashboard-statistics.service'; @Component({ selector: 'app-eu-project-status-chart', diff --git a/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.html b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.html new file mode 100644 index 00000000..badd4753 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.html @@ -0,0 +1,41 @@ +@if (shouldDisplay()) { +
+
+
+

{{ sourceLabel() }}-Projekt-Topics

+

+ Gematchte {{ sourceLabel() }}-Projekte nach Field, Subfield und Topic. + Ein Klick auf ein Topic zeigt die zugehörigen Keywords. +

+
+ @if (projectTopics(); as topics) { +

+ {{ topics.matched_project_count | number }} von + {{ topics.project_count | number }} Projekten gematcht +

+ } +
+ + @if (loading()) { +
+ +
+ } @else if (error()) { +

+ Die {{ sourceLabel() }}-Topic-Treemap konnte nicht geladen werden. +

+ } @else { + + } +
+} diff --git a/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.scss b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.scss new file mode 100644 index 00000000..ad96157d --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.scss @@ -0,0 +1,50 @@ +:host { + display: block; +} + +.topic-heatmap-section { + margin-bottom: 2.5rem; + padding: 1.25rem; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-card-bg); +} + +.topic-heatmap-header { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 1rem; + margin-bottom: 1rem; + + h2, + p { + margin: 0; + } + + p { + margin-top: 0.35rem; + color: var(--sg-text-muted); + } + + @media (max-width: 820px) { + align-items: flex-start; + flex-direction: column; + } +} + +.topic-summary { + flex: 0 0 auto; + color: var(--sg-text-muted); + font-weight: 600; +} + +.topic-heatmap-loading { + display: grid; + min-height: 25rem; + place-items: center; +} + +.statistics-error { + color: var(--sg-error); +} diff --git a/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.ts b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.ts new file mode 100644 index 00000000..5299c7e8 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/project-topics/project-topics.component.ts @@ -0,0 +1,72 @@ +import { DecimalPipe } from '@angular/common'; +import { Component, computed, inject, input, model } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { ACCOUNT_TREE_ICON } from '../../../../shared/ui/icons'; +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 { + BundProjectTopics, + DfgProjectTopics, + EuProjectTopics, +} from '../../dashboard-statistics.service'; +import { + TopicWordCloudDialogComponent, + TopicWordCloudDialogData, +} from '../topic-wordcloud-dialog/topic-wordcloud-dialog.component'; + +@Component({ + selector: 'app-project-topics', + imports: [DecimalPipe, LoadingComponent, TopicTreemapComponent], + templateUrl: './project-topics.component.html', + styleUrl: './project-topics.component.scss', +}) +export class ProjectTopicsComponent { + readonly source = input.required<'eu' | 'bund' | 'dfg'>(); + readonly projectTopics = input< + EuProjectTopics | BundProjectTopics | DfgProjectTopics + >(); + readonly treemap = input(); + readonly loading = input(false); + readonly error = input(false); + readonly selectedNodeId = model(); + + readonly loadingIcon = ACCOUNT_TREE_ICON; + readonly sourceLabel = computed(() => { + if (this.source() === 'eu') return 'EU'; + if (this.source() === 'dfg') return 'DFG'; + return 'BUND'; + }); + readonly shouldDisplay = computed( + () => this.loading() || this.error() || Boolean(this.projectTopics()), + ); + + private readonly dialog = inject(MatDialog); + + openTopic(topic: TopicTreemapTopicSelect): void { + const projectTopic = this.projectTopics()?.topics.find( + (entry) => entry.id === topic.topicId, + ); + if (!projectTopic) return; + + this.dialog.open( + TopicWordCloudDialogComponent, + { + width: '85vw', + maxWidth: '92vw', + data: { + ...topic, + source: this.source(), + words: projectTopic.keywords.map((keyword) => ({ + id: keyword.name, + name: keyword.name, + count: keyword.project_count, + })), + }, + }, + ); + } +} diff --git a/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.html b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.html new file mode 100644 index 00000000..66ff81c1 --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.html @@ -0,0 +1,43 @@ +
+

{{ dataset().icon }}{{ dataset().title }}

+

{{ dataset().subtitle }}

+ + @for ( + entry of dataset().entries; + track entry.id || entry.name; + let rank = $index + ) { +
+ {{ rank + 1 }} +
+
+ @if (entry.id) { + + {{ authorDisplayName(entry) }} + + } @else { + + {{ authorDisplayName(entry) }} + + } + {{ entry.count | number }} +
+
+ +
+
+
+ } @empty { +

+ {{ loading() ? 'Wird geladen …' : 'Keine Daten vorhanden.' }} +

+ } +
diff --git a/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.scss b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.scss new file mode 100644 index 00000000..5320c4ef --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.scss @@ -0,0 +1,99 @@ +:host { + display: block; +} + +.top-authors-chart { + height: 100%; + padding: 1.25rem; + border: 1px solid var(--sg-border); + border-radius: 12px; + background: var(--sg-card-bg); + + h3 { + display: flex; + align-items: center; + gap: 0.5rem; + margin: 0; + color: var(--sg-text); + } +} + +.top-authors-chart-subtitle { + margin: 0.35rem 0 1rem; + color: var(--sg-text-muted); + font-size: 13px; + line-height: 1.45; +} + +.author-bar-row { + display: flex; + align-items: center; + gap: 0.65rem; + margin-top: 0.7rem; +} + +.author-rank { + flex: 0 0 1.4rem; + color: var(--sg-text-muted); + font-size: 0.8rem; + text-align: center; +} + +.author-bar-content { + min-width: 0; + flex: 1; +} + +.author-bar-label { + display: flex; + justify-content: space-between; + gap: 0.75rem; + margin-bottom: 0.25rem; + font-size: 0.85rem; + + .author-name { + overflow: hidden; + color: var(--sg-blue-highlight); + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; + } +} + +.author-link { + overflow: hidden; + text-decoration: none; + text-overflow: ellipsis; + white-space: nowrap; + + &:hover { + text-decoration: underline; + } + + &:focus-visible { + border-radius: 2px; + outline: 2px solid var(--sg-card-hover-border); + outline-offset: 2px; + } +} + +.author-bar-track { + overflow: hidden; + height: 7px; + border-radius: 999px; + background: var(--sg-border); +} + +.author-bar-fill { + display: block; + height: 100%; + border-radius: inherit; + background: var(--sg-blue-highlight); + transition: width 220ms ease; +} + +.empty-chart { + margin: 2rem 0; + color: var(--sg-text-muted); + text-align: center; +} diff --git a/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.ts b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.ts new file mode 100644 index 00000000..81c96dcd --- /dev/null +++ b/webapp/src/app/modules/dashboard/components/top-author-chart/top-author-chart.component.ts @@ -0,0 +1,53 @@ +import { DecimalPipe } from '@angular/common'; +import { Component, input } from '@angular/core'; +import { MatIconModule } from '@angular/material/icon'; +import { RouterLink } from '@angular/router'; +import { ComponentTooltipDirective } from '../../../../directives/component-tooltip.directive'; +import { AppAuthorTooltipComponent } from '../../../../shared/ui/app-author-tooltip/app-author-tooltip.component'; +import { TopAuthor } from '../../dashboard-statistics.service'; + +export interface TopAuthorDataset { + title: string; + subtitle: string; + icon: string; + entries: TopAuthor[]; + stripAuthorTitle?: boolean; +} + +@Component({ + selector: 'app-top-author-chart', + imports: [ + DecimalPipe, + MatIconModule, + RouterLink, + ComponentTooltipDirective, + ], + templateUrl: './top-author-chart.component.html', + styleUrl: './top-author-chart.component.scss', +}) +export class TopAuthorChartComponent { + readonly dataset = input.required(); + readonly loading = input(false); + readonly AuthorTooltipComponent = AppAuthorTooltipComponent; + + authorBarWidth(count: number): number { + const maximum = Math.max( + ...this.dataset().entries.map((entry) => entry.count), + 1, + ); + return (count / maximum) * 100; + } + + authorDisplayName(entry: TopAuthor): string { + if (!this.dataset().stripAuthorTitle) return entry.name; + + return ( + entry.name + .replace( + /^(?:(?:(?:apl\.\s*)?prof(?:essor)?\.?|priv\.-doz\.?|pd|dr\.?)\s+)+/i, + '', + ) + .trim() || entry.name + ); + } +} diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html b/webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html similarity index 100% rename from webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html rename to webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss b/webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss similarity index 100% rename from webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss rename to webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts b/webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts similarity index 98% rename from webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts rename to webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts index 0fa56005..81c51581 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts +++ b/webapp/src/app/modules/dashboard/components/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts @@ -13,7 +13,7 @@ import { RouterLink } from '@angular/router'; import { DashboardStatisticsService, TopicWordCloudWord, -} from '../dashboard-statistics.service'; +} from '../../dashboard-statistics.service'; import { ACCOUNT_TREE_ICON, CATEGORY_ICON, @@ -26,7 +26,7 @@ import { SEARCH_ICON, SEARCH_OFF_ICON, TUNE_ICON, -} from '../../../shared/ui/icons'; +} from '../../../../shared/ui/icons'; export interface TopicWordCloudDialogData { topicId: string; diff --git a/webapp/src/app/modules/dashboard/dashboard.component.html b/webapp/src/app/modules/dashboard/dashboard.component.html index d8b62ad4..cd0177ee 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.html +++ b/webapp/src/app/modules/dashboard/dashboard.component.html @@ -1,579 +1,91 @@
-
-
- - - -
-
- - -
- - Institution - - Alle Institutionen - @for (institution of dashboardInstitutions; track institution.id) { - - {{ institution.display_name }} - - } - - -
+ -
- -
- {{ MENU_BOOK_ICON }} -
-
- Publikationen - - {{ - isStatisticLoading('publications') - ? '…' - : ((statistics?.publications | number) ?? '–') - }} - -
-
+ - -
- {{ GROUPS_ICON }} -
-
- Personen - - {{ - isStatisticLoading('persons') - ? '…' - : ((statistics?.persons | number) ?? '–') - }} - -
-
- - -
- {{ patentIcon }} -
-
- Patente - - {{ - isStatisticLoading('patents') - ? '…' - : ((statistics?.patents | number) ?? '–') - }} - -
-
- - -
- {{ PUBLIC_ICON }} -
-
- EU-Projekte - - {{ - isStatisticLoading('eu_projects') - ? '…' - : ((statistics?.eu_projects | number) ?? '–') - }} - -
-
- - -
- {{ ACCOUNT_BALANCE_ICON }} -
-
- Bund-Projekte - - {{ - isStatisticLoading('bmbf_projects') - ? '…' - : ((statistics?.bmbf_projects | number) ?? '–') - }} - -
-
- - -
- {{ SCIENCE_ICON }} -
-
- DFG-Projekte - - {{ - isStatisticLoading('dfg_projects') - ? '…' - : ((statistics?.dfg_projects | number) ?? '–') - }} - -
-
-
- - @if (statisticsError) { + @if (dashboard.statisticsError) {

Die Kennzahlen konnten nicht geladen werden.

} -
-

Institution auswählen

-
- -
- @for (institution of dashboardInstitutions; track institution.id) { - - } -
- -
- @if (dashboardInstitutionsError) { -

- Die Institutionen konnten nicht geladen werden. -

- } -
+ + + @if (selectedAnalyticalInstitutionId) { - @if ( - euProjectStatusesLoading || - bmbfProjectStatusesLoading || - dfgProjectStatusesLoading || - euProjectStatusesError || - bmbfProjectStatusesError || - dfgProjectStatusesError || - (euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses) - ) { -
-
-
-

Projektstatus nach Fördergeber

-

- Laufende, kommende und abgeschlossene EU-, Bund- und DFG-Projekte - Ihrer Organisation. -

-
- @if (euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses) { -
- - EU: - {{ - euProjectStatuses.ongoing + - euProjectStatuses.upcoming + - euProjectStatuses.completed | number - }} - - - Bund: - {{ - bmbfProjectStatuses.ongoing + - bmbfProjectStatuses.upcoming + - bmbfProjectStatuses.completed | number - }} - - - DFG: - {{ - dfgProjectStatuses.ongoing + - dfgProjectStatuses.upcoming + - dfgProjectStatuses.completed | number - }} - -
- } -
- @if ( - euProjectStatusesLoading || - bmbfProjectStatusesLoading || - dfgProjectStatusesLoading - ) { -
- -
- } @else if ( - euProjectStatusesError && - bmbfProjectStatusesError && - dfgProjectStatusesError - ) { -

- Der Status der EU-, Bund- und DFG-Projekte konnte nicht geladen - werden. -

- } @else if ( - euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses - ) { - @if ( - euProjectStatusesError || - bmbfProjectStatusesError || - dfgProjectStatusesError - ) { -

- Projektstatusdaten für {{ failedProjectStatusSources() }} konnten - nicht geladen werden. Die übrigen Daten werden weiterhin - angezeigt. -

- } - - } -
- } + - @if (topicTreemapLoading || topicTreemapError || hasTopicTreemapData()) { -
-
-
-

Field Treemap

-

Publikationen Ihrer Organisation nach Field.

-
-
+ - @if (topicTreemapLoading) { -
- -
- } @else if (topicTreemapError) { -

- Die Field-Treemap konnte nicht geladen werden. -

- } @else { - - - } -
- } + - @if (dfgTopicsLoading || dfgTopicsError || dfgProjectTopics) { -
-
-
-

DFG-Projekt-Topics

-

- Gematchte DFG-Projekte nach Field, Subfield und Topic. Ein Klick - auf ein Topic zeigt die zugehörigen Keywords. -

-
- @if (dfgProjectTopics) { -

- {{ dfgProjectTopics.matched_project_count | number }} von - {{ dfgProjectTopics.project_count | number }} Projekten gematcht -

- } -
+ - @if (dfgTopicsLoading) { -
- -
- } @else if (dfgTopicsError) { -

- Die DFG-Topic-Treemap konnte nicht geladen werden. -

- } @else { - - - } -
- } - - @if (euTopicsLoading || euTopicsError || euProjectTopics) { -
-
-
-

EU-Projekt-Topics

-

- Gematchte EU-Projekte nach Field, Subfield und Topic. Ein Klick - auf ein Topic zeigt die zugehörigen Keywords. -

-
- @if (euProjectTopics) { -

- {{ euProjectTopics.matched_project_count | number }} von - {{ euProjectTopics.project_count | number }} Projekten gematcht -

- } -
- - @if (euTopicsLoading) { -
- -
- } @else if (euTopicsError) { -

- Die EU-Topic-Treemap konnte nicht geladen werden. -

- } @else { - - - } -
- } - - @if (bundTopicsLoading || bundTopicsError || bundProjectTopics) { -
-
-
-

BUND-Projekt-Topics

-

- Gematchte BUND-Projekte nach Field, Subfield und Topic. Ein Klick - auf ein Topic zeigt die zugehörigen Keywords. -

-
- @if (bundProjectTopics) { -

- {{ bundProjectTopics.matched_project_count | number }} von - {{ bundProjectTopics.project_count | number }} Projekten gematcht -

- } -
- - @if (bundTopicsLoading) { -
- -
- } @else if (bundTopicsError) { -

- Die BUND-Topic-Treemap konnte nicht geladen werden. -

- } @else { - - - } -
- } - - @if (topAuthorsLoading || topAuthorsError || hasTopAuthorData()) { -
-
-
-

Top 10 Personen

-

- Nach Anzahl der Works, DFG-Projekte, Patente und News Ihrer - Organisation. -

-
-
- - @if (topAuthorsError) { -

- Die Autorenstatistiken konnten nicht geladen werden. -

- } @else { -
- @for (dataset of visibleTopAuthorDatasets(); track dataset.title) { -
-

- {{ dataset.icon }}{{ dataset.title }} -

-

- {{ dataset.subtitle }} -

- @for ( - entry of dataset.entries; - track entry.id || entry.name; - let rank = $index - ) { -
- {{ rank + 1 }} -
-
- @if (entry.id) { - - {{ authorDisplayName(dataset, entry) }} - - } @else { - - {{ authorDisplayName(dataset, entry) }} - - } - {{ entry.count | number }} -
-
- -
-
-
- } @empty { -

- {{ - topAuthorsLoading - ? 'Wird geladen …' - : 'Keine Daten vorhanden.' - }} -

- } -
- } -
- } -
- } + }
diff --git a/webapp/src/app/modules/dashboard/dashboard.component.scss b/webapp/src/app/modules/dashboard/dashboard.component.scss index 448825c5..cad096da 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.scss +++ b/webapp/src/app/modules/dashboard/dashboard.component.scss @@ -2,467 +2,9 @@ padding: 2rem; color: var(--sg-text); - .dashboard-period-filter { - display: flex; - align-items: center; - gap: 1rem; - margin-bottom: 1.5rem; - flex-wrap: wrap; - } - - .dashboard-period-presets { - display: inline-flex; - overflow: hidden; - flex: 0 0 auto; - border: 1px solid var(--sg-border); - border-radius: 6px; - background: var(--sg-surface); - - button { - padding: 0.55rem 0.8rem; - border: 0; - border-right: 1px solid var(--sg-border); - background: transparent; - color: var(--sg-text); - cursor: pointer; - font: inherit; - - &.active { - background: var(--sg-blue-highlight); - color: var(--sg-card-bg); - } - } - - button:last-child { - border-right: 0; - } - } - - .dashboard-period-slider { - width: 280px; - max-width: 100%; - } - - .dashboard-institution-filter { - width: 280px; - max-width: 100%; - margin-left: auto; - } - - @media (max-width: 720px) { - .dashboard-institution-filter, - .dashboard-period-slider { - width: 100%; - margin-left: 0; - } - } - - .statistics-grid { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); - gap: 1rem; - margin-bottom: 2rem; - } - - .statistics-card { - display: flex; - align-items: center; - gap: 1rem; - min-height: 120px; - padding: 1.25rem; - border: 1px solid var(--sg-border); - border-radius: 12px; - background: var(--sg-card-bg); - box-shadow: var(--sg-shadow-sm); - color: inherit; - text-decoration: none; - transition: - border-color 160ms ease, - box-shadow 160ms ease, - transform 160ms ease; - - &:hover { - border-color: var(--sg-card-hover-border); - box-shadow: var(--sg-shadow-md); - transform: translateY(-2px); - } - - &:focus-visible { - outline: 3px solid var(--sg-card-hover-border); - outline-offset: 3px; - } - - &.disabled { - pointer-events: none; - } - - span, - small { - display: block; - color: var(--sg-text-muted); - } - - strong { - display: block; - margin: 0.2rem 0; - color: var(--sg-text); - font-size: clamp(1.7rem, 3vw, 2.3rem); - line-height: 1.1; - } - } - - .statistics-icon { - display: grid; - flex: 0 0 52px; - width: 52px; - height: 52px; - place-items: center; - border-radius: 12px; - background: var(--sg-primary-soft); - color: var(--sg-blue-highlight); - - &--persons { - background: var(--sg-success-soft); - color: var(--sg-success); - } - - &--patents { - background: var(--sg-error-soft); - color: var(--sg-error); - } - - &--eu-projects { - background: var(--sg-primary-soft); - color: var(--sg-blue-highlight); - } - - &--bund-projects { - background: var(--sg-warning-soft); - color: var(--sg-warning); - } - - &--dfg-projects { - background: var(--sg-warning-soft); - color: var(--sg-warning); - } - } - .statistics-error { margin: -1rem 0 2rem; color: var(--sg-error); } - .dashboard-institution-tabs { - margin: -0.25rem 0 2rem; - - h2 { - margin: 0 0 0.75rem; - font-size: 1.2rem; - line-height: 1.25; - } - } - - .dashboard-institution-tab-bar { - display: grid; - grid-template-columns: 40px minmax(0, 1fr) 40px; - align-items: stretch; - border-bottom: 1px solid var(--sg-border); - } - - .dashboard-institution-tab-arrow { - display: grid; - width: 40px; - height: 48px; - padding: 0; - place-items: center; - border: 0; - background: transparent; - color: var(--sg-text-muted); - cursor: pointer; - transition: - color 0.15s ease, - background-color 0.15s ease, - opacity 0.15s ease; - - &:hover:not(:disabled) { - background: var(--sg-option-hover); - color: var(--sg-text); - } - - &:focus-visible { - outline-offset: -3px; - } - - &:disabled { - cursor: default; - } - - &.is-hidden { - visibility: hidden; - opacity: 0; - } - } - - .dashboard-institution-tab-list { - display: flex; - overflow-x: auto; - overflow-y: hidden; - border-bottom: 0; - background: transparent; - scrollbar-width: none; - - &::-webkit-scrollbar { - display: none; - } - - button { - position: relative; - flex: 0 0 auto; - min-width: 120px; - height: 48px; - padding: 0 16px; - border: 0; - border-radius: 0; - background: transparent; - color: var(--sg-text-muted); - cursor: pointer; - font: inherit; - font-size: 14px; - font-weight: 600; - line-height: 48px; - text-align: center; - white-space: nowrap; - transition: - color 0.15s ease, - background-color 0.15s ease; - - &::after { - position: absolute; - right: 0; - bottom: 0; - left: 0; - border-top: 3px solid transparent; - background: transparent; - content: ''; - } - - &:hover { - background: var(--sg-option-hover); - color: var(--sg-text); - } - - &:focus-visible { - outline: 3px solid var(--sg-card-hover-border); - outline-offset: -3px; - } - - &.active { - color: var(--sg-blue-highlight); - - &::after { - border-top-color: var(--sg-blue-highlight); - } - } - } - } - - .top-authors-section { - margin-bottom: 2.5rem; - } - - .topic-heatmap-section { - margin-bottom: 2.5rem; - padding: 1.25rem; - border: 1px solid var(--sg-border); - border-radius: 12px; - background: var(--sg-card-bg); - } - - .topic-heatmap-header { - display: flex; - align-items: flex-end; - justify-content: space-between; - gap: 1rem; - margin-bottom: 1rem; - - h2, - p { - margin: 0; - } - - p { - margin-top: 0.35rem; - color: var(--sg-text-muted); - } - - @media (max-width: 820px) { - align-items: flex-start; - flex-direction: column; - } - } - - .topic-heatmap-loading { - min-height: 25rem; - display: grid; - place-items: center; - } - - .project-status-loading { - min-height: 15rem; - display: grid; - place-items: center; - } - - .project-status-summary { - display: flex; - flex: 0 0 auto; - gap: 0.5rem; - - span { - padding: 0.35rem 0.65rem; - border-radius: 999px; - background: var(--sg-surface-muted); - color: var(--sg-text-muted); - font-size: 0.9rem; - font-weight: 600; - } - } - - .dfg-topic-summary { - flex: 0 0 auto; - color: var(--sg-text-muted); - font-weight: 600; - } - - .top-authors-header { - display: flex; - align-items: flex-end; - justify-content: space-between; - gap: 1rem; - margin-bottom: 1rem; - - h2, - p { - margin: 0; - } - - p { - margin-top: 0.35rem; - color: var(--sg-text-muted); - } - - @media (max-width: 720px) { - align-items: flex-start; - flex-direction: column; - } - } - - .top-authors-grid { - display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); - gap: 1rem; - - &.loading { - opacity: 0.65; - } - - @media (max-width: 900px) { - grid-template-columns: 1fr; - } - } - - .top-authors-chart { - padding: 1.25rem; - border: 1px solid var(--sg-border); - border-radius: 12px; - background: var(--sg-card-bg); - - h3 { - display: flex; - align-items: center; - gap: 0.5rem; - margin: 0; - color: var(--sg-text); - } - } - - .top-authors-chart-subtitle { - margin: 0.35rem 0 1rem; - color: var(--sg-text-muted); - font-size: 13px; - line-height: 1.45; - } - - .author-bar-row { - display: flex; - align-items: center; - gap: 0.65rem; - margin-top: 0.7rem; - } - - .author-rank { - flex: 0 0 1.4rem; - color: var(--sg-text-muted); - font-size: 0.8rem; - text-align: center; - } - - .author-bar-content { - min-width: 0; - flex: 1; - } - - .author-bar-label { - display: flex; - justify-content: space-between; - gap: 0.75rem; - margin-bottom: 0.25rem; - font-size: 0.85rem; - - .author-name { - overflow: hidden; - color: var(--sg-blue-highlight); - font-weight: 600; - text-overflow: ellipsis; - white-space: nowrap; - } - } - - .author-link { - overflow: hidden; - text-decoration: none; - text-overflow: ellipsis; - white-space: nowrap; - - &:hover { - text-decoration: underline; - } - - &:focus-visible { - border-radius: 2px; - outline: 2px solid var(--sg-card-hover-border); - outline-offset: 2px; - } - } - - .author-bar-track { - overflow: hidden; - height: 7px; - border-radius: 999px; - background: var(--sg-border); - } - - .author-bar-fill { - display: block; - height: 100%; - border-radius: inherit; - background: var(--sg-blue-highlight); - transition: width 220ms ease; - } - - .empty-chart { - margin: 2rem 0; - color: var(--sg-text-muted); - text-align: center; - } } diff --git a/webapp/src/app/modules/dashboard/dashboard.component.ts b/webapp/src/app/modules/dashboard/dashboard.component.ts index 7b007625..9e75e1de 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/src/app/modules/dashboard/dashboard.component.ts @@ -1,476 +1,62 @@ -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, - CHEVRON_LEFT_ICON, - CHEVRON_RIGHT_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'; +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: [ - DecimalPipe, - MatFormFieldModule, - MatIconModule, - MatSelectModule, - MatTooltipModule, - ComponentTooltipDirective, - RouterLink, - LoadingComponent, - EuProjectStatusChartComponent, - TopicTreemapComponent, - YearRangeSliderComponent, + DashboardFilterComponent, + DashboardStatisticsGridComponent, + DashboardTopAuthorsComponent, + ProjectTopicsComponent, + DashboardProjectStatusComponent, + DashboardFieldTreemapComponent, + DashboardInstitutionTabsComponent, ], templateUrl: './dashboard.component.html', styleUrl: './dashboard.component.scss', + providers: [DashboardFacade], }) -export class DashboardComponent implements OnInit, AfterViewInit { - @ViewChild('analyticalInstitutionTabList') - private analyticalInstitutionTabList?: ElementRef; - - readonly AuthorTooltipComponent = AppAuthorTooltipComponent; - readonly patentIcon = PATENT_ICON; - readonly PATENT_ICON = PATENT_ICON; - readonly CHEVRON_LEFT_ICON = CHEVRON_LEFT_ICON; - readonly CHEVRON_RIGHT_ICON = CHEVRON_RIGHT_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'; +export class DashboardComponent implements OnInit { 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, + readonly dashboard: DashboardFacade, ) {} 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, - }; - }), - }; + this.restoreTreemapNodeState(); + this.dashboard.initialize((institutionId) => { + if (institutionId === this.selectedAnalyticalInstitutionId) return; + this.selectedAnalyticalInstitutionId = institutionId; + this.reloadAnalyticalData(); + }); } setDashboardPeriodMode(mode: DashboardPeriodMode): void { - if (mode === this.dashboardPeriodMode) return; - this.dashboardPeriodMode = mode; - this.applyPresetPeriod(); + if (!this.dashboard.setPeriodMode(mode)) return; 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.dashboard.setCustomPeriod(); this.updateDashboardPeriodUrl(); if (this.topicTreemapReloadQueued) return; this.topicTreemapReloadQueued = true; @@ -481,198 +67,57 @@ export class DashboardComponent implements OnInit, AfterViewInit { } onDashboardInstitutionChange(institutionId: string): void { - this.selectedDashboardInstitutionId = institutionId; + this.dashboard.selectInstitution(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; + this.dashboard.invalidateAnalyticalData(); } } } onAnalyticalInstitutionChange(institutionId: string): void { - if (institutionId === this.selectedAnalyticalInstitutionId) return; + 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(); - 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; + if (analyticalInstitutionChanged) { + this.reloadAnalyticalData(); } - - 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; + onTopicTreemapNodeChange(): void { this.updateDashboardPeriodUrl(); } - onDfgTopicTreemapNodeChange(nodeId: string | undefined): void { - this.selectedDfgTopicTreemapNode = nodeId; + onDfgTopicTreemapNodeChange(): void { 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; + onEuTopicTreemapNodeChange(): void { 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; + onBundTopicTreemapNodeChange(): void { 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 { + private restoreTreemapNodeState(): 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; @@ -681,33 +126,19 @@ export class DashboardComponent implements OnInit, AfterViewInit { 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, + 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.selectedDashboardInstitutionId, + institution: this.dashboard.selectedInstitutionId, analyticalInstitution: this.selectedAnalyticalInstitutionId || null, }, queryParamsHandling: 'merge', @@ -715,358 +146,16 @@ export class DashboardComponent implements OnInit, AfterViewInit { }); } - 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, - }; + return this.dashboard.periodBounds(); } private reloadPeriodData(): void { - this.loadStatistics(); + this.dashboard.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; - } - }, - }); + this.dashboard.loadAnalyticalData(this.selectedAnalyticalInstitutionId); } } diff --git a/webapp/src/app/modules/dashboard/dashboard.models.ts b/webapp/src/app/modules/dashboard/dashboard.models.ts new file mode 100644 index 00000000..9af78e08 --- /dev/null +++ b/webapp/src/app/modules/dashboard/dashboard.models.ts @@ -0,0 +1,13 @@ +export type DashboardPeriodMode = + | 'all_time' + | 'last_10_years' + | 'last_5_years' + | 'custom'; + +export type DashboardStatisticKey = + | 'publications' + | 'persons' + | 'patents' + | 'eu_projects' + | 'bmbf_projects' + | 'dfg_projects'; diff --git a/webapp/src/app/modules/dashboard/services/dashboard-topic-treemap.mapper.ts b/webapp/src/app/modules/dashboard/services/dashboard-topic-treemap.mapper.ts new file mode 100644 index 00000000..99eb1bdc --- /dev/null +++ b/webapp/src/app/modules/dashboard/services/dashboard-topic-treemap.mapper.ts @@ -0,0 +1,64 @@ +import { TopicTreemapData } from '../../../shared/ui/topic-treemap/topic-treemap.models'; +import { + BundProjectTopics, + DfgProjectTopic, + DfgProjectTopics, + EuProjectTopics, +} from '../dashboard-statistics.service'; + +type ProjectTopics = DfgProjectTopics | EuProjectTopics | BundProjectTopics; + +export function mapProjectTopicsToTreemap( + projectTopics: ProjectTopics, +): 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, + }; + }), + }; +} diff --git a/webapp/src/app/modules/dashboard/services/dashboard.facade.ts b/webapp/src/app/modules/dashboard/services/dashboard.facade.ts new file mode 100644 index 00000000..6084b90f --- /dev/null +++ b/webapp/src/app/modules/dashboard/services/dashboard.facade.ts @@ -0,0 +1,567 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { Observable, finalize } from 'rxjs'; +import { TopicTreemapData } from '../../../shared/ui/topic-treemap/topic-treemap.models'; +import { + DashboardPeriodMode, + DashboardStatisticKey, +} from '../dashboard.models'; +import { + BmbfProjectStatusStatistics, + BundProjectTopics, + DashboardInstitution, + DashboardPeriodBounds, + DashboardStatisticValue, + DashboardStatistics, + DashboardStatisticsService, + DfgProjectStatusStatistics, + DfgProjectTopics, + EuProjectStatusStatistics, + EuProjectTopics, + TopAuthorStatistics, +} from '../dashboard-statistics.service'; +import { mapProjectTopicsToTreemap } from './dashboard-topic-treemap.mapper'; + +@Injectable() +export class DashboardFacade { + readonly minYear = 1900; + readonly maxYear = new Date().getFullYear(); + + periodMode: DashboardPeriodMode = 'all_time'; + fromYear = this.minYear; + toYear = this.maxYear; + institutions: DashboardInstitution[] = []; + selectedInstitutionId = 'all'; + institutionsLoading = false; + institutionsError = false; + 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, + }; + dfgProjectTopics?: DfgProjectTopics; + dfgTopicTreemap?: TopicTreemapData; + dfgTopicsLoading = false; + dfgTopicsError = false; + euProjectTopics?: EuProjectTopics; + euTopicTreemap?: TopicTreemapData; + euTopicsLoading = false; + euTopicsError = false; + bundProjectTopics?: BundProjectTopics; + bundTopicTreemap?: TopicTreemapData; + bundTopicsLoading = false; + bundTopicsError = false; + topAuthors?: TopAuthorStatistics; + topAuthorsLoading = false; + topAuthorsError = false; + topicTreemap?: TopicTreemapData; + topicTreemapLoading = false; + topicTreemapError = false; + euProjectStatuses?: EuProjectStatusStatistics; + euProjectStatusesLoading = false; + euProjectStatusesError = false; + bmbfProjectStatuses?: BmbfProjectStatusStatistics; + bmbfProjectStatusesLoading = false; + bmbfProjectStatusesError = false; + dfgProjectStatuses?: DfgProjectStatusStatistics; + dfgProjectStatusesLoading = false; + dfgProjectStatusesError = false; + + private pendingStatisticRequests = 0; + private projectTopicsRequestId = 0; + private analyticalRequestId = 0; + + constructor( + private readonly statisticsService: DashboardStatisticsService, + private readonly route: ActivatedRoute, + ) {} + + initialize(onInstitutionRestored: (institutionId: string) => void): void { + this.restorePeriodState(); + this.loadStatistics(); + this.loadInstitutions(onInstitutionRestored); + } + + setPeriodMode(mode: DashboardPeriodMode): boolean { + if (mode === this.periodMode) return false; + this.periodMode = mode; + this.applyPresetPeriod(); + return true; + } + + setCustomPeriod(): void { + this.periodMode = 'custom'; + } + + selectInstitution(institutionId: string): void { + this.selectedInstitutionId = institutionId; + this.loadStatistics(); + } + + periodBounds(): DashboardPeriodBounds { + return this.periodMode === 'all_time' + ? {} + : { fromYear: this.fromYear, toYear: this.toYear }; + } + + loadStatistics(): void { + this.statisticsError = false; + const period = this.periodBounds(); + const institutionId = this.selectedInstitutionId; + 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), + ); + } + + loadProjectTopics( + period: DashboardPeriodBounds, + institutionId: string, + ): void { + const requestId = ++this.projectTopicsRequestId; + this.loadDfgProjectTopics(period, institutionId, requestId); + this.loadEuProjectTopics(period, institutionId, requestId); + this.loadBundProjectTopics(period, institutionId, requestId); + } + + invalidateProjectTopics(): void { + this.projectTopicsRequestId += 1; + this.dfgTopicsLoading = false; + this.euTopicsLoading = false; + this.bundTopicsLoading = false; + } + + loadAnalyticalData(institutionId: string): void { + if (!institutionId) return; + const requestId = ++this.analyticalRequestId; + const period = this.periodBounds(); + this.euProjectStatuses = undefined; + this.bmbfProjectStatuses = undefined; + this.dfgProjectStatuses = undefined; + this.loadTopAuthors(period, institutionId, requestId); + this.loadTopicTreemap(period, institutionId, requestId); + this.loadProjectTopics(period, institutionId); + this.loadEuProjectStatuses(period, institutionId, requestId); + this.loadBmbfProjectStatuses(period, institutionId, requestId); + this.loadDfgProjectStatuses(period, institutionId, requestId); + } + + invalidateAnalyticalData(): void { + this.analyticalRequestId += 1; + this.invalidateProjectTopics(); + this.topAuthorsLoading = false; + this.topicTreemapLoading = false; + this.euProjectStatusesLoading = false; + this.bmbfProjectStatusesLoading = false; + this.dfgProjectStatusesLoading = false; + } + + private loadInstitutions( + onInstitutionRestored: (institutionId: string) => void, + ): void { + this.institutionsLoading = true; + this.institutionsError = false; + this.statisticsService + .getInstitutions() + .pipe(finalize(() => (this.institutionsLoading = false))) + .subscribe({ + next: (institutions) => { + this.institutions = institutions; + const requestedInstitution = + this.route.snapshot.queryParamMap.get('institution') ?? 'all'; + const restoredInstitution = institutions.some( + (institution) => institution.id === requestedInstitution, + ) + ? requestedInstitution + : 'all'; + if (restoredInstitution !== this.selectedInstitutionId) { + this.selectedInstitutionId = restoredInstitution; + this.loadStatistics(); + } + onInstitutionRestored( + restoredInstitution === 'all' ? '' : restoredInstitution, + ); + }, + error: () => { + this.institutions = []; + this.institutionsError = true; + }, + }); + } + + private loadDfgProjectTopics( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.dfgTopicsLoading = true; + this.dfgTopicsError = false; + this.statisticsService + .getDfgProjectTopics(period, institutionId) + .pipe( + finalize(() => { + if (requestId === this.projectTopicsRequestId) { + this.dfgTopicsLoading = false; + } + }), + ) + .subscribe({ + next: (topics) => { + if (requestId !== this.projectTopicsRequestId) return; + this.dfgProjectTopics = topics; + this.dfgTopicTreemap = mapProjectTopicsToTreemap(topics); + }, + error: () => { + if (requestId === this.projectTopicsRequestId) { + this.dfgTopicsError = true; + } + }, + }); + } + + private loadEuProjectTopics( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.euTopicsLoading = true; + this.euTopicsError = false; + this.statisticsService + .getEuProjectTopics(period, institutionId) + .pipe( + finalize(() => { + if (requestId === this.projectTopicsRequestId) { + this.euTopicsLoading = false; + } + }), + ) + .subscribe({ + next: (topics) => { + if (requestId !== this.projectTopicsRequestId) return; + this.euProjectTopics = topics; + this.euTopicTreemap = mapProjectTopicsToTreemap(topics); + }, + error: () => { + if (requestId === this.projectTopicsRequestId) { + this.euTopicsError = true; + } + }, + }); + } + + private loadBundProjectTopics( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.bundTopicsLoading = true; + this.bundTopicsError = false; + this.statisticsService + .getBundProjectTopics(period, institutionId) + .pipe( + finalize(() => { + if (requestId === this.projectTopicsRequestId) { + this.bundTopicsLoading = false; + } + }), + ) + .subscribe({ + next: (topics) => { + if (requestId !== this.projectTopicsRequestId) return; + this.bundProjectTopics = topics; + this.bundTopicTreemap = mapProjectTopicsToTreemap(topics); + }, + error: () => { + if (requestId === this.projectTopicsRequestId) { + this.bundTopicsError = true; + } + }, + }); + } + + private loadTopAuthors( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.topAuthorsLoading = true; + this.topAuthorsError = false; + this.statisticsService + .getTopAuthors(period, institutionId) + .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 loadTopicTreemap( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + if (this.fromYear > this.toYear) { + this.topicTreemapLoading = false; + this.topicTreemapError = true; + return; + } + this.topicTreemapLoading = true; + this.topicTreemapError = false; + this.statisticsService + .getTopicTreemap(period.fromYear, period.toYear, institutionId) + .pipe( + finalize(() => { + if (requestId === this.analyticalRequestId) { + this.topicTreemapLoading = false; + } + }), + ) + .subscribe({ + next: (treemap) => { + if (requestId === this.analyticalRequestId) { + this.topicTreemap = treemap; + } + }, + error: () => { + if (requestId === this.analyticalRequestId) { + this.topicTreemapError = true; + } + }, + }); + } + + private loadEuProjectStatuses( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.euProjectStatusesLoading = true; + this.euProjectStatusesError = false; + this.statisticsService + .getEuProjectStatuses(period, institutionId) + .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(institutionId); + } + }, + }); + } + + private loadBmbfProjectStatuses( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.bmbfProjectStatusesLoading = true; + this.bmbfProjectStatusesError = false; + this.statisticsService + .getBmbfProjectStatuses(period, institutionId) + .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(institutionId); + } + }, + }); + } + + private loadDfgProjectStatuses( + period: DashboardPeriodBounds, + institutionId: string, + requestId: number, + ): void { + this.dfgProjectStatusesLoading = true; + this.dfgProjectStatusesError = false; + this.statisticsService + .getDfgProjectStatuses(period, institutionId) + .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(institutionId); + } + }, + }); + } + + private emptyProjectStatuses( + institutionId: string, + ): EuProjectStatusStatistics { + const institution = this.institutions.find(({ id }) => id === institutionId); + return { + institution_id: institutionId, + organization_name: institution?.display_name ?? '', + ongoing: 0, + upcoming: 0, + completed: 0, + }; + } + + private restorePeriodState(): 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.periodMode = mode; + } + this.applyPresetPeriod(); + if (this.periodMode !== 'all_time') { + this.fromYear = this.parseYear(params.get('fromYear'), this.fromYear); + this.toYear = this.parseYear(params.get('toYear'), this.toYear); + } + if (this.fromYear > this.toYear) this.fromYear = this.toYear; + } + + private applyPresetPeriod(): void { + if (this.periodMode === 'all_time') { + this.fromYear = this.minYear; + this.toYear = this.maxYear; + } else if (this.periodMode === 'last_10_years') { + this.fromYear = this.maxYear - 9; + this.toYear = this.maxYear; + } else if (this.periodMode === 'last_5_years') { + this.fromYear = this.maxYear - 4; + this.toYear = this.maxYear; + } + } + + private parseYear(value: string | null, fallback: number): number { + const year = Number(value); + return Number.isInteger(year) && year >= this.minYear && year <= this.maxYear + ? year + : fallback; + } + + 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; + } +}