feat: added publication tooltip; added tooltips for person network tables
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<Work>;
|
||||
public getWorkById(rawOaWorkId: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Work>>;
|
||||
public getWorkById(rawOaWorkId: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Work>>;
|
||||
public getWorkById(rawOaWorkId: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
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<Work>('get', `${basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
responseType: <any>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}
|
||||
|
||||
@@ -127,10 +127,11 @@
|
||||
@for (work of element.works; track $index) {
|
||||
<a
|
||||
class="link"
|
||||
[routerLink]="[
|
||||
'/publication',
|
||||
this.stripOpenAlexIdPrefix(work.id),
|
||||
]">
|
||||
[routerLink]="['/publication', this.stripOpenAlexIdPrefix(work.id)]"
|
||||
[appComponentTooltip]="AppPublicationTooltipComponent"
|
||||
[tooltipInputs]="{
|
||||
workId: this.stripOpenAlexIdPrefix(work.id),
|
||||
}">
|
||||
<li>{{ work.display_name }}</li>
|
||||
</a>
|
||||
}
|
||||
@@ -145,7 +146,11 @@
|
||||
[routerLink]="[
|
||||
'/institution',
|
||||
this.stripOpenAlexIdPrefix(institution.id),
|
||||
]">
|
||||
]"
|
||||
[appComponentTooltip]="AppInstitutionTooltipComponent"
|
||||
[tooltipInputs]="{
|
||||
institutionId: this.stripOpenAlexIdPrefix(institution.id),
|
||||
}">
|
||||
<li>{{ institution.display_name }}</li>
|
||||
</a>
|
||||
}
|
||||
@@ -175,11 +180,15 @@
|
||||
@for (collaborator of element.authors; track $index) {
|
||||
<li>
|
||||
<a
|
||||
class="person-link"
|
||||
class="link"
|
||||
[routerLink]="[
|
||||
'/person',
|
||||
this.stripOpenAlexIdPrefix(collaborator.id),
|
||||
]">
|
||||
]"
|
||||
[appComponentTooltip]="AppAuthorTooltipComponent"
|
||||
[tooltipInputs]="{
|
||||
authorId: this.stripOpenAlexIdPrefix(collaborator.id),
|
||||
}">
|
||||
{{ collaborator.display_name }}
|
||||
</a>
|
||||
</li>
|
||||
@@ -214,7 +223,11 @@
|
||||
[routerLink]="[
|
||||
'/person',
|
||||
this.stripOpenAlexIdPrefix(collaborator.id),
|
||||
]">
|
||||
]"
|
||||
[appComponentTooltip]="AppAuthorTooltipComponent"
|
||||
[tooltipInputs]="{
|
||||
authorId: this.stripOpenAlexIdPrefix(collaborator.id),
|
||||
}">
|
||||
{{ collaborator.display_name }}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -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<StartCollaborationGraphResponse>();
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@let work = this._work();
|
||||
|
||||
@if (work) {
|
||||
<app-publication-card [work]="work" />
|
||||
}
|
||||
@@ -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<string>();
|
||||
|
||||
_work = signal<Work | undefined>(undefined);
|
||||
|
||||
_isLoading = signal<boolean>(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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user