feat(news): wire full-text search to global news page and client-side filter to person news tab
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-15 22:35:38 +02:00
parent 977ac97241
commit bd39e16d9b
4 changed files with 122 additions and 33 deletions
@@ -13,14 +13,16 @@
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>
@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>
}
</div>
<div class="table-wrap">
@@ -59,7 +61,13 @@
</table>
@if (!loading && articles.length === 0) {
<div class="empty-state">Keine Nachrichten gefunden.</div>
<div class="empty-state">
@if (isSearching) {
Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden.
} @else {
Keine Nachrichten gefunden.
}
</div>
}
</div>
+65 -19
View File
@@ -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<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;
},
});
if (query) {
const params = new HttpParams()
.set('query', query)
.set('page', this.currentPage)
.set('pageSize', this.paginationService.selection);
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;
},
});
} else {
const params = new HttpParams()
.set('page', this.currentPage)
.set('pageSize', this.paginationService.selection)
.set('sortOrder', this.sortOrder);
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;
},
});
}
}
onPage(event: PageEvent): void {
@@ -59,7 +59,13 @@
</table>
@if (!loading && articles.length === 0) {
<div class="empty-state">Keine Nachrichten gefunden.</div>
<div class="empty-state">
@if (isSearching) {
Keine Ergebnisse für „{{ searchControl.value.trim() }}" gefunden.
} @else {
Keine Nachrichten gefunden.
}
</div>
}
</div>
@@ -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,
);