From 4c97983f51fd062c8df1c3a227dc1c21ebc5335e Mon Sep 17 00:00:00 2001 From: Farajollahi Date: Thu, 28 May 2026 09:33:32 +0200 Subject: [PATCH] implement filters --- service/src/main/inse/works/logic.py | 12 +- service/src/main/inse/works/search_client.py | 64 ++++++- service/src/main/inse/works/service.py | 12 +- .../src/main/inse/works/test_search_client.py | 25 ++- service/src/main/inse/works/test_service.py | 17 +- webapp/src/app/api/.openapi-generator/FILES | 2 + webapp/src/app/api/api/api.ts | 5 +- webapp/src/app/api/api/topics.service.ts | 165 ++++++++++++++++++ .../app/api/api/topics.serviceInterface.ts | 42 +++++ webapp/src/app/api/api/works.service.ts | 29 ++- .../src/app/api/api/works.serviceInterface.ts | 5 +- .../person-publications.component.html | 43 +++-- .../person-publications.component.scss | 22 ++- .../person-publications.component.ts | 81 ++++++++- .../shared/services/publications.service.ts | 16 +- 15 files changed, 500 insertions(+), 40 deletions(-) create mode 100644 webapp/src/app/api/api/topics.service.ts create mode 100644 webapp/src/app/api/api/topics.serviceInterface.ts diff --git a/service/src/main/inse/works/logic.py b/service/src/main/inse/works/logic.py index bdf9962e..eb5d6844 100644 --- a/service/src/main/inse/works/logic.py +++ b/service/src/main/inse/works/logic.py @@ -22,11 +22,21 @@ async def get_author_works( author_id: str, page: int, size: int, + publication_year: list[int] | None = None, + work_type: list[str] | None = None, + language: list[str] | None = None, client: OpenAlexWorksSearchClient | None = None, ) -> model.WorkPage: search_client = client or OpenAlexWorksSearchClient() try: - data = await search_client.search_author_works(author_id, page, size) + data = await search_client.search_author_works( + author_id, + page, + size, + publication_year=publication_year, + work_type=work_type, + language=language, + ) except MissingApiKeyError as exc: logger.error("OpenAlex works Elasticsearch API key is not configured.") raise HTTPException( diff --git a/service/src/main/inse/works/search_client.py b/service/src/main/inse/works/search_client.py index 3f44c810..f194b4ef 100644 --- a/service/src/main/inse/works/search_client.py +++ b/service/src/main/inse/works/search_client.py @@ -29,19 +29,35 @@ class OpenAlexWorksSearchClient: self.timeout = timeout if timeout is not None else config.settings.openalex_works_search_timeout_seconds self.transport = transport - def author_works_query(self, author_id: str, page: int, size: int) -> dict[str, Any]: + def author_works_query( + self, + author_id: str, + page: int, + size: int, + publication_year: list[int] | None = None, + work_type: list[str] | None = None, + language: list[str] | None = None, + ) -> dict[str, Any]: indexed_author_id = f"https://openalex.org/{author_id.strip()}" + filters = self._work_filters(publication_year, work_type, language) return { "from": (page - 1) * size, "size": size, "query": { - "nested": { - "path": "authorships", - "query": { - "term": { - "authorships.author.id": indexed_author_id, + "bool": { + "must": [ + { + "nested": { + "path": "authorships", + "query": { + "term": { + "authorships.author.id": indexed_author_id, + }, + }, + }, }, - }, + ], + "filter": filters, }, }, "sort": [ @@ -50,7 +66,30 @@ class OpenAlexWorksSearchClient: ], } - async def search_author_works(self, author_id: str, page: int, size: int) -> dict[str, Any]: + def _work_filters( + self, + publication_year: list[int] | None = None, + work_type: list[str] | None = None, + language: list[str] | None = None, + ) -> list[dict[str, Any]]: + filters: list[dict[str, Any]] = [] + if publication_year: + filters.append({"terms": {"publication_year": publication_year}}) + if work_type: + filters.append({"terms": {"type": work_type}}) + if language: + filters.append({"terms": {"language": language}}) + return filters + + async def search_author_works( + self, + author_id: str, + page: int, + size: int, + publication_year: list[int] | None = None, + work_type: list[str] | None = None, + language: list[str] | None = None, + ) -> dict[str, Any]: if not self.api_key: raise MissingApiKeyError("OpenAlex works Elasticsearch API key is not configured.") @@ -62,7 +101,14 @@ class OpenAlexWorksSearchClient: response = await client.post( f"/{self.index}/_search", headers={"Authorization": f"ApiKey {self.api_key}"}, - json=self.author_works_query(author_id, page, size), + json=self.author_works_query( + author_id, + page, + size, + publication_year=publication_year, + work_type=work_type, + language=language, + ), ) response.raise_for_status() return response.json() diff --git a/service/src/main/inse/works/service.py b/service/src/main/inse/works/service.py index 98f1df0c..a4081dd1 100644 --- a/service/src/main/inse/works/service.py +++ b/service/src/main/inse/works/service.py @@ -26,6 +26,16 @@ async def get_author_works( author_id: Annotated[str, Path(description="The author id, for example A5023888391.")], page: Annotated[int, Query(description="The page number.", ge=1)] = 1, size: Annotated[int, Query(description="The page size.", ge=1, le=100)] = 20, + publication_year: Annotated[list[int] | None, Query(description="Filter by publication year. Can be repeated.")] = None, + work_type: Annotated[list[str] | None, Query(alias="type", description="Filter by publication type. Can be repeated.")] = None, + language: Annotated[list[str] | None, Query(description="Filter by language code. Can be repeated.")] = None, principal: security.Principal = Depends(security.roles_allowed(["SUPER_ADMIN", "UNI_ADMIN"])), ): - return await logic.get_author_works(author_id, page, size) + return await logic.get_author_works( + author_id, + page, + size, + publication_year=publication_year, + work_type=work_type, + language=language, + ) diff --git a/service/src/main/inse/works/test_search_client.py b/service/src/main/inse/works/test_search_client.py index 79d8b332..5a376f26 100644 --- a/service/src/main/inse/works/test_search_client.py +++ b/service/src/main/inse/works/test_search_client.py @@ -17,8 +17,29 @@ def test_author_works_query_searches_authorship_author_id(): assert query["from"] == 25 assert query["size"] == 25 - assert query["query"]["nested"]["path"] == "authorships" - assert query["query"]["nested"]["query"]["term"]["authorships.author.id"] == "https://openalex.org/A5023888391" + author_query = query["query"]["bool"]["must"][0]["nested"] + assert author_query["path"] == "authorships" + assert author_query["query"]["term"]["authorships.author.id"] == "https://openalex.org/A5023888391" + assert query["query"]["bool"]["filter"] == [] + + +def test_author_works_query_adds_publication_filters(): + client = OpenAlexWorksSearchClient(api_key="test-key") + + query = client.author_works_query( + "A5023888391", + page=1, + size=20, + publication_year=[2023, 2024], + work_type=["article", "book-chapter"], + language=["en", "de"], + ) + + assert query["query"]["bool"]["filter"] == [ + {"terms": {"publication_year": [2023, 2024]}}, + {"terms": {"type": ["article", "book-chapter"]}}, + {"terms": {"language": ["en", "de"]}}, + ] @pytest.mark.anyio diff --git a/service/src/main/inse/works/test_service.py b/service/src/main/inse/works/test_service.py index 4435d36f..a2474868 100644 --- a/service/src/main/inse/works/test_service.py +++ b/service/src/main/inse/works/test_service.py @@ -12,10 +12,20 @@ client = TestClient(app) def test_get_author_works_returns_page(monkeypatch): config.settings.auth_disabled = True - async def fake_get_author_works(author_id: str, page: int, size: int): + async def fake_get_author_works( + author_id: str, + page: int, + size: int, + publication_year: list[int] | None = None, + work_type: list[str] | None = None, + language: list[str] | None = None, + ): assert author_id == "A5023888391" assert page == 2 assert size == 5 + assert publication_year == [2023, 2024] + assert work_type == ["article"] + assert language == ["en"] return model.WorkPage( elements=[ model.WorkSummary( @@ -35,7 +45,10 @@ def test_get_author_works_returns_page(monkeypatch): monkeypatch.setattr(logic, "get_author_works", fake_get_author_works) - response = client.get("/inse-service/authors/A5023888391/works?page=2&size=5") + response = client.get( + "/inse-service/authors/A5023888391/works" + "?page=2&size=5&publication_year=2023&publication_year=2024&type=article&language=en" + ) assert response.status_code == 200 data = response.json() diff --git a/webapp/src/app/api/.openapi-generator/FILES b/webapp/src/app/api/.openapi-generator/FILES index f3f08591..391c261c 100644 --- a/webapp/src/app/api/.openapi-generator/FILES +++ b/webapp/src/app/api/.openapi-generator/FILES @@ -7,6 +7,8 @@ api/items.service.ts api/items.serviceInterface.ts api/persons.service.ts api/persons.serviceInterface.ts +api/topics.service.ts +api/topics.serviceInterface.ts api/works.service.ts api/works.serviceInterface.ts configuration.ts diff --git a/webapp/src/app/api/api/api.ts b/webapp/src/app/api/api/api.ts index 06cb77df..720e9649 100644 --- a/webapp/src/app/api/api/api.ts +++ b/webapp/src/app/api/api/api.ts @@ -4,7 +4,10 @@ export * from './items.serviceInterface'; export * from './persons.service'; import { PersonsOpenApiService } from './persons.service'; export * from './persons.serviceInterface'; +export * from './topics.service'; +import { TopicsOpenApiService } from './topics.service'; +export * from './topics.serviceInterface'; export * from './works.service'; import { WorksOpenApiService } from './works.service'; export * from './works.serviceInterface'; -export const APIS = [ItemsOpenApiService, PersonsOpenApiService, WorksOpenApiService]; +export const APIS = [ItemsOpenApiService, PersonsOpenApiService, TopicsOpenApiService, WorksOpenApiService]; diff --git a/webapp/src/app/api/api/topics.service.ts b/webapp/src/app/api/api/topics.service.ts new file mode 100644 index 00000000..9310f8de --- /dev/null +++ b/webapp/src/app/api/api/topics.service.ts @@ -0,0 +1,165 @@ +/** + * My App Service + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +// @ts-ignore +import { HTTPValidationError } from '../model/http-validation-error'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { BaseService } from '../api.base.service'; +import { + TopicsOpenApiServiceInterface +} from './topics.serviceInterface'; + + + +@Injectable({ + providedIn: 'root' +}) +export class TopicsOpenApiService extends BaseService implements TopicsOpenApiServiceInterface { + + constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: Configuration) { + super(basePath, configuration); + } + + /** + * Builds the topic hierarchy cache. + * @endpoint get /topics/cache + * @param pageSize Page size for each search page. + * @param saveJson Persist cache JSON to data folder. + * @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 buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public buildTopicCache(pageSize?: number, saveJson?: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + + let localVarQueryParameters = new HttpParams({encoder: this.encoder}); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + pageSize, 'page_size'); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + saveJson, 'save_json'); + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/topics/cache`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + + /** + * Counts topic hierarchy occurrences from cache. + * @endpoint get /topics/count + * @param topic Topic names (repeat parameter). + * @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 countTopicHierarchy(topic: Array, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public countTopicHierarchy(topic: Array, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public countTopicHierarchy(topic: Array, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public countTopicHierarchy(topic: Array, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (topic === null || topic === undefined) { + throw new Error('Required parameter topic was null or undefined when calling countTopicHierarchy.'); + } + + let localVarQueryParameters = new HttpParams({encoder: this.encoder}); + if (topic) { + topic.forEach((element) => { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + element, 'topic'); + }) + } + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/topics/count`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + +} diff --git a/webapp/src/app/api/api/topics.serviceInterface.ts b/webapp/src/app/api/api/topics.serviceInterface.ts new file mode 100644 index 00000000..578d431b --- /dev/null +++ b/webapp/src/app/api/api/topics.serviceInterface.ts @@ -0,0 +1,42 @@ +/** + * My App Service + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { HttpHeaders } from '@angular/common/http'; + +import { Observable } from 'rxjs'; + +import { HTTPValidationError } from '../model/models'; + + +import { Configuration } from '../configuration'; + + + +export interface TopicsOpenApiServiceInterface { + defaultHeaders: HttpHeaders; + configuration: Configuration; + + /** + * Builds the topic hierarchy cache. + * + * @endpoint get /topics/cache + * @param pageSize Page size for each search page. + * @param saveJson Persist cache JSON to data folder. + */ + buildTopicCache(pageSize?: number, saveJson?: boolean, extraHttpRequestParams?: any): Observable; + + /** + * Counts topic hierarchy occurrences from cache. + * + * @endpoint get /topics/count + * @param topic Topic names (repeat parameter). + */ + countTopicHierarchy(topic: Array, extraHttpRequestParams?: any): Observable; + +} diff --git a/webapp/src/app/api/api/works.service.ts b/webapp/src/app/api/api/works.service.ts index f7993e7a..d4029433 100644 --- a/webapp/src/app/api/api/works.service.ts +++ b/webapp/src/app/api/api/works.service.ts @@ -46,13 +46,16 @@ export class WorksOpenApiService extends BaseService implements WorksOpenApiServ * @param authorId The author id, for example A5023888391. * @param page The page number. * @param size The page size. + * @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 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, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public getAuthorWorks(authorId: string, page?: number, size?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getAuthorWorks(authorId: string, page?: number, size?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getAuthorWorks(authorId: string, page?: number, size?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { if (authorId === null || authorId === undefined) { throw new Error('Required parameter authorId was null or undefined when calling getAuthorWorks.'); } @@ -62,6 +65,24 @@ export class WorksOpenApiService extends BaseService implements WorksOpenApiServ page, 'page'); localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, size, 'size'); + if (publicationYear) { + publicationYear.forEach((element) => { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + element, 'publication_year'); + }) + } + if (type) { + type.forEach((element) => { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + element, 'type'); + }) + } + if (language) { + language.forEach((element) => { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + element, 'language'); + }) + } let localVarHeaders = this.defaultHeaders; diff --git a/webapp/src/app/api/api/works.serviceInterface.ts b/webapp/src/app/api/api/works.serviceInterface.ts index c739cc78..a79775ce 100644 --- a/webapp/src/app/api/api/works.serviceInterface.ts +++ b/webapp/src/app/api/api/works.serviceInterface.ts @@ -30,7 +30,10 @@ export interface WorksOpenApiServiceInterface { * @param authorId The author id, for example A5023888391. * @param page The page number. * @param size The page size. + * @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. */ - getAuthorWorks(authorId: string, page?: number, size?: number, extraHttpRequestParams?: any): Observable; + getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, extraHttpRequestParams?: any): Observable; } diff --git a/webapp/src/app/modules/person-publications/person-publications.component.html b/webapp/src/app/modules/person-publications/person-publications.component.html index 4a0999aa..a3e9a1e8 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.html +++ b/webapp/src/app/modules/person-publications/person-publications.component.html @@ -4,17 +4,39 @@
Publikationen

Übersicht der wissenschaftlichen Veröffentlichungen.

-
- - -
+
@@ -95,6 +117,7 @@ {{ publicationRange() }} diff --git a/webapp/src/app/modules/person-publications/person-publications.component.scss b/webapp/src/app/modules/person-publications/person-publications.component.scss index fb050585..0f05c502 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.scss +++ b/webapp/src/app/modules/person-publications/person-publications.component.scss @@ -25,20 +25,29 @@ h2 { font-size: 14px; } -.table-actions { +.publication-filters { display: flex; flex-wrap: wrap; justify-content: flex-end; - gap: 12px; + align-items: flex-start; + gap: 10px; } -.table-actions button { +.publication-filters mat-form-field { + width: 150px; +} + +.publication-filters button { height: 42px; border-color: var(--sg-border); border-radius: var(--sg-radius-sm); color: var(--sg-text); } +::ng-deep .publication-filters .mat-mdc-form-field-subscript-wrapper { + display: none; +} + .table-wrap { position: relative; overflow-x: auto; @@ -146,7 +155,12 @@ mat-paginator { flex-direction: column; } - .table-actions { + .publication-filters { justify-content: stretch; } + + .publication-filters mat-form-field, + .publication-filters button { + width: 100%; + } } diff --git a/webapp/src/app/modules/person-publications/person-publications.component.ts b/webapp/src/app/modules/person-publications/person-publications.component.ts index e7be4617..9f2a7cb4 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.ts +++ b/webapp/src/app/modules/person-publications/person-publications.component.ts @@ -1,11 +1,14 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; -import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; +import { MatPaginator, MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; 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 { MatSelectModule } from '@angular/material/select'; import { WorkSummary } from '../../api'; import { PublicationsService } from '../../shared/services/publications.service'; @@ -19,15 +22,20 @@ import { ChipComponent } from '../../shared/ui/chip/chip.component'; MatButtonModule, ChipComponent, MatIconModule, + MatFormFieldModule, MatPaginatorModule, MatProgressSpinnerModule, + MatSelectModule, MatSnackBarModule, MatTableModule, + ReactiveFormsModule, ], templateUrl: './person-publications.component.html', styleUrl: './person-publications.component.scss', }) export class PersonPublicationsComponent implements OnInit { + @ViewChild(MatPaginator) paginator?: MatPaginator; + displayedColumns: string[] = [ 'title', 'type', @@ -40,6 +48,42 @@ export class PersonPublicationsComponent implements OnInit { total = 0; loading = false; authorId = ''; + currentPageIndex = 0; + + readonly filterForm = new FormGroup({ + publicationYears: new FormControl([], { nonNullable: true }), + types: new FormControl([], { nonNullable: true }), + languages: new FormControl([], { nonNullable: true }), + }); + + readonly publicationYearOptions = this.createPublicationYearOptions(); + + readonly typeOptions = [ + { value: 'article', label: 'article' }, + { value: 'book', label: 'book' }, + { value: 'book-chapter', label: 'book-chapter' }, + { value: 'dataset', label: 'dataset' }, + { value: 'dissertation', label: 'dissertation' }, + { value: 'editorial', label: 'editorial' }, + { value: 'erratum', label: 'erratum' }, + { value: 'letter', label: 'letter' }, + { value: 'libguides', label: 'libguides' }, + { value: 'other', label: 'other' }, + { value: 'paratext', label: 'paratext' }, + { value: 'peer-review', label: 'peer-review' }, + { value: 'preprint', label: 'preprint' }, + { value: 'reference-entry', label: 'reference-entry' }, + { value: 'report', label: 'report' }, + { value: 'retraction', label: 'retraction' }, + { value: 'review', label: 'review' }, + { value: 'standard', label: 'standard' }, + { value: 'supplementary-materials', label: 'supplementary-materials' }, + ]; + + readonly languageOptions = [ + { value: 'en', label: 'Englisch' }, + { value: 'de', label: 'Deutsch' }, + ]; constructor( private route: ActivatedRoute, @@ -51,7 +95,7 @@ export class PersonPublicationsComponent implements OnInit { ngOnInit(): void { this.route.parent?.paramMap.subscribe((params) => { this.authorId = params.get('id') ?? ''; - this.load(); + this.resetAndLoad(); }); } @@ -60,7 +104,7 @@ export class PersonPublicationsComponent implements OnInit { this.loading = true; this.publicationsService - .getAuthorWorks(this.authorId, pageIndex + 1, pageSize) + .getAuthorWorks(this.authorId, pageIndex + 1, pageSize, this.filters()) .subscribe({ next: (page) => { this.publications = page.elements ?? []; @@ -80,9 +124,25 @@ export class PersonPublicationsComponent implements OnInit { onPage(event: PageEvent): void { this.paginationService.selection = event.pageSize; + this.currentPageIndex = event.pageIndex; this.load(event.pageIndex, event.pageSize); } + resetAndLoad(): void { + this.currentPageIndex = 0; + this.paginator?.firstPage(); + this.load(0, this.paginationService.selection); + } + + clearFilters(): void { + this.filterForm.reset({ + publicationYears: [], + types: [], + languages: [], + }); + this.resetAndLoad(); + } + doiUrl(doi: string | null | undefined): string | null { if (!doi) return null; return doi.startsWith('http') ? doi : `https://doi.org/${doi}`; @@ -102,4 +162,17 @@ export class PersonPublicationsComponent implements OnInit { if (normalized.includes('book')) return 'help'; return 'info'; } + + private filters() { + return { + publicationYears: this.filterForm.controls.publicationYears.value, + types: this.filterForm.controls.types.value, + languages: this.filterForm.controls.languages.value, + }; + } + + private createPublicationYearOptions(): number[] { + const currentYear = new Date().getFullYear(); + return Array.from({ length: 90 }, (_, index) => currentYear - index); + } } diff --git a/webapp/src/app/shared/services/publications.service.ts b/webapp/src/app/shared/services/publications.service.ts index f9e129ea..89878079 100644 --- a/webapp/src/app/shared/services/publications.service.ts +++ b/webapp/src/app/shared/services/publications.service.ts @@ -3,6 +3,12 @@ import { Observable } from 'rxjs'; import { WorkPage, WorksOpenApiService } from '../../api'; +export interface PublicationFilters { + publicationYears?: number[]; + types?: string[]; + languages?: string[]; +} + @Injectable({ providedIn: 'root', }) @@ -13,7 +19,15 @@ export class PublicationsService { authorId: string, page: number = 1, size: number = 10, + filters: PublicationFilters = {}, ): Observable { - return this.worksApi.getAuthorWorks(authorId, page, size); + return this.worksApi.getAuthorWorks( + authorId, + page, + size, + filters.publicationYears, + filters.types, + filters.languages, + ); } } -- 2.56.1