From 51a8d3db71eec0e704e3b75e32936bc3a43145de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Fri, 17 Jul 2026 11:55:14 +0200 Subject: [PATCH] feat(publications): added generic components for searchable selection of years, work_types, languages, authors, institutions, and topics --- service/src/main/inse/works/v2/router.py | 55 ++ service/src/main/inse/works/v2/service.py | 108 ++- ude_person.http | 17 +- webapp/src/app/api/api/worksV2.service.ts | 173 +++++ .../institution-publications.component.html | 14 +- .../institution-publications.component.scss | 6 + .../institution-publications.component.ts | 59 +- .../institutions/institutions.component.ts | 6 +- .../person-publications.component.html | 206 +----- .../person-publications.component.scss | 578 +-------------- .../person-publications.component.ts | 694 +----------------- webapp/src/app/shared/pipes/work-type.pipe.ts | 21 +- .../publication-filters.component.html | 54 ++ .../publication-filters.component.scss | 13 + .../publication-filters.component.ts | 354 +++++++++ .../query-param-input.component.html | 2 +- .../searchable-author-select.component.html | 12 + .../searchable-author-select.component.scss | 0 .../searchable-author-select.component.ts | 42 ++ ...archable-institution-select.component.html | 12 + ...archable-institution-select.component.scss | 0 ...searchable-institution-select.component.ts | 35 + .../searchable-language-select.component.html | 11 + .../searchable-language-select.component.scss | 0 .../searchable-language-select.component.ts | 57 ++ .../searchable-select.component.html | 70 ++ .../searchable-select.component.scss | 18 + .../searchable-select.component.ts | 94 +++ .../searchable-topic-select.component.html | 12 + .../searchable-topic-select.component.scss | 0 .../searchable-topic-select.component.ts | 41 ++ ...searchable-work-type-select.component.html | 11 + ...searchable-work-type-select.component.scss | 0 .../searchable-work-type-select.component.ts | 66 ++ .../searchable-year-select.component.html | 11 + .../searchable-year-select.component.scss | 0 .../searchable-year-select.component.ts | 40 + 37 files changed, 1362 insertions(+), 1530 deletions(-) create mode 100644 webapp/src/app/shared/ui/publication-filters/publication-filters.component.html create mode 100644 webapp/src/app/shared/ui/publication-filters/publication-filters.component.scss create mode 100644 webapp/src/app/shared/ui/publication-filters/publication-filters.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-select/searchable-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-select/searchable-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-select/searchable-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.ts create mode 100644 webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.html create mode 100644 webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.scss create mode 100644 webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.ts diff --git a/service/src/main/inse/works/v2/router.py b/service/src/main/inse/works/v2/router.py index a04fe67e..8301b308 100644 --- a/service/src/main/inse/works/v2/router.py +++ b/service/src/main/inse/works/v2/router.py @@ -8,6 +8,7 @@ from inse.works.v2.model import WorkPage, WorkSortBy from inse.models.openalex.work_topic import WorkTopic from inse.models.openalex.institution import Institution from inse.models.openalex.author import Author +from inse.models.openalex.topic import Topic router = APIRouter(prefix="/api/v2/works", tags=[Tags.WORKS_V2]) @@ -183,3 +184,57 @@ async def get_authors_by_ids( from inse.works.v2.service import get_work_authors_by_ids return await get_work_authors_by_ids(author_ids=author_ids or []) + + +@router.get( + "/topics/autocomplete", + operation_id="getTopicAutocomplete", + summary="Returns a list of work topics based on a search term for autocomplete functionality.", +) +async def get_topic_autocomplete( + query: Annotated[ + str, + Query( + description="A search term to filter topics by (partial matches allowed)." + ), + ] = "", +) -> List[Topic]: + from inse.works.v2.service import search_topics + + return await search_topics(query=query) + + +@router.get( + "/institutions/autocomplete", + operation_id="getInstitutionAutocomplete", + summary="Returns a list of institutions based on a search term for autocomplete functionality.", +) +async def get_institution_autocomplete( + query: Annotated[ + str, + Query( + description="A search term to filter institutions by (partial matches allowed)." + ), + ] = "", +) -> List[Institution]: + from inse.works.v2.service import search_institutions + + return await search_institutions(query=query) + + +@router.get( + "/authors/autocomplete", + operation_id="getAuthorAutocomplete", + summary="Returns a list of authors based on a search term for autocomplete functionality.", +) +async def get_author_autocomplete( + query: Annotated[ + str, + Query( + description="A search term to filter authors by (partial matches allowed)." + ), + ] = "", +) -> List[Author]: + from inse.works.v2.service import search_authors + + return await search_authors(query=query) diff --git a/service/src/main/inse/works/v2/service.py b/service/src/main/inse/works/v2/service.py index 8a037df2..dce8e393 100644 --- a/service/src/main/inse/works/v2/service.py +++ b/service/src/main/inse/works/v2/service.py @@ -11,6 +11,7 @@ from inse.models.openalex.work_topic import WorkTopic from inse.models.openalex.institution import Institution from inse.models.openalex.work import Work from inse.models.openalex.author import Author +from inse.models.openalex.topic import Topic logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -247,7 +248,14 @@ async def get_work_institutions_by_ids(institution_ids: List[str]) -> List[Insti response = await elasticsearch.search( ESIndex.OPENALEX_INSTITUTIONS, - source=["id", "display_name", "country_code"], + source=[ + "id", + "display_name", + "display_name_alternatives", + "country_code", + "type", + "ror", + ], query={"bool": {"must": must}}, size=len(institution_ids), ) @@ -274,7 +282,13 @@ async def get_work_authors_by_ids(author_ids: List[str]) -> List[Author]: response = await elasticsearch.search( ESIndex.OPENALEX_AUTHORS, - source=["id", "display_name", "orcid"], + source=[ + "id", + "display_name", + "orcid", + "last_known_institutions", + "works_count", + ], query={"bool": {"must": must}}, size=len(author_ids), ) @@ -290,6 +304,96 @@ async def get_work_authors_by_ids(author_ids: List[str]) -> List[Author]: return authors +async def search_topics( + query: str, + size: int = 10, +) -> List[Topic]: + response = await elasticsearch.search( + ESIndex.OPENALEX_TOPICS, + source=[ + "id", + "display_name", + "subfield", + "field", + "domain", + ], + query={"match_bool_prefix": {"display_name": query}}, + size=min(size, 10), + ) + + hits_block = response.get("hits", {}) + elements: List[Topic] = [] + for hit in hits_block.get("hits", []): + topic = Topic.from_dict(hit.get("_source", {})) # type: ignore + if topic is not None: + elements.append(topic) + + return elements + + +async def search_institutions( + query: str, + size: int = 10, +) -> List[Institution]: + response = await elasticsearch.search( + ESIndex.OPENALEX_INSTITUTIONS, + source=[ + "id", + "display_name", + "display_name_alternatives", + "country_code", + "type", + "ror", + ], + query={ + "bool": { + "should": [ + {"match_bool_prefix": {"display_name": query}}, + {"match_bool_prefix": {"display_name_alternatives": query}}, + ], + "minimum_should_match": 1, + } + }, + size=min(size, 10), + ) + + hits_block = response.get("hits", {}) + elements: List[Institution] = [] + for hit in hits_block.get("hits", []): + institution = Institution.from_dict(hit.get("_source", {})) # type: ignore + if institution is not None: + elements.append(institution) + + return elements + + +async def search_authors( + query: str, + size: int = 10, +) -> List[Author]: + response = await elasticsearch.search( + ESIndex.OPENALEX_AUTHORS, + source=[ + "id", + "display_name", + "orcid", + "last_known_institutions", + "works_count", + ], + query={"match_phrase_prefix": {"display_name": query}}, + size=min(size, 10), + ) + + hits_block = response.get("hits", {}) + elements: List[Author] = [] + for hit in hits_block.get("hits", []): + author = Author.from_dict(hit.get("_source", {})) # type: ignore + if author is not None: + elements.append(author) + + return elements + + def _prefix_id(raw_id: str) -> str: if not raw_id.startswith("https://openalex.org/"): return f"https://openalex.org/{raw_id}" diff --git a/ude_person.http b/ude_person.http index d01c72a5..e797f39a 100644 --- a/ude_person.http +++ b/ude_person.http @@ -1165,16 +1165,29 @@ Content-Type: application/json ### -GET https://project.nes.uni-due.de/elastic/openalex-authors/_mapping +GET https://project.nes.uni-due.de/elastic/openalex-topics/_mapping Authorization: ApiKey am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ== Content-Type: application/json ### -GET https://project.nes.uni-due.de/elastic/openalex-topics/_search +GET https://project.nes.uni-due.de/elastic/openalex-topics/_mapping Authorization: ApiKey am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ== Content-Type: application/json +### + +GET https://project.nes.uni-due.de/elastic/openalex-institutions/_search +Authorization: ApiKey am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ== +Content-Type: application/json + +### + +GET https://project.nes.uni-due.de/elastic/openalex-authors/_mapping +Authorization: ApiKey am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ== +Content-Type: application/json + + ### GET https://project.nes.uni-due.de/elastic/openalex-authors/_search diff --git a/webapp/src/app/api/api/worksV2.service.ts b/webapp/src/app/api/api/worksV2.service.ts index 94c75150..a2ad4aeb 100644 --- a/webapp/src/app/api/api/worksV2.service.ts +++ b/webapp/src/app/api/api/worksV2.service.ts @@ -27,6 +27,8 @@ import { Institution } from '../model/institution'; // @ts-ignore import { SortDirection } from '../model/sortDirection'; // @ts-ignore +import { Topic } from '../model/topic'; +// @ts-ignore import { WorkSortBy } from '../model/workSortBy'; // @ts-ignore import { WorkTopic } from '../model/workTopic'; @@ -47,6 +49,63 @@ export class WorksV2Service extends BaseService { super(basePath, configuration); } + /** + * Returns a list of authors based on a search term for autocomplete functionality. + * @endpoint get /api/v2/works/authors/autocomplete + * @param query A search term to filter authors by (partial matches allowed). + * @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 getAuthorAutocomplete(query?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAuthorAutocomplete(query?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAuthorAutocomplete(query?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAuthorAutocomplete(query?: string, 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, + query, 'query'); + + 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 = `/api/v2/works/authors/autocomplete`; + 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 + } + ); + } + /** * Returns a paginated list of works for a given author based on their ID. * @endpoint get /api/v2/works/author/{raw_oa_author_id} @@ -216,6 +275,63 @@ export class WorksV2Service extends BaseService { ); } + /** + * Returns a list of institutions based on a search term for autocomplete functionality. + * @endpoint get /api/v2/works/institutions/autocomplete + * @param query A search term to filter institutions by (partial matches allowed). + * @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 getInstitutionAutocomplete(query?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getInstitutionAutocomplete(query?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getInstitutionAutocomplete(query?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getInstitutionAutocomplete(query?: string, 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, + query, 'query'); + + 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 = `/api/v2/works/institutions/autocomplete`; + 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 + } + ); + } + /** * Returns a paginated list of works for a given institution based on their ID. * @endpoint get /api/v2/works/institution/{raw_oa_institution_id} @@ -385,6 +501,63 @@ export class WorksV2Service extends BaseService { ); } + /** + * Returns a list of work topics based on a search term for autocomplete functionality. + * @endpoint get /api/v2/works/topics/autocomplete + * @param query A search term to filter topics by (partial matches allowed). + * @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 getTopicAutocomplete(query?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getTopicAutocomplete(query?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getTopicAutocomplete(query?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getTopicAutocomplete(query?: string, 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, + query, 'query'); + + 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 = `/api/v2/works/topics/autocomplete`; + 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 + } + ); + } + /** * Returns a list of work topics based on their IDs. * @endpoint get /api/v2/works/topics/search diff --git a/webapp/src/app/modules/institution-publications/institution-publications.component.html b/webapp/src/app/modules/institution-publications/institution-publications.component.html index a70da346..73037c00 100644 --- a/webapp/src/app/modules/institution-publications/institution-publications.component.html +++ b/webapp/src/app/modules/institution-publications/institution-publications.component.html @@ -1,13 +1,13 @@ -
- - +
+ + + >(); total = computed(() => this.institutionWorkPage().total ?? 0); - - observers: FilterObserver[] = [ - { - id: 'search', - queryParamKey: workQueryParamKeys.title, - icon: 'search', - }, - { - id: 'types', - queryParamKey: workQueryParamKeys.types, - icon: 'category', - valueFormatter: (value: string) => { - return translateWorkType(value) || value; - }, - }, - { - id: 'years', - queryParamKey: workQueryParamKeys.years, - icon: 'calendar_today', - }, - { - id: 'languages', - queryParamKey: workQueryParamKeys.language, - icon: 'translate', - valueFormatter: (value: string) => { - return translateLanguageCode(value) || value; - }, - }, - { - id: 'authors', - queryParamKey: workQueryParamKeys.authorId, - icon: 'person', - valueFormatter: (value: string) => { - const author = this.selectedAuthors().find((a) => a.id === value); - return author ? author.display_name : value; - }, - }, - { - id: 'topics', - queryParamKey: workQueryParamKeys.topicId, - icon: 'label', - valueFormatter: (value: string) => { - const topic = this.selectedTopics().find((t) => t.id === value); - return topic ? topic.display_name : value; - }, - }, - ]; } diff --git a/webapp/src/app/modules/institutions/institutions.component.ts b/webapp/src/app/modules/institutions/institutions.component.ts index 36722684..57c734df 100644 --- a/webapp/src/app/modules/institutions/institutions.component.ts +++ b/webapp/src/app/modules/institutions/institutions.component.ts @@ -11,11 +11,7 @@ import { Page, CardSearchComponent, } from '../../shared/ui/card-search/card-search.component'; -import { - FilterObserver, - SelectedFiltersComponent, -} from '../../shared/ui/selected-filters/selected-filters.component'; -import { CdkNoDataRow } from '@angular/cdk/table'; +import { FilterObserver } from '../../shared/ui/selected-filters/selected-filters.component'; @Component({ selector: 'app-institutions', 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 c698fcd0..8530504d 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.html +++ b/webapp/src/app/modules/person-publications/person-publications.component.html @@ -18,14 +18,7 @@ [options]="chartOption" style="height: 300px; width: 100%">
} -
+
@@ -47,194 +40,25 @@ Publikationsliste {{ totalElements() }} Publikationen{{ total() }} Publikationen -
-
- - calendar_today - - {{ - yearSelectionSummary() - }} - - @for (year of filteredYearOptions(); track year) { - {{ year }} - } @empty { -
Keine Treffer
- } -
-
- - category - - {{ - typeSelectionSummary() - }} - - @for (type of filteredTypeOptions(); track type.value) { - {{ type.label }} - } @empty { -
Keine Treffer
- } -
-
+
+ - - translate - - {{ - languageSelectionSummary() - }} - - @for ( - language of filteredLanguageOptions(); - track language.value - ) { - {{ - language.label - }} - } @empty { -
Keine Treffer
- } -
-
- - - apartment - - - @for (institution of institutionOptions; track institution.id) { - - {{ institution.display_name }} - @if (institution.hint) { - {{ institution.hint }} - } - - } - @if ( - !institutionLookupLoading && - institutionOptions.length === 0 && - institutionSearchControl.value - ) { - Keine Institution gefunden - } - - - - - label - - - @for (topic of topicOptions; track topic.id) { - - {{ topic.display_name }} - @if (topic.hint) { - {{ topic.hint }} - } - - } - @if ( - !topicLookupLoading && - topicOptions.length === 0 && - topicSearchControl.value - ) { - Kein Thema gefunden - } - - - - - + +
- - - - - - -
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 e11737e0..0f74e8dd 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.scss +++ b/webapp/src/app/modules/person-publications/person-publications.component.scss @@ -1,567 +1,5 @@ .page { - padding: 28px 32px 42px; - max-width: 100%; - margin: 0 auto; -} - -.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: center; - gap: 10px; -} - -.publication-filters mat-form-field { - width: 175px; -} - -.publication-filters .institution-filter, -.publication-filters .topic-filter { - flex: 1 1 200px; - width: auto; - min-width: 180px; - max-width: 320px; -} - -.publication-filters .sort-field { - width: 235px; -} - -.publication-filters .reset-filter-btn { - min-width: 132px; - height: 42px; - 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: var(--sg-surface-soft); - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); - transition: - border-color 0.15s, - box-shadow 0.15s; -} - -::ng-deep .publication-filters .mat-focused .mat-mdc-text-field-wrapper { - border-color: var(--sg-primary); - box-shadow: 0 0 0 2px var(--sg-primary-soft); -} - -::ng-deep .publication-filters .mat-mdc-form-field-flex { - height: 100%; - align-items: center; -} - -::ng-deep .publication-filters .mat-mdc-form-field-infix { - min-height: 0; - padding-top: 0; - padding-bottom: 0; -} - -::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: none; -} - -.filter-prefix-icon { - width: 18px; - height: 18px; - font-size: 18px; - color: var(--sg-text-soft); -} - -::ng-deep .publication-filters .mat-mdc-form-field-icon-prefix { - padding: 0 4px 0 10px; - color: var(--sg-text-soft); -} - -::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; -} - -.active-filters-row { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 10px; - padding: 8px 16px; - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); - background: var(--sg-surface); - font-size: 13px; -} - -.active-filters-label { - font-weight: 600; - color: var(--sg-text-muted); -} - -.chips-container { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 6px; -} - -.filter-meta-chip { - display: inline-flex; - align-items: center; - padding: 2px 8px; - border: 1px solid var(--sg-border-strong); - border-radius: 4px; - background: var(--sg-surface-soft); - color: var(--sg-text); - font-size: 11px; - font-weight: 600; -} - -.filter-topic-chip { - display: inline-flex; - align-items: center; - gap: 4px; - max-width: min(320px, 46vw); - padding: 3px 8px; - border-radius: 7px; - background: color-mix(in srgb, var(--topic-color) 22%, #ffffff); - color: color-mix(in srgb, var(--topic-color) 45%, #07163d); - font-size: 11px; - font-weight: 700; - box-shadow: inset 0 0 0 1px - color-mix(in srgb, var(--topic-color) 45%, transparent); -} - -.filter-topic-chip__icon { - flex: 0 0 auto; - width: 14px; - height: 14px; - font-size: 14px; -} - -.active-institution-filter, -.active-meta-filter { - display: inline-flex; - align-items: center; - gap: 4px; - max-width: 100%; -} - -.filter-institution-chip, -.publication-institution-tag { - display: inline-flex; - align-items: center; - padding: 2px 6px; - border: 1px solid var(--sg-primary-border, var(--sg-border)); - border-radius: 4px; - background: var(--sg-primary-soft); - color: var(--sg-primary); - font-size: 10px; - font-weight: 600; - line-height: normal; -} - -.filter-institution-chip { - max-width: 340px; -} - -.publication-institution-tag { - max-width: 100%; - margin: 0; - font-family: inherit; - cursor: pointer; - transition: all 0.2s ease; - - &:hover, - &:focus-visible { - background: var(--sg-primary); - color: #fff; - border-color: var(--sg-primary); - outline: none; - box-shadow: - 0 0 0 2px var(--sg-background), - 0 0 0 4px var(--sg-primary); - } - - &.active { - border-color: var(--sg-primary); - box-shadow: - 0 0 0 1px #ffffff, - 0 0 0 3px var(--sg-primary); - } - - &.active:hover, - &.active:focus-visible { - background: var(--sg-primary); - color: #fff; - } -} - -.filter-institution-chip .institution-icon, -.publication-institution-tag .institution-icon, -.filter-meta-chip__icon { - flex-shrink: 0; - width: 12px; - height: 12px; - margin-right: 4px; - font-size: 12px; -} - -.filter-meta-chip__icon { - color: var(--sg-text-soft); -} - -.filter-institution-chip .institution-name, -.publication-institution-tag .institution-name { - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; - overflow: hidden; - min-width: 0; - white-space: normal; - overflow-wrap: anywhere; -} - -.filter-institution-chip .flag-img, -.publication-institution-tag .flag-img { - flex-shrink: 0; - margin-left: 6px; - border: 1px solid; -} - -.filter-institution-chip .country-code, -.publication-institution-tag .country-code { - flex-shrink: 0; - margin-left: 2px; - font-size: 9px; -} - -.filter-institution-chip .institution-open-icon, -.publication-institution-tag .institution-open-icon { - flex-shrink: 0; - width: 12px; - height: 12px; - margin-left: 5px; - font-size: 12px; - line-height: 1; - cursor: pointer; - opacity: 0; - transition: opacity 0.15s ease; -} - -.filter-institution-chip:hover .institution-open-icon, -.publication-institution-tag:hover .institution-open-icon { - opacity: 0.7; -} - -.filter-institution-chip .institution-open-icon:hover, -.publication-institution-tag .institution-open-icon:hover { - opacity: 1; -} - -.filter-meta-chip__label, -.filter-topic-chip__label { - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - min-width: 0; -} - -.active-institution-filter button, -.active-meta-filter button { - display: flex; - padding: 0; - border: 0; - background: transparent; - color: var(--sg-text-soft); - cursor: pointer; - - &:hover { - color: var(--sg-text); - } -} - -.active-institution-filter button mat-icon, -.active-meta-filter button mat-icon { - width: 12px; - height: 12px; - font-size: 12px; -} - -.table-wrap { - position: relative; - overflow-x: auto; -} - -table { - width: 100%; - min-width: 1120px; - border-collapse: separate; - border-spacing: 0 10px; - box-shadow: none; - background: transparent; -} - -.title { - display: inline-block; - max-width: 520px; - line-height: 1.35; - color: var(--sg-text); - font-size: 14px; - font-weight: 700; - text-decoration: none; -} - -a.title:hover { - color: var(--sg-text); - text-decoration: underline; -} - -table.is-hidden { - display: none; -} - -.table-status { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - gap: 12px; - min-height: 240px; - padding: 32px; - color: var(--sg-text-muted); - font-size: 14px; - text-align: center; -} - -.empty-text { - color: rgba(0, 0, 0, 0.54); -} - -.cell-filter-pill { - display: inline-flex; - align-items: center; - margin: 0; - padding: 3px 10px; - border: 1px solid var(--sg-border); - border-radius: 999px; - background: #fff; - color: var(--sg-text); - font-family: inherit; - font-size: 12px; - line-height: 1.2; - cursor: pointer; - transition: all 0.2s ease; - - &:hover, - &:focus-visible { - border-color: var(--sg-primary); - background: var(--sg-surface-soft); - outline: none; - } - - &.active { - border-color: var(--sg-primary); - color: var(--sg-primary); - font-weight: 600; - box-shadow: - 0 0 0 1px #ffffff, - 0 0 0 3px var(--sg-primary); - } -} - -.type-filter-btn { - display: inline-flex; - margin: 0; - padding: 0; - border: 0; - border-radius: 7px; - background: transparent; - cursor: pointer; - transition: box-shadow 0.2s ease; - - &:hover, - &:focus-visible { - outline: none; - box-shadow: 0 0 0 1px var(--sg-primary); - } - - &.active { - box-shadow: - 0 0 0 1px #ffffff, - 0 0 0 3px var(--sg-primary); - } -} - -.topic-chips, -.institution-tags { - display: flex; - flex-wrap: wrap; - gap: 6px; -} - -.topic-chips { - max-width: 320px; -} - -.institution-tags { - align-items: flex-start; - max-width: 280px; -} - -.publication-institution-more, -.publication-topic-more { - display: inline-flex; - align-items: center; - min-height: 24px; - padding: 3px 8px; - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); - background: #fff; - color: var(--sg-text-muted); - font-family: inherit; - font-size: 11px; - line-height: 1.2; - cursor: pointer; - transition: all 0.2s ease; - - &:hover, - &:focus-visible { - border-color: var(--sg-primary); - color: var(--sg-primary); - background: var(--sg-surface-soft); - outline: none; - } -} - -.publication-topic-more { - max-width: 180px; -} - -::ng-deep .mat-mdc-header-cell { - color: var(--sg-text-muted); - font-size: 12px; - font-weight: 700; -} - -::ng-deep .mat-mdc-row { - height: 86px; -} - -::ng-deep .mat-mdc-cell { - color: var(--sg-text); - border-bottom-color: var(--sg-border); - font-size: 13px; -} - -.table-wrap ::ng-deep { - .mat-mdc-header-cell { - text-align: center; - } - .mat-sort-header-container { - justify-content: center; - } - .mat-mdc-cell:not(.mat-column-title) { - text-align: center; - } - .mat-column-institutions .institution-tags, - .mat-column-topics .topic-chips { - justify-content: center; - margin-inline: auto; - } - - .mat-mdc-cell:not(:last-child), - .mat-mdc-header-cell:not(:last-child) { - border-right: 1px solid var(--sg-border); - } -} - -mat-paginator { - background: transparent; -} - -.table-footer { - display: flex; - align-items: center; - justify-content: space-between; - min-height: 66px; - padding: 0 22px 0 28px; - border: 0; - color: var(--sg-text-muted); - font-size: 13px; -} - -@media (max-width: 600px) { - .page { - padding: 16px; - } - - .table-footer { - align-items: stretch; - 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%; - } - - .active-filters-row { - align-self: stretch; - } + padding: 2rem; } mat-expansion-panel { @@ -585,3 +23,17 @@ mat-panel-description { font-size: 14px; color: var(--sg-text-muted); } + +.purpose-info-cards { + width: 100%; + display: flex; + gap: 1rem; + flex-wrap: wrap; + margin-top: 1rem; +} + +.publication-list { + display: flex; + flex-direction: column; + gap: 1rem; +} 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 2bbf05c5..651aefe9 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.ts +++ b/webapp/src/app/modules/person-publications/person-publications.component.ts @@ -1,53 +1,13 @@ -import { - Component, - DestroyRef, - OnInit, - computed, - effect, - inject, - input, -} from '@angular/core'; -import { HttpClient, HttpParams } from '@angular/common/http'; -import { FormControl, ReactiveFormsModule } from '@angular/forms'; -import { ActivatedRoute, Router } from '@angular/router'; -import { - MatAutocompleteModule, - MatAutocompleteSelectedEvent, -} from '@angular/material/autocomplete'; -import { MatIconModule } from '@angular/material/icon'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { 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 { MatSelectChange, MatSelectModule } from '@angular/material/select'; -import { MatTooltipModule } from '@angular/material/tooltip'; -import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; -import { - catchError, - debounceTime, - distinctUntilChanged, - finalize, - map, - of, - switchMap, -} from 'rxjs'; +import { Component, computed, effect, input } from '@angular/core'; import { AuthorWorkPurposes, InseWorksV2ModelWorkPage, - Institution, - InstitutionsService, + Author, SpecificWorkPurpose, - Work, WorkPurpose, - WorksService, WorkTopic, } from '../../api'; -import { PaginationService } from '../../shared/services/pagination.service'; -import { topicHierarchyColor } from '../../resolvers/utils/topic-colors'; -import { buildTopicHierarchyTooltip } from '../../resolvers/utils/topic-tooltip'; import { NgxEchartsDirective } from 'ngx-echarts'; import * as echarts from 'echarts/core'; import { @@ -57,19 +17,11 @@ import { } from 'echarts/components'; import { CanvasRenderer } from 'echarts/renderers'; import { GraphChart } from 'echarts/charts'; -import { MatCardModule } from '@angular/material/card'; import { MatExpansionModule } from '@angular/material/expansion'; -import { translateWorkType } from '../../shared/pipes/work-type.pipe'; -import { translateLanguageCode } from '../../shared/pipes/language-code.pipe'; import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component'; import { AppInfoCardComponent } from '../../shared/ui/app-info-card/app-info-card.component'; import { PublicationTableComponent } from '../../shared/ui/publication-table/publication-table.component'; -import { workQueryParamKeys } from '../../resolvers/work-page.resolver'; -import { - FilterObserver, - SelectedFiltersComponent, -} from '../../shared/ui/selected-filters/selected-filters.component'; -import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component'; +import { PublicationFilterComponent } from '../../shared/ui/publication-filters/publication-filters.component'; echarts.use([ GridComponent, CanvasRenderer, @@ -78,34 +30,6 @@ echarts.use([ LegendComponent, ]); -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 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; - field_id?: string | null; - field_name?: string | null; - domain_id?: string | null; - domain_name?: string | null; -} - -interface TopicAutocompleteResponse { - results?: TopicAutocompleteOption[] | null; -} - interface YearlyPurposeCounts { year: number; basicResearch: number; @@ -132,39 +56,22 @@ const PURPOSE_LABELS: Record< @Component({ selector: 'app-person-publications', imports: [ - MatButtonModule, - MatAutocompleteModule, - MatIconModule, - MatFormFieldModule, - MatInputModule, - MatProgressSpinnerModule, - MatSelectModule, - MatSnackBarModule, - MatTableModule, - MatTooltipModule, - ReactiveFormsModule, - NgxEchartsDirective, - MatCardModule, MatExpansionModule, - QueryParamPaginatorComponent, + NgxEchartsDirective, AppInfoCardComponent, PublicationTableComponent, - SelectedFiltersComponent, - QueryParamInputComponent, + PublicationFilterComponent, + QueryParamPaginatorComponent, ], templateUrl: './person-publications.component.html', styleUrl: './person-publications.component.scss', }) -export class PersonPublicationsComponent implements OnInit { - private readonly destroyRef = inject(DestroyRef); - - private readonly worksService = inject(WorksService); - +export class PersonPublicationsComponent { authorWorkPage = input.required(); - totalElements = computed(() => this.authorWorkPage().total ?? 0); + total = computed(() => this.authorWorkPage().total ?? 0); elements = computed(() => this.authorWorkPage().elements ?? []); - selectedInstitutions = input.required>(); + selectedInstitutions = input.required>(); selectedTopics = input.required>(); authorWorkPurposes = input.required(); @@ -203,76 +110,6 @@ export class PersonPublicationsComponent implements OnInit { ); }); - expandedWorkInstitutionsId: string[] = []; - - observers: FilterObserver[] = [ - { - id: 'search', - queryParamKey: workQueryParamKeys.title, - icon: 'search', - }, - { - id: 'types', - queryParamKey: workQueryParamKeys.types, - icon: 'category', - valueFormatter: (value: string) => { - return translateWorkType(value) || value; - }, - }, - { - id: 'years', - queryParamKey: workQueryParamKeys.years, - icon: 'calendar_today', - }, - - { - id: 'languages', - queryParamKey: workQueryParamKeys.language, - icon: 'translate', - valueFormatter: (value: string) => { - return translateLanguageCode(value) || value; - }, - }, - { - id: 'institutions', - queryParamKey: workQueryParamKeys.institutionId, - icon: 'apartment', - valueFormatter: (value: string) => { - const institution = this.selectedInstitutions().find( - (inst) => inst.id === value, - ); - return institution ? institution.display_name : value; - }, - }, - { - id: 'topics', - queryParamKey: workQueryParamKeys.topicId, - icon: 'label', - valueFormatter: (value: string) => { - const topic = this.selectedTopics().find((t) => t.id === value); - return topic ? topic.display_name : value; - }, - }, - ]; - - isWorkInstitutionsExpanded(work: Work): boolean { - if (!work.id) return false; - - return this.expandedWorkInstitutionsId.includes(work.id); - } - - toggleWorkInstitutionsExpansion(work: Work): void { - if (!work.id) return; - - if (this.expandedWorkInstitutionsId.includes(work.id)) { - this.expandedWorkInstitutionsId = this.expandedWorkInstitutionsId.filter( - (id) => id !== work.id, - ); - } else { - this.expandedWorkInstitutionsId.push(work.id); - } - } - countPurpose = ( specificWorkPurposes: SpecificWorkPurpose[], purpose: WorkPurpose, @@ -288,58 +125,7 @@ export class PersonPublicationsComponent implements OnInit { chartOption!: echarts.EChartsCoreOption; - institutionLookupLoading = false; - topicLookupLoading = false; - institutionOptions: InstitutionAutocompleteOption[] = []; - topicOptions: TopicAutocompleteOption[] = []; - readonly institutionSearchControl = new FormControl< - string | InstitutionAutocompleteOption - >('', { nonNullable: true }); - readonly topicSearchControl = new FormControl< - string | TopicAutocompleteOption - >('', { - nonNullable: true, - }); - readonly yearSearchControl = new FormControl('', { nonNullable: true }); - readonly typeSearchControl = new FormControl('', { nonNullable: true }); - readonly languageSearchControl = 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 readonly activatedRoute: ActivatedRoute, - private readonly router: Router, - private readonly httpClient: HttpClient, - public readonly paginationService: PaginationService, - private readonly institutionsService: InstitutionsService, - ) { + constructor() { effect(() => { const yearlyCounts = this.buildYearlyCounts( this.specificWorkPurposesByYear(), @@ -348,78 +134,6 @@ export class PersonPublicationsComponent implements OnInit { }); } - queryParamMap = toSignal(this.activatedRoute.queryParamMap, { - initialValue: this.activatedRoute.snapshot.queryParamMap, - }); - - selectedYearsQueryParams = computed(() => { - return this.queryParamMap().getAll(workQueryParamKeys.years).map(Number); - }); - - handleYearSelectionChange(event: MatSelectChange): void { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.years]: event.value, - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - - selectedTypesQueryParams = computed(() => { - return this.queryParamMap().getAll(workQueryParamKeys.types); - }); - - handleTypeSelectionChange(event: MatSelectChange): void { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.types]: event.value, - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - console.log('Type selection changed:', event.value); - } - - selectedLanguagesQueryParams = computed(() => { - return this.queryParamMap().getAll(workQueryParamKeys.language); - }); - - resolvedInstitutions = computed(() => { - const institutionMap = new Map(); - for (const work of this.elements()) { - for (const authorship of work.authorships ?? []) { - for (const institution of authorship.institutions ?? []) { - if (!institution.id) continue; - - if (!institutionMap.has(institution.id)) { - institutionMap.set(institution.id, institution); - } - } - } - } - return institutionMap; - }); - - handleLanguageSelectionChange(event: MatSelectChange): void { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.language]: event.value, - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - console.log('Language selection changed:', event.value); - } - - selectedInstitutionIdsQueryParams = computed(() => { - return this.queryParamMap().getAll(workQueryParamKeys.institutionId); - }); - - selectedTopicIdsQueryParams = computed(() => { - return this.queryParamMap().getAll(workQueryParamKeys.topicId); - }); - getAuthorSpecificWorkPurposesByYear( authorWorkPurposes: AuthorWorkPurposes, ): Record> { @@ -533,392 +247,4 @@ export class PersonPublicationsComponent implements OnInit { ], }; } - - ngOnInit(): void { - this.setupInstitutionAutocomplete(); - this.setupTopicAutocomplete(); - } - - clearFilters(): void { - this.router.navigate([], { - queryParams: { - page: 0, - size: 10, - sort_by: 'publication_year', - sort_direction: 'desc', - }, - }); - } - - 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.selectedInstitutionIdsQueryParams().includes(institution.id)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.institutionId]: [ - ...this.selectedInstitutionIdsQueryParams(), - institution.id, - ], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - removeInstitution(institution: InstitutionAutocompleteOption): void { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.institutionId]: - this.selectedInstitutionIdsQueryParams().filter( - (id) => id !== institution.id, - ), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - - filterByInstitution(institution: { id: string; name: string }): void { - if (!institution.id) return; - const selectedInstitutionIds = this.selectedInstitutionIdsQueryParams(); - if (selectedInstitutionIds.includes(institution.id)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.institutionId]: selectedInstitutionIds.filter( - (id) => id !== institution.id, - ), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } else { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.institutionId]: [ - ...selectedInstitutionIds, - institution.id, - ], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - isInstitutionActive(id: string): boolean { - return !!id && this.selectedInstitutionIdsQueryParams().includes(id); - } - - selectedInstitutionCountry( - institution: InstitutionAutocompleteOption, - ): string | null { - if (!institution.id) return null; - const authorWorkPage = this.authorWorkPage(); - if (!authorWorkPage?.elements) return null; - for (const publication of authorWorkPage.elements) { - for (const authorship of publication.authorships ?? []) { - for (const inst of authorship.institutions ?? []) { - if (institution.id === inst.id && inst.country_code) { - return inst.country_code; - } - } - } - } - return null; - } - - toggleYearFilter(year: number): void { - const selectedYears = this.selectedYearsQueryParams(); - if (selectedYears.includes(year)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.years]: selectedYears.filter((y) => y !== year), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } else { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.years]: [...selectedYears, year], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - toggleTypeFilter(type: string): void { - const selectedTopics = this.selectedTypesQueryParams(); - if (selectedTopics.includes(type)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.types]: selectedTopics.filter((t) => t !== type), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } else { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.types]: [...selectedTopics, type], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - toggleLanguageFilter(language: string): void { - const selectedLanguages = this.selectedLanguagesQueryParams(); - if (selectedLanguages.includes(language)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.language]: selectedLanguages.filter( - (l) => l !== language, - ), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } else { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.language]: [...selectedLanguages, language], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - isYearActive(year: number): boolean { - return this.selectedYearsQueryParams().includes(year); - } - - isTypeActive(type: string): boolean { - return this.selectedTypesQueryParams().includes(type); - } - - isLanguageActive(language: string): boolean { - return this.selectedLanguagesQueryParams().includes(language); - } - - 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.selectedTopicIdsQueryParams().includes(topic.id)) { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.topicId]: [ - ...this.selectedTopicIdsQueryParams(), - topic.id, - ], - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - } - - removeTopic(topic: TopicAutocompleteOption): void { - this.router.navigate([], { - queryParams: { - [workQueryParamKeys.topicId]: this.selectedTopicIdsQueryParams().filter( - (id) => id !== topic.id, - ), - [workQueryParamKeys.page]: 0, - }, - queryParamsHandling: 'merge', - }); - } - - extractRawId(id: string | null | undefined): string | null { - if (!id) return null; - return id.split('/').filter(Boolean).pop() ?? null; - } - - openInstitutionPage( - institutionId: string | null | undefined, - event: Event, - ): void { - event.stopPropagation(); - event.preventDefault(); - - const id = this.extractRawId(institutionId); - if (!id) return; - - void this.router.navigate(['/institution', id]); - } - - getWorkTopicColor(topic: WorkTopic): string { - return topicHierarchyColor({ - id: topic.id, - name: topic.display_name, - field_id: topic.field?.id, - field_name: topic.field?.display_name, - domain_id: topic.domain?.id, - domain_name: topic.domain?.display_name, - }); - } - - getSelectedWorkTopicTooltip(topic: WorkTopic): string { - return buildTopicHierarchyTooltip({ - topicName: topic.display_name, - description: topic.description, - subfieldName: topic.subfield?.display_name, - fieldName: topic.field?.display_name, - domainName: topic.domain?.display_name, - }); - } - - yearSelectionSummary(): string { - return this.summarizeSelection(this.selectedYearsQueryParams().map(String)); - } - - typeSelectionSummary(): string { - return this.summarizeSelection(this.selectedTypesQueryParams()); - } - - languageSelectionSummary(): string { - return this.summarizeSelection( - this.selectedLanguagesQueryParams().map(String), - ); - } - - private summarizeSelection(labels: string[]): string { - if (labels.length === 0) return ''; - if (labels.length === 1) return labels[0]; - return `+${labels.length}`; - } - - languageLabel(value: string): string { - return ( - this.languageOptions.find((option) => option.value === value)?.label ?? - value - ); - } - - filteredYearOptions(): number[] { - const term = this.yearSearchControl.value.trim(); - if (!term) return this.publicationYearOptions; - return this.publicationYearOptions.filter((year) => - String(year).includes(term), - ); - } - - filteredTypeOptions(): { value: string; label: string }[] { - const term = this.typeSearchControl.value.trim().toLowerCase(); - if (!term) return this.typeOptions; - return this.typeOptions.filter((type) => - type.label.toLowerCase().includes(term), - ); - } - - filteredLanguageOptions(): { value: string; label: string }[] { - const term = this.languageSearchControl.value.trim().toLowerCase(); - if (!term) return this.languageOptions; - return this.languageOptions.filter((language) => - language.label.toLowerCase().includes(term), - ); - } - - focusSelectSearch(input: HTMLInputElement): void { - setTimeout(() => input.focus()); - } - - 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.selectedInstitutionIdsQueryParams()); - 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.selectedTopicIdsQueryParams()); - this.topicOptions = options.filter( - (option) => !!option.id && !selectedIds.has(option.id), - ); - }); - } - - private searchInstitutions(query: string) { - return this.institutionsService - .autocompleteInstitutions(query, undefined, undefined, 10) - .pipe( - map( - (response) => - (response?.results ?? []) as InstitutionAutocompleteOption[], - ), - ); - } - - private searchTopics(query: string) { - const params = new HttpParams().set('query', query).set('limit', '10'); - - const basePath = this.worksService.configuration.basePath ?? ''; - return this.httpClient - .get(`${basePath}/api/topics/autocomplete`, { - params, - }) - .pipe(map((response) => response.results ?? [])); - } - - private createPublicationYearOptions(): number[] { - const currentYear = new Date().getFullYear(); - return Array.from({ length: 90 }, (_, index) => currentYear - index); - } } diff --git a/webapp/src/app/shared/pipes/work-type.pipe.ts b/webapp/src/app/shared/pipes/work-type.pipe.ts index 5c8634de..6e9b99f3 100644 --- a/webapp/src/app/shared/pipes/work-type.pipe.ts +++ b/webapp/src/app/shared/pipes/work-type.pipe.ts @@ -1,24 +1,9 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { findWorkTypeById } from '../ui/searchable-work-type-select/searchable-work-type-select.component'; export const translateWorkType = (value: string | null | undefined): string => { - switch (value) { - case 'article': - return 'Artikel'; - case 'book': - return 'Buch'; - case 'book-chapter': - return 'Buchkapitel'; - case 'dataset': - return 'Datensatz'; - case 'dissertation': - return 'Dissertation'; - case 'report': - return 'Bericht'; - case 'preprint': - return 'Preprint'; - default: - return value ?? 'Unbekannter Typ'; - } + const workType = findWorkTypeById(value ?? ''); + return workType ? workType.name : ''; }; @Pipe({ diff --git a/webapp/src/app/shared/ui/publication-filters/publication-filters.component.html b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.html new file mode 100644 index 00000000..02f447a2 --- /dev/null +++ b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.html @@ -0,0 +1,54 @@ +
+ @if (showTitleFilter()) { + + } +
+ @if (showYearFilter()) { + + } + @if (showWorkTypeFilter()) { + + } + @if (showLanguageFilter()) { + + } + @if (showAuthorFilter()) { + + } + @if (showInstitutionFilter()) { + + } + @if (showTopicFilter()) { + + } + +
+ +
diff --git a/webapp/src/app/shared/ui/publication-filters/publication-filters.component.scss b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.scss new file mode 100644 index 00000000..94044ea1 --- /dev/null +++ b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.scss @@ -0,0 +1,13 @@ +.content { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.select-area { + display: flex; + gap: 1rem; + flex-wrap: wrap; + width: 100%; + align-items: center; +} diff --git a/webapp/src/app/shared/ui/publication-filters/publication-filters.component.ts b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.ts new file mode 100644 index 00000000..f8c8d4c8 --- /dev/null +++ b/webapp/src/app/shared/ui/publication-filters/publication-filters.component.ts @@ -0,0 +1,354 @@ +import { Component, computed, input } from '@angular/core'; +import { SearchableTopicSelectComponent } from '../searchable-topic-select/searchable-topic-select.component'; +import { SearchableYearSelectComponent } from '../searchable-year-select/searchable-year-select.component'; +import { Author, Institution, Topic } from '../../../api'; +import { ActivatedRoute, Router } from '@angular/router'; +import { workQueryParamKeys } from '../../../resolvers/work-page.resolver'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { SearchableInstitutionSelectComponent } from '../searchable-institution-select/searchable-institution-select.component'; +import { + findWorkTypeById, + SearchableWorkTypeSelectComponent, + WorkType, +} from '../searchable-work-type-select/searchable-work-type-select.component'; +import { + findLanguageById, + Language, + SearchableLanguageSelectComponent, +} from '../searchable-language-select/searchable-language-select.component'; +import { SearchableAuthorSelectComponent } from '../searchable-author-select/searchable-author-select.component'; +import { QueryParamInputComponent } from '../query-param-input/query-param-input.component'; +import { MatButtonModule } from '@angular/material/button'; +import { + FilterObserver, + SelectedFiltersComponent, +} from '../selected-filters/selected-filters.component'; +import { translateWorkType } from '../../pipes/work-type.pipe'; +import { translateLanguageCode } from '../../pipes/language-code.pipe'; +import { MatIconModule } from '@angular/material/icon'; + +@Component({ + selector: 'app-publication-filter', + imports: [ + MatButtonModule, + MatIconModule, + SearchableTopicSelectComponent, + SearchableYearSelectComponent, + SearchableInstitutionSelectComponent, + SearchableWorkTypeSelectComponent, + SearchableLanguageSelectComponent, + SearchableAuthorSelectComponent, + QueryParamInputComponent, + SelectedFiltersComponent, + ], + templateUrl: './publication-filters.component.html', + styleUrl: './publication-filters.component.scss', +}) +export class PublicationFilterComponent { + constructor(private readonly router: Router) {} + + selectedAuthors = input([]); + selectedTopics = input([]); + selectedInstitutions = input([]); + + showTitleFilter = input(true); + showYearFilter = input(true); + showWorkTypeFilter = input(true); + showLanguageFilter = input(true); + showAuthorFilter = input(true); + showInstitutionFilter = input(true); + showTopicFilter = input(true); + + observers: FilterObserver[] = [ + { + id: 'search', + queryParamKey: workQueryParamKeys.title, + icon: 'search', + }, + { + id: 'types', + queryParamKey: workQueryParamKeys.types, + icon: 'category', + valueFormatter: (value: string) => { + return translateWorkType(value) || value; + }, + }, + { + id: 'years', + queryParamKey: workQueryParamKeys.years, + icon: 'calendar_today', + }, + { + id: 'languages', + queryParamKey: workQueryParamKeys.language, + icon: 'translate', + valueFormatter: (value: string) => { + return translateLanguageCode(value) || value; + }, + }, + { + id: 'authors', + queryParamKey: workQueryParamKeys.authorId, + icon: 'person', + valueFormatter: (value: string) => { + const author = this.selectedAuthors().find((a) => a.id === value); + console.log('Authors', this.selectedAuthors()); + return author ? author.display_name : value; + }, + }, + { + id: 'topics', + queryParamKey: workQueryParamKeys.topicId, + icon: 'label', + valueFormatter: (value: string) => { + const topic = this.selectedTopics().find((t) => t.id === value); + return topic ? topic.display_name : value; + }, + }, + ]; + + queryParamMap = toSignal(this.router.routerState.root.queryParamMap, { + initialValue: this.router.routerState.snapshot.root.queryParamMap, + }); + + titleQueryParamKey = computed(() => workQueryParamKeys.title); + + selectedYears = computed(() => { + return this.queryParamMap().getAll(workQueryParamKeys.years).map(Number); + }); + + yearLabel = computed(() => { + const selectedYears = this.selectedYears(); + if (selectedYears.length === 0) { + return 'Jahr'; + } else if (selectedYears.length === 1) { + return selectedYears[0].toString(); + } else { + return `${selectedYears.length} Jahre`; + } + }); + + handleYearSelectChange = (selectedYear: number): void => { + if (this.selectedYears().includes(selectedYear)) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.years]: this.selectedYears().filter( + (year) => year !== selectedYear, + ), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.years]: [...this.selectedYears(), selectedYear], + }, + queryParamsHandling: 'merge', + }); + } + }; + + selectedWorkTypes = computed(() => { + const workTypeIds = this.queryParamMap().getAll(workQueryParamKeys.types); + return workTypeIds + .map((id) => findWorkTypeById(id)) + .filter((type) => type !== undefined) as WorkType[]; + }); + + workTypeLabel = computed(() => { + const selectedWorkTypes = this.selectedWorkTypes(); + if (selectedWorkTypes.length === 0) { + return 'Typ'; + } else if (selectedWorkTypes.length === 1) { + return selectedWorkTypes[0].name; + } else { + return `${selectedWorkTypes.length} Typen`; + } + }); + + handleWorkTypeSelectChange = (selectedWorkType: WorkType): void => { + if (this.selectedWorkTypes().some((t) => t.id === selectedWorkType.id)) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.types]: this.selectedWorkTypes() + .filter((t) => t.id !== selectedWorkType.id) + .map((t) => t.id), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.types]: [ + ...this.selectedWorkTypes().map((t) => t.id), + selectedWorkType.id, + ], + }, + queryParamsHandling: 'merge', + }); + } + }; + + selectedLanguages = computed(() => { + const languageCodes = this.queryParamMap().getAll( + workQueryParamKeys.language, + ); + return languageCodes + .map((code) => findLanguageById(code)) + .filter((lang) => lang !== undefined) as Language[]; + }); + + languageLabel = computed(() => { + const selectedLanguages = this.selectedLanguages(); + if (selectedLanguages.length === 0) { + return 'Sprache'; + } else if (selectedLanguages.length === 1) { + return selectedLanguages[0].name; + } else { + return `${selectedLanguages.length} Sprachen`; + } + }); + + handleLanguageSelectChange = (selectedLanguage: Language): void => { + if ( + this.selectedLanguages().some((l) => l.code === selectedLanguage.code) + ) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.language]: this.selectedLanguages() + .filter((l) => l.code !== selectedLanguage.code) + .map((l) => l.code), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.language]: [ + ...this.selectedLanguages().map((l) => l.code), + selectedLanguage.code, + ], + }, + queryParamsHandling: 'merge', + }); + } + }; + + authorLabel = computed(() => { + const selectedAuthors = this.selectedAuthors(); + if (selectedAuthors.length === 0) { + return 'Autor'; + } else if (selectedAuthors.length === 1) { + return selectedAuthors[0].display_name ?? 'Autor'; + } else { + return `${selectedAuthors.length} Autoren`; + } + }); + + handleAuthorSelectChange = (selectedAuthor: Author): void => { + if (this.selectedAuthors().includes(selectedAuthor)) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.authorId]: this.selectedAuthors() + .filter((a) => a !== selectedAuthor) + .map((a) => a.id), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.authorId]: [ + ...this.selectedAuthors().map((a) => a.id), + selectedAuthor.id, + ], + }, + queryParamsHandling: 'merge', + }); + } + }; + + institutionLabel = computed(() => { + const selectedInstitutions = this.selectedInstitutions(); + if (selectedInstitutions.length === 0) { + return 'Institution'; + } else if (selectedInstitutions.length === 1) { + return selectedInstitutions[0].display_name ?? 'Institution'; + } else { + return `${selectedInstitutions.length} Institutionen`; + } + }); + + handleInstitutionSelectChange = (selectedInstitution: Institution): void => { + if (this.selectedInstitutions().includes(selectedInstitution)) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.institutionId]: this.selectedInstitutions() + .filter((inst) => inst !== selectedInstitution) + .map((inst) => inst.id), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.institutionId]: [ + ...this.selectedInstitutions().map((inst) => inst.id), + selectedInstitution.id, + ], + }, + queryParamsHandling: 'merge', + }); + } + }; + + topicLabel = computed(() => { + const selectedTopicIds = this.selectedTopics().map((t) => t.id); + if (selectedTopicIds.length === 0) { + return 'Thema'; + } else if (selectedTopicIds.length === 1) { + const topic = this.selectedTopics()[0]; + return topic.display_name || 'Thema'; + } else { + return `${selectedTopicIds.length} Themen`; + } + }); + + handleTopicSelectChange = (selectedTopic: Topic): void => { + if (this.selectedTopics().some((t) => t.id === selectedTopic.id)) { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.topicId]: this.selectedTopics() + .filter((t) => t.id !== selectedTopic.id) + .map((t) => t.id), + }, + queryParamsHandling: 'merge', + }); + } else { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.topicId]: [ + ...this.selectedTopics().map((t) => t.id!), + selectedTopic.id, + ], + }, + queryParamsHandling: 'merge', + }); + } + }; + + resetFilters = (): void => { + this.router.navigate([], { + queryParams: { + [workQueryParamKeys.title]: null, + [workQueryParamKeys.years]: null, + [workQueryParamKeys.types]: null, + [workQueryParamKeys.language]: null, + [workQueryParamKeys.authorId]: null, + [workQueryParamKeys.institutionId]: null, + [workQueryParamKeys.topicId]: null, + }, + queryParamsHandling: 'merge', + }); + }; +} diff --git a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html index 8ce973c0..ec2be69b 100644 --- a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html +++ b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html @@ -1,4 +1,4 @@ - + {{ this.label() }} diff --git a/webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.scss b/webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.ts b/webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.ts new file mode 100644 index 00000000..f19cda84 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-author-select/searchable-author-select.component.ts @@ -0,0 +1,42 @@ +import { Component, inject, input, output } from '@angular/core'; +import { Author, WorksV2Service } from '../../../api'; +import { Observable } from 'rxjs'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; + +@Component({ + selector: 'app-searchable-author-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-author-select.component.html', + styleUrl: './searchable-author-select.component.scss', +}) +export class SearchableAuthorSelectComponent { + private readonly worksV2Service = inject(WorksV2Service); + + label = input('Authoren'); + selectedAuthors = input.required(); + + handleAuthorSelectChange = output(); + + fetchAuthors = (searchTerm: string): Observable => { + return this.worksV2Service.getAuthorAutocomplete(searchTerm); + }; + + getAuthorLabel = (author: Author): string => { + return author.display_name!; + }; + + getAuthorValue = (author: Author): string => { + return author.id!; + }; + + getAuthorDescription = (author: Author): string => { + const worksCount = author.works_count ?? 0; + const worksCountText = worksCount === 1 ? 'Werk' : 'Werke'; + const lastKnownInstitution = author.last_known_institutions?.[0]; + const lastKnownInstitutionDisplayName = + lastKnownInstitution?.display_name ?? 'Unbekannt'; + const lastKnownInstitutionCountryCode = + lastKnownInstitution?.country_code ?? '??'; + return `${worksCount} ${worksCountText} - ${lastKnownInstitutionDisplayName} (${lastKnownInstitutionCountryCode})`; + }; +} diff --git a/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.html b/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.html new file mode 100644 index 00000000..ea0f7c1f --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.html @@ -0,0 +1,12 @@ + diff --git a/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.scss b/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.ts b/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.ts new file mode 100644 index 00000000..f67ec1b0 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-institution-select/searchable-institution-select.component.ts @@ -0,0 +1,35 @@ +import { Component, inject, input, output } from '@angular/core'; +import { Institution, WorksV2Service } from '../../../api'; +import { Observable } from 'rxjs'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; + +@Component({ + selector: 'app-searchable-institution-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-institution-select.component.html', + styleUrl: './searchable-institution-select.component.scss', +}) +export class SearchableInstitutionSelectComponent { + private readonly worksV2Service = inject(WorksV2Service); + + label = input('Institutionen'); + selectedInstitutions = input.required(); + + handleInstitutionSelectChange = output(); + + fetchInstitutions = (searchTerm: string): Observable => { + return this.worksV2Service.getInstitutionAutocomplete(searchTerm); + }; + + getInstitutionLabel = (institution: Institution): string => { + return institution.display_name!; + }; + + getInstitutionValue = (institution: Institution): string => { + return institution.id!; + }; + + getInstitutionDescription = (institution: Institution): string => { + return institution.country_code + ' - ' + institution.type; + }; +} diff --git a/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.html b/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.html new file mode 100644 index 00000000..568c977f --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.html @@ -0,0 +1,11 @@ + diff --git a/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.scss b/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.ts b/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.ts new file mode 100644 index 00000000..9033d162 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-language-select/searchable-language-select.component.ts @@ -0,0 +1,57 @@ +import { Component, input, output } from '@angular/core'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; +import { Observable } from 'rxjs'; + +export interface Language { + code: string; + name: string; +} + +export const languages: Language[] = [ + { code: 'en', name: 'Englisch' }, + { code: 'de', name: 'Deutsch' }, + { code: 'fr', name: 'Französisch' }, + { code: 'es', name: 'Spanisch' }, + { code: 'it', name: 'Italienisch' }, + { code: 'pt', name: 'Portugiesisch' }, + { code: 'ru', name: 'Russisch' }, + { code: 'zh', name: 'Chinesisch' }, + { code: 'ja', name: 'Japanisch' }, + { code: 'ko', name: 'Koreanisch' }, +]; + +export const findLanguageById = (id: string): Language | undefined => { + return languages.find((language) => language.code === id); +}; + +@Component({ + selector: 'app-searchable-language-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-language-select.component.html', + styleUrl: './searchable-language-select.component.scss', +}) +export class SearchableLanguageSelectComponent { + label = input('Typen'); + selectedLanguages = input.required(); + + handleLanguageSelectChange = output(); + + fetchLanguages = (searchTerm: string): Observable => { + return new Observable((observer) => { + observer.next( + languages.filter((language) => + language.name.toLowerCase().includes(searchTerm.toLowerCase()), + ), + ); + observer.complete(); + }); + }; + + getLanguageLabel = (language: Language): string => { + return language.name; + }; + + getLanguageValue = (language: Language): string => { + return language.code; + }; +} diff --git a/webapp/src/app/shared/ui/searchable-select/searchable-select.component.html b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.html new file mode 100644 index 00000000..4a359964 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.html @@ -0,0 +1,70 @@ + + @if (icon()) { + + } + + {{ label() }} +
+ search + + + +
+ + @if (isLoading()) { + Laden… + } @else { + @if (selectedElements().length > 0) { + + @for ( + element of selectedElements(); + track getSelectValue()(element) + ) { + + check + {{ getSelectLabel()(element) }} + @if (getSelectDescription()) { + {{ + getSelectDescription()!(element) + }} + } + + } @empty { + Keine Ergebnisse + } + + } + + @for (element of fetchedElements(); track getSelectValue()(element)) { + + {{ getSelectLabel()(element) }} + @if (getSelectDescription()) { + {{ + getSelectDescription()!(element) + }} + } + + } @empty { + Keine Ergebnisse + } + + } +
+
diff --git a/webapp/src/app/shared/ui/searchable-select/searchable-select.component.scss b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.scss new file mode 100644 index 00000000..e8e4f433 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.scss @@ -0,0 +1,18 @@ +.search-panel-header { + display: flex; + align-items: center; + padding: 8px 12px; + gap: 8px; + + input { + flex: 1; + border: none; + outline: none; + } +} + +.option-description { + display: block; + font-size: 12px; + opacity: 0.6; +} diff --git a/webapp/src/app/shared/ui/searchable-select/searchable-select.component.ts b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.ts new file mode 100644 index 00000000..b369887d --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-select/searchable-select.component.ts @@ -0,0 +1,94 @@ +import { + Component, + computed, + DestroyRef, + inject, + input, + output, + signal, +} from '@angular/core'; +import { MatSelectModule } from '@angular/material/select'; +import { FormsModule } from '@angular/forms'; +import { MatInputModule } from '@angular/material/input'; +import { MatIconModule } from '@angular/material/icon'; +import { MatButtonModule } from '@angular/material/button'; +import { + BehaviorSubject, + catchError, + debounceTime, + distinctUntilChanged, + Observable, + of, + switchMap, + tap, +} from 'rxjs'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; + +@Component({ + selector: 'app-searchable-select', + imports: [ + MatSelectModule, + MatInputModule, + MatIconModule, + MatButtonModule, + FormsModule, + ], + templateUrl: './searchable-select.component.html', + styleUrl: './searchable-select.component.scss', +}) +export class SearchableSelectComponent { + searchValue: string = ''; + handleSelectChange = output(); + + _elements = computed(() => { + const predefined = this.selectedElements(); + const fetched = this.fetchedElements(); + return [...predefined, ...fetched]; + }); + isLoading = signal(false); + + icon = input(''); + label = input.required(); + selectedLabel = input('Ausgewählt'); + fetchedLabel = input('Verfügbar'); + fetchElements = input<(searchTerm: string) => Observable>(); + fetchedElements = signal([]); + selectedElements = input([]); + getSelectLabel = input.required<(element: T) => string>(); + getSelectValue = input.required<(element: T) => string>(); + getSelectDescription = input<(element: T) => string>(); + + inputPlaceholder = input('Suche'); + + private readonly searchTerms = new BehaviorSubject(''); + private readonly destroyRef = inject(DestroyRef); + + constructor() { + this.searchTerms + .pipe( + debounceTime(300), + distinctUntilChanged(), + tap(() => this.isLoading.set(true)), + switchMap((term) => { + const fetchFn = this.fetchElements(); + if (!fetchFn) { + return of([] as T[]); + } + return fetchFn(term).pipe(catchError(() => of([] as T[]))); + }), + tap(() => this.isLoading.set(false)), + takeUntilDestroyed(this.destroyRef), + ) + .subscribe((results) => this.fetchedElements.set(results)); + } + + _handleValueChange(newValue: string): void { + this.searchValue = newValue; + this.searchTerms.next(newValue); + } + + _clearSearchValue(): void { + this.searchValue = ''; + this.fetchedElements.set([]); + } +} diff --git a/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.html b/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.html new file mode 100644 index 00000000..651d31e7 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.html @@ -0,0 +1,12 @@ + diff --git a/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.scss b/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.ts b/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.ts new file mode 100644 index 00000000..c6aecfae --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-topic-select/searchable-topic-select.component.ts @@ -0,0 +1,41 @@ +import { Component, inject, input, output } from '@angular/core'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; +import { Topic, WorksV2Service } from '../../../api'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'app-searchable-topic-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-topic-select.component.html', + styleUrl: './searchable-topic-select.component.scss', +}) +export class SearchableTopicSelectComponent { + private readonly worksV2Service = inject(WorksV2Service); + + label = input('Themen'); + selectedTopics = input.required(); + + handleTopicSelectChange = output(); + + fetchTopics = (searchTerm: string): Observable => { + return this.worksV2Service.getTopicAutocomplete(searchTerm); + }; + + getTopicLabel = (topic: Topic): string => { + return topic.display_name!; + }; + + getTopicValue = (topic: Topic): string => { + return topic.id!; + }; + + getTopicDescription = (topic: Topic): string => { + return ( + topic.subfield?.display_name + + ' - ' + + topic.field?.display_name + + ' - ' + + topic.domain?.display_name || '' + ); + }; +} diff --git a/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.html b/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.html new file mode 100644 index 00000000..b9094b17 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.html @@ -0,0 +1,11 @@ + diff --git a/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.scss b/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.ts b/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.ts new file mode 100644 index 00000000..6b255bd0 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-work-type-select/searchable-work-type-select.component.ts @@ -0,0 +1,66 @@ +import { Component, input, output } from '@angular/core'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; +import { Observable } from 'rxjs'; + +export interface WorkType { + id: string; + name: string; +} + +export const workTypes: WorkType[] = [ + { id: 'article', name: 'Artikel' }, + { id: 'book', name: 'Buch' }, + { id: 'book-chapter', name: 'Buchkapitel' }, + { id: 'dataset', name: 'Datensatz' }, + { id: 'dissertation', name: 'Dissertation' }, + { id: 'editorial', name: 'Editorial' }, + { id: 'erratum', name: 'Erratum' }, + { id: 'letter', name: 'Brief' }, + { id: 'libguides', name: 'LibGuides' }, + { id: 'other', name: 'Andere' }, + { id: 'paratext', name: 'Paratext' }, + { id: 'peer-review', name: 'Peer Review' }, + { id: 'preprint', name: 'Preprint' }, + { id: 'reference-entry', name: 'Referenzeintrag' }, + { id: 'report', name: 'Bericht' }, + { id: 'retraction', name: 'Retraktion' }, + { id: 'review', name: 'Review' }, + { id: 'standard', name: 'Standard' }, + { id: 'supplementary-materials', name: 'Ergänzende Materialien' }, +]; + +export const findWorkTypeById = (id: string): WorkType | undefined => { + return workTypes.find((workType) => workType.id === id); +}; + +@Component({ + selector: 'app-searchable-work-type-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-work-type-select.component.html', + styleUrl: './searchable-work-type-select.component.scss', +}) +export class SearchableWorkTypeSelectComponent { + label = input('Typen'); + selectedWorkTypes = input.required(); + + handleWorkTypeSelectChange = output(); + + fetchWorkTypes = (searchTerm: string): Observable => { + return new Observable((observer) => { + observer.next( + workTypes.filter((workType) => + workType.name.toLowerCase().includes(searchTerm.toLowerCase()), + ), + ); + observer.complete(); + }); + }; + + getWorkTypeLabel = (workType: WorkType): string => { + return workType.name; + }; + + getWorkTypeValue = (workType: WorkType): string => { + return workType.id; + }; +} diff --git a/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.html b/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.html new file mode 100644 index 00000000..5e6f06df --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.html @@ -0,0 +1,11 @@ + diff --git a/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.scss b/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.ts b/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.ts new file mode 100644 index 00000000..3382af33 --- /dev/null +++ b/webapp/src/app/shared/ui/searchable-year-select/searchable-year-select.component.ts @@ -0,0 +1,40 @@ +import { Component, input, output } from '@angular/core'; +import { SearchableSelectComponent } from '../searchable-select/searchable-select.component'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'app-searchable-year-select', + imports: [SearchableSelectComponent], + templateUrl: './searchable-year-select.component.html', + styleUrl: './searchable-year-select.component.scss', +}) +export class SearchableYearSelectComponent { + label = input('Jahr'); + selectedYears = input.required(); + startYear = input(1900); + endYear = input(new Date().getFullYear()); + + handleYearSelectChange = output(); + + fetchYears = (searchTerm: string): Observable => { + const years: number[] = []; + for (let year = this.endYear(); year >= this.startYear(); year--) { + years.push(year); + } + + return new Observable((observer) => { + observer.next( + years.filter((year) => year.toString().includes(searchTerm)), + ); + observer.complete(); + }); + }; + + getYearLabel = (year: number): string => { + return year.toString(); + }; + + getYearValue = (year: number): string => { + return year.toString(); + }; +}