Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97928d8fff | ||
|
|
10cfb565ea | ||
|
|
de1ff24e35 | ||
|
|
bc31b9f3f5 | ||
|
|
1da8d9085d |
@@ -5,8 +5,9 @@ from .. import config
|
|||||||
|
|
||||||
def search(
|
def search(
|
||||||
index: str,
|
index: str,
|
||||||
query_field: str,
|
query_field: Optional[str] = None,
|
||||||
query_value: str
|
query_value: Optional[str] = None,
|
||||||
|
payload: Optional[dict[str, Any]] = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
@@ -14,6 +15,7 @@ def search(
|
|||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if payload is None:
|
||||||
payload = {
|
payload = {
|
||||||
"query": {
|
"query": {
|
||||||
"query_string": {
|
"query_string": {
|
||||||
@@ -25,7 +27,7 @@ def search(
|
|||||||
|
|
||||||
with httpx.Client() as client:
|
with httpx.Client() as client:
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f"{config.settings.elasticsearch_url}/{index}/_search",
|
f"{config.settings.elasticsearch_url.rstrip('/')}/{index}/_search",
|
||||||
json=payload,
|
json=payload,
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -255,6 +255,62 @@ def count_topic_hierarchy(topic_names: List[str]) -> dict:
|
|||||||
### persons
|
### persons
|
||||||
|
|
||||||
|
|
||||||
|
def list_persons(
|
||||||
|
page_offset: int = 0,
|
||||||
|
page_size: int = 20,
|
||||||
|
query: Optional[str] = None,
|
||||||
|
include: Optional[set[str]] = None,
|
||||||
|
) -> AuthorsListResponse:
|
||||||
|
payload = _author_list_query(page_offset, page_size, query)
|
||||||
|
data = elasticsearch.search(index="openalex-authors", payload=payload)
|
||||||
|
hits = data.get("hits", {}).get("hits", [])
|
||||||
|
persons = [util.get_persons_data(hit) for hit in hits]
|
||||||
|
total = _extract_total_hits(data)
|
||||||
|
return AuthorsListResponse(
|
||||||
|
results=persons,
|
||||||
|
meta=Meta(
|
||||||
|
count=total,
|
||||||
|
page=page_offset // page_size + 1 if page_size > 0 else 1,
|
||||||
|
per_page=page_size,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _author_list_query(
|
||||||
|
page_offset: int, page_size: int, query: Optional[str] = None
|
||||||
|
) -> dict:
|
||||||
|
search_query = {"match_all": {}}
|
||||||
|
if query:
|
||||||
|
search_query = {
|
||||||
|
"query_string": {
|
||||||
|
"fields": [
|
||||||
|
"display_name^3",
|
||||||
|
"display_name_alternatives",
|
||||||
|
"_id",
|
||||||
|
"ids.orcid",
|
||||||
|
],
|
||||||
|
"query": query,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"from": page_offset,
|
||||||
|
"size": page_size,
|
||||||
|
"query": search_query,
|
||||||
|
"sort": [
|
||||||
|
{"works_count": {"order": "desc", "missing": "_last"}},
|
||||||
|
{"cited_by_count": {"order": "desc", "missing": "_last"}},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_total_hits(data: dict) -> int:
|
||||||
|
total = data.get("hits", {}).get("total", 0)
|
||||||
|
if isinstance(total, dict):
|
||||||
|
return total.get("value", 0)
|
||||||
|
return total
|
||||||
|
|
||||||
|
|
||||||
def search_persons(
|
def search_persons(
|
||||||
author_id: Optional[str] = None,
|
author_id: Optional[str] = None,
|
||||||
query: Optional[str] = None,
|
query: Optional[str] = None,
|
||||||
|
|||||||
@@ -38,6 +38,3 @@ class ItemPage(Page[Item]):
|
|||||||
|
|
||||||
class PersonBio(BaseModel):
|
class PersonBio(BaseModel):
|
||||||
bio: str = Field(description="The generated biography.")
|
bio: str = Field(description="The generated biography.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -215,21 +215,23 @@ def count_topic_hierarchy(
|
|||||||
|
|
||||||
### persons
|
### persons
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
"/persons/search",
|
"/persons",
|
||||||
operation_id="searchPersons",
|
operation_id="getPersons",
|
||||||
response_model=AuthorsListResponse,
|
response_model=AuthorsListResponse,
|
||||||
summary="Searches for persons by ID or name.",
|
summary="Returns a page of OpenAlex authors.",
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
tags=["Persons"],
|
tags=["Persons"],
|
||||||
)
|
)
|
||||||
def search_persons(
|
def get_persons(
|
||||||
author_id: Annotated[
|
page_offset: Annotated[
|
||||||
str, Query(description="OpenAlex author ID (e.g., A5093075883)")
|
int, Query(alias="pageOffset", description="The page offset.", ge=0)
|
||||||
] = None,
|
] = 0,
|
||||||
|
page_size: Annotated[
|
||||||
|
int, Query(alias="pageSize", description="The page size.", ge=1, le=100)
|
||||||
|
] = 20,
|
||||||
query: Annotated[
|
query: Annotated[
|
||||||
str, Query(description="Search query (e.g., Arman AND Arzani)")
|
Optional[str], Query(description="Optional author search query.")
|
||||||
] = None,
|
] = None,
|
||||||
include: Annotated[
|
include: Annotated[
|
||||||
Optional[str],
|
Optional[str],
|
||||||
@@ -248,7 +250,9 @@ def search_persons(
|
|||||||
if include
|
if include
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
return logic.search_persons(author_id, query, include_set)
|
return logic.list_persons(
|
||||||
|
page_offset=page_offset, page_size=page_size, query=query, include=include_set
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from inse import logic
|
||||||
|
from inse import model
|
||||||
|
from inse.main import app
|
||||||
|
from inse.models.authors_list_response import AuthorsListResponse
|
||||||
|
from inse.models.meta import Meta
|
||||||
|
from inse.models.author import Author
|
||||||
|
from inse.models.author_ids import AuthorIds
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_persons_searches_openalex_authors(monkeypatch):
|
||||||
|
captured = {}
|
||||||
|
|
||||||
|
def fake_search(index, payload=None, **_):
|
||||||
|
captured["index"] = index
|
||||||
|
captured["payload"] = payload
|
||||||
|
return {
|
||||||
|
"hits": {
|
||||||
|
"total": {"value": 1},
|
||||||
|
"hits": [
|
||||||
|
{
|
||||||
|
"_id": "A5023888391",
|
||||||
|
"_source": {
|
||||||
|
"display_name": "Ada Lovelace",
|
||||||
|
"works_count": 42,
|
||||||
|
"cited_by_count": 1234,
|
||||||
|
"topics": [{"display_name": "Computer Science"}],
|
||||||
|
"affiliations": [
|
||||||
|
{
|
||||||
|
"institution": {
|
||||||
|
"display_name": "University of Example",
|
||||||
|
"country_code": "DE",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
monkeypatch.setattr(logic.elasticsearch, "search", fake_search)
|
||||||
|
|
||||||
|
page = logic.list_persons(page_offset=20, page_size=10, query="Ada")
|
||||||
|
|
||||||
|
assert captured["index"] == "openalex-authors"
|
||||||
|
assert captured["payload"]["from"] == 20
|
||||||
|
assert captured["payload"]["size"] == 10
|
||||||
|
assert captured["payload"]["query"]["query_string"]["query"] == "Ada"
|
||||||
|
assert page.meta.count == 1
|
||||||
|
assert page.results[0].id == "A5023888391"
|
||||||
|
assert page.results[0].display_name == "Ada Lovelace"
|
||||||
|
assert page.results[0].topics[0].display_name == "Computer Science"
|
||||||
|
assert page.results[0].affiliations[0].institution.display_name == "University of Example"
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_persons_uses_match_all_without_query(monkeypatch):
|
||||||
|
captured = {}
|
||||||
|
|
||||||
|
def fake_search(index, payload=None, **_):
|
||||||
|
captured["payload"] = payload
|
||||||
|
return {"hits": {"total": 0, "hits": []}}
|
||||||
|
|
||||||
|
monkeypatch.setattr(logic.elasticsearch, "search", fake_search)
|
||||||
|
|
||||||
|
page = logic.list_persons(page_offset=0, page_size=20)
|
||||||
|
|
||||||
|
assert captured["payload"]["query"] == {"match_all": {}}
|
||||||
|
assert page.results == []
|
||||||
|
assert page.meta.count == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_persons_endpoint_returns_page(monkeypatch):
|
||||||
|
def fake_list_persons(page_offset=0, page_size=20, query=None, include=None):
|
||||||
|
assert page_offset == 5
|
||||||
|
assert page_size == 10
|
||||||
|
assert query == "Ada"
|
||||||
|
assert include == {"ids"}
|
||||||
|
return AuthorsListResponse(
|
||||||
|
meta=Meta(
|
||||||
|
count=1,
|
||||||
|
page=1,
|
||||||
|
per_page=10
|
||||||
|
),
|
||||||
|
results=[
|
||||||
|
Author(
|
||||||
|
id="A5023888391",
|
||||||
|
display_name="Ada Lovelace",
|
||||||
|
works_count=42,
|
||||||
|
cited_by_count=1234,
|
||||||
|
affiliations=[],
|
||||||
|
topics=[],
|
||||||
|
ids=AuthorIds(openalex="https://openalex.org/A5023888391"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
monkeypatch.setattr(logic, "list_persons", fake_list_persons)
|
||||||
|
|
||||||
|
response = client.get("/api/inse-service/persons?pageOffset=5&pageSize=10&query=Ada&include=ids")
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
data = response.json()
|
||||||
|
assert data["meta"]["count"] == 1
|
||||||
|
assert data["results"][0]["display_name"] == "Ada Lovelace"
|
||||||
|
assert data["results"][0]["ids"]["openalex"] == "https://openalex.org/A5023888391"
|
||||||
@@ -5,7 +5,10 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: linear-gradient(160deg, #f4f6fb 0%, #e8ecf7 100%);
|
background:
|
||||||
|
radial-gradient(circle at 18% 18%, var(--sg-cyan-soft), transparent 34%),
|
||||||
|
radial-gradient(circle at 82% 76%, var(--sg-coral-soft), transparent 32%),
|
||||||
|
linear-gradient(160deg, #f8faff 0%, #eef4ff 100%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.form {
|
.form {
|
||||||
@@ -15,7 +18,7 @@
|
|||||||
background: white;
|
background: white;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
box-shadow: 0 2px 12px rgba(26, 58, 110, 0.10), 0 1px 4px rgba(0,0,0,0.06);
|
box-shadow: 0 2px 12px rgba(23, 32, 51, 0.10), 0 1px 4px rgba(0,0,0,0.06);
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
padding: 36px 32px 28px;
|
padding: 36px 32px 28px;
|
||||||
}
|
}
|
||||||
@@ -23,7 +26,7 @@
|
|||||||
.form h3 {
|
.form h3 {
|
||||||
margin: 0 0 4px;
|
margin: 0 0 4px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #1a3a6e;
|
color: var(--sg-primary-strong);
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
@@ -44,9 +47,9 @@
|
|||||||
height: 2em;
|
height: 2em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
color: #585f71;
|
color: var(--sg-text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
color: #ba1a1a;
|
color: var(--sg-danger);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1,78 @@
|
|||||||
@let persons = state.persons();
|
<section class="person-list-page">
|
||||||
@let results = persons.results ?? [];
|
<header class="page-header">
|
||||||
@if (!isPersonsLoading()) {
|
<div>
|
||||||
<mat-grid-list cols="1" rowHeight="65px" gutterSize="16px">
|
<h1>Passende Personen finden</h1>
|
||||||
<mat-grid-tile>
|
<p>
|
||||||
<p class="result-count">{{ results.length }} Ergebnisse</p>
|
Durchsuchen Sie OpenAlex-Autorinnen und -Autoren nach Namen, Themen oder
|
||||||
</mat-grid-tile>
|
Kennungen.
|
||||||
</mat-grid-list>
|
|
||||||
<mat-grid-list cols="1" rowHeight="220px" gutterSize="16px">
|
|
||||||
|
|
||||||
|
|
||||||
@for (person of results; track person.id) {
|
|
||||||
|
|
||||||
<mat-grid-tile>
|
|
||||||
@if (person.id){
|
|
||||||
<mat-card (click)="navigateID(person.id)" class="person-card">
|
|
||||||
|
|
||||||
<div class="card-content">
|
|
||||||
|
|
||||||
<div class="avatar">
|
|
||||||
<mat-icon class="avatar-icon">person</mat-icon>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="info">
|
|
||||||
<h3 class="name">{{ person.display_name }}</h3>
|
|
||||||
<p class="person-id">{{ getDistinguishingId(person) }}</p>
|
|
||||||
@if (person.affiliations!=undefined){
|
|
||||||
<p class="affiliation">
|
|
||||||
{{ person.affiliations[0]?.institution?.display_name }}
|
|
||||||
</p>
|
</p>
|
||||||
}
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="toolbar">
|
||||||
<p class="stats">
|
<span class="result-count">{{ resultRange() }}</span>
|
||||||
Works: {{ person.works_count }} ·
|
|
||||||
Citations: {{ person.cited_by_count }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="topics">
|
|
||||||
@for (t of person.topics; track t) {
|
|
||||||
<mat-chip class="topic-chip">{{ t.display_name }}</mat-chip>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<section class="results-panel">
|
||||||
|
<div class="results-head">
|
||||||
|
<strong>{{ total | number: "1.0-0" }} Personen gefunden</strong>
|
||||||
|
<span>Sortiert nach Publikationen und Zitierungen</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
@if (loading) {
|
||||||
|
<div class="loading-state">
|
||||||
|
|
||||||
</mat-card>
|
|
||||||
}
|
|
||||||
</mat-grid-tile>
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
</mat-grid-list>
|
|
||||||
} @else {
|
|
||||||
<mat-grid-list cols="1" rowHeight="220px" gutterSize="16px">
|
|
||||||
<mat-grid-tile>
|
|
||||||
<div class="loading">
|
|
||||||
<mat-spinner diameter="40"></mat-spinner>
|
<mat-spinner diameter="40"></mat-spinner>
|
||||||
</div>
|
</div>
|
||||||
</mat-grid-tile>
|
} @else if (persons.length) {
|
||||||
</mat-grid-list>
|
<div class="person-grid">
|
||||||
|
@for (person of persons; track person.id) {
|
||||||
|
<article class="person-card">
|
||||||
|
<a
|
||||||
|
class="card-link"
|
||||||
|
[routerLink]="['/person', person.id, 'overview']"
|
||||||
|
>
|
||||||
|
<div class="person-main">
|
||||||
|
<div>
|
||||||
|
<h2>{{ person.display_name }}</h2>
|
||||||
|
<p>{{ institution(person) }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="topic-row">
|
||||||
|
@for (topic of topics(person); track topic) {
|
||||||
|
<span>{{ topic }}</span>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<span>
|
||||||
|
<mat-icon>article</mat-icon>
|
||||||
|
{{ person.works_count | number: "1.0-0" }} Publikationen
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<mat-icon>format_quote</mat-icon>
|
||||||
|
{{ person.cited_by_count | number: "1.0-0" }} Zitierungen
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</article>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div class="empty-state">
|
||||||
|
<mat-icon>person_search</mat-icon>
|
||||||
|
<h2>Keine Personen gefunden</h2>
|
||||||
|
<p>Versuchen Sie einen anderen Suchbegriff.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<mat-paginator
|
||||||
|
[length]="total"
|
||||||
|
[pageIndex]="pageIndex"
|
||||||
|
[pageSize]="paginationService.selection"
|
||||||
|
[pageSizeOptions]="paginationService.options"
|
||||||
|
(page)="onPage($event)"
|
||||||
|
aria-label="Personen Seitensteuerung"
|
||||||
|
></mat-paginator>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|||||||
@@ -1,78 +1,285 @@
|
|||||||
|
.person-list-page {
|
||||||
|
display: grid;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 32px;
|
||||||
|
background: var(--sg-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
|
||||||
|
gap: 32px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
color: var(--sg-primary);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header p:not(.eyebrow) {
|
||||||
|
max-width: 720px;
|
||||||
|
margin: 10px 0 0;
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
min-height: 80px;
|
||||||
|
padding: 18px 20px;
|
||||||
|
border: 1px solid var(--sg-border);
|
||||||
|
border-radius: var(--sg-radius-sm);
|
||||||
|
background: var(--sg-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary div {
|
||||||
|
display: grid;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary strong {
|
||||||
|
color: var(--sg-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary span {
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary mat-icon {
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar mat-form-field {
|
||||||
|
width: min(100%, 520px);
|
||||||
|
}
|
||||||
|
|
||||||
.result-count {
|
.result-count {
|
||||||
margin: 0 0 12px;
|
color: var(--sg-text-muted);
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
color: #666;
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-panel {
|
||||||
|
border: 1px solid var(--sg-border);
|
||||||
|
border-radius: var(--sg-radius-sm);
|
||||||
|
background: var(--sg-surface);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 20px;
|
||||||
|
min-height: 64px;
|
||||||
|
padding: 0 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-head strong {
|
||||||
|
color: var(--sg-text);
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-head span {
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.person-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 16px;
|
||||||
|
padding: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.person-card {
|
.person-card {
|
||||||
width: 100%;
|
min-width: 0;
|
||||||
height: 100%;
|
border: 1px solid var(--sg-border);
|
||||||
padding: 12px;
|
border-radius: var(--sg-radius-sm);
|
||||||
border-radius: 16px;
|
background: var(--sg-surface);
|
||||||
|
box-shadow: var(--sg-shadow-sm);
|
||||||
|
transition:
|
||||||
|
border-color 160ms ease,
|
||||||
|
box-shadow 160ms ease,
|
||||||
|
transform 160ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-content {
|
.person-card:hover {
|
||||||
display: flex;
|
border-color: var(--sg-border-strong);
|
||||||
align-items: center;
|
box-shadow: var(--sg-shadow-md);
|
||||||
gap: 16px;
|
transform: translateY(-1px);
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar {
|
.card-link {
|
||||||
display: flex;
|
display: grid;
|
||||||
justify-content: center;
|
grid-template-rows: 1fr auto;
|
||||||
align-items: center;
|
gap: 18px;
|
||||||
|
min-height: 236px;
|
||||||
|
padding: 20px;
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar-icon {
|
.person-main {
|
||||||
font-size: 48px;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
color: #9e9e9e;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
min-width: 0;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 4px;
|
justify-content: space-between;
|
||||||
|
gap: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.name {
|
.person-main h2 {
|
||||||
margin: 0;
|
margin: 0 0 6px;
|
||||||
|
font-size: 17px;
|
||||||
|
line-height: 1.25;
|
||||||
}
|
}
|
||||||
|
|
||||||
.person-id {
|
.person-main p {
|
||||||
font-size: 11px;
|
display: -webkit-box;
|
||||||
color: #aaa;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.affiliation {
|
.topic-row {
|
||||||
color: #666;
|
display: flex;
|
||||||
margin: 0;
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-row span {
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 5px 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #bcd3ff;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #eff6ff;
|
||||||
|
color: #064fc4;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats {
|
.stats {
|
||||||
font-size: 12px;
|
|
||||||
color: #888;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topics {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 6px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topic-chip {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
.loading {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding-top: 14px;
|
||||||
|
border-top: 1px solid var(--sg-border);
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
width: 100%;
|
.stats span {
|
||||||
min-height: 300px;
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
padding: 2rem;
|
.stats mat-icon {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-state,
|
||||||
|
.empty-state {
|
||||||
|
display: grid;
|
||||||
|
min-height: 320px;
|
||||||
|
place-items: center;
|
||||||
|
padding: 32px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
align-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: var(--sg-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state mat-icon {
|
||||||
|
width: 42px;
|
||||||
|
height: 42px;
|
||||||
|
color: var(--sg-text-soft);
|
||||||
|
font-size: 42px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-paginator {
|
||||||
|
border-top: 1px solid var(--sg-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1280px) {
|
||||||
|
.person-grid {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.person-list-page {
|
||||||
|
padding: 24px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar,
|
||||||
|
.results-head {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-head {
|
||||||
|
justify-content: center;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-count {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.person-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.stats {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,135 +1,113 @@
|
|||||||
import { Component, computed, inject, signal, DestroyRef } from '@angular/core';
|
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { CommonModule } from '@angular/common';
|
||||||
import { toObservable } from '@angular/core/rxjs-interop';
|
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { RouterLink } from '@angular/router';
|
||||||
import { MatGridListModule } from '@angular/material/grid-list';
|
import { Subject, debounceTime, distinctUntilChanged, takeUntil } from 'rxjs';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { MatChipsModule } from '@angular/material/chips';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||||
import { Author, AuthorsListResponse, PersonsService } from '../../api';
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||||
import { SharedStateService } from '../../shared/services/shared-state.service';
|
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||||
import { distinctUntilChanged, switchMap, tap, finalize } from 'rxjs';
|
|
||||||
|
import { Author, WorkTopic } from '../../api';
|
||||||
|
import { PaginationService } from '../../shared/services/pagination.service';
|
||||||
|
import { PersonsService } from '../../shared/services/persons.service';
|
||||||
|
import { createLoadError } from '../../shared/utils/errorHandler';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-person-list',
|
selector: 'app-person-list',
|
||||||
imports: [
|
imports: [
|
||||||
MatCardModule,
|
CommonModule,
|
||||||
MatChipsModule,
|
MatButtonModule,
|
||||||
MatGridListModule,
|
MatFormFieldModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatProgressSpinner,
|
MatInputModule,
|
||||||
|
MatPaginatorModule,
|
||||||
|
MatProgressSpinnerModule,
|
||||||
|
MatSnackBarModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
RouterLink,
|
||||||
],
|
],
|
||||||
templateUrl: './person-list.component.html',
|
templateUrl: './person-list.component.html',
|
||||||
styleUrl: './person-list.component.scss',
|
styleUrl: './person-list.component.scss',
|
||||||
|
standalone: true,
|
||||||
})
|
})
|
||||||
export class PersonListComponent {
|
export class PersonListComponent implements OnInit, OnDestroy {
|
||||||
private readonly router = inject(Router);
|
private personsService = inject(PersonsService);
|
||||||
private readonly personsService = inject(PersonsService);
|
private snackBar = inject(MatSnackBar);
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
private destroy$ = new Subject<void>();
|
||||||
public readonly state = inject(SharedStateService);
|
|
||||||
|
|
||||||
private readonly defaultIncludes =
|
public paginationService = inject(PaginationService);
|
||||||
'display_name,works_count,cited_by_count,topics,orcid';
|
|
||||||
private readonly defaultInstitutionName = 'University of Duisburg-Essen';
|
|
||||||
|
|
||||||
readonly isPersonsLoading = signal<boolean>(false);
|
persons: Author[] = [];
|
||||||
constructor() {
|
loading = false;
|
||||||
toObservable(this.state.searchValue)
|
total = 0;
|
||||||
.pipe(
|
pageIndex = 0;
|
||||||
distinctUntilChanged(),
|
|
||||||
tap(() => {
|
ngOnInit(): void {
|
||||||
this.state.hasSearched.set(false);
|
this.load();
|
||||||
this.isPersonsLoading.set(true);
|
}
|
||||||
}),
|
|
||||||
switchMap((value) =>
|
ngOnDestroy(): void {
|
||||||
value
|
this.destroy$.next();
|
||||||
? this.personsService
|
this.destroy$.complete();
|
||||||
.searchPersonsByName(value, this.defaultIncludes)
|
}
|
||||||
.pipe(
|
|
||||||
tap((result) => {
|
load(
|
||||||
this.state.persons.set(this.sortByRanking(result));
|
pageIndex = this.pageIndex,
|
||||||
this.state.hasSearched.set(true);
|
pageSize = this.paginationService.selection,
|
||||||
}),
|
): void {
|
||||||
)
|
this.loading = true;
|
||||||
: this.personsService
|
const pageOffset = pageIndex * pageSize;
|
||||||
.searchPersonsByInstitution(
|
|
||||||
this.defaultInstitutionName,
|
this.personsService
|
||||||
this.defaultIncludes,
|
.getPersons(pageOffset, pageSize)
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
tap((result) => {
|
|
||||||
this.state.persons.set(this.sortByRanking(result));
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
finalize(() => this.isPersonsLoading.set(false)),
|
|
||||||
takeUntilDestroyed(this.destroyRef),
|
|
||||||
)
|
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => this.isPersonsLoading.set(false),
|
next: (page) => {
|
||||||
error: (err) => {
|
this.persons = page.elements ?? [];
|
||||||
console.error('Error loading persons:', err);
|
this.total = page.total ?? 0;
|
||||||
this.isPersonsLoading.set(false);
|
this.loading = false;
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
this.loading = false;
|
||||||
|
createLoadError(
|
||||||
|
this.snackBar,
|
||||||
|
() => this.load(pageIndex, pageSize),
|
||||||
|
'Personen konnten nicht geladen werden',
|
||||||
|
)(error);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// navigation
|
onPage(event: PageEvent): void {
|
||||||
navigateID(id: string): void {
|
this.paginationService.selection = event.pageSize;
|
||||||
this.router.navigate(['/person', id]);
|
this.pageIndex = event.pageIndex;
|
||||||
|
this.load(event.pageIndex, event.pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sorting logic
|
institution(person: Author): string {
|
||||||
sortByRanking(response: AuthorsListResponse): AuthorsListResponse {
|
return (
|
||||||
if (!response.results) return response;
|
person.last_known_institutions?.[0]?.display_name ??
|
||||||
|
person.affiliations?.[0]?.institution?.display_name ??
|
||||||
return {
|
'Keine Institution angegeben'
|
||||||
...response,
|
);
|
||||||
results: [...response.results].sort((personA, personB) => {
|
|
||||||
const rankDiff = this.getSortRank(personA) - this.getSortRank(personB);
|
|
||||||
if (rankDiff !== 0) {
|
|
||||||
return rankDiff;
|
|
||||||
}
|
|
||||||
return this.getWorksCount(personB) - this.getWorksCount(personA);
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getWorksCount(person: Author): number {
|
topics(person: Author): string[] {
|
||||||
return person.works_count ?? 0;
|
return (person.topics ?? [])
|
||||||
|
.map((topic: WorkTopic) => topic.display_name ?? '')
|
||||||
|
.filter((topic): topic is string => Boolean(topic))
|
||||||
|
.slice(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSortRank(person: Author): number {
|
resultRange(): string {
|
||||||
if (this.hasInstitution(person) && this.hasOrcid(person)) return 0;
|
if (!this.total || !this.persons.length) return 'Keine Personen gefunden';
|
||||||
if (this.hasInstitution(person)) return 1;
|
|
||||||
if (this.hasOrcid(person)) return 2;
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasInstitution(person: Author): boolean {
|
const start = this.pageIndex * this.paginationService.selection + 1;
|
||||||
if (!person.affiliations) {
|
const end = start + this.persons.length - 1;
|
||||||
return false;
|
return `${start}-${end} von ${this.total} Personen`;
|
||||||
}
|
|
||||||
for (const affiliation of person.affiliations) {
|
|
||||||
if (affiliation.institution) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasOrcid(person: Author): boolean {
|
|
||||||
const ids = person.ids as { orcid?: string } | null | undefined;
|
|
||||||
return !!ids?.orcid;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDistinguishingId(person: Author): string {
|
|
||||||
const ids = person.ids as { orcid?: string } | null | undefined;
|
|
||||||
const orcid = ids?.orcid;
|
|
||||||
|
|
||||||
return orcid
|
|
||||||
? 'ORCID: ' + orcid.replace('https://orcid.org/', '')
|
|
||||||
: 'OpenAlexID: ' + person.id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-contact .orcid {
|
.profile-contact .orcid {
|
||||||
color: #6cc24a;
|
color: var(--sg-success);
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-contact a {
|
.profile-contact a {
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
|
|
||||||
.interest-tags span {
|
.interest-tags span {
|
||||||
padding: 9px 16px;
|
padding: 9px 16px;
|
||||||
border: 1px solid #a8c0ff;
|
border: 1px solid var(--sg-border-strong);
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
color: var(--sg-primary);
|
color: var(--sg-primary);
|
||||||
@@ -181,11 +181,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-card {
|
.profile-card {
|
||||||
grid-template-columns: 112px 1fr;
|
grid-template-columns: minmax(240px, 1fr) minmax(260px, 360px);
|
||||||
}
|
|
||||||
|
|
||||||
.profile-contact {
|
|
||||||
grid-column: 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
|
import { Inject, Injectable, Optional } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
import { Author } from '../../api';
|
||||||
|
import { BASE_PATH } from '../../api/variables';
|
||||||
|
|
||||||
|
export interface AuthorPage {
|
||||||
|
elements?: Author[];
|
||||||
|
offset?: number;
|
||||||
|
total?: number;
|
||||||
|
size?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class PersonsService {
|
||||||
|
private readonly basePath: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: HttpClient,
|
||||||
|
@Optional() @Inject(BASE_PATH) basePath: string | null,
|
||||||
|
) {
|
||||||
|
this.basePath = basePath ?? 'http://localhost:8000';
|
||||||
|
}
|
||||||
|
|
||||||
|
getPersons(
|
||||||
|
pageOffset: number = 0,
|
||||||
|
pageSize: number = 24,
|
||||||
|
query?: string,
|
||||||
|
): Observable<AuthorPage> {
|
||||||
|
let params = new HttpParams()
|
||||||
|
.set('pageOffset', pageOffset)
|
||||||
|
.set('pageSize', pageSize);
|
||||||
|
|
||||||
|
if (query?.trim()) {
|
||||||
|
params = params.set('query', query.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.http.get<AuthorPage>(`${this.basePath}/api/inse-service/persons`, { params });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 10px 8px;
|
inset: 10px 8px;
|
||||||
border: 2px solid rgba(0, 87, 255, 0.22);
|
border: 2px solid color-mix(in srgb, var(--sg-primary) 22%, transparent);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: linear-gradient(135deg, #dce8ff, #ffffff);
|
background: linear-gradient(135deg, var(--sg-primary-soft), #ffffff);
|
||||||
color: var(--sg-primary);
|
color: var(--sg-primary);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user