diff --git a/service/src/main/inse/integrations/elasticsearch.py b/service/src/main/inse/integrations/elasticsearch.py index 2bb78629..654cf455 100644 --- a/service/src/main/inse/integrations/elasticsearch.py +++ b/service/src/main/inse/integrations/elasticsearch.py @@ -45,7 +45,7 @@ def search( } } - with httpx.Client() as client: + with httpx.Client(timeout=httpx.Timeout(30.0)) as client: response = client.post( f"{config.settings.elasticsearch_url}/{index}/_search", json=payload, diff --git a/service/src/main/inse/persons/logic.py b/service/src/main/inse/persons/logic.py index d7b70048..409ce5ae 100644 --- a/service/src/main/inse/persons/logic.py +++ b/service/src/main/inse/persons/logic.py @@ -19,7 +19,7 @@ from inse.models.openalex.authors_list_response import AuthorsListResponse from inse import util from inse.integrations import elasticsearch from inse.models.openalex.meta import Meta -from inse.persons.query_builder import build_authors_search +from inse.persons.query_builder import build_authors_search_rescored from inse.persons.model import CustomAuthor, CustomAuthorsListResponse, PersonSearchRequest logger = logging.getLogger(__name__) INDEX_NAME="openalex-authors" @@ -237,30 +237,6 @@ def get_person_by_id(author_id: str, include: Optional[str] = None) -> AuthorsLi return AuthorsListResponse(results=persons) - -def get_person_by_id(author_id: str, include: Optional[str] = None) -> AuthorsListResponse: - body = { - "_source":include.split(",") if include else True, - } - - try: - hit = elasticsearch.get( - index="openalex-authors", - body=body, - doc_id=author_id - ) - except NotFoundError: - raise HTTPException( - status_code=404, detail=f"Person with id {author_id} not found" - ) - - except ApiError as e: - raise HTTPException(status_code=500, detail=f"Elasticsearch error: {str(e)}") - persons = [util.get_persons_data(hit)] - - return AuthorsListResponse(results=persons) - - def search_persons_by_name( author_name: str, limit: Optional[int] = 10, page_offset: Optional[int] = 0, include: Optional[str] = None ) -> AuthorsListResponse: @@ -473,6 +449,8 @@ def _enrich_author_data(author_data) -> Optional[CustomAuthor]: def advanced_search_persons( query: Optional[str] = None, institution_name: Optional[str] = None, + sort_by: Optional[str] = None, + sort_order: Optional[str] = None, topics: Optional[List[str]] = None, page: int = 1, page_size: int = 10, @@ -482,9 +460,11 @@ def advanced_search_persons( filter_year: Optional[int] = None, ) -> CustomAuthorsListResponse: try: - query_body = build_authors_search( + query_body = build_authors_search_rescored( query=query, institution_name=institution_name, + sort_by=sort_by, + sort_order=sort_order, topics=topics, page=page, page_size=page_size, diff --git a/service/src/main/inse/persons/query_builder.py b/service/src/main/inse/persons/query_builder.py index 279bfb98..a258b99a 100644 --- a/service/src/main/inse/persons/query_builder.py +++ b/service/src/main/inse/persons/query_builder.py @@ -1,11 +1,241 @@ # -*- coding: utf-8 -*- from typing import List, Optional, Set, Any +import json +# def build_authors_search( +# using: Any = None, +# index: Optional[str] = None, +# query: Optional[str] = None, +# institution_name: Optional[str] = None, +# sort_by: Optional[str] = None, +# sort_order: Optional[str] = None, +# topics: Optional[List[str]] = None, +# page: int = 1, +# page_size: int = 10, +# include: Optional[Set[str]] = None, +# strict: Optional[bool] = False, +# track_total_hits: Optional[bool] = False, +# filter_mode: Optional[str] = "from", +# filter_year: Optional[int] = None, +# ) -> dict: +# """ +# Builds an Elasticsearch search request query body for authors as a dictionary. +# """ +# # 1. Build Query Clauses +# query_clause = None +# if query: +# query_clause = { +# "bool": { +# "should": [ +# { +# "match_phrase": { +# "display_name": { +# "query": query, +# "boost": 5 +# } +# } +# }, +# { +# "match_phrase_prefix": { +# "display_name": { +# "query": query, +# "boost": 3 +# } +# } +# }, +# { +# "match": { +# "display_name": { +# "query": query, +# "fuzziness": 1 +# } +# } +# } +# ], +# "minimum_should_match": 1 +# } +# } -def build_authors_search( +# # 2. Build Filters +# filter_clauses = [] + +# # Filter against false entries (nested ((Works > 2 AND Year > 2020) OR has last_known_institution)) +# filter_clauses.append({ +# "bool": { +# "should": [ +# { +# "bool": { +# "filter": [ +# { +# "range": { "works_count": { "gt": 2 } } +# }, +# { +# "nested": { +# "path": "counts_by_year", +# "query": { +# "range": { "counts_by_year.year": { "gt": 2020 } } # hardcoded for now +# } +# } +# } +# ] +# } +# }, +# { +# "nested": { +# "path": "last_known_institutions", +# "query": { +# "exists": { +# "field": "last_known_institutions.id" +# } +# } +# } +# } + +# ], +# "minimum_should_match": 1 +# } +# }) +# # Institution filter with optional year-based filtering +# if institution_name: +# if filter_year is not None: +# target_year = filter_year +# mode = filter_mode or "from" +# else: +# from datetime import datetime +# current_year = datetime.now().year +# target_year = current_year - 1 +# mode = "from" + +# range_query = {"gte": target_year} +# if mode == "in": +# range_query["lte"] = target_year + +# if strict: +# filter_clauses.append({ +# "nested": { +# "path": "affiliations", +# "query": { +# "bool": { +# "filter": [ +# { +# "match_phrase": { +# "affiliations.institution.display_name": institution_name +# } +# }, +# { +# "range": { +# "affiliations.years": range_query +# } +# } +# ] +# } +# } +# } +# }) +# else: +# filter_clauses.append({ +# "bool": { +# "filter": [ +# { +# "nested": { +# "path": "last_known_institutions", +# "query": { +# "match_phrase": { +# "last_known_institutions.display_name": institution_name +# } +# } +# } +# }, +# { +# "nested": { +# "path": "affiliations", +# "query": { +# "bool": { +# "filter": [ +# { +# "match_phrase": { +# "affiliations.institution.display_name": institution_name +# } +# }, +# { +# "range": { +# "affiliations.years": range_query +# } +# } +# ] +# } +# } +# } +# } +# ] +# } +# }) + +# if topics: +# for t in topics: +# if t: +# filter_clauses.append({ +# "nested": { +# "path": "topics", +# "query": { +# "match_phrase": { +# "topics.display_name": t +# } +# } +# } +# }) + +# # Combine query and filters +# body = {} +# if query_clause: +# if filter_clauses: +# body["query"] = { +# "bool": { +# "must": [query_clause], +# "filter": filter_clauses +# } +# } +# else: +# body["query"] = query_clause +# else: +# if filter_clauses: +# body["query"] = { +# "bool": { +# "filter": filter_clauses +# } +# } +# else: +# body["query"] = { +# "match_all": {} +# } + +# # 3. Source Filtering +# if include: +# body["_source"] = list(include) +# else: +# body["_source"] = True + +# # 4. Pagination +# es_size = page_size +# es_from = (page - 1) * page_size +# body["from"] = es_from +# body["size"] = es_size +# body["track_total_hits"] = track_total_hits + +# # 5. Sorting +# if sort_by and sort_order: +# body["sort"] = [ +# {sort_by: {"order": sort_order}}, +# ] +# return body + + +def build_authors_search_rescored( using: Any = None, index: Optional[str] = None, query: Optional[str] = None, institution_name: Optional[str] = None, + sort_by: Optional[str] = None, + sort_order: Optional[str] = None, topics: Optional[List[str]] = None, page: int = 1, page_size: int = 10, @@ -13,7 +243,12 @@ def build_authors_search( strict: Optional[bool] = False, track_total_hits: Optional[bool] = False, filter_mode: Optional[str] = "from", - filter_year: Optional[int] = None + filter_year: Optional[int] = None, + name_quality_boost = True, + h_index_boost = True, + citations_boost =True, + works_boost = True, + _2yr_mean_citedness_boost = True, ) -> dict: """ Builds an Elasticsearch search request query body for authors as a dictionary. @@ -43,8 +278,7 @@ def build_authors_search( { "match": { "display_name": { - "query": query, - "fuzziness": 1 + "query": query } } } @@ -167,7 +401,7 @@ def build_authors_search( ] } }) - + if topics: for t in topics: if t: @@ -181,30 +415,123 @@ def build_authors_search( } } }) + functions = [] + if not sort_by: + + if (name_quality_boost): # Name quality boost, boost names which are not "Value Value" + name_boost_query={ + "script_score": { + "script": { + "lang": "painless", + "source": "String name = doc['display_name.keyword'].value.toLowerCase(); String[] parts = name.splitOnToken(' ');Set unique = new HashSet();for (String p : parts) { unique.add(p); }return unique.size() > 1 ? 1.0 : 0.3;" + } + } + } + functions.append(name_boost_query) + if (h_index_boost): # h_index boost + h_index_boost_query={ + "script_score": { + "script": { + "lang": "painless", + "source": "if (!doc.containsKey('summary_stats.h_index') || doc['summary_stats.h_index'].empty) return 1.0;double h = doc['summary_stats.h_index'].value;return 1.0 + Math.log1p(h) / 5.0;" + } + } + } + functions.append(h_index_boost_query) + if (citations_boost): # cited_by_count boost + cited_by_count_boost_query = { + "script_score": { + "script": { + "lang": "painless", + "source": "if (!doc.containsKey('cited_by_count') || doc['cited_by_count'].empty) return 1.0;double citations = doc['cited_by_count'].value;return 1.0 + Math.log1p(citations) / 10.0;" + } + } + } + functions.append(cited_by_count_boost_query) + if (_2yr_mean_citedness_boost): # 2yr mean citedness boost + mean_citedness_boost_query = { + "script_score": { + "script": { + "lang": "painless", + "source": "if (!doc.containsKey('summary_stats.2yr_mean_citedness') || doc['summary_stats.2yr_mean_citedness'].empty) return 1.0;double recent = doc['summary_stats.2yr_mean_citedness'].value;return 1.0 + Math.log1p(recent) / 8.0;" + } + } + } + functions.append(mean_citedness_boost_query) + + if (works_boost): # works_count boost + works_count_boost_query = { + "script_score": { + "script": { + "lang": "painless", + "source": "if (!doc.containsKey('works_count') || doc['works_count'].empty) return 1.0;double works = doc['works_count'].value;return 1.0 + Math.log1p(works) / 8.0;" + } + } + } + functions.append(works_count_boost_query) # Combine query and filters body = {} - if query_clause: - if filter_clauses: - body["query"] = { - "bool": { - "must": [query_clause], - "filter": filter_clauses + + if functions: + inner_query = None + if query_clause: + if filter_clauses: + inner_query = { + "bool": { + "must": [query_clause], + "filter": filter_clauses + } + } + else: + inner_query = query_clause + # if query not null then multiply with name matching + body["query"] = { + "function_score": { + "query": inner_query, + "functions": functions, + "score_mode": "multiply", + "boost_mode": "multiply" } } else: - body["query"] = query_clause + if filter_clauses: + inner_query = { + "bool": { + "filter": filter_clauses + } + } + else: + inner_query = {"match_all": {}} + # if the query is null, replace the scoring completely + body["query"] = { + "function_score": { + "query": inner_query, + "functions": functions, + "score_mode": "multiply", + "boost_mode": "replace" + } + } else: - if filter_clauses: - body["query"] = { - "bool": { - "filter": filter_clauses + if query_clause: + if filter_clauses: + body["query"] = { + "bool": { + "must": [query_clause], + "filter": filter_clauses + } } - } + else: + body["query"] = query_clause else: - body["query"] = { - "match_all": {} - } + if filter_clauses: + body["query"] = { + "bool": { + "filter": filter_clauses + } + } + else: + body["query"] = {"match_all": {}} # 3. Source Filtering if include: @@ -220,11 +547,9 @@ def build_authors_search( body["track_total_hits"] = track_total_hits # 5. Sorting - if not query: + if sort_by and sort_order: body["sort"] = [ - {"cited_by_count": {"order": "desc"}}, - {"works_count": {"order": "desc"}} + {sort_by: {"order": sort_order}}, ] - return body diff --git a/service/src/main/inse/persons/service.py b/service/src/main/inse/persons/service.py index a2000ab9..35034d82 100644 --- a/service/src/main/inse/persons/service.py +++ b/service/src/main/inse/persons/service.py @@ -190,6 +190,12 @@ def search_persons_list( institution_name: Annotated[ Optional[str], Query(alias="institutionName", description="Filter by institution name") ] = None, + sort_by: Annotated[ + Optional[str], Query(alias="sortBy", description="Value to sort by") + ] = None, + sort_order: Annotated[ + Optional[str], Query(alias="sortOrder", description="asc or desc?") + ] = None, topic: Annotated[ Optional[List[str]], Query(description="Filter by topic display names") ] = None, @@ -224,6 +230,8 @@ def search_persons_list( return logic.advanced_search_persons( query=query, institution_name=institution_name, + sort_by=sort_by, + sort_order=sort_order, topics=topic, page=page, page_size=page_size, diff --git a/webapp/src/app/api/api/persons.service.ts b/webapp/src/app/api/api/persons.service.ts index da1cde14..141555ce 100644 --- a/webapp/src/app/api/api/persons.service.ts +++ b/webapp/src/app/api/api/persons.service.ts @@ -1371,6 +1371,8 @@ export class PersonsService * @endpoint get /api/inse-service/persons/search-list * @param query Search query (e.g., Arman AND Arzani) * @param institutionName Filter by institution name + * @param sortBy Value to sort by + * @param sortOrder asc or desc? * @param topic Filter by topic display names * @param page Page number (1-indexed) * @param pageSize Results per page @@ -1384,6 +1386,8 @@ export class PersonsService public searchPersonsList( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1402,6 +1406,8 @@ export class PersonsService public searchPersonsList( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1420,6 +1426,8 @@ export class PersonsService public searchPersonsList( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1438,6 +1446,8 @@ export class PersonsService public searchPersonsList( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1464,6 +1474,16 @@ export class PersonsService institutionName, 'institutionName', ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sortBy, + 'sortBy', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sortOrder, + 'sortOrder', + ); if (topic) { topic.forEach((element) => { localVarQueryParameters = this.addToHttpParams( @@ -1559,6 +1579,8 @@ export class PersonsService * @endpoint get /api/inse-service/persons/search-list * @param query Search query (e.g., Arman AND Arzani) * @param institutionName Filter by institution name + * @param sortBy Value to sort by + * @param sortOrder asc or desc? * @param topic Filter by topic display names * @param page Page number (1-indexed) * @param pageSize Results per page @@ -1572,6 +1594,8 @@ export class PersonsService public searchPersonsList_5( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1590,6 +1614,8 @@ export class PersonsService public searchPersonsList_5( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1608,6 +1634,8 @@ export class PersonsService public searchPersonsList_5( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1626,6 +1654,8 @@ export class PersonsService public searchPersonsList_5( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -1652,6 +1682,16 @@ export class PersonsService institutionName, 'institutionName', ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sortBy, + 'sortBy', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sortOrder, + 'sortOrder', + ); if (topic) { topic.forEach((element) => { localVarQueryParameters = this.addToHttpParams( diff --git a/webapp/src/app/api/api/persons.serviceInterface.ts b/webapp/src/app/api/api/persons.serviceInterface.ts index d6b3e740..19c4be40 100644 --- a/webapp/src/app/api/api/persons.serviceInterface.ts +++ b/webapp/src/app/api/api/persons.serviceInterface.ts @@ -176,6 +176,8 @@ export interface PersonsServiceInterface { * @endpoint get /api/inse-service/persons/search-list * @param query Search query (e.g., Arman AND Arzani) * @param institutionName Filter by institution name + * @param sortBy Value to sort by + * @param sortOrder asc or desc? * @param topic Filter by topic display names * @param page Page number (1-indexed) * @param pageSize Results per page @@ -187,6 +189,8 @@ export interface PersonsServiceInterface { searchPersonsList( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, @@ -203,6 +207,8 @@ export interface PersonsServiceInterface { * @endpoint get /api/inse-service/persons/search-list * @param query Search query (e.g., Arman AND Arzani) * @param institutionName Filter by institution name + * @param sortBy Value to sort by + * @param sortOrder asc or desc? * @param topic Filter by topic display names * @param page Page number (1-indexed) * @param pageSize Results per page @@ -214,6 +220,8 @@ export interface PersonsServiceInterface { searchPersonsList_5( query?: string, institutionName?: string, + sortBy?: string, + sortOrder?: string, topic?: Array, page?: number, pageSize?: number, diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index b9139a9a..c19c5b60 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -3,6 +3,7 @@ import { userGuard } from './shared/guards/user.guard'; import { collaborationNetworkResolver } from './resolvers/collaboration-network.resolver'; import { personListResolver } from './resolvers/person-list.resolver'; import { personBioResolver } from './resolvers/person-bio.resolver'; +import { personResolver } from './resolvers/person.resolver'; export const routes: Routes = [ { @@ -36,6 +37,8 @@ export const routes: Routes = [ 'page', 'pageSize', 'institutionName', + 'sortBy', + 'sortOrder', 'yearFilterEnabled', 'filterMode', 'filterYear', @@ -73,6 +76,7 @@ export const routes: Routes = [ (mod) => mod.PersonComponent, ), resolve: { + personData: personResolver, personBio: personBioResolver, }, runGuardsAndResolvers: (from, to) => from.params['id'] !== to.params['id'], 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 5738c4e9..f2348b2b 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -56,10 +56,15 @@
Sortierung:
- + + + + + +
@@ -74,9 +79,9 @@ Sortiert nach Publikationen und Zitierungen--> - @if (sortedPersons.length) { + @if (getPersons().length) {
- @for (person of sortedPersons; track person.id) { + @for (person of getPersons(); track person.id) { (false); + readonly loadingState = computed(() => + this.resolverStateService.isResolvingInside('/persons'), + ); persons: CustomAuthor[] = []; total = 0; currentPage = 1; readonly institutionOptions = signal([]); readonly institutionLookupLoading = signal(false); + defaultOrderValue = 'desc'; + // Selected filter states selectedTopics = new Set(); searchValue = signal(null); @@ -98,7 +95,13 @@ export class PersonListComponent { appliedFilterYear = new Date().getFullYear() - 1; // Forms - sortControl = new FormControl('works', { nonNullable: true }); + sortValueControl = new FormControl(null, { + nonNullable: true, + }); + sortOrderControl = new FormControl( + { value: this.defaultOrderValue, disabled: this.isRelevanceSelected() }, + { nonNullable: true }, + ); topicSearchControl = new FormControl('', { nonNullable: true }); institutionControl = new FormControl('', { nonNullable: true }); yearFilterEnabledControl = new FormControl(false, { nonNullable: true }); @@ -116,22 +119,6 @@ export class PersonListComponent { // Bookmarking bookmarkedIds = new Set(); constructor() { - this.router.events - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((event) => { - if (event instanceof NavigationStart) { - this.loadingState.set(true); - } - - if ( - event instanceof NavigationEnd || - event instanceof NavigationCancel || - event instanceof NavigationError - ) { - this.loadingState.set(false); - } - }); - if (!this.institutionControl.value) { this.yearFilterEnabledControl.disable(); } @@ -154,6 +141,8 @@ export class PersonListComponent { ? Number.parseInt(params['pageSize'], 10) : 10; const institutionName = params['institutionName'] || ''; + const sortBy = params['sortBy'] || null; + const sortOrder = params['sortOrder'] || this.defaultOrderValue; const yearFilterEnabled = params['yearFilterEnabled'] === 'true'; const filterMode = params['filterMode'] === 'in' || params['filterMode'] === 'from' @@ -165,10 +154,17 @@ export class PersonListComponent { const topics = this.parseQueryParamArray(params['topic']); + // restore values from query params this.selectedTopics = new Set(topics); this.currentPage = page; this.paginationService.selection = pageSize; + if (this.sortValueControl.value !== sortBy) { + this.sortValueControl.setValue(sortBy, { emitEvent: false }); + this.sortOrderControl.setValue(sortOrder, { emitEvent: false }); + this.updateSortOrderState(this.sortValueControl.value); + } + // Sync search box & institution input if (this.searchValue() !== query) { this.searchValue.set(query || null); @@ -202,22 +198,44 @@ export class PersonListComponent { .subscribe(({ persons }) => { this.persons = (persons.results ?? []) as CustomAuthor[]; this.total = persons.meta?.count; - this.loadingState.set(false); + }); + + // listen for sorting selectors changes + this.sortValueControl.valueChanges + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe((value) => { + if (!value) { + this.sortOrderControl.setValue(this.defaultOrderValue, { + emitEvent: false, + }); + this.sortOrderControl.disable(); + } else { + this.sortOrderControl.enable(); + } + + this.applySidebarFilters(); + }); + + this.sortOrderControl.valueChanges + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { + this.applySidebarFilters(); }); } - // Getters for filtered results - get sortedPersons(): CustomAuthor[] { - const sorted = [...this.persons]; - const val = this.sortControl.value; - if (val === 'works') { - return sorted.sort((a, b) => (b.works_count ?? 0) - (a.works_count ?? 0)); - } else if (val === 'citations') { - return sorted.sort( - (a, b) => (b.cited_by_count ?? 0) - (a.cited_by_count ?? 0), - ); + private updateSortOrderState(value: any) { + if (!value) { + this.sortOrderControl.setValue(this.defaultOrderValue, { + emitEvent: false, + }); + this.sortOrderControl.disable({ emitEvent: false }); + } else { + this.sortOrderControl.enable({ emitEvent: false }); } - return sorted; + } + // Getters for filtered results + getPersons(): CustomAuthor[] { + return this.persons; } get loading(): boolean { @@ -229,6 +247,10 @@ export class PersonListComponent { return this.selectedTopics.has(topic); } + isRelevanceSelected(): boolean { + return !this.sortValueControl.value; + } + toggleTopic(topic: string): void { if (this.selectedTopics.has(topic)) { this.selectedTopics.delete(topic); @@ -298,6 +320,8 @@ export class PersonListComponent { ? Array.from(this.selectedTopics) : null, institutionName: this.institutionControl.value || null, + sortBy: this.sortValueControl.value || null, + sortOrder: this.sortOrderControl.value || null, yearFilterEnabled: this.institutionControl.value && this.yearFilterEnabledControl.value ? 'true' diff --git a/webapp/src/app/modules/person/person.component.html b/webapp/src/app/modules/person/person.component.html index 065b3638..ad1e8518 100644 --- a/webapp/src/app/modules/person/person.component.html +++ b/webapp/src/app/modules/person/person.component.html @@ -50,10 +50,10 @@
@if (isBioLoading()) { + [size]="150" + [diameter]="150"> } @else if (personBio() != null) {

Biografie

{{ personBio() }}

@@ -86,15 +86,11 @@ } @if (isNetworkResolving()) { -
-
- - - graph_3 - -
- Das Netzwerk wird gebaut, kleinen Moment... -
+ } @else { } diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index 0d975d90..2dd189ec 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -93,20 +93,9 @@ export class PersonComponent { readonly isBioLoading = signal(false); readonly person = toSignal( - toObservable(this.authorId).pipe( - switchMap((id) => { - if (!id) return of(null); - this.isPersonLoading.set(true); - return this.personsApi - .searchPersons(id, undefined, PERSON_INCLUDE_TAGS) - .pipe( - map((result) => result.results?.[0] ?? null), - catchError((err) => { - console.error('Failed to load person:', err); - return of(null); - }), - finalize(() => this.isPersonLoading.set(false)), - ); + this.activatedRoute.data.pipe( + map(({ personData }) => { + return personData?.results[0] ?? null; }), ), { initialValue: null }, diff --git a/webapp/src/app/resolvers/person-list.resolver.ts b/webapp/src/app/resolvers/person-list.resolver.ts index 6af7cfd6..793e225d 100644 --- a/webapp/src/app/resolvers/person-list.resolver.ts +++ b/webapp/src/app/resolvers/person-list.resolver.ts @@ -26,6 +26,8 @@ export const personListResolver: ResolveFn = ( : 10; const institutionName = params.get('institutionName') || undefined; + const sortBy= params.get('sortBy') || undefined; + const sortOrder= params.get('sortOrder') || undefined; const topicsParam = params.getAll('topic'); @@ -47,6 +49,8 @@ export const personListResolver: ResolveFn = ( return personsService.searchPersonsList( query, institutionName, + sortBy, + sortOrder, topics, page, pageSize, diff --git a/webapp/src/app/resolvers/person.resolver.ts b/webapp/src/app/resolvers/person.resolver.ts new file mode 100644 index 00000000..a20198f2 --- /dev/null +++ b/webapp/src/app/resolvers/person.resolver.ts @@ -0,0 +1,23 @@ +import { ResolveFn } from '@angular/router'; +import { inject } from '@angular/core'; +import { AuthorsListResponse, PersonsService } from '../api'; + +export const personResolver: ResolveFn = ( + route, + state, +) => { + const parseQueryParamArray = (val: any): string[] => { + if (!val) return []; + if (Array.isArray(val)) return val; + return [val]; + }; + const PERSON_INCLUDE_TAGS = + 'topics_full,topic_share,summary_stats,ids,last_known_institutions,' + + 'sources,counts_by_year,works_api_url,dates,cited_by_count_boost'; + const params = route.paramMap; + + const query = params.get('id') || undefined; + const personsService = inject(PersonsService); + + return personsService.searchPersons(query, undefined, PERSON_INCLUDE_TAGS); +}; diff --git a/webapp/src/app/shared/services/resolver-state.service.ts b/webapp/src/app/shared/services/resolver-state.service.ts index f3a3b79c..d992ae74 100644 --- a/webapp/src/app/shared/services/resolver-state.service.ts +++ b/webapp/src/app/shared/services/resolver-state.service.ts @@ -15,12 +15,6 @@ export class ResolverStateService { readonly previousUrl = signal(null); readonly isResolving = computed(() => this.resolvingUrl() !== null); - readonly isResolvingPersonsFromOutside = computed(() => { - const from = this.previousUrl(); - const to = this.resolvingUrl(); - if (!to?.startsWith('/persons')) return false; - return !from?.startsWith('/persons'); // came from outside - }); constructor() { this.router.events.subscribe((event) => { @@ -38,4 +32,19 @@ export class ResolverStateService { } }); } + + isResolvingFromOutside(path: string) { + const from = this.previousUrl(); + const to = this.resolvingUrl(); + if (!to?.startsWith(path)) return false; + return !from?.startsWith(path); // came from outside + } + + isResolvingInside(path: string) { + const from = this.previousUrl(); + const to = this.resolvingUrl(); + console.log(from, to, to?.startsWith(path) && from?.startsWith(path)); + if (to?.startsWith(path) && from?.startsWith(path)) return true; + return false; + } } diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.html b/webapp/src/app/shared/ui/app-layout/app-layout.component.html index b0149b11..1c3a8d9b 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.html +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.html @@ -39,12 +39,18 @@
- @if (resolverState.isResolvingPersonsFromOutside()) { + @if (resolverState.isResolvingFromOutside('/persons')) { + [size]="200" + [diameter]="200" /> + } @else if (resolverState.isResolvingFromOutside('/person/')) { + } @else { } diff --git a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html index e726bca1..1be92231 100644 --- a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html +++ b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html @@ -18,6 +18,7 @@ + person {{ person.display_name }} } diff --git a/webapp/src/app/shared/ui/loading/loading.component.html b/webapp/src/app/shared/ui/loading/loading.component.html index c85ce5c1..e8f07ec6 100644 --- a/webapp/src/app/shared/ui/loading/loading.component.html +++ b/webapp/src/app/shared/ui/loading/loading.component.html @@ -1,6 +1,8 @@
- + {{ icon }} diff --git a/webapp/src/app/shared/ui/loading/loading.component.ts b/webapp/src/app/shared/ui/loading/loading.component.ts index 4e658d55..2a317fd4 100644 --- a/webapp/src/app/shared/ui/loading/loading.component.ts +++ b/webapp/src/app/shared/ui/loading/loading.component.ts @@ -1,6 +1,7 @@ import { Component, Input } from '@angular/core'; import { MatProgressSpinner } from '@angular/material/progress-spinner'; import { MatIcon } from '@angular/material/icon'; +import { numberAttribute } from '@angular/core'; @Component({ selector: 'app-loading', imports: [MatProgressSpinner, MatIcon], @@ -10,6 +11,6 @@ import { MatIcon } from '@angular/material/icon'; export class LoadingComponent { @Input() text = 'Laden...'; @Input() icon = 'graph_3'; - @Input() size = '150'; - @Input() diameter = '150'; + @Input({ transform: numberAttribute }) size = 150; + @Input({ transform: numberAttribute }) diameter = 150; } diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index 852866e8..b69df54f 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -195,3 +195,27 @@ h3 { background-position: 600px 0; } } +.cdk-overlay-pane { + color: var(--sg-text); +} + +.cdk-overlay-pane .mat-mdc-option { + padding: 0 18px; + font-size: 13px; + background: var(--sg-surface-muted); + border-bottom: 1px solid var(--sg-border); +} + +.cdk-overlay-pane .mat-mdc-option:last-child { + border-bottom: none; +} + +.cdk-overlay-pane .mat-mdc-option mat-icon { + margin-right: 12px; + color: var(--sg-text-soft); +} + +.cdk-overlay-pane .mat-mdc-option:hover, +.cdk-overlay-pane .mat-mdc-option.mdc-list-item--focused { + background: rgba(0, 0, 0, 0.04); +} \ No newline at end of file