diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index 006b1c65..19a5df19 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -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', diff --git a/webapp/src/app/custom-directives/sk-text.directive.ts b/webapp/src/app/custom-directives/sk-text.directive.ts new file mode 100644 index 00000000..4884dde1 --- /dev/null +++ b/webapp/src/app/custom-directives/sk-text.directive.ts @@ -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'); + + } +} \ No newline at end of file diff --git a/webapp/src/app/modules/person-card/person-card.component.html b/webapp/src/app/modules/person-card/person-card.component.html index 7c89ad6e..5107366d 100644 --- a/webapp/src/app/modules/person-card/person-card.component.html +++ b/webapp/src/app/modules/person-card/person-card.component.html @@ -1,13 +1,13 @@
-
+
{{ getInitials(person.display_name) }}
@if (person.relevance_rating) { - + {{ person.relevance_rating }} } @@ -16,9 +16,9 @@ {{ isBookmarked ? 'bookmark' : 'bookmark_border' }}
-

{{ person.display_name }}

-

{{ getDistinguishingId(person) }}

-

+

{{ person.display_name }}

+

{{ getDistinguishingId(person) }}

+

Publikationen: {{ person.works_count }} · Zitationen: {{ person.cited_by_count }}

@@ -32,8 +32,8 @@ [title]="inst.display_name || ''"> apartment - {{ (inst.display_name ?? '') | truncate: 30 }} - @if (inst.country_code) { + {{ (inst.display_name ?? '') | truncate: 30 }} + @if (inst.country_code && !loading) { {{ inst.country_code.toUpperCase() @@ -45,7 +45,7 @@
@for (topic of topics(person); track topic.id) { - {{ topic.display_name }} }
diff --git a/webapp/src/app/modules/person-card/person-card.component.ts b/webapp/src/app/modules/person-card/person-card.component.ts index 26c3cc4c..a384b76a 100644 --- a/webapp/src/app/modules/person-card/person-card.component.ts +++ b/webapp/src/app/modules/person-card/person-card.component.ts @@ -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(); @Output() topicClick = new EventEmitter(); @Output() institutionClick = new EventEmitter(); 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 cda03546..789862a8 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -10,11 +10,11 @@ Durchsuchen Sie OpenAlex-Autorinnen und -Autoren nach Namen, Themen oder Kennungen.

- @if (state.searchValue()) { + @if (searchValue()) {
Aktive Suche - „{{ state.searchValue() }}“ + „{{ searchValue() }}“
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 ca4805de..b1afc0f0 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -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(); + searchValue = signal(null); // Applied filter states (reflecting actual URL query params) appliedInstitutionName = ''; @@ -94,8 +99,27 @@ export class PersonListComponent { // Bookmarking bookmarkedIds = new Set(); - 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", }); } diff --git a/webapp/src/app/resolvers/person-list.resolver.ts b/webapp/src/app/resolvers/person-list.resolver.ts new file mode 100644 index 00000000..a5503d67 --- /dev/null +++ b/webapp/src/app/resolvers/person-list.resolver.ts @@ -0,0 +1,58 @@ +import { ResolveFn } from '@angular/router'; +import { inject } from '@angular/core'; +import { PersonsService, CustomAuthorsListResponse } from '../api'; + +export const personListResolver: ResolveFn = ( + 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, + ); +}; diff --git a/webapp/src/app/shared/services/shared-state.service.ts b/webapp/src/app/shared/services/shared-state.service.ts index e03428ba..4dda1383 100644 --- a/webapp/src/app/shared/services/shared-state.service.ts +++ b/webapp/src/app/shared/services/shared-state.service.ts @@ -3,7 +3,6 @@ import { AuthorsListResponse } from '../../api'; @Injectable({ providedIn: 'root' }) export class SharedStateService { - searchValue = signal(null); persons = signal({ meta: null, results: [], diff --git a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts index 711c0211..3196c3b5 100644 --- a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts +++ b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts @@ -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 diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index 271f28ac..0a3a5f8d 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -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; } +} \ No newline at end of file