diff --git a/service/src/main/inse/works/logic.py b/service/src/main/inse/works/logic.py index 96bf0ef2..ec4f16af 100644 --- a/service/src/main/inse/works/logic.py +++ b/service/src/main/inse/works/logic.py @@ -55,6 +55,7 @@ async def get_author_works( language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + sort: str = "year", client: OpenAlexWorksSearchClient | None = None, ) -> WorkPage: search_client = client or OpenAlexWorksSearchClient() @@ -68,6 +69,7 @@ async def get_author_works( language=language, institution_id=institution_id, topic_id=topic_id, + sort=sort, ) elements, total = _parse_full_work_search_response(data) @@ -929,6 +931,7 @@ async def _search_author_works_data( language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + sort: str = "year", ) -> dict: return await search_client.search_author_works( author_id, @@ -939,6 +942,7 @@ async def _search_author_works_data( language=language, institution_id=institution_id, topic_id=topic_id, + sort=sort, ) diff --git a/service/src/main/inse/works/search_client.py b/service/src/main/inse/works/search_client.py index 42b2ee8b..2e52a9a6 100644 --- a/service/src/main/inse/works/search_client.py +++ b/service/src/main/inse/works/search_client.py @@ -35,6 +35,7 @@ class OpenAlexWorksSearchClient: language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + sort: str = "year", ) -> dict[str, Any]: indexed_author_id = f"https://openalex.org/{author_id.strip()}" filters = self._work_filters( @@ -73,6 +74,16 @@ class OpenAlexWorksSearchClient: }, }, }) + if sort == "citations": + sort_clauses = [ + {"cited_by_count": {"order": "desc", "missing": "_last"}}, + {"publication_year": {"order": "desc", "missing": "_last"}}, + ] + else: + sort_clauses = [ + {"publication_year": {"order": "desc", "missing": "_last"}}, + {"cited_by_count": {"order": "desc", "missing": "_last"}}, + ] return { "from": (page - 1) * size, "size": size, @@ -83,10 +94,7 @@ class OpenAlexWorksSearchClient: "filter": filters, }, }, - "sort": [ - {"publication_year": {"order": "desc", "missing": "_last"}}, - {"cited_by_count": {"order": "desc", "missing": "_last"}}, - ], + "sort": sort_clauses, } def _work_filters( @@ -130,6 +138,7 @@ class OpenAlexWorksSearchClient: language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + sort: str = "year", ) -> dict[str, Any]: if not self.api_key: raise MissingApiKeyError("OpenAlex works Elasticsearch API key is not configured.") @@ -143,6 +152,7 @@ class OpenAlexWorksSearchClient: language=language, institution_id=institution_id, topic_id=topic_id, + sort=sort, ) return await elasticsearch.search(index=self.index,body=body,cluster=ESCluster.NES,) diff --git a/service/src/main/inse/works/service.py b/service/src/main/inse/works/service.py index 382f3fd7..ead6daad 100644 --- a/service/src/main/inse/works/service.py +++ b/service/src/main/inse/works/service.py @@ -4,7 +4,7 @@ REST API for publication works. """ -from typing import Annotated, Optional +from typing import Annotated, Literal, Optional from fastapi import APIRouter from fastapi import Path @@ -54,6 +54,10 @@ async def get_author_works( list[str] | None, Query(description="Filter by OpenAlex topic id. Can be repeated."), ] = None, + sort: Annotated[ + Literal["year", "citations"], + Query(description="Sort order: by publication year or by citation count."), + ] = "year", ): return await logic.get_author_works( author_id, @@ -64,6 +68,7 @@ async def get_author_works( language=language, institution_id=institution_id, topic_id=topic_id, + sort=sort, ) diff --git a/service/src/main/inse/works/test_search_client.py b/service/src/main/inse/works/test_search_client.py index 2d9e2a41..1f3c905e 100644 --- a/service/src/main/inse/works/test_search_client.py +++ b/service/src/main/inse/works/test_search_client.py @@ -26,6 +26,28 @@ def test_author_works_query_searches_authorship_author_id(): assert query["query"]["bool"]["filter"] == [] +def test_author_works_query_sorts_by_year_by_default(): + client = OpenAlexWorksSearchClient(api_key="test-key") + + query = client.author_works_query("A5023888391", page=1, size=20) + + assert query["sort"] == [ + {"publication_year": {"order": "desc", "missing": "_last"}}, + {"cited_by_count": {"order": "desc", "missing": "_last"}}, + ] + + +def test_author_works_query_sorts_by_citations(): + client = OpenAlexWorksSearchClient(api_key="test-key") + + query = client.author_works_query("A5023888391", page=1, size=20, sort="citations") + + assert query["sort"] == [ + {"cited_by_count": {"order": "desc", "missing": "_last"}}, + {"publication_year": {"order": "desc", "missing": "_last"}}, + ] + + def test_author_works_query_adds_publication_filters(): client = OpenAlexWorksSearchClient(api_key="test-key") diff --git a/webapp/src/app/api/api/works.service.ts b/webapp/src/app/api/api/works.service.ts index c9f9a95e..6db4cd1a 100644 --- a/webapp/src/app/api/api/works.service.ts +++ b/webapp/src/app/api/api/works.service.ts @@ -170,13 +170,14 @@ export class WorksService extends BaseService { * @param language Filter by language code. Can be repeated. * @param institutionId Filter by OpenAlex institution id. Can be repeated. * @param topicId Filter by OpenAlex topic id. Can be repeated. + * @param sort Sort order: by publication year or by citation count. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public getAuthorWorks(authorId: string, page?: number, size?: number, publicationYear?: Array, type?: Array, language?: Array, institutionId?: Array, topicId?: 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, institutionId?: Array, topicId?: 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, institutionId?: Array, topicId?: 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, institutionId?: Array, topicId?: Array, 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, institutionId?: Array, topicId?: Array, sort?: 'year' | 'citations', 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, institutionId?: Array, topicId?: Array, sort?: 'year' | 'citations', 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, institutionId?: Array, topicId?: Array, sort?: 'year' | 'citations', 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, institutionId?: Array, topicId?: Array, sort?: 'year' | 'citations', 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.'); } @@ -216,6 +217,8 @@ export class WorksService extends BaseService { element, 'topic_id'); }) } + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + sort, 'sort'); let localVarHeaders = this.defaultHeaders; diff --git a/webapp/src/app/modules/person-card/person-card.component.html b/webapp/src/app/modules/person-card/person-card.component.html index 946430ae..1f7741d4 100644 --- a/webapp/src/app/modules/person-card/person-card.component.html +++ b/webapp/src/app/modules/person-card/person-card.component.html @@ -95,6 +95,14 @@ >{{ inst.country_code.toUpperCase() }} } + @if (institutionPageId() && !loading()) { + open_in_new + } } diff --git a/webapp/src/app/modules/person-card/person-card.component.scss b/webapp/src/app/modules/person-card/person-card.component.scss index 75f0ed69..2172cd99 100644 --- a/webapp/src/app/modules/person-card/person-card.component.scss +++ b/webapp/src/app/modules/person-card/person-card.component.scss @@ -162,6 +162,31 @@ white-space: nowrap; } + .institution-open-icon { + flex-shrink: 0; + width: 12px; + height: 12px; + margin-left: 5px; + font-size: 12px; + line-height: 1; + vertical-align: middle; + cursor: pointer; + opacity: 0; + transition: opacity 0.15s ease; + + &:hover { + opacity: 1; + } + } + + &:hover .institution-open-icon { + opacity: 0.7; + + &:hover { + opacity: 1; + } + } + &:hover, &:focus-visible { background: var(--sg-primary); diff --git a/webapp/src/app/modules/person-card/person-card.component.ts b/webapp/src/app/modules/person-card/person-card.component.ts index e8a50711..aef4cd8f 100644 --- a/webapp/src/app/modules/person-card/person-card.component.ts +++ b/webapp/src/app/modules/person-card/person-card.component.ts @@ -1,6 +1,6 @@ -import { Component, input, computed, output } from '@angular/core'; +import { Component, inject, input, computed, output } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { RouterLink } from '@angular/router'; +import { Router, RouterLink } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CustomAuthor, DehydratedInstitution, WorkTopic } from '../../api'; @@ -23,6 +23,8 @@ import { topicHierarchyColor } from '../../resolvers/utils/topic-colors'; styleUrl: './person-card.component.scss', }) export class PersonCardComponent { + private readonly router = inject(Router); + person = input.required(); isBookmarked = input(false); loading = input(false); @@ -66,6 +68,20 @@ export class PersonCardComponent { return newestInstitution; }); + institutionPageId = computed( + () => this.institution()?.id?.split('/').pop() ?? null, + ); + + openInstitutionPage(event: Event): void { + event.stopPropagation(); + event.preventDefault(); + + const id = this.institutionPageId(); + if (!id) return; + + void this.router.navigate(['/institution', id]); + } + isInstitutionActive = computed(() => { const active = this.activeInstitutionName().trim().toLowerCase(); if (!active) return false; diff --git a/webapp/src/app/modules/person-list/person-list.component.html b/webapp/src/app/modules/person-list/person-list.component.html index 0dc9fe14..9647b24a 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -82,6 +82,14 @@ filter.countryCode.toUpperCase() }} } + @if (findInstitutionPageIdByName(filter.value)) { + open_in_new + } + @if (authorsExpanded) { +
+
+ @for ( + authorship of pagedAuthors(); + track authorship.author?.id + ) { + + } @empty { +

Keine Angaben vorhanden.

+ } +
+ @if (authorsPageCount() > 1) { +
+ + {{ authorsPage + 1 }} / {{ authorsPageCount() }} + +
+ } +
+ } @if (publication.topics?.length) { @@ -182,7 +226,8 @@ [subfieldName]="topic.subfield?.display_name" [fieldName]="topic.field?.display_name" [domainName]="topic.domain?.display_name" - [color]="getTopicColor(topic)"> + [color]="getTopicColor(topic)" + (chipClick)="findAuthorsForTopic(topic)"> } @@ -204,52 +249,71 @@ } @if (sources().length) { -
-
+
+
-
- @for ( - location of sources(); - track location.source?.id || location.landing_page_url - ) { -
-
- {{ - location.source?.display_name || 'Externe Quelle' - }} -

- {{ - location.version || - location.source?.type || - 'Veröffentlichte Version' - }} - @if (location.license) { - · {{ location.license }} - } -

-
-
- @if (location.is_oa) { - Open Access - } - @if ( - location.pdf_url || location.landing_page_url; - as sourceUrl - ) { - - open_in_new - - } -
-
- } -
+ Quellen und Versionen + info_outline + {{ sources().length }} + expand_more + + @if (sourcesExpanded) { +
+
+ @for ( + location of sources(); + track location.source?.id || location.landing_page_url + ) { +
+
+ {{ + location.source?.display_name || 'Externe Quelle' + }} +

+ {{ + location.version || + location.source?.type || + 'Veröffentlichte Version' + }} + @if (location.license) { + · {{ location.license }} + } +

+
+
+ @if (location.is_oa) { + Open Access + } + @if ( + location.pdf_url || location.landing_page_url; + as sourceUrl + ) { + + open_in_new + + } +
+
+ } +
+
+ }
} @@ -299,83 +363,169 @@ @if (institutions().length) { -
-
+
+
-
- @for (institution of institutions(); track institution.id) { -
- - {{ institution.name }} - - @if (institution.country) { - - - {{ institution.country.toUpperCase() }} - - } @else if (institution.type) { - {{ institution.type }} + Institutionen + info_outline + {{ institutions().length }} + expand_more + + @if (institutionsExpanded) { +
+
+ @for ( + institution of pagedInstitutions(); + track institution.id + ) { +
+ + {{ institution.name }} + + @if (institution.country) { + + + {{ institution.country.toUpperCase() }} + + } @else if (institution.type) { + {{ institution.type }} + } +
}
- } -
+ @if (institutionsPageCount() > 1) { +
+ + {{ institutionsPage + 1 }} / + {{ institutionsPageCount() }} + +
+ } +
+ }
} @if (publication.funders?.length || publication.awards?.length) { -
-
+
+
-
- @for (funder of publication.funders ?? []; track funder.id) { -
- {{ funder.display_name }}Förderorganisation + Förderungen + info_outline + {{ fundingCount() }} + expand_more + + @if (fundingExpanded) { +
+
+ @for (funder of publication.funders ?? []; track funder.id) { +
+ {{ funder.display_name }}Förderorganisation +
+ } + @for (award of publication.awards ?? []; track award.id) { +
+ {{ + award.display_name || award.funder_award_id + }}{{ + award.funder_display_name || 'Förderung' + }} +
+ }
- } - @for (award of publication.awards ?? []; track award.id) { -
- {{ - award.display_name || award.funder_award_id - }}{{ award.funder_display_name || 'Förderung' }} -
- } -
+
+ }
} @if (externalLinks().length) { -
-
+
+
- + Externe Links + info_outline + {{ externalLinks().length }} + expand_more + + @if (linksExpanded) { +
+ +
+ }
} diff --git a/webapp/src/app/modules/publication-detail/publication-detail.component.scss b/webapp/src/app/modules/publication-detail/publication-detail.component.scss index 2e8c72d4..6c9b3334 100644 --- a/webapp/src/app/modules/publication-detail/publication-detail.component.scss +++ b/webapp/src/app/modules/publication-detail/publication-detail.component.scss @@ -188,6 +188,79 @@ aside { box-shadow: var(--sg-shadow-sm); } +.accordion-card { + padding: 0; + overflow: hidden; +} + +.accordion-header { + display: flex; + align-items: center; + gap: 8px; + width: 100%; + padding: 18px 22px; + background: none; + border: none; + cursor: pointer; + text-align: left; + font-family: inherit; + font-size: 16px; + font-weight: 700; + color: var(--sg-text); + transition: background 0.12s; + + &:hover { + background: #f6f9ff; + } + + mat-icon { + flex-shrink: 0; + width: 20px; + height: 20px; + font-size: 20px; + color: var(--sg-text-muted); + } +} + +.accordion-title { + flex: 1; +} + +.count-badge { + padding: 2px 7px; + border-radius: 999px; + background: #e8effe; + color: #3b5bd6; + font-size: 11px; + font-weight: 700; +} + +.info-icon { + flex-shrink: 0; + width: 16px !important; + height: 16px !important; + font-size: 16px !important; + color: var(--sg-text-muted); + opacity: 0.7; + cursor: default; + + &:hover { + opacity: 1; + } +} + +.chevron { + transition: transform 0.2s ease; + + &.rotated { + transform: rotate(-90deg); + } +} + +.accordion-body { + padding: 4px 22px 22px; +} + .section-title { display: flex; align-items: center; @@ -371,6 +444,50 @@ dd { font-size: 11px; } +.list-pagination { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + margin-top: 12px; +} + +.page-btn { + display: grid; + place-items: center; + width: 28px; + height: 28px; + border: 1px solid var(--sg-border); + border-radius: 8px; + background: none; + cursor: pointer; + color: var(--sg-text-muted); + transition: background 0.12s; + + &:hover:not(:disabled) { + background: var(--sg-surface-muted); + color: var(--sg-text); + } + + &:disabled { + opacity: 0.35; + cursor: default; + } + + mat-icon { + font-size: 18px; + width: 18px; + height: 18px; + } +} + +.page-indicator { + font-size: 12px; + color: var(--sg-text-muted); + min-width: 36px; + text-align: center; +} + .institution-country { display: inline-flex; align-items: center; @@ -445,6 +562,18 @@ dd { padding: 22px 20px; } + .accordion-card { + padding: 0; + } + + .accordion-header { + padding: 16px 20px; + } + + .accordion-body { + padding: 4px 20px 20px; + } + .metrics, .author-list { grid-template-columns: 1fr; diff --git a/webapp/src/app/modules/publication-detail/publication-detail.component.ts b/webapp/src/app/modules/publication-detail/publication-detail.component.ts index 57094961..dcef9877 100644 --- a/webapp/src/app/modules/publication-detail/publication-detail.component.ts +++ b/webapp/src/app/modules/publication-detail/publication-detail.component.ts @@ -1,13 +1,13 @@ -import { DatePipe, DecimalPipe, UpperCasePipe } from '@angular/common'; -import { Location } from '@angular/common'; +import { DatePipe, DecimalPipe, Location } from '@angular/common'; + import { Component, DestroyRef, OnInit, inject } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { HttpClient } from '@angular/common/http'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { ActivatedRoute, RouterLink } from '@angular/router'; -import { finalize } from 'rxjs'; +import { MatTooltipModule } from '@angular/material/tooltip'; +import { ActivatedRoute, Router, RouterLink } from '@angular/router'; import { Authorship, Location as ApiLocation, @@ -40,11 +40,11 @@ interface InstitutionDetail { MatButtonModule, MatIconModule, MatProgressSpinnerModule, + MatTooltipModule, RouterLink, TopicChipComponent, - UpperCasePipe, WorkTypePipe, - LanguageCodePipe + LanguageCodePipe, ], templateUrl: './publication-detail.component.html', styleUrl: './publication-detail.component.scss', @@ -54,18 +54,33 @@ export class PublicationDetailComponent implements OnInit { private readonly route = inject(ActivatedRoute); private readonly httpClient = inject(HttpClient); private readonly location = inject(Location); + private readonly router = inject(Router); private readonly worksService = inject(WorksService); publication: Work | null = null; loading = true; notFound = false; + authorsExpanded = true; + institutionsExpanded = false; + sourcesExpanded = false; + fundingExpanded = false; + linksExpanded = false; + + authorsPage = 0; + readonly authorsPageSize = 10; + + institutionsPage = 0; + readonly institutionsPageSize = 5; + ngOnInit(): void { this.loading = true; this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({ next: ({ publication }) => { this.publication = publication; + this.authorsPage = 0; + this.institutionsPage = 0; this.loading = false; }, error: () => { @@ -79,6 +94,17 @@ export class PublicationDetailComponent implements OnInit { this.location.back(); } + findAuthorsForTopic(topic: WorkTopic): void { + const topicName = topic.display_name?.trim(); + if (!topicName) return; + + // Deep link into the person search with this topic preset as filter, + // so matching authors show up directly. + void this.router.navigate(['/persons'], { + queryParams: { topic: topicName }, + }); + } + getTopicColor(topic: WorkTopic): string { return topicHierarchyColor({ id: topic.id, @@ -114,6 +140,28 @@ export class PublicationDetailComponent implements OnInit { return this.publication?.authorships ?? []; } + pagedAuthors(): Authorship[] { + return this.authors().slice( + this.authorsPage * this.authorsPageSize, + (this.authorsPage + 1) * this.authorsPageSize, + ); + } + + authorsPageCount(): number { + return Math.ceil(this.authors().length / this.authorsPageSize); + } + + pagedInstitutions(): InstitutionDetail[] { + return this.institutions().slice( + this.institutionsPage * this.institutionsPageSize, + (this.institutionsPage + 1) * this.institutionsPageSize, + ); + } + + institutionsPageCount(): number { + return Math.ceil(this.institutions().length / this.institutionsPageSize); + } + institutions(): InstitutionDetail[] { const institutions = new Map(); for (const authorship of this.authors()) { @@ -159,6 +207,13 @@ export class PublicationDetailComponent implements OnInit { ); } + fundingCount(): number { + return ( + (this.publication?.funders?.length ?? 0) + + (this.publication?.awards?.length ?? 0) + ); + } + pages(): string | null { const first = this.publication?.biblio?.first_page; const last = this.publication?.biblio?.last_page;