feat/add_site_news_2 #173
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from typing import Any, Dict, Iterator, List, Optional, Tuple
|
||||
import httpx
|
||||
|
||||
from inse.model import ESCluster, ESIndex
|
||||
@@ -172,6 +172,93 @@ def search(
|
||||
return response.json()
|
||||
|
||||
|
||||
def open_point_in_time(index: str, keep_alive: str = "1m", cluster: str = "nes") -> str:
|
||||
"""Opens a point-in-time on the given index and returns its id."""
|
||||
elasticsearch_url, api_key = _cluster_credentials(cluster)
|
||||
headers = {"Authorization": f"ApiKey {api_key}", "Content-Type": "application/json"}
|
||||
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
response = client.post(
|
||||
f"{elasticsearch_url}/{index}/_pit",
|
||||
params={"keep_alive": keep_alive},
|
||||
headers=headers,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["id"]
|
||||
|
||||
|
||||
def close_point_in_time(pit_id: str, cluster: str = "nes") -> None:
|
||||
"""Closes a previously opened point-in-time."""
|
||||
elasticsearch_url, api_key = _cluster_credentials(cluster)
|
||||
headers = {"Authorization": f"ApiKey {api_key}", "Content-Type": "application/json"}
|
||||
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
response = client.request(
|
||||
"DELETE",
|
||||
f"{elasticsearch_url}/_pit",
|
||||
json={"id": pit_id},
|
||||
headers=headers,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
def scan(
|
||||
index: str,
|
||||
query: Dict,
|
||||
source: Optional[List] = None,
|
||||
page_size: int = 1000,
|
||||
keep_alive: str = "1m",
|
||||
cluster: str = "nes",
|
||||
) -> Iterator[Dict[str, Any]]:
|
||||
"""Yields every hit matching ``query`` using a point-in-time + ``search_after``.
|
||||
|
||||
Unlike ``from``/``size`` pagination, this is not bounded by
|
||||
``index.max_result_window``, so it can stream result sets larger than 10k.
|
||||
"""
|
||||
elasticsearch_url, api_key = _cluster_credentials(cluster)
|
||||
headers = {"Authorization": f"ApiKey {api_key}", "Content-Type": "application/json"}
|
||||
|
||||
pit_id = open_point_in_time(index, keep_alive=keep_alive, cluster=cluster)
|
||||
search_after: Optional[List] = None
|
||||
try:
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
while True:
|
||||
payload: Dict[str, Any] = {
|
||||
"size": page_size,
|
||||
"query": query,
|
||||
"pit": {"id": pit_id, "keep_alive": keep_alive},
|
||||
"sort": [{"_shard_doc": "asc"}],
|
||||
"track_total_hits": False,
|
||||
}
|
||||
if source is not None:
|
||||
payload["_source"] = source
|
||||
if search_after is not None:
|
||||
payload["search_after"] = search_after
|
||||
|
||||
response = client.post(
|
||||
f"{elasticsearch_url}/_search", json=payload, headers=headers
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
hits = result.get("hits", {}).get("hits", [])
|
||||
if not hits:
|
||||
break
|
||||
|
||||
yield from hits
|
||||
|
||||
# The pit id can be refreshed between requests; keep the latest.
|
||||
pit_id = result.get("pit_id", pit_id)
|
||||
search_after = hits[-1].get("sort")
|
||||
if search_after is None or len(hits) < page_size:
|
||||
break
|
||||
finally:
|
||||
try:
|
||||
close_point_in_time(pit_id, cluster=cluster)
|
||||
except Exception:
|
||||
logger.exception("Failed to close Elasticsearch point-in-time.")
|
||||
|
||||
|
||||
def get(
|
||||
index: ESIndex,
|
||||
doc_id: str,
|
||||
@@ -193,3 +280,41 @@ def get(
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
def update(
|
||||
index: str,
|
||||
doc_id: str,
|
||||
doc: Dict[str, Any],
|
||||
cluster: ESCluster = ESCluster.NES,
|
||||
) -> Dict[str, Any]:
|
||||
elasticsearch_url, api_key = _cluster_credentials(cluster)
|
||||
headers = {"Authorization": f"ApiKey {api_key}", "Content-Type": "application/json"}
|
||||
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
response = client.post(
|
||||
f"{elasticsearch_url}/{index}/_update/{doc_id}",
|
||||
json={"doc": doc},
|
||||
headers=headers,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
def index_doc(
|
||||
index: str,
|
||||
doc_id: str,
|
||||
document: Dict[str, Any],
|
||||
cluster: ESCluster = ESCluster.NES,
|
||||
) -> Dict[str, Any]:
|
||||
elasticsearch_url, api_key = _cluster_credentials(cluster)
|
||||
headers = {"Authorization": f"ApiKey {api_key}", "Content-Type": "application/json"}
|
||||
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
response = client.put(
|
||||
f"{elasticsearch_url}/{index}/_doc/{doc_id}",
|
||||
json=document,
|
||||
headers=headers,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -4,24 +4,54 @@
|
||||
Business logic for the "aktuell" news index on the INSE cluster.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
||||
from fastapi import HTTPException
|
||||
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR
|
||||
|
||||
from ..integrations import elasticsearch
|
||||
from ..integrations import elasticsearch, llm
|
||||
from ..persons.logic import find_ude_author_by_name, get_author_name_by_id
|
||||
from .model import MentionedPerson, NewsArticle, NewsArticleDetail, NewsPage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TOPIC_LIMIT = 4
|
||||
TOPIC_QUERY_CONTENT_CHARS = 300
|
||||
TOPIC_NUM_CANDIDATES = 100
|
||||
TOPIC_SIMILARITY = 0.5
|
||||
|
||||
def get_news_page(page: int, page_size: int, sort_order: str = "desc") -> NewsPage:
|
||||
KEYWORD_LIMIT = 6
|
||||
KEYWORD_CONTENT_CHARS = 4000
|
||||
KEYWORD_SYSTEM_PROMPT = """\
|
||||
Extrahiere aus dem folgenden Nachrichtenartikel die wichtigsten Schlagwörter (Keywords).
|
||||
Gib maximal sechs prägnante Begriffe oder kurze Phrasen zurück, die den inhaltlichen Kern
|
||||
des Artikels erfassen. Antworte ausschließlich mit einem JSON-Array von Strings, ohne
|
||||
weiteren Text, zum Beispiel ["Künstliche Intelligenz", "Klimaforschung"].
|
||||
"""
|
||||
|
||||
RELATED_BLOCK_SIZE = 5
|
||||
RELATED_TOPIC_K = 1
|
||||
EXACT_ID_CAP = 1000
|
||||
|
||||
|
||||
def get_news_page(
|
||||
page: int,
|
||||
page_size: int,
|
||||
sort_order: str = "desc",
|
||||
year_from: int | None = None,
|
||||
year_to: int | None = None,
|
||||
relevance_values: list | None = None,
|
||||
) -> NewsPage:
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
clauses = _filter_clauses(year_from, year_to, relevance_values)
|
||||
query = {"bool": {"filter": clauses}} if clauses else {"match_all": {}}
|
||||
|
||||
response = _run_search(
|
||||
query={"match_all": {}},
|
||||
source=["date", "maintitle", "author", "url"],
|
||||
query=query,
|
||||
source=["date", "maintitle", "author", "url", "intro_content", "full_content"],
|
||||
size=page_size,
|
||||
offset=offset,
|
||||
sort=[{"date_full": sort_order}],
|
||||
@@ -30,7 +60,14 @@ def get_news_page(page: int, page_size: int, sort_order: str = "desc") -> NewsPa
|
||||
return _build_page(response, page, page_size)
|
||||
|
||||
|
||||
def search_news(query_text: str, page: int, page_size: int) -> NewsPage:
|
||||
def search_news(
|
||||
query_text: str,
|
||||
page: int,
|
||||
page_size: int,
|
||||
year_from: int | None = None,
|
||||
year_to: int | None = None,
|
||||
relevance_values: list | None = None,
|
||||
) -> NewsPage:
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
highlight = {
|
||||
@@ -40,8 +77,16 @@ def search_news(query_text: str, page: int, page_size: int) -> NewsPage:
|
||||
"encoder": "html",
|
||||
}
|
||||
|
||||
# Filter einmal berechnen (der Relevanz-Filter macht eine ES-Abfrage).
|
||||
clauses = _filter_clauses(year_from, year_to, relevance_values)
|
||||
exact_query = {
|
||||
"bool": {
|
||||
"must": [{"match": {"full_content": query_text}}],
|
||||
"filter": clauses,
|
||||
}
|
||||
}
|
||||
response = _run_search(
|
||||
query={"match": {"full_content": query_text}},
|
||||
query=exact_query,
|
||||
source=["date", "maintitle", "author", "url"],
|
||||
size=page_size,
|
||||
offset=offset,
|
||||
@@ -49,7 +94,17 @@ def search_news(query_text: str, page: int, page_size: int) -> NewsPage:
|
||||
highlight=highlight,
|
||||
)
|
||||
|
||||
return _build_page(response, page, page_size)
|
||||
news_page = _build_page(response, page, page_size)
|
||||
|
||||
if _is_last_page(page, page_size, news_page.total):
|
||||
exclude_ids = _exact_match_ids(exact_query)
|
||||
news_page.results.extend(
|
||||
_related_articles(
|
||||
query_text, exclude_ids=exclude_ids, extra_filters=clauses
|
||||
)
|
||||
)
|
||||
|
||||
return news_page
|
||||
|
||||
def get_news_by_author(
|
||||
author_id: str,
|
||||
@@ -82,7 +137,65 @@ def get_news_by_author(
|
||||
sort=[{"date_full": sort_order}],
|
||||
)
|
||||
|
||||
return _build_page(response, page, page_size)
|
||||
news_page = _build_page(response, page, page_size)
|
||||
|
||||
if query_text and _is_last_page(page, page_size, news_page.total):
|
||||
exclude_ids = _exact_match_ids(es_query)
|
||||
news_page.results.extend(
|
||||
_related_articles(
|
||||
query_text, exclude_ids=exclude_ids, filter_news_ids=news_ids
|
||||
)
|
||||
)
|
||||
|
||||
return news_page
|
||||
|
||||
|
||||
def _filter_clauses(
|
||||
year_from: int | None,
|
||||
year_to: int | None,
|
||||
relevance_values: list | None,
|
||||
) -> list:
|
||||
clauses = []
|
||||
|
||||
if year_from is not None or year_to is not None:
|
||||
date_range = {}
|
||||
if year_from is not None:
|
||||
date_range["gte"] = year_from
|
||||
if year_to is not None:
|
||||
date_range["lte"] = year_to
|
||||
clauses.append({"range": {"date_year": date_range}})
|
||||
|
||||
relevant_ids = _relevance_news_ids(relevance_values)
|
||||
if relevant_ids is not None:
|
||||
clauses.append({"ids": {"values": relevant_ids}})
|
||||
|
||||
return clauses
|
||||
|
||||
|
||||
def _relevance_news_ids(relevance_values: list | None) -> list | None:
|
||||
selected = set(relevance_values or [])
|
||||
|
||||
if not selected or {"relevant", "not_relevant"} <= selected:
|
||||
return None
|
||||
|
||||
relevant_value = 1 if "relevant" in selected else 0
|
||||
|
||||
news_ids = []
|
||||
try:
|
||||
for hit in elasticsearch.scan(
|
||||
index="aktuell_postproc",
|
||||
query={"term": {"relevant": relevant_value}},
|
||||
source=["news_id"],
|
||||
cluster="inse",
|
||||
):
|
||||
news_id = hit.get("_source", {}).get("news_id")
|
||||
if news_id:
|
||||
news_ids.append(news_id)
|
||||
except Exception:
|
||||
logger.exception("Relevanz-IDs aus aktuell_postproc konnten nicht geladen werden.")
|
||||
return []
|
||||
|
||||
return news_ids
|
||||
|
||||
|
||||
def _find_news_ids_for_author(author_name: str) -> list:
|
||||
@@ -129,7 +242,15 @@ def get_news_by_id(news_id: str) -> NewsArticleDetail:
|
||||
|
||||
source = response.get("_source", {})
|
||||
|
||||
relevant, authors = _get_postproc_labels(news_id)
|
||||
relevant, authors, cached_keywords, postproc_id = _get_postproc_labels(news_id)
|
||||
topics = _get_article_topics(source.get("maintitle"), source.get("full_content"))
|
||||
keywords = _get_article_keywords(
|
||||
news_id,
|
||||
postproc_id,
|
||||
cached_keywords,
|
||||
source.get("maintitle"),
|
||||
source.get("full_content"),
|
||||
)
|
||||
|
||||
return NewsArticleDetail(
|
||||
id=response.get("_id"),
|
||||
@@ -140,9 +261,123 @@ def get_news_by_id(news_id: str) -> NewsArticleDetail:
|
||||
full_content=source.get("full_content"),
|
||||
relevant=relevant,
|
||||
authors=_build_mentioned_persons(authors),
|
||||
topics=topics,
|
||||
keywords=keywords,
|
||||
)
|
||||
|
||||
|
||||
def _get_article_topics(maintitle: str | None, full_content: str | None) -> list:
|
||||
query = " ".join(
|
||||
part for part in (maintitle, (full_content or "")[:TOPIC_QUERY_CONTENT_CHARS]) if part
|
||||
).strip()
|
||||
if not query:
|
||||
return []
|
||||
|
||||
topics = _topic_vector_search(query, TOPIC_LIMIT, ["display_name"])
|
||||
return [topic["display_name"] for topic in topics if topic.get("display_name")]
|
||||
|
||||
|
||||
def _get_article_keywords(
|
||||
news_id: str,
|
||||
postproc_id: str | None,
|
||||
cached_keywords: list,
|
||||
maintitle: str | None,
|
||||
full_content: str | None,
|
||||
) -> list:
|
||||
if cached_keywords:
|
||||
return cached_keywords
|
||||
|
||||
text = " ".join(
|
||||
part for part in (maintitle, (full_content or "")[:KEYWORD_CONTENT_CHARS]) if part
|
||||
).strip()
|
||||
if not text:
|
||||
return []
|
||||
|
||||
raw = llm.call(
|
||||
system_prompt=KEYWORD_SYSTEM_PROMPT,
|
||||
user_prompt=f"Artikel:\n{text}",
|
||||
temperature=0.3,
|
||||
)
|
||||
keywords = _parse_keywords(raw)
|
||||
|
||||
if keywords:
|
||||
_store_keywords(news_id, postproc_id, keywords)
|
||||
|
||||
return keywords
|
||||
|
||||
|
||||
def _parse_keywords(raw: str) -> list:
|
||||
raw = (raw or "").strip()
|
||||
|
||||
try:
|
||||
parsed = json.loads(raw)
|
||||
candidates = parsed if isinstance(parsed, list) else []
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
candidates = re.split(r"[,\n]", raw)
|
||||
|
||||
seen = set()
|
||||
keywords = []
|
||||
for item in candidates:
|
||||
term = str(item).strip().strip('"').strip()
|
||||
if term and term.lower() not in seen:
|
||||
seen.add(term.lower())
|
||||
keywords.append(term)
|
||||
|
||||
return keywords[:KEYWORD_LIMIT]
|
||||
|
||||
|
||||
def _store_keywords(news_id: str, postproc_id: str | None, keywords: list) -> None:
|
||||
try:
|
||||
if postproc_id:
|
||||
elasticsearch.update(
|
||||
index="aktuell_postproc",
|
||||
doc_id=postproc_id,
|
||||
doc={"keywords": keywords},
|
||||
cluster="inse",
|
||||
)
|
||||
else:
|
||||
elasticsearch.index_doc(
|
||||
index="aktuell_postproc",
|
||||
doc_id=news_id,
|
||||
document={"news_id": news_id, "keywords": keywords},
|
||||
cluster="inse",
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(f"Failed to cache keywords for {news_id}.")
|
||||
|
||||
|
||||
def _topic_vector_search(query_text: str, k: int, source_fields: list) -> list:
|
||||
try:
|
||||
from ..util import get_model
|
||||
|
||||
query_vector = get_model().encode(query_text).tolist()
|
||||
except Exception:
|
||||
logger.exception("Failed to encode text for topic vector search.")
|
||||
return []
|
||||
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="topicvectors",
|
||||
body={
|
||||
"knn": {
|
||||
"field": "display_name_vector",
|
||||
"query_vector": query_vector,
|
||||
"k": k,
|
||||
"num_candidates": TOPIC_NUM_CANDIDATES,
|
||||
"similarity": TOPIC_SIMILARITY,
|
||||
},
|
||||
"_source": source_fields,
|
||||
"size": k,
|
||||
},
|
||||
cluster="nes",
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Topic vector search failed.")
|
||||
return []
|
||||
|
||||
return [hit.get("_source", {}) for hit in response.get("hits", {}).get("hits", [])]
|
||||
|
||||
|
||||
def _build_mentioned_persons(author_names: list) -> list:
|
||||
|
||||
ude_persons = []
|
||||
@@ -160,28 +395,30 @@ def _build_mentioned_persons(author_names: list) -> list:
|
||||
return ude_persons + other_persons
|
||||
|
||||
|
||||
def _get_postproc_labels(news_id: str) -> tuple[bool | None, list]:
|
||||
def _get_postproc_labels(news_id: str) -> tuple[bool | None, list, list, str | None]:
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="aktuell_postproc",
|
||||
query={"term": {"news_id.keyword": news_id}},
|
||||
source=["relevant", "authors"],
|
||||
source=["relevant", "authors", "keywords"],
|
||||
size=1,
|
||||
cluster="inse",
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(f"Postproc-Lookup for {news_id} failed.")
|
||||
return None, []
|
||||
return None, [], [], None
|
||||
|
||||
hits = response.get("hits", {}).get("hits", [])
|
||||
if not hits:
|
||||
return None, []
|
||||
return None, [], [], None
|
||||
|
||||
postproc_source = hits[0].get("_source", {})
|
||||
hit = hits[0]
|
||||
postproc_source = hit.get("_source", {})
|
||||
relevant = bool(postproc_source.get("relevant", 0))
|
||||
authors = postproc_source.get("authors") or []
|
||||
keywords = postproc_source.get("keywords") or []
|
||||
|
||||
return relevant, authors
|
||||
return relevant, authors, keywords, hit.get("_id")
|
||||
|
||||
|
||||
def _run_search(query: dict, source: list, size: int, offset: int, sort, highlight: dict = None) -> dict:
|
||||
@@ -262,7 +499,11 @@ def _parse_hit(hit: dict) -> NewsArticle:
|
||||
source = hit.get("_source", {})
|
||||
|
||||
fragments = hit.get("highlight", {}).get("full_content")
|
||||
snippet = fragments[0] if fragments else None
|
||||
|
||||
if fragments:
|
||||
snippet = fragments[0]
|
||||
else:
|
||||
snippet = _make_preview(source)
|
||||
|
||||
return NewsArticle(
|
||||
id=hit.get("_id"),
|
||||
@@ -272,3 +513,104 @@ def _parse_hit(hit: dict) -> NewsArticle:
|
||||
url=source.get("url"),
|
||||
snippet=snippet,
|
||||
)
|
||||
|
||||
|
||||
def _make_preview(source: dict) -> str | None:
|
||||
text = source.get("intro_content") or source.get("full_content")
|
||||
|
||||
if not text:
|
||||
return None
|
||||
|
||||
words = text.split()
|
||||
|
||||
PREVIEW_WORD_COUNT = 10
|
||||
preview = " ".join(words[:PREVIEW_WORD_COUNT])
|
||||
if len(words) > PREVIEW_WORD_COUNT:
|
||||
preview = preview + " …"
|
||||
return preview
|
||||
|
||||
|
||||
def _is_last_page(page: int, page_size: int, total: int) -> bool:
|
||||
return page * page_size >= total
|
||||
|
||||
|
||||
def _exact_match_ids(query: dict) -> list:
|
||||
try:
|
||||
response = _run_search(
|
||||
query=query,
|
||||
source=[],
|
||||
size=EXACT_ID_CAP,
|
||||
offset=0,
|
||||
sort=None,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to collect exact-match ids for dedup.")
|
||||
return []
|
||||
|
||||
return [
|
||||
hit.get("_id")
|
||||
for hit in response.get("hits", {}).get("hits", [])
|
||||
if hit.get("_id")
|
||||
]
|
||||
|
||||
|
||||
def _related_articles(
|
||||
query_text: str,
|
||||
exclude_ids: list | None = None,
|
||||
filter_news_ids: list | None = None,
|
||||
extra_filters: list | None = None,
|
||||
k: int = RELATED_BLOCK_SIZE,
|
||||
) -> list:
|
||||
related_terms = _related_search_terms(query_text)
|
||||
if not related_terms:
|
||||
return []
|
||||
|
||||
bool_query = {
|
||||
"should": [{"match": {"full_content": term}} for term in related_terms],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
if exclude_ids:
|
||||
bool_query["must_not"] = [{"ids": {"values": exclude_ids}}]
|
||||
if filter_news_ids is not None:
|
||||
bool_query["filter"] = [{"ids": {"values": filter_news_ids}}]
|
||||
if extra_filters:
|
||||
bool_query.setdefault("filter", []).extend(extra_filters)
|
||||
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="aktuell",
|
||||
query={"bool": bool_query},
|
||||
source=["date", "maintitle", "author", "url", "intro_content", "full_content"],
|
||||
size=k,
|
||||
offset=0,
|
||||
cluster="inse",
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Related-articles search failed.")
|
||||
return []
|
||||
|
||||
articles = []
|
||||
for hit in response.get("hits", {}).get("hits", []):
|
||||
article = _parse_hit(hit)
|
||||
article.related = True
|
||||
articles.append(article)
|
||||
|
||||
relevance_map = _get_relevance_map([article.id for article in articles])
|
||||
for article in articles:
|
||||
article.relevant = relevance_map.get(article.id)
|
||||
|
||||
return articles
|
||||
|
||||
|
||||
def _related_search_terms(query_text: str) -> list:
|
||||
topics = _topic_vector_search(query_text, RELATED_TOPIC_K, ["display_name", "keywords"])
|
||||
|
||||
seen = {query_text.lower()}
|
||||
terms = []
|
||||
for topic in topics:
|
||||
for term in [topic.get("display_name"), *(topic.get("keywords") or [])]:
|
||||
if term and term.lower() not in seen:
|
||||
seen.add(term.lower())
|
||||
terms.append(term)
|
||||
|
||||
return terms
|
||||
|
||||
@@ -14,6 +14,7 @@ class NewsArticle(BaseModel):
|
||||
url: Optional[str] = None
|
||||
relevant: Optional[bool] = None
|
||||
snippet: Optional[str] = None
|
||||
related: Optional[bool] = None
|
||||
|
||||
|
||||
class MentionedPerson(BaseModel):
|
||||
@@ -26,6 +27,8 @@ class NewsArticleDetail(NewsArticle):
|
||||
full_content: Optional[str] = None
|
||||
relevant: Optional[bool] = None
|
||||
authors: List[MentionedPerson] = []
|
||||
topics: List[str] = []
|
||||
keywords: List[str] = []
|
||||
|
||||
|
||||
class NewsPage(BaseModel):
|
||||
|
||||
@@ -16,6 +16,15 @@ from .model import NewsArticleDetail, NewsPage
|
||||
|
||||
router = APIRouter(prefix="/api/news", tags=[Tags.NEWS])
|
||||
|
||||
ALLOWED_RELEVANCE_VALUES = {"relevant", "not_relevant"}
|
||||
|
||||
|
||||
def _parse_relevance(relevance: str | None) -> list:
|
||||
if not relevance:
|
||||
return []
|
||||
values = [entry.strip() for entry in relevance.split(",")]
|
||||
return [value for value in values if value in ALLOWED_RELEVANCE_VALUES]
|
||||
|
||||
|
||||
@router.get(
|
||||
"",
|
||||
@@ -35,8 +44,24 @@ def list_news(
|
||||
sort_order: Annotated[
|
||||
str, Query(alias="sortOrder", description="Sort order: 'desc' (newest first) or 'asc' (oldest first).", pattern="^(asc|desc)$")
|
||||
] = "desc",
|
||||
relevance: Annotated[
|
||||
str | None, Query(description="Comma-separated relevance filter: 'relevant', 'not_relevant'.")
|
||||
] = None,
|
||||
year_from: Annotated[
|
||||
int | None, Query(alias="yearFrom", description="Earliest publication year (inclusive).", ge=0)
|
||||
] = None,
|
||||
year_to: Annotated[
|
||||
int | None, Query(alias="yearTo", description="Latest publication year (inclusive).", ge=0)
|
||||
] = None,
|
||||
):
|
||||
return logic.get_news_page(page, page_size, sort_order)
|
||||
return logic.get_news_page(
|
||||
page,
|
||||
page_size,
|
||||
sort_order,
|
||||
year_from=year_from,
|
||||
year_to=year_to,
|
||||
relevance_values=_parse_relevance(relevance),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -57,8 +82,24 @@ def search_news(
|
||||
page_size: Annotated[
|
||||
int, Query(alias="pageSize", description="Articles per page.", ge=1, le=100)
|
||||
] = 10,
|
||||
relevance: Annotated[
|
||||
str | None, Query(description="Comma-separated relevance filter: 'relevant', 'not_relevant'.")
|
||||
] = None,
|
||||
year_from: Annotated[
|
||||
int | None, Query(alias="yearFrom", description="Earliest publication year (inclusive).", ge=0)
|
||||
] = None,
|
||||
year_to: Annotated[
|
||||
int | None, Query(alias="yearTo", description="Latest publication year (inclusive).", ge=0)
|
||||
] = None,
|
||||
):
|
||||
return logic.search_news(query, page, page_size)
|
||||
return logic.search_news(
|
||||
query,
|
||||
page,
|
||||
page_size,
|
||||
year_from=year_from,
|
||||
year_to=year_to,
|
||||
relevance_values=_parse_relevance(relevance),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
@@ -7,6 +7,7 @@ import { personResolver } from './resolvers/person.resolver';
|
||||
import { institutionResolver } from './resolvers/institution.resolver';
|
||||
import { bundProjectPageResolver } from './resolvers/bund-project-page.resolver';
|
||||
import { dfgProjectsResolver } from './resolvers/dfg-projects.resolver';
|
||||
import { personNewsResolver } from './resolvers/person-news.resolver';
|
||||
import { institutionsResolver } from './resolvers/institutions.resolver';
|
||||
import { bundProjectsFundingResolver } from './resolvers/bund-projects-funding.resolver';
|
||||
import { dfgSingleProjectResolver } from './resolvers/dfg-single-project-resolver';
|
||||
@@ -57,8 +58,15 @@ export const routes: Routes = [
|
||||
},
|
||||
runGuardsAndResolvers: (to, from) => {
|
||||
const keys = [
|
||||
'query', 'page', 'pageSize', 'institutionName',
|
||||
'sortBy', 'sortOrder', 'yearFilterEnabled', 'filterMode', 'filterYear',
|
||||
'query',
|
||||
'page',
|
||||
'pageSize',
|
||||
'institutionName',
|
||||
'sortBy',
|
||||
'sortOrder',
|
||||
'yearFilterEnabled',
|
||||
'filterMode',
|
||||
'filterYear',
|
||||
];
|
||||
const scalarChanged = keys.some(
|
||||
(key) => to.queryParamMap.get(key) !== from.queryParamMap.get(key),
|
||||
@@ -71,6 +79,20 @@ export const routes: Routes = [
|
||||
return scalarChanged || topicsChanged;
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'news',
|
||||
canActivate: [userGuard],
|
||||
loadComponent: () =>
|
||||
import('./modules/news/news.component').then((mod) => mod.NewsComponent),
|
||||
},
|
||||
{
|
||||
path: 'news/:id',
|
||||
canActivate: [userGuard],
|
||||
loadComponent: () =>
|
||||
import('./modules/news-detail/news-detail.component').then(
|
||||
(mod) => mod.NewsDetailComponent,
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'publication/:publicationId',
|
||||
canActivate: [userGuard],
|
||||
@@ -102,7 +124,7 @@ export const routes: Routes = [
|
||||
),
|
||||
resolve: { bundSingleProject: bundSingleProjectResolver },
|
||||
},
|
||||
{
|
||||
{
|
||||
path: 'projects/eu/:id',
|
||||
canActivate: [userGuard],
|
||||
pathMatch: 'full',
|
||||
@@ -165,9 +187,15 @@ export const routes: Routes = [
|
||||
resolve: { collaborationNetwork: collaborationNetworkResolver },
|
||||
runGuardsAndResolvers: (from, to) => {
|
||||
const keys = [
|
||||
'filter_by', 'start_year', 'end_year', 'min_contributors',
|
||||
'max_contributors', 'min_collaborations', 'max_collaborations',
|
||||
'institutions', 'topics',
|
||||
'filter_by',
|
||||
'start_year',
|
||||
'end_year',
|
||||
'min_contributors',
|
||||
'max_contributors',
|
||||
'min_collaborations',
|
||||
'max_collaborations',
|
||||
'institutions',
|
||||
'topics',
|
||||
];
|
||||
return keys.some(
|
||||
(key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key),
|
||||
@@ -267,7 +295,12 @@ export const routes: Routes = [
|
||||
resolve: { fundingProjectPage: fundingProjectPageResolver },
|
||||
runGuardsAndResolvers: (from, to) => {
|
||||
const keys = [
|
||||
'search', 'page', 'size', 'selected_project_types', 'sort_by', 'sorting_order',
|
||||
'search',
|
||||
'page',
|
||||
'size',
|
||||
'selected_project_types',
|
||||
'sort_by',
|
||||
'sorting_order',
|
||||
];
|
||||
return keys.some(
|
||||
(key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key),
|
||||
@@ -298,7 +331,8 @@ export const routes: Routes = [
|
||||
data: {
|
||||
routeStatusCode: 404,
|
||||
routeTitle: 'Seite nicht gefunden',
|
||||
routeMessage: 'Die gesuchte Seite existiert leider nicht oder wurde verschoben.',
|
||||
routeMessage:
|
||||
'Die gesuchte Seite existiert leider nicht oder wurde verschoben.',
|
||||
},
|
||||
canActivate: [userGuard],
|
||||
},
|
||||
|
||||
@@ -107,13 +107,21 @@
|
||||
<div class="sidebar-card">
|
||||
<h3>
|
||||
<mat-icon>label</mat-icon>
|
||||
Relevante Themen
|
||||
Schlüsselwörter
|
||||
</h3>
|
||||
<div class="chip-list">
|
||||
@for (topic of relevantTopics; track topic; let i = $index) {
|
||||
<span class="topic-chip" [ngClass]="chipColor(i)">{{
|
||||
topic
|
||||
}}</span>
|
||||
@if (article.keywords && article.keywords.length) {
|
||||
@for (
|
||||
keyword of article.keywords;
|
||||
track keyword;
|
||||
let i = $index
|
||||
) {
|
||||
<span class="topic-chip" [ngClass]="chipColor(i)">{{
|
||||
keyword
|
||||
}}</span>
|
||||
}
|
||||
} @else {
|
||||
<p class="placeholder">Keine Schlüsselwörter gefunden.</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -180,6 +180,9 @@ main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
max-height: 375px;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.person-item {
|
||||
|
||||
@@ -24,6 +24,7 @@ interface NewsArticleDetail {
|
||||
full_content?: string | null;
|
||||
relevant?: boolean;
|
||||
authors?: MentionedPerson[];
|
||||
keywords?: string[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -49,13 +50,6 @@ export class NewsDetailComponent implements OnInit {
|
||||
loading = false;
|
||||
notFound = false;
|
||||
|
||||
readonly relevantTopics = [
|
||||
'Künstliche Intelligenz',
|
||||
'Maschinelles Lernen',
|
||||
'Digitalisierung',
|
||||
'Datenwissenschaft',
|
||||
];
|
||||
|
||||
private readonly chipColors = ['purple', 'blue', 'green', 'orange', 'pink'];
|
||||
|
||||
chipColor(index: number): string {
|
||||
|
||||
@@ -4,107 +4,31 @@
|
||||
<p>Aktuelle Nachrichten aus Campus-Aktuell.</p>
|
||||
</div>
|
||||
|
||||
<div class="news-toolbar">
|
||||
<mat-form-field appearance="outline" class="search-field">
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<input
|
||||
matInput
|
||||
[formControl]="searchControl"
|
||||
placeholder="Nachrichten durchsuchen..." />
|
||||
</mat-form-field>
|
||||
|
||||
@if (!isSearching) {
|
||||
<mat-form-field appearance="outline" class="sort-field">
|
||||
<mat-select
|
||||
[value]="sortOrder"
|
||||
(selectionChange)="onSortChange($event.value)">
|
||||
<mat-option value="desc">Neueste zuerst</mat-option>
|
||||
<mat-option value="asc">Älteste zuerst</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<ng-template #snippetTpl let-article>
|
||||
@if (article.snippet) {
|
||||
<span class="snippet" [innerHTML]="article.snippet"></span>
|
||||
} @else {
|
||||
<span class="snippet-empty">—</span>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<div class="table-wrap">
|
||||
@if (loading) {
|
||||
<div class="loading">
|
||||
<mat-spinner diameter="36"></mat-spinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="articles" class="mat-elevation-z2">
|
||||
<ng-container matColumnDef="maintitle">
|
||||
<th mat-header-cell *matHeaderCellDef>Titel</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
<a class="article-title" [routerLink]="['/news', article.id]">{{
|
||||
article.maintitle || 'Kein Titel'
|
||||
}}</a>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="snippet">
|
||||
<th mat-header-cell *matHeaderCellDef>Fundstelle</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
@if (article.snippet) {
|
||||
<span class="snippet" [innerHTML]="article.snippet"></span>
|
||||
} @else {
|
||||
<span class="snippet-empty">—</span>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="relevance">
|
||||
<th mat-header-cell *matHeaderCellDef>Relevanz</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
@if (article.relevant === true) {
|
||||
<span class="relevance-badge is-relevant">
|
||||
<mat-icon>check_circle</mat-icon>
|
||||
Relevant
|
||||
</span>
|
||||
} @else if (article.relevant === false) {
|
||||
<span class="relevance-badge not-relevant">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
Nicht relevant
|
||||
</span>
|
||||
} @else {
|
||||
<span class="relevance-badge undetermined">
|
||||
<mat-icon>help</mat-icon>
|
||||
Nicht bestimmt
|
||||
</span>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="date">
|
||||
<th mat-header-cell *matHeaderCellDef>Datum</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
{{ formatDate(article.date) }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading && articles.length === 0) {
|
||||
<div class="empty-state">
|
||||
@if (isSearching) {
|
||||
Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden.
|
||||
} @else {
|
||||
Keine Nachrichten gefunden.
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="table-footer">
|
||||
<span>{{ articleRange() }}</span>
|
||||
<mat-paginator
|
||||
[length]="total"
|
||||
[pageIndex]="currentPage - 1"
|
||||
[pageSize]="paginationService.selection"
|
||||
[pageSizeOptions]="paginationService.options"
|
||||
(page)="onPage($event)">
|
||||
</mat-paginator>
|
||||
</div>
|
||||
<app-news-list
|
||||
[articles]="articles"
|
||||
[showFilters]="true"
|
||||
[displayedColumns]="displayedColumns"
|
||||
[total]="total"
|
||||
[loading]="loading"
|
||||
[currentPage]="currentPage"
|
||||
[sortOrder]="sortOrder"
|
||||
[searchControl]="searchControl"
|
||||
[initialRelevance]="relevanceValues"
|
||||
[initialYearFrom]="yearFrom"
|
||||
[initialYearTo]="yearTo"
|
||||
extraColumnId="snippet"
|
||||
extraColumnHeader="Inhalt"
|
||||
[extraColumnTemplate]="snippetTpl"
|
||||
(sortChange)="onSortChange($event)"
|
||||
(pageChange)="onPage($event)"
|
||||
(filtersChange)="onFiltersChange($event)">
|
||||
</app-news-list>
|
||||
</div>
|
||||
|
||||
@@ -17,107 +17,14 @@ h6 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.news-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 25px;
|
||||
}
|
||||
|
||||
.search-field {
|
||||
max-width: 480px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-subscript-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-text-field-wrapper {
|
||||
height: 42px;
|
||||
background: #fff;
|
||||
border-radius: var(--sg-radius-sm);
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-infix {
|
||||
min-height: unset;
|
||||
height: 42px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__leading,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__notch,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__trailing {
|
||||
border-color: #d9e2f0;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element {
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element::placeholder {
|
||||
color: var(--sg-text-muted);
|
||||
opacity: 1;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.sort-field {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
position: relative;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
min-width: 600px;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 10px;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: inline-block;
|
||||
max-width: 520px;
|
||||
line-height: 1.35;
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--sg-text);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.snippet {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
::ng-deep .snippet em {
|
||||
@@ -131,79 +38,8 @@ table {
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
.relevance-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 5px 12px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
|
||||
mat-icon {
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
&.is-relevant {
|
||||
background: #effaf3;
|
||||
border: 1px solid #bdebcf;
|
||||
color: #24834f;
|
||||
}
|
||||
|
||||
&.not-relevant {
|
||||
background: var(--sg-surface-muted);
|
||||
border: 1px solid #e2e2e2;
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
&.undetermined {
|
||||
background: #fff7e8;
|
||||
border: 1px solid #ffd796;
|
||||
color: #c67500;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-header-cell {
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-row {
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-cell {
|
||||
color: var(--sg-text);
|
||||
border-bottom-color: var(--sg-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.table-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 66px;
|
||||
padding: 0 22px 0 28px;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.page {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.table-footer {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { PageEvent } from '@angular/material/paginator';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||
|
||||
import { WorksService } from '../../api';
|
||||
import { PaginationService } from '../../shared/services/pagination.service';
|
||||
import {
|
||||
NewsArticleBase,
|
||||
NewsFilterState,
|
||||
NewsListComponent,
|
||||
NEWS_MIN_YEAR,
|
||||
SortOrder,
|
||||
} from '../../shared/ui/news-list/news-list.component';
|
||||
|
||||
interface NewsArticle {
|
||||
id: string;
|
||||
date?: string | null;
|
||||
maintitle?: string | null;
|
||||
interface NewsArticle extends NewsArticleBase {
|
||||
author?: string | null;
|
||||
url?: string | null;
|
||||
relevant?: boolean | null;
|
||||
snippet?: string | null;
|
||||
}
|
||||
|
||||
@@ -32,22 +28,11 @@ interface NewsPage {
|
||||
results: NewsArticle[];
|
||||
}
|
||||
|
||||
type SortOrder = 'desc' | 'asc';
|
||||
const DEFAULT_SORT_ORDER: SortOrder = 'desc';
|
||||
|
||||
@Component({
|
||||
selector: 'app-news',
|
||||
imports: [
|
||||
MatIconModule,
|
||||
MatSelectModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
RouterLink,
|
||||
],
|
||||
imports: [ReactiveFormsModule, NewsListComponent],
|
||||
templateUrl: './news.component.html',
|
||||
styleUrl: './news.component.scss',
|
||||
})
|
||||
@@ -61,12 +46,12 @@ export class NewsComponent implements OnInit {
|
||||
|
||||
readonly searchControl = new FormControl('', { nonNullable: true });
|
||||
|
||||
get displayedColumns(): string[] {
|
||||
if (this.isSearching) {
|
||||
return ['maintitle', 'snippet', 'relevance', 'date'];
|
||||
}
|
||||
return ['maintitle', 'relevance', 'date'];
|
||||
}
|
||||
readonly displayedColumns: string[] = [
|
||||
'maintitle',
|
||||
'snippet',
|
||||
'relevance',
|
||||
'date',
|
||||
];
|
||||
|
||||
articles: NewsArticle[] = [];
|
||||
total = 0;
|
||||
@@ -75,9 +60,12 @@ export class NewsComponent implements OnInit {
|
||||
currentPage = 1;
|
||||
sortOrder: SortOrder = DEFAULT_SORT_ORDER;
|
||||
|
||||
get isSearching(): boolean {
|
||||
return this.searchControl.value.trim().length > 0;
|
||||
}
|
||||
relevanceValues: string[] = [];
|
||||
yearFrom: number | null = null;
|
||||
yearTo: number | null = null;
|
||||
|
||||
private readonly minYear = NEWS_MIN_YEAR;
|
||||
private readonly maxYear = new Date().getFullYear();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParamMap
|
||||
@@ -88,6 +76,9 @@ export class NewsComponent implements OnInit {
|
||||
params.get('pageSize'),
|
||||
);
|
||||
this.sortOrder = this.parseSortOrder(params.get('sortOrder'));
|
||||
this.relevanceValues = this.parseRelevance(params.get('relevance'));
|
||||
this.yearFrom = this.parseYear(params.get('yearFrom'));
|
||||
this.yearTo = this.parseYear(params.get('yearTo'));
|
||||
this.searchControl.setValue(params.get('q') ?? '', {
|
||||
emitEvent: false,
|
||||
});
|
||||
@@ -115,10 +106,11 @@ export class NewsComponent implements OnInit {
|
||||
const basePath = this.worksService.configuration.basePath ?? '';
|
||||
|
||||
if (query) {
|
||||
const params = new HttpParams()
|
||||
let params = new HttpParams()
|
||||
.set('query', query)
|
||||
.set('page', this.currentPage)
|
||||
.set('pageSize', this.paginationService.selection);
|
||||
params = this.appendFilters(params);
|
||||
|
||||
this.httpClient
|
||||
.get<NewsPage>(`${basePath}/api/news/search`, { params })
|
||||
@@ -135,10 +127,11 @@ export class NewsComponent implements OnInit {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const params = new HttpParams()
|
||||
let params = new HttpParams()
|
||||
.set('page', this.currentPage)
|
||||
.set('pageSize', this.paginationService.selection)
|
||||
.set('sortOrder', this.sortOrder);
|
||||
params = this.appendFilters(params);
|
||||
|
||||
this.httpClient
|
||||
.get<NewsPage>(`${basePath}/api/news`, { params })
|
||||
@@ -157,6 +150,19 @@ export class NewsComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
private appendFilters(params: HttpParams): HttpParams {
|
||||
if (this.relevanceValues.length > 0) {
|
||||
params = params.set('relevance', this.relevanceValues.join(','));
|
||||
}
|
||||
if (this.yearFrom !== null) {
|
||||
params = params.set('yearFrom', this.yearFrom);
|
||||
}
|
||||
if (this.yearTo !== null) {
|
||||
params = params.set('yearTo', this.yearTo);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
@@ -179,19 +185,22 @@ export class NewsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
formatDate(dateStr?: string | null): string {
|
||||
if (!dateStr) return '-';
|
||||
const date = new Date(dateStr);
|
||||
if (isNaN(date.getTime())) return dateStr;
|
||||
return new Intl.DateTimeFormat('de-DE').format(date);
|
||||
}
|
||||
onFiltersChange(state: NewsFilterState): void {
|
||||
const relevance =
|
||||
state.relevance.length > 0 ? state.relevance.join(',') : null;
|
||||
const yearFrom = state.yearFrom > this.minYear ? state.yearFrom : null;
|
||||
const yearTo = state.yearTo < this.maxYear ? state.yearTo : null;
|
||||
|
||||
articleRange(): string {
|
||||
if (this.total === 0) return 'Keine Nachrichten gefunden';
|
||||
const pageSize = this.paginationService.selection;
|
||||
const start = (this.currentPage - 1) * pageSize + 1;
|
||||
const end = Math.min(start + this.articles.length - 1, this.total);
|
||||
return `Zeige ${start} bis ${end} von ${this.total} Nachrichten`;
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
relevance,
|
||||
yearFrom,
|
||||
yearTo,
|
||||
page: 1,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
private parsePage(value: string | null): number {
|
||||
@@ -216,4 +225,23 @@ export class NewsComponent implements OnInit {
|
||||
}
|
||||
return DEFAULT_SORT_ORDER;
|
||||
}
|
||||
|
||||
private parseRelevance(value: string | null): string[] {
|
||||
if (!value) {
|
||||
return [];
|
||||
}
|
||||
const allowed = ['relevant', 'not_relevant'];
|
||||
return value
|
||||
.split(',')
|
||||
.map((entry) => entry.trim())
|
||||
.filter((entry) => allowed.includes(entry));
|
||||
}
|
||||
|
||||
private parseYear(value: string | null): number | null {
|
||||
const year = Number.parseInt(value ?? '', 10);
|
||||
if (Number.isNaN(year)) {
|
||||
return null;
|
||||
}
|
||||
return year;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,79 +4,15 @@
|
||||
<p>Aktuelle Nachrichten zu dieser Person.</p>
|
||||
</div>
|
||||
|
||||
<div class="news-toolbar">
|
||||
<mat-form-field appearance="outline" class="search-field">
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<input
|
||||
matInput
|
||||
[formControl]="searchControl"
|
||||
placeholder="Nachrichten durchsuchen..." />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" class="sort-field">
|
||||
<mat-select
|
||||
[value]="sortOrder"
|
||||
(selectionChange)="onSortChange($event.value)">
|
||||
<mat-option value="desc">Neueste zuerst</mat-option>
|
||||
<mat-option value="asc">Älteste zuerst</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div class="table-wrap">
|
||||
@if (loading) {
|
||||
<div class="loading">
|
||||
<mat-spinner diameter="36"></mat-spinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="articles" class="mat-elevation-z2">
|
||||
<ng-container matColumnDef="maintitle">
|
||||
<th mat-header-cell *matHeaderCellDef>Titel</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
<a class="article-title" [routerLink]="['/news', article.id]">{{
|
||||
article.maintitle || 'Kein Titel'
|
||||
}}</a>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="author">
|
||||
<th mat-header-cell *matHeaderCellDef>Autor</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
{{ article.author || '-' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="date">
|
||||
<th mat-header-cell *matHeaderCellDef>Datum</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
{{ formatDate(article.date) }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading && articles.length === 0) {
|
||||
<div class="empty-state">
|
||||
@if (isSearching) {
|
||||
Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden.
|
||||
} @else {
|
||||
Keine Nachrichten gefunden.
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="table-footer">
|
||||
<span>{{ articleRange() }}</span>
|
||||
<mat-paginator
|
||||
[length]="total"
|
||||
[pageIndex]="currentPageIndex"
|
||||
[pageSize]="paginationService.selection"
|
||||
[pageSizeOptions]="paginationService.options"
|
||||
(page)="onPage($event)">
|
||||
</mat-paginator>
|
||||
</div>
|
||||
<app-news-list
|
||||
[articles]="articles"
|
||||
[displayedColumns]="displayedColumns"
|
||||
[total]="total"
|
||||
[loading]="loading"
|
||||
[currentPage]="currentPage"
|
||||
[sortOrder]="sortOrder"
|
||||
[searchControl]="searchControl"
|
||||
(sortChange)="onSortChange($event)"
|
||||
(pageChange)="onPage($event)">
|
||||
</app-news-list>
|
||||
</div>
|
||||
|
||||
@@ -17,140 +17,8 @@ h6 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.news-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 25px;
|
||||
}
|
||||
|
||||
.search-field {
|
||||
max-width: 480px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-subscript-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-text-field-wrapper {
|
||||
height: 42px;
|
||||
background: #fff;
|
||||
border-radius: var(--sg-radius-sm);
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-infix {
|
||||
min-height: unset;
|
||||
height: 42px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__leading,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__notch,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__trailing {
|
||||
border-color: #d9e2f0;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element {
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element::placeholder {
|
||||
color: var(--sg-text-muted);
|
||||
opacity: 1;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.sort-field {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
position: relative;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
min-width: 600px;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 10px;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: inline-block;
|
||||
max-width: 520px;
|
||||
line-height: 1.35;
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--sg-text);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-header-cell {
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-row {
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-cell {
|
||||
color: var(--sg-text);
|
||||
border-bottom-color: var(--sg-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.table-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 66px;
|
||||
padding: 0 22px 0 28px;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.page {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.table-footer {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,21 @@
|
||||
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { PageEvent } from '@angular/material/paginator';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||
|
||||
import { PaginationService } from '../../shared/services/pagination.service';
|
||||
import { ResolverStateService } from '../../shared/services/resolver-state.service';
|
||||
import { NewsArticle, NewsPage } from '../../resolvers/person-news.resolver';
|
||||
import {
|
||||
NewsListComponent,
|
||||
SortOrder,
|
||||
} from '../../shared/ui/news-list/news-list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-news',
|
||||
imports: [
|
||||
MatIconModule,
|
||||
MatSelectModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
RouterLink,
|
||||
],
|
||||
imports: [ReactiveFormsModule, NewsListComponent],
|
||||
templateUrl: './person-news.component.html',
|
||||
styleUrl: './person-news.component.scss',
|
||||
})
|
||||
@@ -40,11 +28,11 @@ export class PersonNewsComponent implements OnInit {
|
||||
|
||||
readonly searchControl = new FormControl('', { nonNullable: true });
|
||||
|
||||
displayedColumns = ['maintitle', 'author', 'date'];
|
||||
displayedColumns = ['maintitle', 'relevance', 'date'];
|
||||
articles: NewsArticle[] = [];
|
||||
total = 0;
|
||||
currentPageIndex = 0;
|
||||
sortOrder: 'desc' | 'asc' = 'desc';
|
||||
currentPage = 1;
|
||||
sortOrder: SortOrder = 'desc';
|
||||
|
||||
get loading(): boolean {
|
||||
return this.resolverStateService.isResolving();
|
||||
@@ -75,7 +63,7 @@ export class PersonNewsComponent implements OnInit {
|
||||
const sortOrder = params.get('sortOrder');
|
||||
const query = params.get('query') ?? '';
|
||||
|
||||
this.currentPageIndex = page - 1;
|
||||
this.currentPage = page;
|
||||
this.paginationService.selection = pageSize;
|
||||
this.sortOrder = sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
this.searchControl.setValue(query, { emitEvent: false });
|
||||
@@ -103,30 +91,13 @@ export class PersonNewsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onSortChange(order: 'desc' | 'asc'): void {
|
||||
onSortChange(order: SortOrder): void {
|
||||
this.updateQueryParams({
|
||||
sortOrder: order,
|
||||
page: 1,
|
||||
});
|
||||
}
|
||||
|
||||
formatDate(dateStr?: string | null): string {
|
||||
if (!dateStr) return '-';
|
||||
const date = new Date(dateStr);
|
||||
if (isNaN(date.getTime())) return dateStr;
|
||||
return new Intl.DateTimeFormat('de-DE').format(date);
|
||||
}
|
||||
|
||||
articleRange(): string {
|
||||
if (this.total === 0) return 'Keine Nachrichten gefunden';
|
||||
const start = this.currentPageIndex * this.paginationService.selection + 1;
|
||||
const end = Math.min(
|
||||
start + this.paginationService.selection - 1,
|
||||
this.total,
|
||||
);
|
||||
return `Zeige ${start} bis ${end} von ${this.total} Nachrichten`;
|
||||
}
|
||||
|
||||
private updateQueryParams(
|
||||
overrides: Record<string, string | number | null>,
|
||||
): void {
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface NewsArticle {
|
||||
maintitle?: string | null;
|
||||
author?: string | null;
|
||||
url?: string | null;
|
||||
relevant?: boolean | null;
|
||||
}
|
||||
|
||||
export interface NewsPage {
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<div class="news-toolbar">
|
||||
<mat-form-field appearance="outline" class="search-field">
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<input
|
||||
matInput
|
||||
[formControl]="searchControl"
|
||||
placeholder="Nachrichten durchsuchen..." />
|
||||
</mat-form-field>
|
||||
|
||||
@if (!isSearching) {
|
||||
<mat-form-field appearance="outline" class="sort-field">
|
||||
<mat-select
|
||||
[value]="sortOrder"
|
||||
(selectionChange)="onSortChange($event.value)"
|
||||
placeholder="Sortierung">
|
||||
<mat-option value="desc">Neueste zuerst</mat-option>
|
||||
<mat-option value="asc">Älteste zuerst</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
}
|
||||
|
||||
@if (showFilters) {
|
||||
<mat-form-field appearance="outline" class="relevance-field">
|
||||
<mat-select
|
||||
[formControl]="relevanceFilter"
|
||||
placeholder="Relevanz"
|
||||
multiple>
|
||||
<mat-option value="relevant">Relevant</mat-option>
|
||||
<mat-option value="not_relevant">Nicht relevant</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<div class="year-field">
|
||||
<div class="year-field__head">
|
||||
<span class="year-field__label">Datum</span>
|
||||
<span class="year-field__range">
|
||||
{{ yearFrom.value }} – {{ yearTo.value }}
|
||||
</span>
|
||||
</div>
|
||||
<mat-slider [min]="minYear" [max]="maxYear" step="1" discrete>
|
||||
<input matSliderStartThumb [formControl]="yearFrom" />
|
||||
<input matSliderEndThumb [formControl]="yearTo" />
|
||||
</mat-slider>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="reset-filter-btn"
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
(click)="resetFilters()"
|
||||
aria-label="Filter zurücksetzen">
|
||||
<mat-icon>filter_alt_off</mat-icon>
|
||||
<span>Zurücksetzen</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="table-wrap">
|
||||
@if (loading) {
|
||||
<div class="loading">
|
||||
<mat-spinner diameter="36"></mat-spinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="articles" class="mat-elevation-z2">
|
||||
<ng-container matColumnDef="maintitle">
|
||||
<th mat-header-cell *matHeaderCellDef>Titel</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
<a class="article-title" [routerLink]="['/news', article.id]">{{
|
||||
article.maintitle || 'Kein Titel'
|
||||
}}</a>
|
||||
@if (article.related) {
|
||||
<span class="related-badge"> Ähnlich zu deiner Suche </span>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="relevance">
|
||||
<th mat-header-cell *matHeaderCellDef>
|
||||
<span class="relevance-header">
|
||||
Relevanz
|
||||
<mat-icon
|
||||
class="relevance-info"
|
||||
tabindex="0"
|
||||
aria-label="Was bedeutet die Relevanz?"
|
||||
[matTooltip]="relevanceHelp"
|
||||
matTooltipClass="relevance-tooltip">
|
||||
info
|
||||
</mat-icon>
|
||||
</span>
|
||||
</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
@if (article.relevant === true) {
|
||||
<span class="relevance-badge is-relevant">
|
||||
<mat-icon>check_circle</mat-icon>
|
||||
Relevant
|
||||
</span>
|
||||
} @else if (article.relevant === false) {
|
||||
<span class="relevance-badge not-relevant">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
Nicht relevant
|
||||
</span>
|
||||
} @else {
|
||||
<span class="relevance-badge undetermined">
|
||||
<mat-icon>help</mat-icon>
|
||||
Nicht bestimmt
|
||||
</span>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="date">
|
||||
<th mat-header-cell *matHeaderCellDef>Datum</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
{{ formatDate(article.date) }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
@if (extraColumnId && extraColumnTemplate) {
|
||||
<ng-container [matColumnDef]="extraColumnId">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ extraColumnHeader }}</th>
|
||||
<td mat-cell *matCellDef="let article">
|
||||
<ng-container
|
||||
*ngTemplateOutlet="
|
||||
extraColumnTemplate;
|
||||
context: { $implicit: article }
|
||||
"></ng-container>
|
||||
</td>
|
||||
</ng-container>
|
||||
}
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading && articles.length === 0) {
|
||||
<div class="empty-state">
|
||||
@if (isSearching) {
|
||||
Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden.
|
||||
} @else {
|
||||
Keine Nachrichten gefunden.
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="table-footer">
|
||||
<span>{{ articleRange() }}</span>
|
||||
<mat-paginator
|
||||
[length]="total"
|
||||
[pageIndex]="currentPage - 1"
|
||||
[pageSize]="paginationService.selection"
|
||||
[pageSizeOptions]="paginationService.options"
|
||||
(page)="onPage($event)">
|
||||
</mat-paginator>
|
||||
</div>
|
||||
@@ -0,0 +1,279 @@
|
||||
.news-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 25px;
|
||||
}
|
||||
|
||||
.search-field {
|
||||
max-width: 480px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-subscript-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-text-field-wrapper {
|
||||
height: 42px;
|
||||
background: #fff;
|
||||
border-radius: var(--sg-radius-sm);
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mat-mdc-form-field-infix {
|
||||
min-height: unset;
|
||||
height: 42px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__leading,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__notch,
|
||||
::ng-deep .news-toolbar .mdc-notched-outline__trailing {
|
||||
border-color: #d9e2f0;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element {
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
::ng-deep .news-toolbar input.mat-mdc-input-element::placeholder {
|
||||
color: var(--sg-text-muted);
|
||||
opacity: 1;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.sort-field {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.relevance-field {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.year-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
min-width: 220px;
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
.year-field__head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.year-field__label {
|
||||
color: var(--sg-text-muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.year-field__range {
|
||||
color: var(--sg-text);
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.year-field mat-slider {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.reset-filter-btn {
|
||||
min-width: 132px;
|
||||
height: 42px;
|
||||
padding: 0 14px;
|
||||
border-color: #d9e2f0;
|
||||
border-radius: var(--sg-radius-sm);
|
||||
color: var(--sg-text);
|
||||
background: #fff;
|
||||
|
||||
mat-icon {
|
||||
margin-right: 6px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
position: relative;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
min-width: 600px;
|
||||
table-layout: fixed;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 10px;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-maintitle {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-relevance {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-date {
|
||||
width: 110px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
line-height: 1.45;
|
||||
color: var(--sg-text);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--sg-text);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.related-badge {
|
||||
display: flex;
|
||||
width: fit-content;
|
||||
align-items: center;
|
||||
margin-top: 6px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
background: #eef3fe;
|
||||
border: 1px solid #c5d6f7;
|
||||
color: #2f5bd0;
|
||||
}
|
||||
|
||||
.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;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.relevance-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 5px 12px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
|
||||
mat-icon {
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
&.is-relevant {
|
||||
background: #effaf3;
|
||||
border: 1px solid #bdebcf;
|
||||
color: #24834f;
|
||||
}
|
||||
|
||||
&.not-relevant {
|
||||
background: var(--sg-surface-muted);
|
||||
border: 1px solid #e2e2e2;
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
&.undetermined {
|
||||
background: #fff7e8;
|
||||
border: 1px solid #ffd796;
|
||||
color: #c67500;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-header-cell {
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.relevance-header {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.relevance-info {
|
||||
font-size: 15px;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
color: var(--sg-text-muted);
|
||||
cursor: help;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: var(--sg-text);
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .relevance-tooltip.mdc-tooltip .mdc-tooltip__surface {
|
||||
max-width: 260px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
::ng-deep .mat-mdc-cell {
|
||||
padding-top: 18px;
|
||||
padding-bottom: 18px;
|
||||
vertical-align: top;
|
||||
color: var(--sg-text);
|
||||
border-bottom-color: var(--sg-border);
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.table-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 66px;
|
||||
padding: 0 22px 0 28px;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.table-footer {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
TemplateRef,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { merge, debounceTime } from 'rxjs';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
import { PaginationService } from '../../services/pagination.service';
|
||||
|
||||
export interface NewsArticleBase {
|
||||
id: string;
|
||||
date?: string | null;
|
||||
maintitle?: string | null;
|
||||
url?: string | null;
|
||||
relevant?: boolean | null;
|
||||
related?: boolean | null;
|
||||
}
|
||||
|
||||
export type SortOrder = 'desc' | 'asc';
|
||||
|
||||
export const NEWS_MIN_YEAR = 2000;
|
||||
|
||||
export interface NewsFilterState {
|
||||
relevance: string[];
|
||||
yearFrom: number;
|
||||
yearTo: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-news-list',
|
||||
imports: [
|
||||
MatIconModule,
|
||||
MatSelectModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
MatTooltipModule,
|
||||
MatSliderModule,
|
||||
MatButtonModule,
|
||||
NgTemplateOutlet,
|
||||
ReactiveFormsModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './news-list.component.html',
|
||||
styleUrl: './news-list.component.scss',
|
||||
})
|
||||
export class NewsListComponent {
|
||||
readonly paginationService = inject(PaginationService);
|
||||
|
||||
readonly relevanceHelp =
|
||||
'Zeigt, ob ein Artikel inhaltlich über eine konkrete Person berichtet ' +
|
||||
'(Relevant) oder eine allgemeine Mitteilung ohne Personenbezug ist ' +
|
||||
'(Nicht relevant).';
|
||||
|
||||
@Input({ required: true }) articles: NewsArticleBase[] = [];
|
||||
@Input({ required: true }) displayedColumns: string[] = [];
|
||||
@Input() total = 0;
|
||||
@Input() loading = false;
|
||||
@Input() currentPage = 1;
|
||||
@Input() sortOrder: SortOrder = 'desc';
|
||||
@Input({ required: true }) searchControl!: FormControl<string>;
|
||||
@Input() showFilters = false;
|
||||
|
||||
readonly minYear = NEWS_MIN_YEAR;
|
||||
readonly maxYear = new Date().getFullYear();
|
||||
|
||||
readonly relevanceFilter = new FormControl<string[]>([], {
|
||||
nonNullable: true,
|
||||
});
|
||||
readonly yearFrom = new FormControl<number>(this.minYear, {
|
||||
nonNullable: true,
|
||||
});
|
||||
readonly yearTo = new FormControl<number>(this.maxYear, {
|
||||
nonNullable: true,
|
||||
});
|
||||
|
||||
@Input() set initialRelevance(values: string[] | null) {
|
||||
this.relevanceFilter.setValue(values ?? [], { emitEvent: false });
|
||||
}
|
||||
@Input() set initialYearFrom(year: number | null) {
|
||||
this.yearFrom.setValue(year ?? this.minYear, { emitEvent: false });
|
||||
}
|
||||
@Input() set initialYearTo(year: number | null) {
|
||||
this.yearTo.setValue(year ?? this.maxYear, { emitEvent: false });
|
||||
}
|
||||
|
||||
@Input() extraColumnId: string | null = null;
|
||||
@Input() extraColumnHeader = '';
|
||||
@Input() extraColumnTemplate: TemplateRef<{
|
||||
$implicit: NewsArticleBase;
|
||||
}> | null = null;
|
||||
|
||||
@Output() sortChange = new EventEmitter<SortOrder>();
|
||||
@Output() pageChange = new EventEmitter<PageEvent>();
|
||||
@Output() filtersChange = new EventEmitter<NewsFilterState>();
|
||||
|
||||
constructor() {
|
||||
merge(
|
||||
this.relevanceFilter.valueChanges,
|
||||
this.yearFrom.valueChanges,
|
||||
this.yearTo.valueChanges,
|
||||
)
|
||||
.pipe(debounceTime(300), takeUntilDestroyed())
|
||||
.subscribe(() => {
|
||||
this.filtersChange.emit({
|
||||
relevance: this.relevanceFilter.value,
|
||||
yearFrom: this.yearFrom.value,
|
||||
yearTo: this.yearTo.value,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get isSearching(): boolean {
|
||||
return this.searchControl.value.trim().length > 0;
|
||||
}
|
||||
|
||||
onSortChange(order: SortOrder): void {
|
||||
this.sortChange.emit(order);
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.pageChange.emit(event);
|
||||
}
|
||||
|
||||
resetFilters(): void {
|
||||
this.relevanceFilter.setValue([]);
|
||||
this.yearFrom.setValue(this.minYear);
|
||||
this.yearTo.setValue(this.maxYear);
|
||||
}
|
||||
|
||||
formatDate(dateStr?: string | null): string {
|
||||
if (!dateStr) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
const parts = dateStr.split('.');
|
||||
|
||||
if (parts.length === 3) {
|
||||
const day = parts[0].trim().padStart(2, '0');
|
||||
const month = parts[1].trim().padStart(2, '0');
|
||||
const year = parts[2].trim();
|
||||
return `${day}.${month}.${year}`;
|
||||
}
|
||||
|
||||
const date = new Date(dateStr);
|
||||
|
||||
if (isNaN(date.getTime())) {
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat('de-DE', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
articleRange(): string {
|
||||
const relatedCount = this.articles.filter(
|
||||
(article) => article.related,
|
||||
).length;
|
||||
const matchCount = this.articles.length - relatedCount;
|
||||
|
||||
if (this.total === 0 && relatedCount === 0) {
|
||||
return 'Keine Nachrichten gefunden';
|
||||
}
|
||||
|
||||
const pageSize = this.paginationService.selection;
|
||||
const start = matchCount > 0 ? (this.currentPage - 1) * pageSize + 1 : 0;
|
||||
const end = Math.min(start + matchCount - 1, this.total);
|
||||
|
||||
const base =
|
||||
matchCount > 0
|
||||
? `Zeige ${start} bis ${end} von ${this.total} Nachrichten`
|
||||
: 'Keine direkten Treffer';
|
||||
|
||||
if (relatedCount > 0) {
|
||||
const suffix =
|
||||
relatedCount === 1
|
||||
? '1 ähnlicher Vorschlag'
|
||||
: `${relatedCount} ähnliche Vorschläge`;
|
||||
return `${base} · ${suffix}`;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user