refactor/news-list-ui #194
@@ -80,7 +80,14 @@ async def search_news(
|
||||
clauses = await _filter_clauses(year_from, year_to, relevance_values)
|
||||
exact_query = {
|
||||
"bool": {
|
||||
"must": [{"match": {"full_content": query_text}}],
|
||||
"must": [
|
||||
{
|
||||
"multi_match": {
|
||||
"query": query_text,
|
||||
"fields": ["maintitle^2", "full_content"],
|
||||
}
|
||||
}
|
||||
],
|
||||
"filter": clauses,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="page">
|
||||
<div>
|
||||
<h6>Nachrichten</h6>
|
||||
<div class="page-header">
|
||||
<h1>Nachrichten</h1>
|
||||
<p>Aktuelle Nachrichten aus Campus-Aktuell.</p>
|
||||
</div>
|
||||
|
||||
@@ -12,23 +12,65 @@
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<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>
|
||||
<ng-template #cardTmp let-article>
|
||||
<app-news-card [article]="article" [snippetTemplate]="snippetTpl" />
|
||||
</ng-template>
|
||||
|
||||
<ng-template #additionalFiltersTmp>
|
||||
<div class="additional-filters">
|
||||
<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>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #noResultsTmp>
|
||||
<div class="no-results">
|
||||
@if (isSearching()) {
|
||||
<span>Keine Ergebnisse für „{{ searchQuery().trim() }}" gefunden.</span>
|
||||
} @else {
|
||||
<span>Keine Nachrichten gefunden.</span>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<app-card-search
|
||||
[page]="page()"
|
||||
[loading]="loading()"
|
||||
[cardTmp]="cardTmp"
|
||||
[additionalFiltersTmp]="additionalFiltersTmp"
|
||||
[noResultsTmp]="noResultsTmp"
|
||||
[cardMinWidth]="380"
|
||||
[sortingDirectionOptions]="sortingDirectionOptions()"
|
||||
sortingDirectionLabel="Sortierung"
|
||||
searchLabel="Nachrichten durchsuchen" />
|
||||
</div>
|
||||
|
||||
@@ -4,22 +4,27 @@
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h6 {
|
||||
margin: 0 0 6px;
|
||||
font-size: 22px;
|
||||
line-height: 1.2;
|
||||
font-weight: 700;
|
||||
}
|
||||
.page-header {
|
||||
padding: 0 1rem;
|
||||
margin-bottom: 10px;
|
||||
|
||||
.page > div:first-child p {
|
||||
margin: 0;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 14px;
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: var(--sg-text);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 4px 0 0;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.snippet {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
color: var(--sg-text-muted);
|
||||
@@ -38,6 +43,69 @@ h6 {
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
.additional-filters {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding: 0 1rem 1rem;
|
||||
}
|
||||
|
||||
.relevance-field {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.year-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
min-width: 220px;
|
||||
padding: 0 6px;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.year-field__head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.page {
|
||||
padding: 16px;
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
DestroyRef,
|
||||
OnInit,
|
||||
computed,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
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 { debounceTime, merge } from 'rxjs';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
|
||||
import { WorksService } from '../../api';
|
||||
import { PaginationService } from '../../shared/services/pagination.service';
|
||||
import {
|
||||
CardSearchComponent,
|
||||
Page,
|
||||
} from '../../shared/ui/card-search/card-search.component';
|
||||
import {
|
||||
NewsArticleBase,
|
||||
NewsFilterState,
|
||||
NewsListComponent,
|
||||
NewsCardComponent,
|
||||
NEWS_MIN_YEAR,
|
||||
SortOrder,
|
||||
} from '../../shared/ui/news-list/news-list.component';
|
||||
} from '../../shared/ui/news-card/news-card.component';
|
||||
import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component';
|
||||
|
||||
interface NewsArticle extends NewsArticleBase {
|
||||
author?: string | null;
|
||||
@@ -28,11 +41,20 @@ interface NewsPage {
|
||||
results: NewsArticle[];
|
||||
}
|
||||
|
||||
const DEFAULT_SORT_ORDER: SortOrder = 'desc';
|
||||
type SortOrder = 'desc' | 'asc';
|
||||
|
||||
@Component({
|
||||
selector: 'app-news',
|
||||
imports: [ReactiveFormsModule, NewsListComponent],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
MatFormFieldModule,
|
||||
MatSelectModule,
|
||||
MatSliderModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
CardSearchComponent,
|
||||
NewsCardComponent,
|
||||
],
|
||||
templateUrl: './news.component.html',
|
||||
styleUrl: './news.component.scss',
|
||||
})
|
||||
@@ -42,188 +64,160 @@ export class NewsComponent implements OnInit {
|
||||
private readonly router = inject(Router);
|
||||
private readonly httpClient = inject(HttpClient);
|
||||
private readonly worksService = inject(WorksService);
|
||||
readonly paginationService = inject(PaginationService);
|
||||
|
||||
readonly searchControl = new FormControl('', { nonNullable: true });
|
||||
readonly minYear = NEWS_MIN_YEAR;
|
||||
readonly maxYear = new Date().getFullYear();
|
||||
|
||||
readonly displayedColumns: string[] = [
|
||||
'maintitle',
|
||||
'snippet',
|
||||
'relevance',
|
||||
'date',
|
||||
private readonly sortingDirectionOptionsAll: SelectorOption[] = [
|
||||
{ value: 'desc', display_name: 'Neueste zuerst' },
|
||||
{ value: 'asc', display_name: 'Älteste zuerst' },
|
||||
];
|
||||
|
||||
articles: NewsArticle[] = [];
|
||||
total = 0;
|
||||
loading = false;
|
||||
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,
|
||||
});
|
||||
|
||||
currentPage = 1;
|
||||
sortOrder: SortOrder = DEFAULT_SORT_ORDER;
|
||||
private readonly articles = signal<NewsArticle[]>([]);
|
||||
private readonly total = signal(0);
|
||||
readonly loading = signal(false);
|
||||
readonly searchQuery = signal('');
|
||||
|
||||
relevanceValues: string[] = [];
|
||||
yearFrom: number | null = null;
|
||||
yearTo: number | null = null;
|
||||
readonly isSearching = computed(() => this.searchQuery().trim().length > 0);
|
||||
readonly sortingDirectionOptions = computed<SelectorOption[]>(() =>
|
||||
this.isSearching() ? [] : this.sortingDirectionOptionsAll,
|
||||
);
|
||||
|
||||
private readonly minYear = NEWS_MIN_YEAR;
|
||||
private readonly maxYear = new Date().getFullYear();
|
||||
readonly page = computed<Page>(() => ({
|
||||
page: this.currentPage,
|
||||
size: this.currentSize,
|
||||
total: this.total(),
|
||||
elements: this.articles(),
|
||||
}));
|
||||
|
||||
private currentPage = 0;
|
||||
private currentSize = 10;
|
||||
private sortOrder: SortOrder = 'desc';
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((params) => {
|
||||
this.currentPage = this.parsePage(params.get('page'));
|
||||
this.paginationService.selection = this.parsePageSize(
|
||||
params.get('pageSize'),
|
||||
this.currentPage = this.parseIndex(params.get('page'), 0);
|
||||
this.currentSize = this.parseIndex(params.get('size'), 10);
|
||||
this.sortOrder = params.get('sorting_order') === 'asc' ? 'asc' : 'desc';
|
||||
this.searchQuery.set(params.get('search') ?? '');
|
||||
|
||||
this.relevanceFilter.setValue(
|
||||
this.parseRelevance(params.get('relevance')),
|
||||
{ emitEvent: false },
|
||||
);
|
||||
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,
|
||||
});
|
||||
this.yearFrom.setValue(
|
||||
this.parseYear(params.get('yearFrom')) ?? this.minYear,
|
||||
{ emitEvent: false },
|
||||
);
|
||||
this.yearTo.setValue(
|
||||
this.parseYear(params.get('yearTo')) ?? this.maxYear,
|
||||
{ emitEvent: false },
|
||||
);
|
||||
|
||||
this.load();
|
||||
});
|
||||
|
||||
this.searchControl.valueChanges
|
||||
.pipe(
|
||||
debounceTime(300),
|
||||
distinctUntilChanged(),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
)
|
||||
.subscribe((query) => {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { q: query.trim() || null, page: 1 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
});
|
||||
merge(
|
||||
this.relevanceFilter.valueChanges,
|
||||
this.yearFrom.valueChanges,
|
||||
this.yearTo.valueChanges,
|
||||
)
|
||||
.pipe(debounceTime(300), takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.applyFilters());
|
||||
}
|
||||
|
||||
load(): void {
|
||||
this.loading = true;
|
||||
const query = this.searchControl.value.trim();
|
||||
resetFilters(): void {
|
||||
this.relevanceFilter.setValue([]);
|
||||
this.yearFrom.setValue(this.minYear);
|
||||
this.yearTo.setValue(this.maxYear);
|
||||
}
|
||||
|
||||
private applyFilters(): void {
|
||||
const relevance =
|
||||
this.relevanceFilter.value.length > 0
|
||||
? this.relevanceFilter.value.join(',')
|
||||
: null;
|
||||
const yearFrom =
|
||||
this.yearFrom.value > this.minYear ? this.yearFrom.value : null;
|
||||
const yearTo = this.yearTo.value < this.maxYear ? this.yearTo.value : null;
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { relevance, yearFrom, yearTo, page: 0 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
private load(): void {
|
||||
this.loading.set(true);
|
||||
const query = this.searchQuery().trim();
|
||||
const basePath = this.worksService.configuration.basePath ?? '';
|
||||
const backendPage = this.currentPage + 1;
|
||||
|
||||
if (query) {
|
||||
let params = new HttpParams()
|
||||
.set('query', query)
|
||||
.set('page', this.currentPage)
|
||||
.set('pageSize', this.paginationService.selection);
|
||||
.set('page', backendPage)
|
||||
.set('pageSize', this.currentSize);
|
||||
params = this.appendFilters(params);
|
||||
|
||||
this.httpClient
|
||||
.get<NewsPage>(`${basePath}/api/news/search`, { params })
|
||||
.subscribe({
|
||||
next: (page) => {
|
||||
this.articles = page.results ?? [];
|
||||
this.total = page.total ?? 0;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.articles = [];
|
||||
this.total = 0;
|
||||
this.loading = false;
|
||||
},
|
||||
next: (page) => this.applyResult(page),
|
||||
error: () => this.applyResult(null),
|
||||
});
|
||||
} else {
|
||||
let params = new HttpParams()
|
||||
.set('page', this.currentPage)
|
||||
.set('pageSize', this.paginationService.selection)
|
||||
.set('page', backendPage)
|
||||
.set('pageSize', this.currentSize)
|
||||
.set('sortOrder', this.sortOrder);
|
||||
params = this.appendFilters(params);
|
||||
|
||||
this.httpClient
|
||||
.get<NewsPage>(`${basePath}/api/news`, { params })
|
||||
.subscribe({
|
||||
next: (page) => {
|
||||
this.articles = page.results ?? [];
|
||||
this.total = page.total ?? 0;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.articles = [];
|
||||
this.total = 0;
|
||||
this.loading = false;
|
||||
},
|
||||
next: (page) => this.applyResult(page),
|
||||
error: () => this.applyResult(null),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private applyResult(page: NewsPage | null): void {
|
||||
this.articles.set(page?.results ?? []);
|
||||
this.total.set(page?.total ?? 0);
|
||||
this.loading.set(false);
|
||||
}
|
||||
|
||||
private appendFilters(params: HttpParams): HttpParams {
|
||||
if (this.relevanceValues.length > 0) {
|
||||
params = params.set('relevance', this.relevanceValues.join(','));
|
||||
const relevance = this.relevanceFilter.value;
|
||||
if (relevance.length > 0) {
|
||||
params = params.set('relevance', relevance.join(','));
|
||||
}
|
||||
if (this.yearFrom !== null) {
|
||||
params = params.set('yearFrom', this.yearFrom);
|
||||
if (this.yearFrom.value > this.minYear) {
|
||||
params = params.set('yearFrom', this.yearFrom.value);
|
||||
}
|
||||
if (this.yearTo !== null) {
|
||||
params = params.set('yearTo', this.yearTo);
|
||||
if (this.yearTo.value < this.maxYear) {
|
||||
params = params.set('yearTo', this.yearTo.value);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
page: event.pageIndex + 1,
|
||||
pageSize: event.pageSize,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
onSortChange(order: SortOrder): void {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
sortOrder: order,
|
||||
page: 1,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
relevance,
|
||||
yearFrom,
|
||||
yearTo,
|
||||
page: 1,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
private parsePage(value: string | null): number {
|
||||
const page = Number.parseInt(value ?? '', 10);
|
||||
if (Number.isNaN(page) || page < 1) {
|
||||
return 1;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private parsePageSize(value: string | null): number {
|
||||
const pageSize = Number.parseInt(value ?? '', 10);
|
||||
if (this.paginationService.options.includes(pageSize)) {
|
||||
return pageSize;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
private parseSortOrder(value: string | null): SortOrder {
|
||||
if (value === 'asc' || value === 'desc') {
|
||||
return value;
|
||||
}
|
||||
return DEFAULT_SORT_ORDER;
|
||||
private parseIndex(value: string | null, fallback: number): number {
|
||||
const parsed = Number.parseInt(value ?? '', 10);
|
||||
return Number.isNaN(parsed) || parsed < 0 ? fallback : parsed;
|
||||
}
|
||||
|
||||
private parseRelevance(value: string | null): string[] {
|
||||
@@ -239,9 +233,6 @@ export class NewsComponent implements OnInit {
|
||||
|
||||
private parseYear(value: string | null): number | null {
|
||||
const year = Number.parseInt(value ?? '', 10);
|
||||
if (Number.isNaN(year)) {
|
||||
return null;
|
||||
}
|
||||
return year;
|
||||
return Number.isNaN(year) ? null : year;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
<p>Aktuelle Nachrichten zu dieser Person.</p>
|
||||
</div>
|
||||
|
||||
<app-news-list
|
||||
[articles]="articles"
|
||||
[displayedColumns]="displayedColumns"
|
||||
[total]="total"
|
||||
<ng-template #cardTmp let-article>
|
||||
<app-news-card [article]="article" />
|
||||
</ng-template>
|
||||
|
||||
<app-card-search
|
||||
[page]="page()"
|
||||
[loading]="loading"
|
||||
[currentPage]="currentPage"
|
||||
[sortOrder]="sortOrder"
|
||||
[searchControl]="searchControl"
|
||||
(sortChange)="onSortChange($event)"
|
||||
(pageChange)="onPage($event)">
|
||||
</app-news-list>
|
||||
[cardTmp]="cardTmp"
|
||||
[cardMinWidth]="380"
|
||||
[sortingDirectionOptions]="sortingDirectionOptions"
|
||||
sortingDirectionLabel="Sortierung"
|
||||
searchLabel="Nachrichten durchsuchen" />
|
||||
</div>
|
||||
|
||||
@@ -1,110 +1,69 @@
|
||||
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { PageEvent } from '@angular/material/paginator';
|
||||
import {
|
||||
Component,
|
||||
DestroyRef,
|
||||
OnInit,
|
||||
computed,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
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';
|
||||
CardSearchComponent,
|
||||
Page,
|
||||
} from '../../shared/ui/card-search/card-search.component';
|
||||
import { NewsCardComponent } from '../../shared/ui/news-card/news-card.component';
|
||||
import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-news',
|
||||
imports: [ReactiveFormsModule, NewsListComponent],
|
||||
imports: [CardSearchComponent, NewsCardComponent],
|
||||
templateUrl: './person-news.component.html',
|
||||
styleUrl: './person-news.component.scss',
|
||||
})
|
||||
export class PersonNewsComponent implements OnInit {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
readonly paginationService = inject(PaginationService);
|
||||
private readonly resolverStateService = inject(ResolverStateService);
|
||||
|
||||
readonly searchControl = new FormControl('', { nonNullable: true });
|
||||
readonly sortingDirectionOptions: SelectorOption[] = [
|
||||
{ value: 'desc', display_name: 'Neueste zuerst' },
|
||||
{ value: 'asc', display_name: 'Älteste zuerst' },
|
||||
];
|
||||
|
||||
displayedColumns = ['maintitle', 'relevance', 'date'];
|
||||
articles: NewsArticle[] = [];
|
||||
total = 0;
|
||||
currentPage = 1;
|
||||
sortOrder: SortOrder = 'desc';
|
||||
private readonly articles = signal<NewsArticle[]>([]);
|
||||
private readonly total = signal(0);
|
||||
private currentPage = 0;
|
||||
private currentSize = 10;
|
||||
|
||||
get loading(): boolean {
|
||||
return this.resolverStateService.isResolving();
|
||||
}
|
||||
|
||||
get isSearching(): boolean {
|
||||
return this.searchControl.value.trim().length > 0;
|
||||
}
|
||||
readonly page = computed<Page>(() => ({
|
||||
page: this.currentPage,
|
||||
size: this.currentSize,
|
||||
total: this.total(),
|
||||
elements: this.articles(),
|
||||
}));
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.data
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(({ newsPage }) => {
|
||||
const page = newsPage as NewsPage;
|
||||
this.articles = page.results ?? [];
|
||||
this.total = page.total ?? 0;
|
||||
this.articles.set(page.results ?? []);
|
||||
this.total.set(page.total ?? 0);
|
||||
});
|
||||
|
||||
this.route.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((params) => {
|
||||
const page = params.get('page')
|
||||
? Number.parseInt(params.get('page')!, 10)
|
||||
: 1;
|
||||
const pageSize = params.get('pageSize')
|
||||
? Number.parseInt(params.get('pageSize')!, 10)
|
||||
: 10;
|
||||
const sortOrder = params.get('sortOrder');
|
||||
const query = params.get('query') ?? '';
|
||||
|
||||
this.currentPage = page;
|
||||
this.paginationService.selection = pageSize;
|
||||
this.sortOrder = sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
this.searchControl.setValue(query, { emitEvent: false });
|
||||
this.currentPage = Number.parseInt(params.get('page') ?? '', 10) || 0;
|
||||
this.currentSize = Number.parseInt(params.get('size') ?? '', 10) || 10;
|
||||
});
|
||||
|
||||
this.searchControl.valueChanges
|
||||
.pipe(
|
||||
debounceTime(300),
|
||||
distinctUntilChanged(),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
)
|
||||
.subscribe((value) => {
|
||||
this.updateQueryParams({
|
||||
query: value.trim() || null,
|
||||
page: 1,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.paginationService.selection = event.pageSize;
|
||||
this.updateQueryParams({
|
||||
page: event.pageIndex + 1,
|
||||
pageSize: event.pageSize,
|
||||
});
|
||||
}
|
||||
|
||||
onSortChange(order: SortOrder): void {
|
||||
this.updateQueryParams({
|
||||
sortOrder: order,
|
||||
page: 1,
|
||||
});
|
||||
}
|
||||
|
||||
private updateQueryParams(
|
||||
overrides: Record<string, string | number | null>,
|
||||
): void {
|
||||
void this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: overrides,
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,25 +27,25 @@ export const personNewsResolver: ResolveFn<NewsPage> = (route) => {
|
||||
|
||||
const authorId = route.parent?.paramMap.get('id');
|
||||
if (!authorId) {
|
||||
return of({ total: 0, page: 1, page_size: 0, results: [] });
|
||||
return of({ total: 0, page: 0, page_size: 0, results: [] });
|
||||
}
|
||||
|
||||
const queryParams = route.queryParamMap;
|
||||
|
||||
const page = queryParams.get('page')
|
||||
? Number.parseInt(queryParams.get('page')!, 10)
|
||||
: 1;
|
||||
: 0;
|
||||
|
||||
const pageSize = queryParams.get('pageSize')
|
||||
? Number.parseInt(queryParams.get('pageSize')!, 10)
|
||||
const pageSize = queryParams.get('size')
|
||||
? Number.parseInt(queryParams.get('size')!, 10)
|
||||
: 10;
|
||||
|
||||
const sortOrder = queryParams.get('sortOrder') || 'desc';
|
||||
const query = queryParams.get('query') || '';
|
||||
const sortOrder = queryParams.get('sorting_order') || 'desc';
|
||||
const query = queryParams.get('search') || '';
|
||||
|
||||
let params = new HttpParams()
|
||||
.set('authorId', authorId)
|
||||
.set('page', page)
|
||||
.set('page', page + 1)
|
||||
.set('pageSize', pageSize)
|
||||
.set('sortOrder', sortOrder);
|
||||
|
||||
|
||||
@@ -27,24 +27,33 @@
|
||||
|
||||
<mat-divider />
|
||||
@let pageValue = page();
|
||||
@if (pageValue.elements && pageValue.elements.length > 0) {
|
||||
<div class="cards" [style.--card-min-width.px]="cardMinWidth()">
|
||||
@for (element of pageValue.elements; track $index) {
|
||||
<ng-container
|
||||
[ngTemplateOutlet]="cardTmp()"
|
||||
[ngTemplateOutletContext]="{ $implicit: element }">
|
||||
</ng-container>
|
||||
}
|
||||
</div>
|
||||
<mat-divider />
|
||||
} @else {
|
||||
@if (this.noResultsTmp()) {
|
||||
<ng-container [ngTemplateOutlet]="noResultsTmp()"></ng-container>
|
||||
} @else {
|
||||
<div class="no-results">
|
||||
<span>Keine Ergebnisse gefunden.</span>
|
||||
<div class="card-search-results">
|
||||
@if (loading()) {
|
||||
<div class="loading-overlay">
|
||||
<mat-spinner diameter="36"></mat-spinner>
|
||||
</div>
|
||||
}
|
||||
@if (pageValue.elements && pageValue.elements.length > 0) {
|
||||
<div class="cards" [style.--card-min-width.px]="cardMinWidth()">
|
||||
@for (element of pageValue.elements; track $index) {
|
||||
<ng-container
|
||||
[ngTemplateOutlet]="cardTmp()"
|
||||
[ngTemplateOutletContext]="{ $implicit: element }">
|
||||
</ng-container>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@if (this.noResultsTmp()) {
|
||||
<ng-container [ngTemplateOutlet]="noResultsTmp()"></ng-container>
|
||||
} @else {
|
||||
<div class="no-results">
|
||||
<span>Keine Ergebnisse gefunden.</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@if (pageValue.elements && pageValue.elements.length > 0) {
|
||||
<mat-divider />
|
||||
}
|
||||
<div class="pagination">
|
||||
<app-query-param-paginator
|
||||
|
||||
@@ -11,6 +11,19 @@
|
||||
padding: 0rem 1rem;
|
||||
}
|
||||
|
||||
.card-search-results {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(255, 255, 255, 0.65);
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { MatDivider } from '@angular/material/divider';
|
||||
import { QueryParamPaginatorComponent } from '../query-param-paginator/query-param-paginator.component';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
|
||||
export type Page = {
|
||||
page: number;
|
||||
@@ -23,6 +24,7 @@ export type Page = {
|
||||
MatDivider,
|
||||
QueryParamPaginatorComponent,
|
||||
NgTemplateOutlet,
|
||||
MatProgressSpinnerModule,
|
||||
],
|
||||
templateUrl: './card-search.component.html',
|
||||
styleUrl: './card-search.component.scss',
|
||||
@@ -33,6 +35,7 @@ export class CardSearchComponent {
|
||||
noResultsTmp = input<TemplateRef<any>>();
|
||||
|
||||
cardMinWidth = input<number>(300);
|
||||
loading = input<boolean>(false);
|
||||
|
||||
page = input.required<Page>();
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<mat-card
|
||||
class="card"
|
||||
appearance="outlined"
|
||||
[routerLink]="['/news', article().id]">
|
||||
<mat-card-header>
|
||||
<mat-card-title class="article-title">{{
|
||||
article().maintitle || 'Kein Titel'
|
||||
}}</mat-card-title>
|
||||
<mat-card-subtitle>{{ formatDate(article().date) }}</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content class="card-content">
|
||||
<mat-divider />
|
||||
|
||||
@if (snippetTemplate()) {
|
||||
<div class="card-snippet">
|
||||
<ng-container
|
||||
*ngTemplateOutlet="
|
||||
snippetTemplate()!;
|
||||
context: { $implicit: article() }
|
||||
"></ng-container>
|
||||
</div>
|
||||
}
|
||||
|
||||
<mat-divider class="footer-divider" />
|
||||
<div class="card-badges">
|
||||
@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>
|
||||
}
|
||||
<mat-icon
|
||||
class="relevance-info"
|
||||
tabindex="0"
|
||||
aria-label="Was bedeutet die Relevanz?"
|
||||
[matTooltip]="relevanceHelp"
|
||||
matTooltipClass="relevance-tooltip"
|
||||
(click)="$event.stopPropagation()">
|
||||
info
|
||||
</mat-icon>
|
||||
@if (article().related) {
|
||||
<span class="related-badge">Ähnlich zu deiner Suche</span>
|
||||
}
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@@ -0,0 +1,125 @@
|
||||
:host {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 0.5rem;
|
||||
background-color: var(--sg-background);
|
||||
transition: transform 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
}
|
||||
|
||||
.card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.footer-divider {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.card-badges {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card-snippet {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--sg-text-secondary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
height: 2.9em;
|
||||
line-height: 1.45;
|
||||
color: var(--sg-text);
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.related-badge {
|
||||
display: flex;
|
||||
width: fit-content;
|
||||
align-items: center;
|
||||
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;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { Component, TemplateRef, input } from '@angular/core';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
|
||||
export interface NewsArticleBase {
|
||||
id: string;
|
||||
date?: string | null;
|
||||
maintitle?: string | null;
|
||||
url?: string | null;
|
||||
relevant?: boolean | null;
|
||||
related?: boolean | null;
|
||||
}
|
||||
|
||||
export const NEWS_MIN_YEAR = 2000;
|
||||
|
||||
@Component({
|
||||
selector: 'app-news-card',
|
||||
imports: [
|
||||
MatCardModule,
|
||||
MatDividerModule,
|
||||
MatIconModule,
|
||||
MatTooltipModule,
|
||||
NgTemplateOutlet,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './news-card.component.html',
|
||||
styleUrl: './news-card.component.scss',
|
||||
})
|
||||
export class NewsCardComponent {
|
||||
article = input.required<NewsArticleBase>();
|
||||
snippetTemplate = input<TemplateRef<{ $implicit: NewsArticleBase }> | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
readonly relevanceHelp =
|
||||
'Zeigt, ob ein Artikel inhaltlich über eine konkrete Person berichtet ' +
|
||||
'(Relevant) oder eine allgemeine Mitteilung ohne Personenbezug ist ' +
|
||||
'(Nicht relevant).';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
<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>
|
||||
@@ -1,279 +0,0 @@
|
||||
.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;
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
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