From bd39e16d9bcaa62ca8d3d6b4c633a701e64367dc Mon Sep 17 00:00:00 2001 From: "noemi.kallweit" Date: Mon, 15 Jun 2026 22:35:38 +0200 Subject: [PATCH] feat(news): wire full-text search to global news page and client-side filter to person news tab --- .../src/app/modules/news/news.component.html | 26 ++++-- webapp/src/app/modules/news/news.component.ts | 84 ++++++++++++++----- .../person-news/person-news.component.html | 8 +- .../person-news/person-news.component.ts | 37 +++++++- 4 files changed, 122 insertions(+), 33 deletions(-) diff --git a/webapp/src/app/modules/news/news.component.html b/webapp/src/app/modules/news/news.component.html index 5004b3e5..05ca40a8 100644 --- a/webapp/src/app/modules/news/news.component.html +++ b/webapp/src/app/modules/news/news.component.html @@ -13,14 +13,16 @@ placeholder="Nachrichten durchsuchen..." /> - - - Neueste zuerst - Älteste zuerst - - + @if (!isSearching) { + + + Neueste zuerst + Älteste zuerst + + + }
@@ -59,7 +61,13 @@ @if (!loading && articles.length === 0) { -
Keine Nachrichten gefunden.
+
+ @if (isSearching) { + Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden. + } @else { + Keine Nachrichten gefunden. + } +
}
diff --git a/webapp/src/app/modules/news/news.component.ts b/webapp/src/app/modules/news/news.component.ts index a6df56f2..e6990dbb 100644 --- a/webapp/src/app/modules/news/news.component.ts +++ b/webapp/src/app/modules/news/news.component.ts @@ -10,6 +10,7 @@ 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 { debounceTime, distinctUntilChanged } from 'rxjs'; import { WorksService } from '../../api'; import { PaginationService } from '../../shared/services/pagination.service'; @@ -66,6 +67,10 @@ export class NewsComponent implements OnInit { currentPage = 1; sortOrder: SortOrder = DEFAULT_SORT_ORDER; + get isSearching(): boolean { + return this.searchControl.value.trim().length > 0; + } + ngOnInit(): void { this.route.queryParamMap .pipe(takeUntilDestroyed(this.destroyRef)) @@ -75,32 +80,73 @@ export class NewsComponent implements OnInit { params.get('pageSize'), ); this.sortOrder = this.parseSortOrder(params.get('sortOrder')); + this.searchControl.setValue(params.get('q') ?? '', { + 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', + }); + }); } load(): void { this.loading = true; - const params = new HttpParams() - .set('page', this.currentPage) - .set('pageSize', this.paginationService.selection) - .set('sortOrder', this.sortOrder); - + const query = this.searchControl.value.trim(); const basePath = this.worksService.configuration.basePath ?? ''; - this.httpClient - .get(`${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; - }, - }); + + if (query) { + const params = new HttpParams() + .set('query', query) + .set('page', this.currentPage) + .set('pageSize', this.paginationService.selection); + + this.httpClient + .get(`${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; + }, + }); + } else { + const params = new HttpParams() + .set('page', this.currentPage) + .set('pageSize', this.paginationService.selection) + .set('sortOrder', this.sortOrder); + + this.httpClient + .get(`${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; + }, + }); + } } onPage(event: PageEvent): void { diff --git a/webapp/src/app/modules/person-news/person-news.component.html b/webapp/src/app/modules/person-news/person-news.component.html index d5477d07..b4f717db 100644 --- a/webapp/src/app/modules/person-news/person-news.component.html +++ b/webapp/src/app/modules/person-news/person-news.component.html @@ -59,7 +59,13 @@ @if (!loading && articles.length === 0) { -
Keine Nachrichten gefunden.
+
+ @if (isSearching) { + Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden. + } @else { + Keine Nachrichten gefunden. + } +
} diff --git a/webapp/src/app/modules/person-news/person-news.component.ts b/webapp/src/app/modules/person-news/person-news.component.ts index 7c69ef2c..230f51a2 100644 --- a/webapp/src/app/modules/person-news/person-news.component.ts +++ b/webapp/src/app/modules/person-news/person-news.component.ts @@ -20,6 +20,7 @@ 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 { debounceTime, distinctUntilChanged } from 'rxjs'; import { WorksService } from '../../api'; import { PaginationService } from '../../shared/services/pagination.service'; @@ -69,18 +70,33 @@ export class PersonNewsComponent implements OnInit { displayedColumns = ['maintitle', 'author', 'date']; private allArticles: NewsArticle[] = []; + private filteredArticles: NewsArticle[] = []; articles: NewsArticle[] = []; total = 0; loading = false; currentPageIndex = 0; sortOrder: 'desc' | 'asc' = 'desc'; + get isSearching(): boolean { + return this.searchControl.value.trim().length > 0; + } + ngOnInit(): void { this.route.parent?.paramMap .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe(() => { this.load(); }); + + this.searchControl.valueChanges + .pipe( + debounceTime(300), + distinctUntilChanged(), + takeUntilDestroyed(this.destroyRef), + ) + .subscribe(() => { + this.applyFilter(); + }); } load(): void { @@ -96,9 +112,7 @@ export class PersonNewsComponent implements OnInit { .subscribe({ next: (page) => { this.allArticles = page.results ?? []; - this.total = this.allArticles.length; - this.currentPageIndex = 0; - this.updatePage(); + this.applyFilter(); this.loading = false; }, error: () => { @@ -135,9 +149,24 @@ export class PersonNewsComponent implements OnInit { this.load(); } + private applyFilter(): void { + const query = this.searchControl.value.trim().toLowerCase(); + this.filteredArticles = query + ? this.allArticles.filter( + (a) => + a.maintitle?.toLowerCase().includes(query) || + a.author?.toLowerCase().includes(query), + ) + : this.allArticles; + this.total = this.filteredArticles.length; + this.currentPageIndex = 0; + this.paginator?.firstPage(); + this.updatePage(); + } + private updatePage(): void { const start = this.currentPageIndex * this.paginationService.selection; - this.articles = this.allArticles.slice( + this.articles = this.filteredArticles.slice( start, start + this.paginationService.selection, );