moved sorting logic to backend

This commit is contained in:
2026-06-09 18:21:16 +02:00
parent e9d931fe74
commit bc99b6deb8
8 changed files with 117 additions and 64 deletions
@@ -50,10 +50,15 @@
<div class="sort-selector">
<span class="sort-label">Sortierung:</span>
<div class="select-wrapper">
<select [formControl]="sortControl">
<option value="relevance">Beste Treffer (Relevanz)</option>
<option value="works">Publikationen (absteigend)</option>
<option value="citations">Zitierungen (absteigend)</option>
<select [formControl]="sortValueControl">
<option [ngValue]="null">Beste Treffer (Relevanz)</option>
<option value="works_count">Publikationen</option>
<option value="cited_by_count">Zitierungen</option>
</select>
<select [formControl]="sortOrderControl">
<option value="desc">Absteigend</option>
<option value="asc">Aufsteigend</option>
</select>
</div>
</div>
@@ -66,9 +71,9 @@
<!--><span>Sortiert nach Publikationen und Zitierungen</span>-->
</div>
@if (sortedPersons.length) {
@if (getPersons().length) {
<div class="person-grid">
@for (person of sortedPersons; track person.id) {
@for (person of getPersons(); track person.id) {
<app-person-card [loading]="loading" [person]="person" [isBookmarked]="isBookmarked(person)"
(bookmarkToggle)="toggleBookmark($event)" (topicClick)="onCardTopicClick($event)"
(institutionClick)="onCardInstitutionClick($event)">
@@ -12,14 +12,30 @@ import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatRadioModule } from '@angular/material/radio';
import { CustomAuthor, DehydratedInstitution, PersonsService, InstitutionsService } from '../../api';
import {
CustomAuthor,
DehydratedInstitution,
PersonsService,
InstitutionsService,
} from '../../api';
import { TopicsService } from '../../api/api/topics.service';
import { TopicHierarchyComponent } from '../topic-hierarchy/topic-hierarchy.component';
import { PersonCardComponent } from '../person-card/person-card.component';
import { SharedStateService } from '../../shared/services/shared-state.service';
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 {
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 {
@@ -71,6 +87,8 @@ export class PersonListComponent {
readonly institutionOptions = signal<any[]>([]);
readonly institutionLookupLoading = signal<boolean>(false);
defaultOrderValue = 'desc';
// Selected filter states
selectedTopics = new Set<string>();
searchValue = signal<string | null>(null);
@@ -82,7 +100,13 @@ export class PersonListComponent {
appliedFilterYear = new Date().getFullYear() - 1;
// Forms
sortControl = new FormControl('works', { nonNullable: true });
sortValueControl = new FormControl(null, {
nonNullable: true,
});
sortOrderControl = new FormControl(
{ value: this.defaultOrderValue, disabled: this.isRelevanceSelected() },
{ nonNullable: true },
);
topicSearchControl = new FormControl('', { nonNullable: true });
institutionControl = new FormControl('', { nonNullable: true });
yearFilterEnabledControl = new FormControl(false, { nonNullable: true });
@@ -138,6 +162,8 @@ export class PersonListComponent {
? Number.parseInt(params['pageSize'], 10)
: 10;
const institutionName = params['institutionName'] || '';
const sortBy = params['sortBy'] || null
const sortOrder = params['sortOrder'] || this.defaultOrderValue;
const yearFilterEnabled = params['yearFilterEnabled'] === 'true';
const filterMode =
params['filterMode'] === 'in' || params['filterMode'] === 'from'
@@ -149,16 +175,21 @@ export class PersonListComponent {
const topics = this.parseQueryParamArray(params['topic']);
// restore values from query params
this.selectedTopics = new Set(topics);
this.currentPage = page;
this.paginationService.selection = pageSize;
this.sortValueControl.setValue(sortBy);
this.sortOrderControl.setValue(sortOrder);
// Sync search box & institution input
if (this.searchValue() !== query) {
this.searchValue.set(query || null);
}
if (this.institutionControl.value !== institutionName) {
this.institutionControl.setValue(institutionName, { emitEvent: false });
this.institutionControl.setValue(institutionName, {
emitEvent: false,
});
this.updateYearFilterState(institutionName);
}
if (this.yearFilterEnabledControl.value !== yearFilterEnabled) {
@@ -186,20 +217,24 @@ export class PersonListComponent {
this.total = persons.meta?.count;
this.loadingState.set(false);
});
// listen for sorting selectors changes
this.sortValueControl.valueChanges.subscribe((value) => {
if (!value) {
this.sortOrderControl.setValue(this.defaultOrderValue)
this.sortOrderControl.disable();
} else {
this.sortOrderControl.enable();
}
this.applySidebarFilters();
});
this.sortOrderControl.valueChanges.subscribe(() => {
this.applySidebarFilters();
});
}
// Getters for filtered results
get sortedPersons(): CustomAuthor[] {
const sorted = [...this.persons];
const val = this.sortControl.value;
if (val === 'works') {
return sorted.sort((a, b) => (b.works_count ?? 0) - (a.works_count ?? 0));
} else if (val === 'citations') {
return sorted.sort(
(a, b) => (b.cited_by_count ?? 0) - (a.cited_by_count ?? 0),
);
}
return sorted;
getPersons(): CustomAuthor[] {
return this.persons;
}
get loading(): boolean {
@@ -211,6 +246,10 @@ export class PersonListComponent {
return this.selectedTopics.has(topic);
}
isRelevanceSelected(): boolean {
return !this.sortValueControl.value;
}
toggleTopic(topic: string): void {
if (this.selectedTopics.has(topic)) {
this.selectedTopics.delete(topic);
@@ -280,6 +319,8 @@ export class PersonListComponent {
? Array.from(this.selectedTopics)
: null,
institutionName: this.institutionControl.value || null,
sortBy: this.sortValueControl.value || null,
sortOrder: this.sortOrderControl.value || null,
yearFilterEnabled:
this.institutionControl.value && this.yearFilterEnabledControl.value
? 'true'
@@ -317,8 +358,6 @@ export class PersonListComponent {
return `${start}-${end} von ${this.total} Personen`;
}
// Bookmarks
toggleBookmark(person: CustomAuthor): void {
if (!person.id) return;
@@ -353,12 +392,10 @@ export class PersonListComponent {
this.searchValue.set(null);
this.router.navigate([], {
queryParams: { query: null, page: 1 },
queryParamsHandling:"merge",
queryParamsHandling: 'merge',
});
}
private setupInstitutionAutocomplete(): void {
this.institutionControl.valueChanges
.pipe(
@@ -386,7 +423,8 @@ export class PersonListComponent {
}
private searchInstitutions(query: string) {
return this.institutionsService.autocompleteInstitutions(query, undefined, undefined, 10)
return this.institutionsService
.autocompleteInstitutions(query, undefined, undefined, 10)
.pipe(map((response) => response.results ?? []));
}