implement topics and institute filters
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-06 11:45:49 +02:00
parent c77149dcc3
commit fdb0cb3daa
24 changed files with 2557 additions and 54 deletions
+18 -4
View File
@@ -112,13 +112,15 @@ export class WorksService extends BaseService implements WorksServiceInterface {
* @param publicationYear Filter by publication year. Can be repeated.
* @param type Filter by publication type. Can be repeated.
* @param language Filter by language code. Can be repeated.
* @param institutionId Filter by OpenAlex institution id. Can be repeated.
* @param topicId Filter by OpenAlex topic id. Can be repeated.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, observe?: 'body', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<WorkPage>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, observe?: 'response', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<HttpResponse<WorkPage>>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, observe?: 'events', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<HttpEvent<WorkPage>>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<any> {
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, institutionId?: Array<string>, topicId?: Array<string>, observe?: 'body', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<WorkPage>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, institutionId?: Array<string>, topicId?: Array<string>, observe?: 'response', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<HttpResponse<WorkPage>>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, institutionId?: Array<string>, topicId?: Array<string>, observe?: 'events', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<HttpEvent<WorkPage>>;
public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, institutionId?: Array<string>, topicId?: Array<string>, observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean }): Observable<any> {
if (authorId === null || authorId === undefined) {
throw new Error('Required parameter authorId was null or undefined when calling getAuthorWorks.');
}
@@ -146,6 +148,18 @@ export class WorksService extends BaseService implements WorksServiceInterface {
<any>element, 'language');
})
}
if (institutionId) {
institutionId.forEach((element) => {
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
<any>element, 'institution_id');
})
}
if (topicId) {
topicId.forEach((element) => {
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
<any>element, 'topic_id');
})
}
let localVarHeaders = this.defaultHeaders;
@@ -42,7 +42,9 @@ export interface WorksServiceInterface {
* @param publicationYear Filter by publication year. Can be repeated.
* @param type Filter by publication type. Can be repeated.
* @param language Filter by language code. Can be repeated.
* @param institutionId Filter by OpenAlex institution id. Can be repeated.
* @param topicId Filter by OpenAlex topic id. Can be repeated.
*/
getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, extraHttpRequestParams?: any): Observable<WorkPage>;
getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array<number>, type?: Array<string>, language?: Array<string>, institutionId?: Array<string>, topicId?: Array<string>, extraHttpRequestParams?: any): Observable<WorkPage>;
}
@@ -1,16 +1,16 @@
<div class="page">
<div class="section-heading">
<div>
<h6>Publikationen</h6>
<p>Übersicht der wissenschaftlichen Veröffentlichungen.</p>
</div>
<div>
<h6>Publikationen</h6>
<p>Übersicht der wissenschaftlichen Veröffentlichungen.</p>
</div>
<div class="publication-filter-stack">
<form class="publication-filters" [formGroup]="filterForm">
<mat-form-field>
<mat-label>Jahr</mat-label>
<mat-select
placeholder="Jahr"
formControlName="publicationYears"
multiple
(selectionChange)="resetAndLoad()"
(selectionChange)="applyFilters()"
>
@for (year of publicationYearOptions; track year) {
<mat-option [value]="year">{{ year }}</mat-option>
@@ -19,11 +19,11 @@
</mat-form-field>
<mat-form-field>
<mat-label>Typ</mat-label>
<mat-select
placeholder="Typ"
formControlName="types"
multiple
(selectionChange)="resetAndLoad()"
(selectionChange)="applyFilters()"
>
@for (type of typeOptions; track type.value) {
<mat-option [value]="type.value">{{ type.label }}</mat-option>
@@ -32,11 +32,11 @@
</mat-form-field>
<mat-form-field>
<mat-label>Sprache</mat-label>
<mat-select
placeholder="Sprache"
formControlName="languages"
multiple
(selectionChange)="resetAndLoad()"
(selectionChange)="applyFilters()"
>
@for (language of languageOptions; track language.value) {
<mat-option [value]="language.value">{{
@@ -46,11 +46,108 @@
</mat-select>
</mat-form-field>
<button mat-stroked-button type="button" (click)="clearFilters()">
<mat-form-field class="institution-filter">
<input
type="text"
matInput
[formControl]="institutionSearchControl"
[matAutocomplete]="institutionAutocomplete"
placeholder="Institution suchen"
/>
<mat-autocomplete
#institutionAutocomplete="matAutocomplete"
[displayWith]="displayInstitution"
(optionSelected)="selectInstitution($event)"
>
@for (institution of institutionOptions; track institution.id) {
<mat-option [value]="institution">
<span>{{ institution.display_name }}</span>
@if (institution.hint) {
<small>{{ institution.hint }}</small>
}
</mat-option>
}
@if (
!institutionLookupLoading &&
institutionOptions.length === 0 &&
institutionSearchControl.value
) {
<mat-option disabled>Keine Institution gefunden</mat-option>
}
</mat-autocomplete>
</mat-form-field>
<mat-form-field class="topic-filter">
<input
type="text"
matInput
[formControl]="topicSearchControl"
[matAutocomplete]="topicAutocomplete"
placeholder="Topic suchen"
/>
<mat-autocomplete
#topicAutocomplete="matAutocomplete"
[displayWith]="displayTopic"
(optionSelected)="selectTopic($event)"
>
@for (topic of topicOptions; track topic.id) {
<mat-option [value]="topic">
<span>{{ topic.display_name }}</span>
@if (topic.hint) {
<small>{{ topic.hint }}</small>
}
</mat-option>
}
@if (
!topicLookupLoading &&
topicOptions.length === 0 &&
topicSearchControl.value
) {
<mat-option disabled>Kein Topic gefunden</mat-option>
}
</mat-autocomplete>
</mat-form-field>
<button
class="reset-filter-btn"
mat-stroked-button
type="button"
(click)="clearFilters()"
aria-label="Filter zurücksetzen"
>
<mat-icon>filter_alt_off</mat-icon>
Zurücksetzen
<span>Zurücksetzen</span>
</button>
</form>
@if (selectedInstitutions.length || selectedTopics.length) {
<div class="selected-filter-chips" aria-label="Ausgewählte Filter">
@for (institution of selectedInstitutions; track institution.id) {
<span class="selected-filter-chip">
{{ institution.display_name }}
<button
type="button"
(click)="removeInstitution(institution)"
aria-label="Institution entfernen"
>
<mat-icon>close</mat-icon>
</button>
</span>
}
@for (topic of selectedTopics; track topic.id) {
<span class="selected-filter-chip">
{{ topic.display_name }}
<button
type="button"
(click)="removeTopic(topic)"
aria-label="Topic entfernen"
>
<mat-icon>close</mat-icon>
</button>
</span>
}
</div>
}
</div>
<div class="table-wrap">
@@ -71,7 +168,6 @@
} @else {
<div class="title">{{ publication.title || "Ohne Titel" }}</div>
}
<div class="authors">Becker, A.; Müller, T.; Zhang, L.</div>
</td>
</ng-container>
@@ -102,6 +198,33 @@
</td>
</ng-container>
<ng-container matColumnDef="institutions">
<th mat-header-cell *matHeaderCellDef>Institutionen</th>
<td mat-cell *matCellDef="let publication">
@let publicationInstitutions = institutions(publication);
<div class="institution-tags" aria-label="Institutionen">
@for (
institution of publicationInstitutions.slice(0, 3);
track institution.id
) {
<span
class="publication-institution-tag"
[title]="institution.name"
>
{{ institution.name }}
</span>
} @empty {
<span class="empty-text">-</span>
}
@if (publicationInstitutions.length > 3) {
<span class="publication-institution-more">
+{{ publicationInstitutions.length - 3 }}
</span>
}
</div>
</td>
</ng-container>
<ng-container matColumnDef="citations">
<th mat-header-cell *matHeaderCellDef>Zitationen</th>
<td mat-cell *matCellDef="let publication">
@@ -112,14 +235,20 @@
<ng-container matColumnDef="topics">
<th mat-header-cell *matHeaderCellDef>Themen</th>
<td mat-cell *matCellDef="let publication">
@let publicationTopics = publication.topics ?? [];
<div class="topic-chips" aria-label="Themen">
@for (topic of (publication.topics ?? []).slice(0, 3); track topic.id) {
<app-chip variant="outlined" color="primary">
@for (topic of publicationTopics.slice(0, 3); track topic.id) {
<span class="publication-topic-tag" [title]="topic.display_name">
{{ topic.display_name }}
</app-chip>
</span>
} @empty {
<span class="empty-text">-</span>
}
@if (publicationTopics.length > 3) {
<span class="publication-topic-more">
+{{ publicationTopics.length - 3 }}
</span>
}
</div>
</td>
</ng-container>
@@ -6,10 +6,10 @@
.section-heading {
display: flex;
align-items: flex-start;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-bottom: 22px;
gap: 18px;
margin-bottom: 18px;
}
h2 {
@@ -25,11 +25,20 @@ h2 {
font-size: 14px;
}
.publication-filter-stack {
display: flex;
align-items: flex-start;
flex-direction: column;
gap: 8px;
padding-top: 10px;
padding-bottom: 25px;
}
.publication-filters {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
align-items: flex-start;
align-items: center;
gap: 10px;
}
@@ -37,17 +46,117 @@ h2 {
width: 150px;
}
.publication-filters button {
.publication-filters .institution-filter,
.publication-filters .topic-filter {
width: 320px;
}
.publication-filters .reset-filter-btn {
min-width: 132px;
height: 42px;
border-color: var(--sg-border);
padding: 0 14px;
border-color: #d9e2f0;
border-radius: var(--sg-radius-sm);
color: var(--sg-text);
background: #fff;
}
.publication-filters .reset-filter-btn mat-icon {
margin-right: 6px;
width: 20px;
height: 20px;
font-size: 20px;
}
::ng-deep .publication-filters .mat-mdc-form-field-subscript-wrapper {
display: none;
}
::ng-deep .publication-filters .mat-mdc-text-field-wrapper {
height: 42px;
background: #fff;
border-radius: var(--sg-radius-sm);
}
::ng-deep .publication-filters .mat-mdc-form-field-infix {
min-height: 42px;
padding-top: 11px;
padding-bottom: 9px;
}
::ng-deep .publication-filters .mdc-notched-outline__leading,
::ng-deep .publication-filters .mdc-notched-outline__notch,
::ng-deep .publication-filters .mdc-notched-outline__trailing {
border-color: #d9e2f0;
}
::ng-deep .publication-filters .mat-mdc-select-value,
::ng-deep .publication-filters input.mat-mdc-input-element {
color: var(--sg-text);
font-size: 14px;
}
::ng-deep .publication-filters .mat-mdc-select-placeholder,
::ng-deep .publication-filters input.mat-mdc-input-element::placeholder {
color: var(--sg-text-muted);
opacity: 1;
font-size: 14px;
}
::ng-deep .publication-filters .mat-mdc-form-field-icon-suffix,
::ng-deep .publication-filters .mat-mdc-select-arrow-wrapper {
transform: none;
}
::ng-deep .mat-mdc-option small {
display: block;
color: var(--sg-text-muted);
font-size: 11px;
line-height: 1.2;
}
.selected-filter-chips {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: 900px;
margin: 0;
}
.selected-filter-chip {
display: inline-flex;
align-items: center;
max-width: 320px;
min-height: 26px;
padding: 3px 4px 3px 9px;
border: 1px solid #d9e2f0;
border-radius: var(--sg-radius-sm);
background: #fff;
color: var(--sg-text);
font-size: 11px;
line-height: 1.2;
}
.selected-filter-chip button {
display: inline-grid;
place-items: center;
width: 20px;
height: 20px;
margin-left: 3px;
padding: 0;
border: 0;
background: transparent;
color: var(--sg-text-muted);
cursor: pointer;
}
.selected-filter-chip mat-icon {
width: 14px;
height: 14px;
font-size: 14px;
}
.table-wrap {
position: relative;
overflow-x: auto;
@@ -55,7 +164,7 @@ h2 {
table {
width: 100%;
min-width: 980px;
min-width: 1120px;
border-collapse: separate;
border-spacing: 0 10px;
overflow: hidden;
@@ -111,6 +220,63 @@ a.title:hover {
max-width: 320px;
}
.publication-topic-tag,
.publication-topic-more {
display: inline-flex;
align-items: center;
max-width: 180px;
min-height: 24px;
padding: 3px 8px;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
background: #fff;
color: var(--sg-text);
font-size: 11px;
line-height: 1.2;
}
.publication-topic-tag {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.publication-topic-more {
color: var(--sg-text-muted);
}
.institution-tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
max-width: 280px;
}
.publication-institution-tag,
.publication-institution-more {
display: inline-flex;
align-items: center;
max-width: 180px;
min-height: 24px;
padding: 3px 8px;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
background: #fff;
color: var(--sg-text);
font-size: 11px;
line-height: 1.2;
}
.publication-institution-tag {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.publication-institution-more {
color: var(--sg-text-muted);
}
::ng-deep .mat-mdc-header-cell {
color: var(--sg-text-muted);
font-size: 12px;
@@ -155,12 +321,27 @@ mat-paginator {
flex-direction: column;
}
.publication-filter-stack {
align-items: stretch;
}
.publication-filters {
justify-content: stretch;
max-width: none;
}
.publication-filters mat-form-field,
.publication-filters button {
width: 100%;
}
.publication-filters .institution-filter,
.publication-filters .topic-filter {
width: 100%;
}
.selected-filter-chips {
justify-content: flex-start;
max-width: none;
}
}
@@ -1,6 +1,11 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, DestroyRef, OnInit, ViewChild, inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import {
MatAutocompleteModule,
MatAutocompleteSelectedEvent,
} from '@angular/material/autocomplete';
import { MatIconModule } from '@angular/material/icon';
import {
MatPaginator,
@@ -12,20 +17,72 @@ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTableModule } from '@angular/material/table';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
catchError,
combineLatest,
debounceTime,
distinctUntilChanged,
finalize,
map,
of,
switchMap,
} from 'rxjs';
import { Work, WorksService } from '../../api';
import { PaginationService } from '../../shared/services/pagination.service';
import { createLoadError } from '../../shared/utils/errorHandler';
import { ChipComponent } from '../../shared/ui/chip/chip.component';
interface InstitutionAutocompleteOption {
id?: string | null;
display_name?: string | null;
hint?: string | null;
cited_by_count?: number | null;
works_count?: number | null;
entity_type?: string | null;
external_id?: string | null;
}
interface InstitutionAutocompleteResponse {
results?: InstitutionAutocompleteOption[] | null;
}
interface TopicAutocompleteOption {
id?: string | null;
display_name?: string | null;
hint?: string | null;
cited_by_count?: number | null;
works_count?: number | null;
entity_type?: string | null;
external_id?: string | null;
}
interface TopicAutocompleteResponse {
results?: TopicAutocompleteOption[] | null;
}
interface PublicationFilterQueryState {
pageIndex: number;
pageSize: number;
publicationYears: number[];
types: string[];
languages: string[];
institutions: InstitutionAutocompleteOption[];
topics: TopicAutocompleteOption[];
}
@Component({
selector: 'app-person-publications',
imports: [
MatButtonModule,
MatAutocompleteModule,
ChipComponent,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSelectModule,
@@ -38,20 +95,34 @@ import { ChipComponent } from '../../shared/ui/chip/chip.component';
})
export class PersonPublicationsComponent implements OnInit {
@ViewChild(MatPaginator) paginator?: MatPaginator;
private readonly destroyRef = inject(DestroyRef);
displayedColumns: string[] = [
'title',
'type',
'year',
'language',
'institutions',
'topics',
'citations',
];
publications: Work[] = [];
total = 0;
loading = false;
institutionLookupLoading = false;
topicLookupLoading = false;
authorId = '';
currentPageIndex = 0;
institutionOptions: InstitutionAutocompleteOption[] = [];
selectedInstitutions: InstitutionAutocompleteOption[] = [];
topicOptions: TopicAutocompleteOption[] = [];
selectedTopics: TopicAutocompleteOption[] = [];
readonly institutionSearchControl = new FormControl<
string | InstitutionAutocompleteOption
>('', { nonNullable: true });
readonly topicSearchControl = new FormControl<string | TopicAutocompleteOption>('', {
nonNullable: true,
});
readonly filterForm = new FormGroup({
publicationYears: new FormControl<number[]>([], { nonNullable: true }),
@@ -61,6 +132,18 @@ export class PersonPublicationsComponent implements OnInit {
readonly publicationYearOptions = this.createPublicationYearOptions();
private readonly queryParamKeys = {
page: 'publicationPage',
pageSize: 'publicationPageSize',
years: 'publicationYear',
types: 'publicationType',
languages: 'publicationLanguage',
institutionIds: 'publicationInstitutionId',
institutionNames: 'publicationInstitutionName',
topicIds: 'publicationTopicId',
topicNames: 'publicationTopicName',
} as const;
readonly typeOptions = [
{ value: 'article', label: 'article' },
{ value: 'book', label: 'book' },
@@ -90,16 +173,28 @@ export class PersonPublicationsComponent implements OnInit {
constructor(
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly workService: WorksService,
private readonly httpClient: HttpClient,
public readonly paginationService: PaginationService,
private readonly snackBar: MatSnackBar,
) {}
ngOnInit(): void {
this.route.parent?.paramMap.subscribe((params) => {
this.authorId = params.get('id') ?? '';
this.resetAndLoad();
});
this.setupInstitutionAutocomplete();
this.setupTopicAutocomplete();
const parentParamMap = this.route.parent?.paramMap;
if (!parentParamMap) return;
combineLatest([parentParamMap, this.route.queryParamMap])
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(([params, queryParams]) => {
this.authorId = params.get('id') ?? '';
const queryState = this.parsePublicationFilterQueryParams(queryParams);
this.applyPublicationFilterQueryState(queryState);
this.load(queryState.pageIndex, queryState.pageSize);
});
}
load(pageIndex = 0, pageSize = this.paginationService.selection): void {
@@ -116,6 +211,8 @@ export class PersonPublicationsComponent implements OnInit {
this.filters().publicationYears,
this.filters().types,
this.filters().languages,
this.selectedInstitutionIds(),
this.selectedTopicIds(),
)
.subscribe({
next: (page) => {
@@ -137,13 +234,19 @@ export class PersonPublicationsComponent implements OnInit {
onPage(event: PageEvent): void {
this.paginationService.selection = event.pageSize;
this.currentPageIndex = event.pageIndex;
this.load(event.pageIndex, event.pageSize);
this.updatePublicationFilterQueryParams({
[this.queryParamKeys.page]: event.pageIndex + 1,
[this.queryParamKeys.pageSize]: event.pageSize,
});
}
resetAndLoad(): void {
applyFilters(): void {
this.currentPageIndex = 0;
this.paginator?.firstPage();
this.load(0, this.paginationService.selection);
this.updatePublicationFilterQueryParams({
[this.queryParamKeys.page]: 1,
[this.queryParamKeys.pageSize]: this.paginationService.selection,
});
}
clearFilters(): void {
@@ -152,7 +255,65 @@ export class PersonPublicationsComponent implements OnInit {
types: [],
languages: [],
});
this.resetAndLoad();
this.selectedInstitutions = [];
this.selectedTopics = [];
this.institutionOptions = [];
this.topicOptions = [];
this.institutionSearchControl.setValue('', { emitEvent: false });
this.topicSearchControl.setValue('', { emitEvent: false });
this.updatePublicationFilterQueryParams({
[this.queryParamKeys.page]: 1,
[this.queryParamKeys.pageSize]: this.paginationService.selection,
[this.queryParamKeys.years]: null,
[this.queryParamKeys.types]: null,
[this.queryParamKeys.languages]: null,
[this.queryParamKeys.institutionIds]: null,
[this.queryParamKeys.institutionNames]: null,
[this.queryParamKeys.topicIds]: null,
[this.queryParamKeys.topicNames]: null,
});
}
displayInstitution(option: string | InstitutionAutocompleteOption): string {
return typeof option === 'string' ? option : (option.display_name ?? '');
}
selectInstitution(event: MatAutocompleteSelectedEvent): void {
const institution = event.option.value as InstitutionAutocompleteOption;
if (!institution.id) return;
if (!this.selectedInstitutions.some((item) => item.id === institution.id)) {
this.selectedInstitutions = [...this.selectedInstitutions, institution];
this.applyFilters();
}
this.institutionSearchControl.setValue('', { emitEvent: false });
this.institutionOptions = [];
}
removeInstitution(institution: InstitutionAutocompleteOption): void {
this.selectedInstitutions = this.selectedInstitutions.filter(
(item) => item.id !== institution.id,
);
this.applyFilters();
}
displayTopic(option: string | TopicAutocompleteOption): string {
return typeof option === 'string' ? option : (option.display_name ?? '');
}
selectTopic(event: MatAutocompleteSelectedEvent): void {
const topic = event.option.value as TopicAutocompleteOption;
if (!topic.id) return;
if (!this.selectedTopics.some((item) => item.id === topic.id)) {
this.selectedTopics = [...this.selectedTopics, topic];
this.applyFilters();
}
this.topicSearchControl.setValue('', { emitEvent: false });
this.topicOptions = [];
}
removeTopic(topic: TopicAutocompleteOption): void {
this.selectedTopics = this.selectedTopics.filter((item) => item.id !== topic.id);
this.applyFilters();
}
doiUrl(doi: string | null | undefined): string | null {
@@ -175,6 +336,24 @@ export class PersonPublicationsComponent implements OnInit {
return 'info';
}
institutions(publication: Work): Array<{ id: string; name: string }> {
const institutionsById = new Map<string, { id: string; name: string }>();
for (const authorship of publication.authorships ?? []) {
for (const institution of authorship.institutions ?? []) {
if (!institution.id || !institution.display_name) continue;
if (!institutionsById.has(institution.id)) {
institutionsById.set(institution.id, {
id: institution.id,
name: institution.display_name,
});
}
}
}
return Array.from(institutionsById.values());
}
private filters() {
return {
publicationYears: this.filterForm.controls.publicationYears.value,
@@ -183,6 +362,210 @@ export class PersonPublicationsComponent implements OnInit {
};
}
private setupInstitutionAutocomplete(): void {
this.institutionSearchControl.valueChanges
.pipe(
debounceTime(250),
map((value) => (typeof value === 'string' ? value.trim() : '')),
distinctUntilChanged(),
switchMap((query) => {
if (query.length < 2) {
this.institutionOptions = [];
return of([]);
}
this.institutionLookupLoading = true;
return this.searchInstitutions(query).pipe(
catchError(() => of([])),
finalize(() => {
this.institutionLookupLoading = false;
}),
);
}),
takeUntilDestroyed(this.destroyRef),
)
.subscribe((options) => {
const selectedIds = new Set(this.selectedInstitutionIds());
this.institutionOptions = options.filter(
(option) => !!option.id && !selectedIds.has(option.id),
);
});
}
private setupTopicAutocomplete(): void {
this.topicSearchControl.valueChanges
.pipe(
debounceTime(250),
map((value) => (typeof value === 'string' ? value.trim() : '')),
distinctUntilChanged(),
switchMap((query) => {
if (query.length < 2) {
this.topicOptions = [];
return of([]);
}
this.topicLookupLoading = true;
return this.searchTopics(query).pipe(
catchError(() => of([])),
finalize(() => {
this.topicLookupLoading = false;
}),
);
}),
takeUntilDestroyed(this.destroyRef),
)
.subscribe((options) => {
const selectedIds = new Set(this.selectedTopicIds());
this.topicOptions = options.filter(
(option) => !!option.id && !selectedIds.has(option.id),
);
});
}
private searchInstitutions(query: string) {
const params = new HttpParams()
.set('query', query)
.set('limit', '10');
const basePath = this.workService.configuration.basePath ?? '';
return this.httpClient
.get<InstitutionAutocompleteResponse>(`${basePath}/api/institutions/autocomplete`, {
params,
})
.pipe(map((response) => response.results ?? []));
}
private searchTopics(query: string) {
const params = new HttpParams().set('query', query).set('limit', '10');
const basePath = this.workService.configuration.basePath ?? '';
return this.httpClient
.get<TopicAutocompleteResponse>(`${basePath}/api/topics/autocomplete`, {
params,
})
.pipe(map((response) => response.results ?? []));
}
private selectedInstitutionIds(): string[] {
return this.selectedInstitutions
.map((institution) => institution.id)
.filter((id): id is string => !!id);
}
private selectedTopicIds(): string[] {
return this.selectedTopics
.map((topic) => topic.id)
.filter((id): id is string => !!id);
}
private updatePublicationFilterQueryParams(
overrides: Record<string, string | number | Array<string | number> | null>,
): void {
const filters = this.filters();
const institutionIds = this.selectedInstitutionIds();
const institutionNames = this.selectedInstitutions
.map((institution) => institution.display_name)
.filter((name): name is string => !!name);
const topicIds = this.selectedTopicIds();
const topicNames = this.selectedTopics
.map((topic) => topic.display_name)
.filter((name): name is string => !!name);
void this.router.navigate([], {
relativeTo: this.route,
queryParams: {
[this.queryParamKeys.years]: filters.publicationYears.length
? filters.publicationYears
: null,
[this.queryParamKeys.types]: filters.types.length ? filters.types : null,
[this.queryParamKeys.languages]: filters.languages.length
? filters.languages
: null,
[this.queryParamKeys.institutionIds]: institutionIds.length
? institutionIds
: null,
[this.queryParamKeys.institutionNames]: institutionNames.length
? institutionNames
: null,
[this.queryParamKeys.topicIds]: topicIds.length ? topicIds : null,
[this.queryParamKeys.topicNames]: topicNames.length ? topicNames : null,
...overrides,
},
queryParamsHandling: 'merge',
});
}
private parsePublicationFilterQueryParams(
queryParams: ParamMap,
): PublicationFilterQueryState {
const institutionIds = queryParams.getAll(this.queryParamKeys.institutionIds);
const institutionNames = queryParams.getAll(this.queryParamKeys.institutionNames);
const topicIds = queryParams.getAll(this.queryParamKeys.topicIds);
const topicNames = queryParams.getAll(this.queryParamKeys.topicNames);
return {
pageIndex:
this.parsePositiveInteger(queryParams.get(this.queryParamKeys.page), 1) - 1,
pageSize: this.parsePositiveInteger(
queryParams.get(this.queryParamKeys.pageSize),
this.paginationService.selection,
),
publicationYears: this.parseNumberParams(
queryParams.getAll(this.queryParamKeys.years),
),
types: this.parseStringParams(queryParams.getAll(this.queryParamKeys.types)),
languages: this.parseStringParams(
queryParams.getAll(this.queryParamKeys.languages),
),
institutions: institutionIds
.filter(Boolean)
.map((id, index) => ({
id,
display_name: institutionNames[index] || id,
})),
topics: topicIds
.filter(Boolean)
.map((id, index) => ({
id,
display_name: topicNames[index] || id,
})),
};
}
private applyPublicationFilterQueryState(
queryState: PublicationFilterQueryState,
): void {
this.currentPageIndex = queryState.pageIndex;
this.paginationService.selection = queryState.pageSize;
this.selectedInstitutions = queryState.institutions;
this.selectedTopics = queryState.topics;
this.filterForm.setValue(
{
publicationYears: queryState.publicationYears,
types: queryState.types,
languages: queryState.languages,
},
{ emitEvent: false },
);
}
private parseStringParams(values: string[]): string[] {
return values.map((value) => value.trim()).filter(Boolean);
}
private parseNumberParams(values: string[]): number[] {
return values
.map((value) => Number(value))
.filter((value) => Number.isInteger(value));
}
private parsePositiveInteger(value: string | null, fallback: number): number {
const parsedValue = Number(value);
if (!Number.isInteger(parsedValue) || parsedValue < 1) {
return fallback;
}
return parsedValue;
}
private createPublicationYearOptions(): number[] {
const currentYear = new Date().getFullYear();
return Array.from({ length: 90 }, (_, index) => currentYear - index);