diff --git a/service/src/main/inse/works/logic.py b/service/src/main/inse/works/logic.py index 40e2c9f1..0addb229 100644 --- a/service/src/main/inse/works/logic.py +++ b/service/src/main/inse/works/logic.py @@ -39,6 +39,7 @@ async def get_author_works( language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + search: str | None = None, client: OpenAlexWorksSearchClient | None = None, ) -> WorkPage: search_client = client or OpenAlexWorksSearchClient() @@ -52,6 +53,7 @@ async def get_author_works( language=language, institution_id=institution_id, topic_id=topic_id, + search=search, ) elements, total = _parse_full_work_search_response(data) @@ -469,6 +471,7 @@ async def _search_author_works_data( language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + search: str | None = None, ) -> dict: try: return await search_client.search_author_works( @@ -480,6 +483,7 @@ async def _search_author_works_data( language=language, institution_id=institution_id, topic_id=topic_id, + search=search, ) except MissingApiKeyError as exc: logger.error("OpenAlex works Elasticsearch API key is not configured.") diff --git a/service/src/main/inse/works/search_client.py b/service/src/main/inse/works/search_client.py index 36b1b3bb..11e532ee 100644 --- a/service/src/main/inse/works/search_client.py +++ b/service/src/main/inse/works/search_client.py @@ -42,6 +42,7 @@ class OpenAlexWorksSearchClient: language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + search: str | None = None, ) -> dict[str, Any]: indexed_author_id = f"https://openalex.org/{author_id.strip()}" filters = self._work_filters( @@ -80,6 +81,15 @@ class OpenAlexWorksSearchClient: }, }, }) + if search and search.strip(): + must_clauses.append({ + "match": { + "title": { + "query": search.strip(), + "operator": "and", + }, + }, + }) return { "from": (page - 1) * size, "size": size, @@ -136,6 +146,7 @@ class OpenAlexWorksSearchClient: language: list[str] | None = None, institution_id: list[str] | None = None, topic_id: list[str] | None = None, + search: str | None = None, ) -> dict[str, Any]: if not self.api_key: raise MissingApiKeyError("OpenAlex works Elasticsearch API key is not configured.") @@ -157,6 +168,7 @@ class OpenAlexWorksSearchClient: language=language, institution_id=institution_id, topic_id=topic_id, + search=search, ), ) # logging.debug(f"Response: {response.text}") diff --git a/service/src/main/inse/works/service.py b/service/src/main/inse/works/service.py index e0d84c57..ea2f266a 100644 --- a/service/src/main/inse/works/service.py +++ b/service/src/main/inse/works/service.py @@ -56,6 +56,10 @@ async def get_author_works( list[str] | None, Query(description="Filter by OpenAlex topic id. Can be repeated."), ] = None, + search: Annotated[ + str | None, + Query(description="Search publication titles."), + ] = None, principal: security.Principal = Depends( security.roles_allowed(["SUPER_ADMIN", "UNI_ADMIN"]) ), @@ -69,6 +73,7 @@ async def get_author_works( language=language, institution_id=institution_id, topic_id=topic_id, + search=search, ) diff --git a/service/src/main/inse/works/test_search_client.py b/service/src/main/inse/works/test_search_client.py index 0bfe1a44..ac28ebb2 100644 --- a/service/src/main/inse/works/test_search_client.py +++ b/service/src/main/inse/works/test_search_client.py @@ -152,6 +152,26 @@ def test_author_works_query_adds_topic_filter(): ] +def test_author_works_query_adds_title_search(): + client = OpenAlexWorksSearchClient(api_key="test-key") + + query = client.author_works_query( + "A5023888391", + page=1, + size=20, + search="machine learning", + ) + + assert query["query"]["bool"]["must"][1] == { + "match": { + "title": { + "query": "machine learning", + "operator": "and", + }, + }, + } + + @pytest.mark.anyio async def test_search_author_works_passes_institution_filter_to_query(): def handler(request: httpx.Request) -> httpx.Response: diff --git a/webapp/src/app/api/api/works.service.ts b/webapp/src/app/api/api/works.service.ts index 20d855a3..ed802a33 100644 --- a/webapp/src/app/api/api/works.service.ts +++ b/webapp/src/app/api/api/works.service.ts @@ -173,6 +173,7 @@ 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 search Search publication titles. * @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. */ @@ -185,6 +186,7 @@ export class WorksService extends BaseService { language?: Array, institutionId?: Array, topicId?: Array, + search?: string, observe?: 'body', reportProgress?: boolean, options?: { @@ -202,6 +204,7 @@ export class WorksService extends BaseService { language?: Array, institutionId?: Array, topicId?: Array, + search?: string, observe?: 'response', reportProgress?: boolean, options?: { @@ -219,6 +222,7 @@ export class WorksService extends BaseService { language?: Array, institutionId?: Array, topicId?: Array, + search?: string, observe?: 'events', reportProgress?: boolean, options?: { @@ -236,6 +240,7 @@ export class WorksService extends BaseService { language?: Array, institutionId?: Array, topicId?: Array, + search?: string, observe: any = 'body', reportProgress: boolean = false, options?: { @@ -306,6 +311,11 @@ export class WorksService extends BaseService { ); }); } + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + search, + 'search', + ); let localVarHeaders = this.defaultHeaders; diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index dab2a1f0..1f7b3f08 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -8,8 +8,14 @@ import { institutionResolver } from './resolvers/institution.resolver'; import { bundProjectsResolver } from './resolvers/bund-projects.resolver'; import { euProjectsResolver } from './resolvers/eu-projects.resolver'; import { dfgProjectsResolver } from './resolvers/dfg-projects.resolver'; +import { publicationsResolver } from './resolvers/publications.resolver'; export const routes: Routes = [ + { + path: '', + pathMatch: 'full', + redirectTo: 'dashboard', + }, { path: 'login', loadComponent: () => @@ -120,6 +126,27 @@ export const routes: Routes = [ import('./modules/person-publications/person-publications.component').then( (mod) => mod.PersonPublicationsComponent, ), + resolve: { + publicationPage: publicationsResolver, + }, + runGuardsAndResolvers: (from, to) => { + const keys = [ + 'publicationPage', + 'publicationPageSize', + 'publicationYear', + 'publicationType', + 'publicationLanguage', + 'publicationInstitutionId', + 'publicationTopicId', + 'publicationSearch', + ]; + + return keys.some( + (key) => + from.queryParamMap.getAll(key).join(',') !== + to.queryParamMap.getAll(key).join(','), + ); + }, }, { path: 'network', 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 6da7971d..c283c5cf 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.html +++ b/webapp/src/app/modules/person-publications/person-publications.component.html @@ -5,6 +5,16 @@
+ + search + + +
- @if (loading) { -
- -
- } - @@ -180,12 +184,27 @@ - + + + + + +
Titel Sprache / QuelleSprache {{ publication.language || '-' }} Publisher + @if (publication.primary_location?.source?.display_name) { + + {{ publication.primary_location.source.display_name }} + + } @else { + - + } + Institutionen @@ -244,7 +263,7 @@
- @if (!loading && publications.length === 0) { + @if (publications.length === 0) {
Keine Publikationen 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 e6d4fe76..2f69b485 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.scss +++ b/webapp/src/app/modules/person-publications/person-publications.component.scss @@ -46,6 +46,10 @@ h2 { width: 150px; } +.publication-filters .publication-search { + width: 320px; +} + .publication-filters .institution-filter, .publication-filters .topic-filter { width: 320px; @@ -164,7 +168,7 @@ h2 { table { width: 100%; - min-width: 1120px; + min-width: 1240px; border-collapse: separate; border-spacing: 0 10px; overflow: hidden; @@ -193,15 +197,6 @@ a.title:hover { font-size: 12px; } -.loading { - position: absolute; - inset: 0; - z-index: 1; - display: grid; - place-items: center; - background: rgba(255, 255, 255, 0.65); -} - .empty-state { padding: 28px; text-align: center; @@ -213,6 +208,14 @@ a.title:hover { color: rgba(0, 0, 0, 0.54); } +.publication-source { + display: inline-block; + max-width: 220px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + .topic-chips { display: flex; flex-wrap: wrap; @@ -336,7 +339,8 @@ mat-paginator { } .publication-filters .institution-filter, - .publication-filters .topic-filter { + .publication-filters .topic-filter, + .publication-filters .publication-search { width: 100%; } diff --git a/webapp/src/app/modules/person-publications/person-publications.component.ts b/webapp/src/app/modules/person-publications/person-publications.component.ts index 8ab1923f..08fad8fe 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.ts +++ b/webapp/src/app/modules/person-publications/person-publications.component.ts @@ -18,8 +18,6 @@ import { MatPaginatorModule, PageEvent, } from '@angular/material/paginator'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { MatTableModule } from '@angular/material/table'; import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; @@ -37,9 +35,8 @@ import { switchMap, } from 'rxjs'; -import { Work, WorksService } from '../../api'; +import { Work, WorkPage, WorksService } from '../../api'; import { PaginationService } from '../../shared/services/pagination.service'; -import { createLoadError } from '../../shared/utils/errorHandler'; import { ChipComponent } from '../../shared/ui/chip/chip.component'; interface InstitutionAutocompleteOption { @@ -73,6 +70,7 @@ interface TopicAutocompleteResponse { interface PublicationFilterQueryState { pageIndex: number; pageSize: number; + search: string; publicationYears: number[]; types: string[]; languages: string[]; @@ -90,9 +88,7 @@ interface PublicationFilterQueryState { MatFormFieldModule, MatInputModule, MatPaginatorModule, - MatProgressSpinnerModule, MatSelectModule, - MatSnackBarModule, MatTableModule, ReactiveFormsModule, RouterLink, @@ -109,21 +105,21 @@ export class PersonPublicationsComponent implements OnInit { 'type', 'year', 'language', + 'publisher', 'institutions', 'topics', 'citations', ]; publications: Work[] = []; total = 0; - loading = false; institutionLookupLoading = false; topicLookupLoading = false; - authorId = ''; currentPageIndex = 0; institutionOptions: InstitutionAutocompleteOption[] = []; selectedInstitutions: InstitutionAutocompleteOption[] = []; topicOptions: TopicAutocompleteOption[] = []; selectedTopics: TopicAutocompleteOption[] = []; + readonly publicationSearchControl = new FormControl('', { nonNullable: true }); readonly institutionSearchControl = new FormControl< string | InstitutionAutocompleteOption >('', { nonNullable: true }); @@ -151,6 +147,7 @@ export class PersonPublicationsComponent implements OnInit { institutionNames: 'publicationInstitutionName', topicIds: 'publicationTopicId', topicNames: 'publicationTopicName', + search: 'publicationSearch', } as const; readonly typeOptions = [ @@ -186,57 +183,19 @@ export class PersonPublicationsComponent implements OnInit { private readonly workService: WorksService, private readonly httpClient: HttpClient, public readonly paginationService: PaginationService, - private readonly snackBar: MatSnackBar, ) {} ngOnInit(): void { + this.setupPublicationSearch(); this.setupInstitutionAutocomplete(); this.setupTopicAutocomplete(); - const parentParamMap = this.route.parent?.paramMap; - if (!parentParamMap) return; - - combineLatest([parentParamMap, this.route.queryParamMap]) + combineLatest([this.route.data, this.route.queryParamMap]) .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe(([params, queryParams]) => { - this.authorId = params.get('id') ?? ''; + .subscribe(([data, queryParams]) => { const queryState = this.parsePublicationFilterQueryParams(queryParams); this.applyPublicationFilterQueryState(queryState); - this.load(queryState.pageIndex, queryState.pageSize); - }); - } - - load(pageIndex = 0, pageSize = this.paginationService.selection): void { - console.log('Loading publications for author ID:', this.authorId); - - if (!this.authorId) return; - - this.loading = true; - this.workService - .getAuthorWorks( - this.authorId, - pageIndex + 1, - pageSize, - this.filters().publicationYears, - this.filters().types, - this.filters().languages, - this.selectedInstitutionIds(), - this.selectedTopicIds(), - ) - .subscribe({ - next: (page) => { - this.publications = page.elements ?? []; - this.total = page.total ?? 0; - this.loading = false; - }, - error: (error) => { - this.loading = false; - createLoadError( - this.snackBar, - () => this.load(pageIndex, pageSize), - 'Publikationen konnten nicht geladen werden', - )(error); - }, + this.applyPublicationPage(data['publicationPage'] as WorkPage); }); } @@ -266,6 +225,7 @@ export class PersonPublicationsComponent implements OnInit { }); this.selectedInstitutions = []; this.selectedTopics = []; + this.publicationSearchControl.setValue('', { emitEvent: false }); this.institutionOptions = []; this.topicOptions = []; this.institutionSearchControl.setValue('', { emitEvent: false }); @@ -280,6 +240,7 @@ export class PersonPublicationsComponent implements OnInit { [this.queryParamKeys.institutionNames]: null, [this.queryParamKeys.topicIds]: null, [this.queryParamKeys.topicNames]: null, + [this.queryParamKeys.search]: null, }); } @@ -379,6 +340,27 @@ export class PersonPublicationsComponent implements OnInit { }; } + private applyPublicationPage(page: WorkPage): void { + this.publications = page.elements ?? []; + this.total = page.total ?? 0; + } + + private setupPublicationSearch(): void { + this.publicationSearchControl.valueChanges + .pipe( + map((value) => value.trim()), + debounceTime(350), + distinctUntilChanged(), + takeUntilDestroyed(this.destroyRef), + ) + .subscribe((search) => { + this.updatePublicationFilterQueryParams({ + [this.queryParamKeys.page]: 1, + [this.queryParamKeys.search]: search || null, + }); + }); + } + private setupInstitutionAutocomplete(): void { this.institutionSearchControl.valueChanges .pipe( @@ -535,6 +517,7 @@ export class PersonPublicationsComponent implements OnInit { queryParams.get(this.queryParamKeys.pageSize), this.paginationService.selection, ), + search: queryParams.get(this.queryParamKeys.search)?.trim() ?? '', publicationYears: this.parseNumberParams( queryParams.getAll(this.queryParamKeys.years), ), @@ -562,6 +545,9 @@ export class PersonPublicationsComponent implements OnInit { this.paginationService.selection = queryState.pageSize; this.selectedInstitutions = queryState.institutions; this.selectedTopics = queryState.topics; + this.publicationSearchControl.setValue(queryState.search, { + emitEvent: false, + }); this.filterForm.setValue( { publicationYears: queryState.publicationYears, diff --git a/webapp/src/app/modules/publication-detail/publication-detail.component.html b/webapp/src/app/modules/publication-detail/publication-detail.component.html index 7e9001cb..bcb6fb99 100644 --- a/webapp/src/app/modules/publication-detail/publication-detail.component.html +++ b/webapp/src/app/modules/publication-detail/publication-detail.component.html @@ -107,15 +107,17 @@
- @if (abstractText(); as abstract) { -
-
- subject -

Abstract

-
+
+
+ subject +

Abstract

+
+ @if (abstractText(); as abstract) {

{{ abstract }}

-
- } + } @else { +

Kein Abstract verfügbar.

+ } +
@@ -261,6 +263,12 @@
Sprache
{{ publication.language || '-' }}
+
+
Publisher
+
+ {{ publication.primary_location?.source?.display_name || '-' }} +
+
Open Access
{{ openAccessLabel() }}
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 2eeb7feb..5d9604db 100644 --- a/webapp/src/app/modules/publication-detail/publication-detail.component.ts +++ b/webapp/src/app/modules/publication-detail/publication-detail.component.ts @@ -73,6 +73,11 @@ export class PublicationDetailComponent implements OnInit { } abstractText(): string | null { + const plainAbstract = ( + this.publication as (Work & { abstract?: string | null }) | null + )?.abstract?.trim(); + if (plainAbstract) return plainAbstract; + const index = this.publication?.abstract_inverted_index; if (!index || typeof index !== 'object') return null; diff --git a/webapp/src/app/resolvers/publications.resolver.ts b/webapp/src/app/resolvers/publications.resolver.ts new file mode 100644 index 00000000..8cd9afdc --- /dev/null +++ b/webapp/src/app/resolvers/publications.resolver.ts @@ -0,0 +1,36 @@ +import { inject } from '@angular/core'; +import { ResolveFn } from '@angular/router'; +import { WorkPage, WorksService } from '../api'; +import { PaginationService } from '../shared/services/pagination.service'; + +export const publicationsResolver: ResolveFn = (route) => { + const authorId = route.parent?.paramMap.get('id'); + if (!authorId) { + throw new Error('Author ID is required to resolve publications'); + } + + const params = route.queryParamMap; + const pageSize = inject(PaginationService).selection; + + return inject(WorksService).getAuthorWorks( + authorId, + parsePositiveInteger(params.get('publicationPage'), 1), + parsePositiveInteger(params.get('publicationPageSize'), pageSize), + params + .getAll('publicationYear') + .map(Number) + .filter(Number.isInteger), + params.getAll('publicationType').filter(Boolean), + params.getAll('publicationLanguage').filter(Boolean), + params.getAll('publicationInstitutionId').filter(Boolean), + params.getAll('publicationTopicId').filter(Boolean), + params.get('publicationSearch')?.trim() || undefined, + ); +}; + +function parsePositiveInteger(value: string | null, fallback: number): number { + const parsedValue = Number(value); + return Number.isInteger(parsedValue) && parsedValue > 0 + ? parsedValue + : fallback; +}