From ff639ec74eb498d61862b36c5dbcf7720c337c83 Mon Sep 17 00:00:00 2001 From: genja Date: Thu, 4 Jun 2026 22:57:21 +0200 Subject: [PATCH] adjusted UI for persons list --- .../person-list/person-list.component.html | 127 +++---- .../person-list/person-list.component.scss | 311 +++++++++++++++--- .../person-list/person-list.component.ts | 192 +++++++---- 3 files changed, 466 insertions(+), 164 deletions(-) diff --git a/webapp/src/app/modules/person-list/person-list.component.html b/webapp/src/app/modules/person-list/person-list.component.html index 0b3fdf33..1ae258b0 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -1,65 +1,80 @@ -@let persons = state.persons(); -@let results = persons.results ?? []; -@if (!isPersonsLoading()) { - - -

{{ results.length }} Ergebnisse

-
-
- +
+ - @for (person of results; track person.id) { +
+ {{ resultRange() }} +
- - @if (person.id){ - +
+
+ {{ total() | number: "1.0-0" }} Personen gefunden + Sortiert nach Publikationen und Zitierungen +
-
+
diff --git a/webapp/src/app/modules/person-list/person-list.component.scss b/webapp/src/app/modules/person-list/person-list.component.scss index 10174b2e..ef1c22ac 100644 --- a/webapp/src/app/modules/person-list/person-list.component.scss +++ b/webapp/src/app/modules/person-list/person-list.component.scss @@ -1,78 +1,285 @@ +.person-list-page { + display: grid; + gap: 24px; + padding: 32px; + background: var(--sg-background); +} + +.page-header { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); + gap: 32px; + align-items: center; +} + +.eyebrow { + margin: 0 0 8px; + color: var(--sg-primary); + font-size: 12px; + font-weight: 700; + text-transform: uppercase; +} + +.page-header h1 { + margin: 0; + font-size: 28px; + line-height: 1.2; +} + +.page-header p:not(.eyebrow) { + max-width: 720px; + margin: 10px 0 0; + color: var(--sg-text-muted); +} + +.selection-summary { + display: flex; + align-items: center; + justify-content: space-between; + min-height: 80px; + padding: 18px 20px; + border: 1px solid var(--sg-border); + border-radius: var(--sg-radius-sm); + background: var(--sg-surface); +} + +.selection-summary div { + display: grid; + gap: 5px; +} + +.selection-summary strong { + color: var(--sg-text); +} + +.selection-summary span { + color: var(--sg-text-muted); + font-size: 12px; +} + +.selection-summary mat-icon { + color: var(--sg-text-muted); +} + +.toolbar { + display: flex; + align-items: center; + justify-content: space-between; + gap: 20px; +} + +.toolbar mat-form-field { + width: min(100%, 520px); +} + .result-count { - margin: 0 0 12px; - font-size: 14px; - color: #666; + color: var(--sg-text-muted); + font-size: 13px; + white-space: nowrap; +} + +.results-panel { + border: 1px solid var(--sg-border); + border-radius: var(--sg-radius-sm); + background: var(--sg-surface); + overflow: hidden; +} + +.results-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 20px; + min-height: 64px; + padding: 0 22px; +} + +.results-head strong { + color: var(--sg-text); + font-size: 15px; +} + +.results-head span { + color: var(--sg-text-muted); + font-size: 13px; +} + +.person-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 16px; + padding: 16px; } .person-card { - width: 100%; - height: 100%; - padding: 12px; - border-radius: 16px; + min-width: 0; + border: 1px solid var(--sg-border); + border-radius: var(--sg-radius-sm); + background: var(--sg-surface); + box-shadow: var(--sg-shadow-sm); + transition: + border-color 160ms ease, + box-shadow 160ms ease, + transform 160ms ease; } -.card-content { - display: flex; - align-items: center; - gap: 16px; - height: 100%; +.person-card:hover { + border-color: var(--sg-border-strong); + box-shadow: var(--sg-shadow-md); + transform: translateY(-1px); } -.avatar { - display: flex; - justify-content: center; - align-items: center; +.card-link { + display: grid; + grid-template-rows: 1fr auto; + gap: 18px; + min-height: 236px; + padding: 20px; + color: inherit; + text-decoration: none; } -.avatar-icon { - font-size: 48px; - width: 48px; - height: 48px; - color: #9e9e9e; -} - -.info { +.person-main { display: flex; + min-width: 0; flex-direction: column; - gap: 4px; + justify-content: space-between; + gap: 18px; } -.name { - margin: 0; +.person-main h2 { + margin: 0 0 6px; + font-size: 17px; + line-height: 1.25; } -.person-id { - font-size: 11px; - color: #aaa; +.person-main p { + display: -webkit-box; margin: 0; + overflow: hidden; + color: var(--sg-text-muted); + font-size: 13px; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; } -.affiliation { - color: #666; - margin: 0; +.topic-row { + display: flex; + flex-wrap: wrap; + gap: 8px; +} + +.topic-row span { + max-width: 100%; + padding: 5px 10px; + overflow: hidden; + border: 1px solid #bcd3ff; + border-radius: 6px; + background: #eff6ff; + color: #064fc4; + font-size: 12px; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; } .stats { - font-size: 12px; - color: #888; -} - -.topics { display: flex; - gap: 6px; - flex-wrap: wrap; -} - -.topic-chip { - font-size: 12px; -} -.loading { - display: flex; - justify-content: center; align-items: center; + justify-content: space-between; + gap: 12px; + padding-top: 14px; + border-top: 1px solid var(--sg-border); + color: var(--sg-text-muted); + font-size: 12px; +} - width: 100%; - min-height: 300px; +.stats span { + display: inline-flex; + align-items: center; + min-width: 0; + gap: 6px; +} - padding: 2rem; -} \ No newline at end of file +.stats mat-icon { + width: 18px; + height: 18px; + font-size: 18px; +} + +.loading-state, +.empty-state { + display: grid; + min-height: 320px; + place-items: center; + padding: 32px; + text-align: center; +} + +.empty-state { + align-content: center; + gap: 8px; + color: var(--sg-text-muted); +} + +.empty-state mat-icon { + width: 42px; + height: 42px; + color: var(--sg-text-soft); + font-size: 42px; +} + +.empty-state h2 { + margin: 0; + font-size: 18px; +} + +.empty-state p { + margin: 0; +} + +mat-paginator { + border-top: 1px solid var(--sg-border); +} + +@media (max-width: 1280px) { + .person-grid { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } +} + +@media (max-width: 860px) { + .person-list-page { + padding: 24px 16px; + } + + .page-header { + grid-template-columns: 1fr; + } + + .toolbar, + .results-head { + align-items: stretch; + flex-direction: column; + } + + .results-head { + justify-content: center; + padding: 16px; + } + + .result-count { + white-space: normal; + } + + .person-grid { + grid-template-columns: 1fr; + } +} + +@media (max-width: 560px) { + .stats { + align-items: flex-start; + flex-direction: column; + } +} diff --git a/webapp/src/app/modules/person-list/person-list.component.ts b/webapp/src/app/modules/person-list/person-list.component.ts index ad002537..ccca7dba 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -1,51 +1,126 @@ -import { Component, computed, inject, signal, DestroyRef } from '@angular/core'; -import { Router } from '@angular/router'; -import { toObservable } from '@angular/core/rxjs-interop'; +import { Component, inject, DestroyRef, computed, signal } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterLink, ActivatedRoute, Router } from '@angular/router'; +import { toObservable, toSignal } from '@angular/core/rxjs-interop'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { MatGridListModule } from '@angular/material/grid-list'; -import { MatCardModule } from '@angular/material/card'; import { MatIconModule } from '@angular/material/icon'; -import { MatChipsModule } from '@angular/material/chips'; -import { MatProgressSpinner } from '@angular/material/progress-spinner'; -import { Author, AuthorsListResponse, PersonsService } from '../../api'; +import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; +import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; +import { + Author, + AuthorsListResponse, + DehydratedInstitution, + PersonsService, +} from '../../api'; import { SharedStateService } from '../../shared/services/shared-state.service'; -import { distinctUntilChanged, switchMap, tap, finalize } from 'rxjs'; +import { PaginationService } from '../../shared/services/pagination.service'; +import { createLoadError } from '../../shared/utils/errorHandler'; +import { distinctUntilChanged, switchMap, tap, finalize, map } from 'rxjs'; +import { AuthorAffiliationsInner } from '../../api'; @Component({ selector: 'app-person-list', imports: [ - MatCardModule, - MatChipsModule, - MatGridListModule, + CommonModule, MatIconModule, - MatProgressSpinner, + MatPaginatorModule, + MatProgressSpinnerModule, + MatSnackBarModule, + RouterLink, ], templateUrl: './person-list.component.html', styleUrl: './person-list.component.scss', + standalone: true, }) export class PersonListComponent { - private readonly router = inject(Router); private readonly personsService = inject(PersonsService); private readonly destroyRef = inject(DestroyRef); + private readonly snackBar = inject(MatSnackBar); + private readonly route = inject(ActivatedRoute); + private readonly router = inject(Router); public readonly state = inject(SharedStateService); + public readonly paginationService = inject(PaginationService); private readonly defaultIncludes = - 'display_name,works_count,cited_by_count,topics,orcid'; + 'display_name,works_count,cited_by_count,topics,orcid,affiliations'; private readonly defaultInstitutionName = 'University of Duisburg-Essen'; - readonly isPersonsLoading = signal(false); + private readonly queryParams = toSignal( + this.route.queryParams.pipe( + map((params) => ({ + search: params['search'] as string | null, + page: Number(params['page'] ?? 0), + size: Number(params['size'] ?? this.paginationService.options[2]), + })), + ), + { + initialValue: { + search: null, + page: 0, + size: this.paginationService.options[2], + }, + }, + ); + + readonly searchValue = computed( + () => this.queryParams()['search'] ?? null, + ); + readonly pageIndex = computed(() => + Number(this.queryParams()['page'] ?? 0), + ); + readonly pageSize = computed( + () => + Number(this.queryParams()['size'] ?? this.paginationService.options[2]), // default 10 + ); + + loading = false; + + readonly persons = computed( + () => this.state.persons() ?? [], + ); + + readonly total = computed( + () => this.state.persons().meta?.count ?? this.persons().results?.length, + ); + + readonly resultRange = computed(() => { + const total = this.total(); + const persons = this.persons(); + if (!total || !persons.results?.length) return 'Keine Personen gefunden'; + const start = this.pageIndex() * this.pageSize() + 1; + const end = start + persons.results.length - 1; + return `${start}–${end} von ${total} Personen`; + }); + constructor() { - toObservable(this.state.searchValue) + toObservable(this.queryParams) .pipe( - distinctUntilChanged(), - tap(() => { + map(() => ({ + search: this.searchValue(), + page: this.pageIndex(), + pageSize: this.pageSize(), + })), + distinctUntilChanged( + (a, b) => + a.search === b.search && + a.page === b.page && + a.pageSize === b.pageSize, + ), + tap(({ search }) => { this.state.hasSearched.set(false); - this.isPersonsLoading.set(true); + this.loading = true; + if (!search) this.state.hasSearched.set(false); }), - switchMap((value) => - value + switchMap(({ search, page, pageSize }) => + search ? this.personsService - .searchPersonsByName(value, this.defaultIncludes) + .searchPersonsByName( + search, + this.defaultIncludes, + pageSize, + page, + ) .pipe( tap((result) => { this.state.persons.set(this.sortByRanking(result)); @@ -56,6 +131,8 @@ export class PersonListComponent { .searchPersonsByInstitution( this.defaultInstitutionName, this.defaultIncludes, + pageSize, + page, ) .pipe( tap((result) => { @@ -63,35 +140,55 @@ export class PersonListComponent { }), ), ), - finalize(() => this.isPersonsLoading.set(false)), + finalize(() => (this.loading = false)), takeUntilDestroyed(this.destroyRef), ) .subscribe({ - next: () => this.isPersonsLoading.set(false), + next: () => (this.loading = false), error: (err) => { - console.error('Error loading persons:', err); - this.isPersonsLoading.set(false); + this.loading = false; + createLoadError( + this.snackBar, + () => {}, + 'Personen konnten nicht geladen werden', + )(err); }, }); } - // navigation - navigateID(id: string): void { - this.router.navigate(['/person', id]); + onPage(event: PageEvent): void { + this.router.navigate([], { + relativeTo: this.route, + queryParams: { + page: event.pageIndex, + size: event.pageSize, + }, + queryParamsHandling: 'merge', // preserve search param + }); } - // sorting logic + institution(person: Author): DehydratedInstitution | null { + if (!person.affiliations?.length) null; + return person.affiliations?.at(-1)?.institution ?? null; + } + + topics(person: Author): string[] { + return ((person.topics ?? []) as any[]) + .slice(0, 3) + .map((t) => (typeof t === 'string' ? t : (t?.display_name ?? ''))) + .filter(Boolean); + } + + // Sorting logic sortByRanking(response: AuthorsListResponse): AuthorsListResponse { if (!response.results) return response; - return { ...response, - results: [...response.results].sort((personA, personB) => { - const rankDiff = this.getSortRank(personA) - this.getSortRank(personB); - if (rankDiff !== 0) { - return rankDiff; - } - return this.getWorksCount(personB) - this.getWorksCount(personA); + results: [...response.results].sort((a, b) => { + const rankDiff = this.getSortRank(a) - this.getSortRank(b); + return rankDiff !== 0 + ? rankDiff + : this.getWorksCount(b) - this.getWorksCount(a); }), }; } @@ -108,28 +205,11 @@ export class PersonListComponent { } hasInstitution(person: Author): boolean { - if (!person.affiliations) { - return false; - } - for (const affiliation of person.affiliations) { - if (affiliation.institution) { - return true; - } - } - return false; + return !!person.affiliations?.some((a) => a.institution); } hasOrcid(person: Author): boolean { const ids = person.ids as { orcid?: string } | null | undefined; return !!ids?.orcid; } - - getDistinguishingId(person: Author): string { - const ids = person.ids as { orcid?: string } | null | undefined; - const orcid = ids?.orcid; - - return orcid - ? 'ORCID: ' + orcid.replace('https://orcid.org/', '') - : 'OpenAlexID: ' + person.id; - } }