ts-82-author-overview-and-description #118

Merged
genja merged 10 commits from ts-82-author-overview-and-description into dev 2026-06-08 15:40:02 +02:00
10 changed files with 218 additions and 100 deletions
+30
View File
@@ -1,6 +1,7 @@
import { Routes } from '@angular/router';
import { userGuard } from './shared/guards/user.guard';
import { collaborationNetworkResolver } from './resolvers/collaboration-network.resolver';
import { personListResolver } from './resolvers/person-list.resolver';
export const routes: Routes = [
{
@@ -25,6 +26,35 @@ export const routes: Routes = [
import('./modules/person-list/person-list.component').then(
(mod) => mod.PersonListComponent,
),
resolve: {
persons: personListResolver,
},
runGuardsAndResolvers: (to, from) => {
const keys = [
'query',
'page',
'pageSize',
'institutionName',
'yearFilterEnabled',
'filterMode',
'filterYear',
];
// scalar params
const scalarChanged = keys.some(
(key) => to.queryParamMap.get(key) !== from.queryParamMap.get(key),
);
// multi-value param: topics
const toTopics = to.queryParamMap.getAll('topic');
const fromTopics = from.queryParamMap.getAll('topic');
const topicsChanged =
toTopics.length !== fromTopics.length ||
toTopics.some((t, i) => t !== fromTopics[i]);
return scalarChanged || topicsChanged;
}
},
{
path: 'publication/:publicationId',
@@ -0,0 +1,51 @@
import { Directive, OnChanges,Input,ElementRef,Renderer2 } from "@angular/core";
import { SimpleChanges } from "@angular/core";
@Directive({ selector: '[skText]', standalone: true })
export class SkTextDirective implements OnChanges {
@Input() skText = false;
private originalText = '';
private originalColor = '';
constructor(private el: ElementRef, private renderer: Renderer2) {}
ngOnChanges(changes: SimpleChanges) {
const change = changes['skText'];
// skip if value didn't actually change, or is undefined
if (!change) return;
this.skText ? this.showSkeleton() : this.hideSkeleton();
}
private showSkeleton() {
const el: HTMLElement = this.el.nativeElement;
this.originalText = el.textContent ?? '';
this.originalColor = el.style.color;
// measure natural width before blanking text
const width = Math.min(Math.max(this.originalText.length * 7.5, 48), 280);
const height = 20;
this.renderer.setStyle(el, 'color', 'transparent');
this.renderer.setStyle(el, 'background', 'linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%)');
this.renderer.setStyle(el, 'background-size', '600px 100%');
this.renderer.setStyle(el, 'animation', 'sk-shimmer 1.6s infinite linear');
this.renderer.setStyle(el, 'border-radius', '4px');
this.renderer.setStyle(el, 'min-width', `${width}px`);
this.renderer.setStyle(el, 'max-height', `${height}px`);
this.renderer.setStyle(el, 'display', 'inline-block');
}
private hideSkeleton() {
const el: HTMLElement = this.el.nativeElement;
this.renderer.removeStyle(el, 'color');
this.renderer.removeStyle(el, 'background');
this.renderer.removeStyle(el, 'background-size');
this.renderer.removeStyle(el, 'animation');
this.renderer.removeStyle(el, 'border-radius');
this.renderer.removeStyle(el, 'min-width');
this.renderer.removeStyle(el, 'max-height');
this.renderer.removeStyle(el, 'display');
}
}
@@ -1,13 +1,13 @@
<article class="person-card">
<a [routerLink]="['/person', person.id, 'overview']" class="card-header">
<!-- Initials Avatar or Profile Image fallback -->
<div class="avatar">
<div [skText]="loading" class="avatar">
{{ getInitials(person.display_name) }}
</div>
<div class="header-main">
<div class="rating-and-bookmark">
@if (person.relevance_rating) {
<span class="suitability-badge" [ngClass]="getRatingClass(person.relevance_rating)">
<span [skText]="loading" class="suitability-badge" [ngClass]="getRatingClass(person.relevance_rating)">
{{ person.relevance_rating }}
</span>
}
@@ -16,9 +16,9 @@
<mat-icon>{{ isBookmarked ? 'bookmark' : 'bookmark_border' }}</mat-icon>
</button>
</div>
<h2 class="person-name">{{ person.display_name }}</h2>
<p class="person-id">{{ getDistinguishingId(person) }}</p>
<p class="stats">
<h2 [skText]="loading" class="person-name">{{ person.display_name }}</h2>
<p [skText]="loading" class="person-id">{{ getDistinguishingId(person) }}</p>
<p [skText]="loading" class="stats">
Publikationen: {{ person.works_count }} ·
Zitationen: {{ person.cited_by_count }}
</p>
@@ -32,8 +32,8 @@
[title]="inst.display_name || ''">
<mat-icon
style="font-size: 12px; width: 12px; height: 12px; margin-right: 4px; vertical-align: middle;">apartment</mat-icon>
<span style="vertical-align: middle;">{{ (inst.display_name ?? '') | truncate: 30 }}</span>
@if (inst.country_code) {
<span [skText]="loading" style="vertical-align: middle;">{{ (inst.display_name ?? '') | truncate: 30 }}</span>
@if (inst.country_code && !loading) {
<img alt="" class="flag-img" [src]="`https://flagcdn.io/${inst.country_code.toLowerCase()}.svg`" height="10"
style="margin-left: 6px; vertical-align: middle;">
<span style="font-size: 9px; margin-left: 2px; vertical-align: middle;">{{ inst.country_code.toUpperCase()
@@ -45,7 +45,7 @@
<div class="topic-row">
@for (topic of topics(person); track topic.id) {
<span class="topic-tag" (click)="topicClick.emit(topic.display_name || ''); $event.stopPropagation()"
<span [skText]="loading" class="topic-tag" (click)="topicClick.emit(topic.display_name || ''); $event.stopPropagation()"
[title]="getTopicTooltip(topic)">{{ topic.display_name }}</span>
}
</div>
@@ -4,17 +4,18 @@ import { RouterLink } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { CustomAuthor, DehydratedInstitution, WorkTopic } from '../../api';
import { TruncatePipe } from '../../shared/pipes/truncate.pipe';
import { SkTextDirective } from '../../custom-directives/sk-text.directive';
@Component({
selector: 'app-person-card',
standalone: true,
imports: [CommonModule, RouterLink, MatIconModule, TruncatePipe],
imports: [CommonModule, RouterLink, MatIconModule, TruncatePipe,SkTextDirective],
templateUrl: './person-card.component.html',
styleUrl: './person-card.component.scss',
})
export class PersonCardComponent {
@Input({ required: true }) person!: CustomAuthor;
@Input() isBookmarked = false;
@Input() loading = false;
@Output() bookmarkToggle = new EventEmitter<CustomAuthor>();
@Output() topicClick = new EventEmitter<string>();
@Output() institutionClick = new EventEmitter<string>();
@@ -10,11 +10,11 @@
Durchsuchen Sie OpenAlex-Autorinnen und -Autoren nach Namen, Themen oder Kennungen.
</p>
</div>
@if (state.searchValue()) {
@if (searchValue()) {
<div class="selection-summary">
<div>
<strong>Aktive Suche</strong>
<span>„{{ state.searchValue() }}“</span>
<span [skText]="loading">„{{ searchValue() }}“</span>
</div>
<button mat-icon-button (click)="clearSearch()" matTooltip="Suche zurücksetzen">
<mat-icon>close</mat-icon>
@@ -29,7 +29,7 @@
<span class="active-filters-label">Aktive Filter:</span>
<div class="chips-container">
@for (filter of activeFilters; track filter.value) {
<span class="filter-chip">
<span [skText]="loading" class="filter-chip">
{{ filter.label }}
<button class="remove-chip-btn" (click)="removeFilter(filter)" aria-label="Filter entfernen">
<mat-icon>close</mat-icon>
@@ -44,7 +44,7 @@
}
<div class="toolbar">
<span class="result-count">{{ resultRange() }}</span>
<span [skText]="loading" class="result-count">{{ resultRange() }}</span>
<div class="toolbar-actions">
<div class="sort-selector">
@@ -62,18 +62,14 @@
<section class="results-panel">
<div class="results-head">
<strong>{{ total | number: "1.0-0" }} Personen gefunden</strong>
<strong [skText]="loading" >{{ total | number: "1.0-0" }} Personen gefunden</strong>
<!--><span>Sortiert nach Publikationen und Zitierungen</span>-->
</div>
@if (loading) {
<div class="loading-state">
<mat-spinner diameter="40"></mat-spinner>
</div>
} @else if (sortedPersons.length) {
@if (sortedPersons.length) {
<div class="person-grid">
@for (person of sortedPersons; track person.id) {
<app-person-card [person]="person" [isBookmarked]="isBookmarked(person)"
<app-person-card [loading]="loading" [person]="person" [isBookmarked]="isBookmarked(person)"
(bookmarkToggle)="toggleBookmark($event)" (topicClick)="onCardTopicClick($event)"
(institutionClick)="onCardInstitutionClick($event)">
</app-person-card>
@@ -182,8 +178,8 @@
<!-- Sidebar Footer Action showing matches count -->
<div class="sidebar-footer">
<button class="submit-btn" (click)="applySidebarFilters()" [disabled]="loading">
<span>{{ total | number: "1.0-0" }} Personen anzeigen</span>
<button class="submit-btn" (click)="applySidebarFilters()">
<span [skText]="loading" >{{ total | number: "1.0-0" }} Personen anzeigen</span>
</button>
</div>
</aside>
@@ -1,9 +1,8 @@
import { Component, inject, signal, DestroyRef } from '@angular/core';
import { Component, inject, signal, DestroyRef, Signal } from '@angular/core';
import { Router, RouterLink, ActivatedRoute } from '@angular/router';
import { CommonModule } from '@angular/common';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
@@ -22,13 +21,19 @@ import { PaginationService } from '../../shared/services/pagination.service';
import { finalize, debounceTime, distinctUntilChanged, switchMap, map, of, catchError } from 'rxjs';
import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SkTextDirective } from '../../custom-directives/sk-text.directive';
import {
NavigationError,
NavigationEnd,
NavigationStart,
NavigationCancel,
} from '@angular/router';
import { createLoadError } from '../../shared/utils/errorHandler';
@Component({
selector: 'app-person-list',
imports: [
CommonModule,
RouterLink,
ReactiveFormsModule,
MatIconModule,
MatPaginatorModule,
@@ -40,6 +45,7 @@ import { createLoadError } from '../../shared/utils/errorHandler';
MatRadioModule,
TopicHierarchyComponent,
PersonCardComponent,
SkTextDirective,
MatAutocompleteModule,
],
templateUrl: './person-list.component.html',
@@ -53,10 +59,8 @@ export class PersonListComponent {
private readonly topicsService = inject(TopicsService);
private readonly institutionsService = inject(InstitutionsService);
private readonly destroyRef = inject(DestroyRef);
private readonly snackBar = inject(MatSnackBar);
public readonly state = inject(SharedStateService);
public readonly paginationService = inject(PaginationService);
private readonly defaultIncludes =
'display_name,works_count,cited_by_count,topics,orcid,relevance_rating,last_known_institutions,affiliations';
@@ -69,6 +73,7 @@ export class PersonListComponent {
// Selected filter states
selectedTopics = new Set<string>();
searchValue = signal<string | null>(null);
// Applied filter states (reflecting actual URL query params)
appliedInstitutionName = '';
@@ -94,8 +99,27 @@ export class PersonListComponent {
// Bookmarking
bookmarkedIds = new Set<string>();
constructor() {
this.router.events
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event) => {
if (event instanceof NavigationStart) {
this.loadingState.set(true);
}
if (
event instanceof NavigationEnd ||
event instanceof NavigationCancel ||
event instanceof NavigationError
) {
this.loadingState.set(false);
}
});
if (!this.institutionControl.value) {
this.yearFilterEnabledControl.disable();
}
this.setupInstitutionAutocomplete();
// Enable/disable the year filter checkbox based on the presence of an institution value
this.updateYearFilterState(this.institutionControl.value);
@@ -105,7 +129,6 @@ export class PersonListComponent {
this.updateYearFilterState(val);
});
// Subscribe to route query parameters to trigger searches
this.route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => {
@@ -131,8 +154,8 @@ export class PersonListComponent {
this.paginationService.selection = pageSize;
// Sync search box & institution input
if (this.state.searchValue() !== query) {
this.state.searchValue.set(query || null);
if (this.searchValue() !== query) {
this.searchValue.set(query || null);
}
if (this.institutionControl.value !== institutionName) {
this.institutionControl.setValue(institutionName, { emitEvent: false });
@@ -153,68 +176,15 @@ export class PersonListComponent {
this.appliedYearFilterEnabled = yearFilterEnabled;
this.appliedFilterMode = filterMode;
this.appliedFilterYear = filterYear;
this.load(
query,
page,
pageSize,
topics,
institutionName,
yearFilterEnabled,
filterMode,
filterYear,
);
});
}
load(
query?: string,
page: number = 1,
pageSize: number = 10,
topics?: string[],
institutionName?: string,
yearFilterEnabled: boolean = false,
filterMode: 'in' | 'from' = 'from',
filterYear?: number,
): void {
this.loadingState.set(true);
this.personsService
.searchPersonsList(
query || undefined,
institutionName || undefined,
topics?.length ? topics : undefined,
page,
pageSize,
this.defaultIncludes,
yearFilterEnabled ? true : undefined,
yearFilterEnabled ? filterMode : undefined,
yearFilterEnabled ? filterYear : undefined,
)
.pipe(
finalize(() => this.loadingState.set(false)),
takeUntilDestroyed(this.destroyRef),
)
.subscribe({
next: (response) => {
this.persons = (response.results ?? []) as CustomAuthor[];
this.total = response.meta?.count ?? 0;
},
error: createLoadError(
this.snackBar,
() =>
this.load(
query,
page,
pageSize,
topics,
institutionName,
yearFilterEnabled,
filterMode,
filterYear,
),
'Beim Laden der Personen ist ein Fehler aufgetreten',
),
// Use resolver value
this.route.data
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ persons }) => {
this.persons = (persons.results ?? []) as CustomAuthor[];
this.total = persons.meta?.count;
this.loadingState.set(false);
});
}
@@ -380,10 +350,10 @@ export class PersonListComponent {
}
clearSearch(): void {
this.state.searchValue.set(null);
this.searchValue.set(null);
this.router.navigate([], {
queryParams: { query: null, page: 1 },
queryParamsHandling: 'merge',
queryParamsHandling:"merge",
});
}
@@ -0,0 +1,58 @@
import { ResolveFn } from '@angular/router';
import { inject } from '@angular/core';
import { PersonsService, CustomAuthorsListResponse } from '../api';
export const personListResolver: ResolveFn<CustomAuthorsListResponse> = (
route,
state,
) => {
const parseQueryParamArray = (val: any): string[] => {
if (!val) return [];
if (Array.isArray(val)) return val;
return [val];
};
const defaultIncludes =
'display_name,works_count,cited_by_count,topics,orcid,relevance_rating,last_known_institutions,affiliations';
const params = route.queryParamMap;
const query = params.get('query') || undefined;
const page = params.get('page')
? Number.parseInt(params.get('page')!, 10)
: 1;
const pageSize = params.get('pageSize')
? Number.parseInt(params.get('pageSize')!, 10)
: 10;
const institutionName = params.get('institutionName') || undefined;
const topicsParam = params.getAll('topic');
const topics = parseQueryParamArray(topicsParam)
const yearFilterEnabled = params.get('yearFilterEnabled') === 'true';
const filterModeRaw = params.get('filterMode');
const filterMode =
filterModeRaw === 'in' || filterModeRaw === 'from'
? filterModeRaw
: undefined;
const filterYear = params.get('filterYear')
? Number.parseInt(params.get('filterYear')!, 10)
: undefined;
const personsService = inject(PersonsService);
return personsService.searchPersonsList(
query,
institutionName,
topics,
page,
pageSize,
defaultIncludes,
yearFilterEnabled ? true : undefined,
yearFilterEnabled ? filterMode : undefined,
yearFilterEnabled ? filterYear : undefined,
);
};
@@ -3,7 +3,6 @@ import { AuthorsListResponse } from '../../api';
@Injectable({ providedIn: 'root' })
export class SharedStateService {
searchValue = signal<string | null>(null);
persons = signal<AuthorsListResponse>({
meta: null,
results: [],
@@ -1,4 +1,4 @@
import { Component, inject, ViewChild, DestroyRef} from '@angular/core';
import { Component, inject, ViewChild, DestroyRef } from '@angular/core';
import { MatIcon } from '@angular/material/icon';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
@@ -43,11 +43,19 @@ export class AppSearchbarComponent {
private readonly router = inject(Router);
private readonly route = inject(ActivatedRoute);
private readonly personService = inject(PersonsService);
constructor() {
const params = new URLSearchParams(window.location.search);
const currentSearch = params.get('query') ?? '';
this.searchControl.setValue(currentSearch, { emitEvent: false });
const route = inject(ActivatedRoute);
const router = inject(Router);
// Sync searchControl from query param on every URL change
route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => {
const query = params['query'] ?? '';
if (this.searchControl.value !== query) {
this.searchControl.setValue(query, { emitEvent: false });
}
});
// Autocomplete suggestions
this.searchControl.valueChanges
+5
View File
@@ -186,3 +186,8 @@ h3 {
--mat-icon-button-disabled-icon-color: rgba(255, 255, 255, 0.35);
--mat-icon-button-icon-color: #ffffff;
}
@keyframes sk-shimmer {
0% { background-position: -600px 0; }
100% { background-position: 600px 0; }
}