feat(news-tab): add news tab and details page to person overview
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-11 21:40:26 +02:00
parent 9432d01135
commit 7442a56b0a
10 changed files with 824 additions and 3 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ from .model import NewsArticle, NewsArticleDetail, NewsPage
logger = logging.getLogger(__name__)
def get_news_page(page: int, page_size: int) -> NewsPage:
def get_news_page(page: int, page_size: int, sort_order: str = "desc") -> NewsPage:
offset = (page - 1) * page_size
response = _run_search(
@@ -23,7 +23,7 @@ def get_news_page(page: int, page_size: int) -> NewsPage:
source=["date", "maintitle", "author", "url"],
size=page_size,
offset=offset,
sort=[{"date_full": "desc"}],
sort=[{"date_full": sort_order}],
)
return _build_page(response, page, page_size)
+4 -1
View File
@@ -32,8 +32,11 @@ def list_news(
page_size: Annotated[
int, Query(alias="pageSize", description="Articles per page.", ge=1, le=100)
] = 10,
sort_order: Annotated[
str, Query(alias="sortOrder", description="Sort order: 'desc' (newest first) or 'asc' (oldest first).", pattern="^(asc|desc)$")
] = "desc",
):
return logic.get_news_page(page, page_size)
return logic.get_news_page(page, page_size, sort_order)
@router.get(
+15
View File
@@ -60,6 +60,14 @@ export const routes: Routes = [
return scalarChanged || topicsChanged;
},
},
{
path: 'news/:id',
canActivate: [userGuard],
loadComponent: () =>
import('./modules/news-detail/news-detail.component').then(
(mod) => mod.NewsDetailComponent,
),
},
{
path: 'publication/:publicationId',
canActivate: [userGuard],
@@ -135,6 +143,13 @@ export const routes: Routes = [
(mod) => mod.PersonFundingComponent,
),
},
{
path: 'news',
loadComponent: () =>
import('./modules/person-news/person-news.component').then(
(mod) => mod.PersonNewsComponent,
),
},
],
},
{
@@ -0,0 +1,92 @@
<div class="detail-page">
<button
type="button"
class="back-link"
(click)="navigateBack()"
aria-label="Zurück zu den Nachrichten">
<mat-icon>arrow_back</mat-icon>
Alle Nachrichten
</button>
@if (loading) {
<div class="state">
<mat-spinner diameter="42"></mat-spinner>
<p>Nachricht wird geladen...</p>
</div>
} @else if (notFound || !article) {
<div class="state error-state">
<mat-icon>search_off</mat-icon>
<h2>Nachricht nicht gefunden</h2>
<p>Der Artikel konnte nicht geladen werden.</p>
<a mat-stroked-button routerLink="/persons">Zur Personensuche</a>
</div>
} @else {
<div class="detail-layout">
<main>
<header class="hero">
<div class="eyebrow">
@if (article.author) {
<span>{{ article.author }}</span>
}
@if (article.date) {
<span>{{ formatDate(article.date) }}</span>
}
</div>
<p class="article-heading">{{ article.maintitle || 'Kein Titel' }}</p>
</header>
<div class="article-body">
@if (article.full_content) {
<p class="content">{{ article.full_content }}</p>
} @else {
<p class="placeholder">Kein Inhalt verfügbar.</p>
}
</div>
@if (article.url) {
<div class="article-actions">
<a
mat-stroked-button
[href]="article.url"
target="_blank"
rel="noopener">
<mat-icon>open_in_new</mat-icon>
Originalartikel öffnen
</a>
</div>
}
</main>
<aside class="sidebar">
<div class="sidebar-card">
<h3>
<mat-icon>group</mat-icon>
Erwähnte Personen
</h3>
<div class="person-list">
@for (person of mentionedPersons; track person) {
<article class="person-item">
<div class="avatar">{{ person.charAt(0) }}</div>
<span class="person-name">{{ person }}</span>
</article>
}
</div>
</div>
<div class="sidebar-card">
<h3>
<mat-icon>label</mat-icon>
Relevante Themen
</h3>
<div class="chip-list">
@for (topic of relevantTopics; track topic; let i = $index) {
<span class="topic-chip" [ngClass]="chipColor(i)">{{
topic
}}</span>
}
</div>
</div>
</aside>
</div>
}
</div>
@@ -0,0 +1,226 @@
.detail-page {
max-width: 1200px;
margin: 0 auto;
padding: 28px 32px 64px;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 6px;
background: none;
border: none;
cursor: pointer;
font-size: 14px;
color: var(--sg-text-muted);
padding: 0;
margin-bottom: 32px;
&:hover {
color: var(--sg-text);
}
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
}
}
.state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
padding: 80px 0;
text-align: center;
color: var(--sg-text-muted);
mat-icon {
font-size: 48px;
width: 48px;
height: 48px;
}
p {
margin: 0;
}
}
.error-state h2 {
margin: 0;
}
.detail-layout {
display: grid;
grid-template-columns: 1fr 280px;
gap: 40px;
align-items: start;
}
main {
min-width: 0;
}
.hero {
margin-bottom: 32px;
}
.eyebrow {
display: flex;
gap: 12px;
font-size: 13px;
color: var(--sg-text-muted);
margin-bottom: 12px;
span + span::before {
content: '·';
margin-right: 12px;
}
}
.article-heading {
margin: 0;
font-size: 28px;
font-weight: 700;
line-height: 1.3;
}
.article-body {
font-size: 15px;
line-height: 1.7;
color: var(--sg-text);
}
.content {
margin: 0;
white-space: pre-wrap;
}
.placeholder {
margin: 0;
color: var(--sg-text-muted);
font-style: italic;
}
.article-actions {
margin-top: 32px;
}
.sidebar {
display: flex;
flex-direction: column;
gap: 16px;
position: sticky;
top: 24px;
}
.sidebar-card {
padding: 20px;
border: 1px solid #d7e4ff;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
h3 {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 14px;
font-size: 14px;
font-weight: 600;
color: var(--sg-text);
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
color: var(--sg-text-muted);
}
}
}
.person-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.person-item {
display: grid;
grid-template-columns: 38px minmax(0, 1fr);
gap: 11px;
align-items: center;
padding: 12px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
}
.avatar {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 50%;
background: #e5ecfb;
color: var(--sg-text);
font-size: 15px;
font-weight: 700;
text-transform: uppercase;
}
.person-name {
color: var(--sg-text);
font-size: 13px;
font-weight: 700;
}
.chip-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.topic-chip {
display: inline-flex;
align-items: center;
padding: 6px 12px;
border: 1px solid var(--topic-border);
border-radius: 8px;
background: var(--topic-bg);
color: var(--topic-color);
font-size: 12px;
font-weight: 500;
line-height: 1.25;
}
.purple {
--topic-border: #d8cafe;
--topic-bg: #f6f0ff;
--topic-color: #7255d9;
}
.blue {
--topic-border: #bdd4ff;
--topic-bg: #f0f6ff;
--topic-color: #0b63ce;
}
.green {
--topic-border: #bdebcf;
--topic-bg: #effaf3;
--topic-color: #24834f;
}
.orange {
--topic-border: #ffd796;
--topic-bg: #fff7e8;
--topic-color: #c67500;
}
.pink {
--topic-border: #ffc7d7;
--topic-bg: #fff1f5;
--topic-color: #d12f61;
}
@@ -0,0 +1,107 @@
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { Location, NgClass } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { WorksService } from '../../api';
interface NewsArticleDetail {
id: string;
date?: string | null;
maintitle?: string | null;
author?: string | null;
url?: string | null;
full_content?: string | null;
}
@Component({
selector: 'app-news-detail',
imports: [
MatButtonModule,
MatIconModule,
MatProgressSpinnerModule,
RouterLink,
NgClass,
],
templateUrl: './news-detail.component.html',
styleUrl: './news-detail.component.scss',
})
export class NewsDetailComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute);
private readonly httpClient = inject(HttpClient);
private readonly worksService = inject(WorksService);
private readonly location = inject(Location);
article: NewsArticleDetail | null = null;
loading = false;
notFound = false;
readonly mentionedPersons = [
'Prof. Dr. Anna Müller',
'Dr. Hans Schmidt',
'Dr. Lena Weber',
];
readonly relevantTopics = [
'Künstliche Intelligenz',
'Maschinelles Lernen',
'Digitalisierung',
'Datenwissenschaft',
];
private readonly chipColors = ['purple', 'blue', 'green', 'orange', 'pink'];
chipColor(index: number): string {
return this.chipColors[index % this.chipColors.length];
}
ngOnInit(): void {
this.route.paramMap
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => {
const id = params.get('id');
if (id) {
this.fetchArticle(id);
}
});
}
navigateBack(): void {
this.location.back();
}
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', {
day: '2-digit',
month: 'long',
year: 'numeric',
}).format(date);
}
private fetchArticle(id: string): void {
this.loading = true;
this.notFound = false;
const basePath = this.worksService.configuration.basePath ?? '';
this.httpClient
.get<NewsArticleDetail>(`${basePath}/api/news/${encodeURIComponent(id)}`)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (article) => {
this.article = article;
this.loading = false;
},
error: () => {
this.notFound = true;
this.loading = false;
},
});
}
}
@@ -0,0 +1,76 @@
<div class="page">
<div>
<h6>Nachrichten</h6>
<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">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>
</div>
@@ -0,0 +1,156 @@
.page {
padding: 28px 32px 42px;
max-width: 100%;
margin: 0 auto;
}
h6 {
margin: 0 0 6px;
font-size: 22px;
line-height: 1.2;
font-weight: 700;
}
.page > div:first-child p {
margin: 0;
color: var(--sg-text-muted);
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;
}
}
@@ -0,0 +1,145 @@
import {
Component,
DestroyRef,
OnInit,
ViewChild,
inject,
} from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { MatSelectModule } from '@angular/material/select';
import {
MatPaginator,
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 { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { WorksService } from '../../api';
import { PaginationService } from '../../shared/services/pagination.service';
interface NewsArticle {
id: string;
date?: string | null;
maintitle?: string | null;
author?: string | null;
url?: string | null;
}
interface NewsPage {
total: number;
page: number;
page_size: number;
results: NewsArticle[];
}
const ARTICLE_CAP = 100;
@Component({
selector: 'app-person-news',
imports: [
MatIconModule,
MatSelectModule,
MatFormFieldModule,
MatInputModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatTableModule,
ReactiveFormsModule,
RouterLink,
],
templateUrl: './person-news.component.html',
styleUrl: './person-news.component.scss',
})
export class PersonNewsComponent implements OnInit {
@ViewChild(MatPaginator) paginator?: MatPaginator;
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute);
private readonly httpClient = inject(HttpClient);
private readonly worksService = inject(WorksService);
readonly paginationService = inject(PaginationService);
readonly searchControl = new FormControl('', { nonNullable: true });
displayedColumns = ['maintitle', 'author', 'date'];
private allArticles: NewsArticle[] = [];
articles: NewsArticle[] = [];
total = 0;
loading = false;
currentPageIndex = 0;
sortOrder: 'desc' | 'asc' = 'desc';
ngOnInit(): void {
this.route.parent?.paramMap
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.load();
});
}
load(): void {
this.loading = true;
const params = new HttpParams()
.set('page', 1)
.set('pageSize', ARTICLE_CAP)
.set('sortOrder', this.sortOrder);
const basePath = this.worksService.configuration.basePath ?? '';
this.httpClient
.get<NewsPage>(`${basePath}/api/news`, { params })
.subscribe({
next: (page) => {
this.allArticles = page.results ?? [];
this.total = this.allArticles.length;
this.currentPageIndex = 0;
this.updatePage();
this.loading = false;
},
error: () => {
this.loading = false;
},
});
}
onPage(event: PageEvent): void {
this.paginationService.selection = event.pageSize;
this.currentPageIndex = event.pageIndex;
this.updatePage();
}
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`;
}
onSortChange(order: 'desc' | 'asc'): void {
this.sortOrder = order;
this.load();
}
private updatePage(): void {
const start = this.currentPageIndex * this.paginationService.selection;
this.articles = this.allArticles.slice(
start,
start + this.paginationService.selection,
);
}
}
@@ -176,6 +176,7 @@ export class PersonComponent {
{ label: 'Netzwerk', path: 'network', disabled: false },
{ label: 'Gründungen', path: 'foundings', disabled: true },
{ label: 'Förderungen', path: 'funding', disabled: false },
{ label: 'Nachrichten', path: 'news', disabled: false },
];
onInterestingTagClick(selection: { id: string; name: string }): void {