From be20407238493370cf6f5ad4f601bf2b7c66f180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Sun, 2 Aug 2026 14:01:08 +0200 Subject: [PATCH] feat: added publication tooltip; added tooltips for person network tables --- service/src/main/inse/works/v2/router.py | 12 ++++ service/src/main/inse/works/v2/service.py | 29 +++++++++- webapp/src/app/api/api/worksV2.service.ts | 57 +++++++++++++++++++ .../person-network.component.html | 29 +++++++--- .../person-network.component.ts | 9 +++ .../app-publication-tooltip.component.html | 5 ++ .../app-publication-tooltip.component.scss | 0 .../app-publication-tooltip.component.ts | 33 +++++++++++ 8 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html create mode 100644 webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.scss create mode 100644 webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.ts diff --git a/service/src/main/inse/works/v2/router.py b/service/src/main/inse/works/v2/router.py index b0d413f0..87596cdd 100644 --- a/service/src/main/inse/works/v2/router.py +++ b/service/src/main/inse/works/v2/router.py @@ -6,6 +6,7 @@ from fastapi import APIRouter, Path, Query from inse.auth.model import AccessTokenMetadata from inse.auth.service import CurrentUserAccessTokenPayloadDep from inse.model import SortDirection +from inse.models.openalex.work import Work from inse.router_prefixes import RouterPrefixes from inse.tags import Tags from inse.works.v2.model import ( @@ -22,6 +23,17 @@ logger = logging.getLogger(__name__) router = APIRouter(prefix=RouterPrefixes.WORKS_V2, tags=[Tags.WORKS_V2]) +@router.get( + "/{raw_oa_work_id}", + operation_id="getWorkById", + summary="Returns a work based on its ID.", +) +async def get_work_by_id( + raw_oa_work_id: Annotated[str, Path(description="The raw OpenAlex work id.")], +) -> Work: + return await works_service.get_work_by_id_or_raise(raw_oa_work_id=raw_oa_work_id) + + @router.get( "/search", operation_id="searchWorks", diff --git a/service/src/main/inse/works/v2/service.py b/service/src/main/inse/works/v2/service.py index 65f6a358..f1fa10d2 100644 --- a/service/src/main/inse/works/v2/service.py +++ b/service/src/main/inse/works/v2/service.py @@ -2,7 +2,7 @@ import logging import inse.authors.v2.service as author_service from inse.auth.model import AccessTokenMetadata -from inse.exceptions import ElasticsearchNotFoundException +from inse.exceptions import ElasticsearchNotFoundException, NotFoundException from inse.integrations import elasticsearch from inse.model import ESCluster, ESIndex, SortDirection from inse.models.openalex.work import Work @@ -581,7 +581,9 @@ async def search_works( ) -async def get_work(raw_oa_work_id: str, source: list[str] | None = None) -> Work | None: +async def get_work_by_id( + raw_oa_work_id: str, source: list[str] | None = None +) -> Work | None: """Retrieves a work based on its OpenAlex ID. Args: @@ -605,6 +607,27 @@ async def get_work(raw_oa_work_id: str, source: list[str] | None = None) -> Work return None +async def get_work_by_id_or_raise( + raw_oa_work_id: str, source: list[str] | None = None +) -> Work: + """Retrieves a work based on its OpenAlex ID or raises an exception if not found. + + Args: + raw_oa_work_id (str): The ID of the work to retrieve. + source (Optional[List[str]], optional): A list of fields to include in the response. Defaults to None. + + Returns: + Work: The retrieved work. + + Raises: + NotFoundException: If the work is not found. + """ + work = await get_work_by_id(raw_oa_work_id=raw_oa_work_id, source=source) + if work is None: + raise NotFoundException(f"Work with id {raw_oa_work_id} not found.") + return work + + async def _search_works( query: dict | None = None, source: list[str] | None = None, @@ -946,7 +969,7 @@ async def get_work_classification_by_work_id( if not raw_account_institution_id: return None - work = await get_work( + work = await get_work_by_id( raw_oa_work_id=raw_oa_work_id, source=["id", "authorships.author.id"] ) if not work: diff --git a/webapp/src/app/api/api/worksV2.service.ts b/webapp/src/app/api/api/worksV2.service.ts index 5f629ee0..5e4801f2 100644 --- a/webapp/src/app/api/api/worksV2.service.ts +++ b/webapp/src/app/api/api/worksV2.service.ts @@ -23,6 +23,8 @@ import { PrimaryCategoryYearAggregationPage } from '../model/primaryCategoryYear // @ts-ignore import { SortDirection } from '../model/sortDirection'; // @ts-ignore +import { Work } from '../model/work'; +// @ts-ignore import { WorkClassification } from '../model/workClassification'; // @ts-ignore import { WorkClassificationPage } from '../model/workClassificationPage'; @@ -507,6 +509,61 @@ export class WorksV2Service extends BaseService { ); } + /** + * Returns a work based on its ID. + * @endpoint get /api/works/v2/{raw_oa_work_id} + * @param rawOaWorkId The raw OpenAlex work id. + * @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 getWorkById(rawOaWorkId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getWorkById(rawOaWorkId: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getWorkById(rawOaWorkId: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getWorkById(rawOaWorkId: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (rawOaWorkId === null || rawOaWorkId === undefined) { + throw new Error('Required parameter rawOaWorkId was null or undefined when calling getWorkById.'); + } + + 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/works/v2/${this.configuration.encodeParam({name: "rawOaWorkId", value: rawOaWorkId, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + /** * Returns the classifications of a work based on its ID. * @endpoint get /api/works/v2/classification/work/{raw_oa_work_id} diff --git a/webapp/src/app/modules/person-network/person-network.component.html b/webapp/src/app/modules/person-network/person-network.component.html index 8755c91c..e17a31e0 100644 --- a/webapp/src/app/modules/person-network/person-network.component.html +++ b/webapp/src/app/modules/person-network/person-network.component.html @@ -127,10 +127,11 @@ @for (work of element.works; track $index) { + [routerLink]="['/publication', this.stripOpenAlexIdPrefix(work.id)]" + [appComponentTooltip]="AppPublicationTooltipComponent" + [tooltipInputs]="{ + workId: this.stripOpenAlexIdPrefix(work.id), + }">
  • {{ work.display_name }}
  • } @@ -145,7 +146,11 @@ [routerLink]="[ '/institution', this.stripOpenAlexIdPrefix(institution.id), - ]"> + ]" + [appComponentTooltip]="AppInstitutionTooltipComponent" + [tooltipInputs]="{ + institutionId: this.stripOpenAlexIdPrefix(institution.id), + }">
  • {{ institution.display_name }}
  • } @@ -175,11 +180,15 @@ @for (collaborator of element.authors; track $index) {
  • + ]" + [appComponentTooltip]="AppAuthorTooltipComponent" + [tooltipInputs]="{ + authorId: this.stripOpenAlexIdPrefix(collaborator.id), + }"> {{ collaborator.display_name }}
  • @@ -214,7 +223,11 @@ [routerLink]="[ '/person', this.stripOpenAlexIdPrefix(collaborator.id), - ]"> + ]" + [appComponentTooltip]="AppAuthorTooltipComponent" + [tooltipInputs]="{ + authorId: this.stripOpenAlexIdPrefix(collaborator.id), + }"> {{ collaborator.display_name }} diff --git a/webapp/src/app/modules/person-network/person-network.component.ts b/webapp/src/app/modules/person-network/person-network.component.ts index e5d7d617..92124161 100644 --- a/webapp/src/app/modules/person-network/person-network.component.ts +++ b/webapp/src/app/modules/person-network/person-network.component.ts @@ -65,6 +65,10 @@ import { import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component'; import { from, interval, startWith, switchMap, takeWhile, tap } from 'rxjs'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; +import { ComponentTooltipDirective } from '../../directives/component-tooltip.directive'; +import { AppAuthorTooltipComponent } from '../../shared/ui/app-author-tooltip/app-author-tooltip.component'; +import { AppInstitutionTooltipComponent } from '../../shared/ui/app-institution-tooltip/app-institution-tooltip.component'; +import { AppPublicationTooltipComponent } from '../../shared/ui/app-publication-tooltip/app-publication-tooltip.component'; type DetailedWorkNode = WorkNode & { authors: AuthorNode[]; @@ -111,12 +115,17 @@ interface FilterData { QueryParamInputComponent, LoadingComponent, MatGridListModule, + ComponentTooltipDirective, ], templateUrl: './person-network.component.html', styleUrl: './person-network.component.scss', providers: [], }) export class PersonNetworkComponent implements OnInit { + readonly AppAuthorTooltipComponent = AppAuthorTooltipComponent; + readonly AppInstitutionTooltipComponent = AppInstitutionTooltipComponent; + readonly AppPublicationTooltipComponent = AppPublicationTooltipComponent; + startCollaborationGraphResponse = input.required(); diff --git a/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html new file mode 100644 index 00000000..7d134a10 --- /dev/null +++ b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html @@ -0,0 +1,5 @@ +@let work = this._work(); + +@if (work) { + +} diff --git a/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.scss b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.ts b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.ts new file mode 100644 index 00000000..43cbd28b --- /dev/null +++ b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.ts @@ -0,0 +1,33 @@ +import { Component, effect, inject, input, signal } from '@angular/core'; +import { Work, WorksV2Service } from '../../../api'; +import { AppPublicationCardComponent } from '../app-publication-card/app-publication-card.component'; + +@Component({ + selector: 'app-publication-tooltip', + imports: [AppPublicationCardComponent], + templateUrl: './app-publication-tooltip.component.html', + styleUrl: './app-publication-tooltip.component.scss', +}) +export class AppPublicationTooltipComponent { + private readonly worksService = inject(WorksV2Service); + + workId = input.required(); + + _work = signal(undefined); + + _isLoading = signal(false); + + constructor() { + effect(() => { + const workId = this.workId(); + if (!workId) { + this._work.set(undefined); + } + this._isLoading.set(true); + this.worksService.getWorkById(workId).subscribe((work) => { + this._work.set(work); + this._isLoading.set(false); + }); + }); + } +}