-
-
- Relevant
- Nicht relevant
-
-
+
+ label="Sortierung"
+ icon="sort" />
([], {
- nonNullable: true,
- });
+ readonly relevanceOptions: SelectorOption[] = [
+ { value: 'relevant', display_name: 'Relevant' },
+ { value: 'not_relevant', display_name: 'Nicht relevant' },
+ ];
readonly yearFrom = signal(this.minYear);
readonly yearTo = signal(this.maxYear);
@@ -185,11 +177,6 @@ export class KeywordsToNewsResultsComponent {
this.route.queryParamMap
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => {
- this.relevanceFilter.setValue(
- this.parseRelevance(params.get(keywordsNewsQueryParamKeys.relevance)),
- { emitEvent: false },
- );
-
this.yearFrom.set(
this.parseYear(params.get(keywordsNewsQueryParamKeys.yearFrom)) ??
this.minYear,
@@ -199,10 +186,6 @@ export class KeywordsToNewsResultsComponent {
this.maxYear,
);
});
-
- this.relevanceFilter.valueChanges
- .pipe(debounceTime(300), takeUntilDestroyed(this.destroyRef))
- .subscribe(() => this.applyRelevanceFilter());
}
applyYearFilter(): void {
@@ -292,28 +275,6 @@ export class KeywordsToNewsResultsComponent {
});
}
- private applyRelevanceFilter(): void {
- this.router.navigate([], {
- relativeTo: this.route,
- queryParams: {
- [keywordsNewsQueryParamKeys.relevance]:
- this.relevanceFilter.value.length > 0
- ? this.relevanceFilter.value.join(',')
- : null,
- [keywordsNewsQueryParamKeys.page]: 0,
- },
- queryParamsHandling: 'merge',
- });
- }
-
- private parseRelevance(raw: string | null): string[] {
- if (!raw) return [];
- return raw
- .split(',')
- .map((entry) => entry.trim())
- .filter((entry) => RELEVANCE_VALUES.includes(entry));
- }
-
private parseYear(raw: string | null): number | null {
const year = Number.parseInt(raw ?? '', 10);
return Number.isNaN(year) ? null : year;
diff --git a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html
index 2ce167fe..77129614 100644
--- a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html
+++ b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html
@@ -2,9 +2,14 @@
@if (label()) {
{{ label() }}
}
+ @if (icon()) {
+
+ }
+ (openedChange)="_handleOpenedChange($event)"
+ [multiple]="multiple()"
+ [value]="_value()">
@for (option of _options(); track $index) {
{{ option.display_name }}
}
diff --git a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts
index 2b51fdd4..b82698f0 100644
--- a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts
+++ b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts
@@ -1,6 +1,14 @@
-import { Component, computed, inject, input, output } from '@angular/core';
+import {
+ Component,
+ computed,
+ inject,
+ input,
+ output,
+ signal,
+} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
+import { MatIconModule } from '@angular/material/icon';
import { MatSelectChange, MatSelectModule } from '@angular/material/select';
import { ActivatedRoute, Router } from '@angular/router';
@@ -11,7 +19,7 @@ export type SelectorOption = {
@Component({
selector: 'app-query-param-selector',
- imports: [FormsModule, MatSelectModule],
+ imports: [FormsModule, MatIconModule, MatSelectModule],
templateUrl: './query-param-selector.component.html',
styleUrl: './query-param-selector.component.scss',
})
@@ -21,6 +29,13 @@ export class QueryParamSelectorComponent {
handleSelectionChange = output();
allowEmptyValue = input(false);
label = input('');
+ icon = input('');
+
+ multiple = input(false);
+
+ pageQueryParamKey = input('page');
+
+ private readonly pendingValues = signal(null);
_options = computed(() => {
const options = this.options();
@@ -50,14 +65,54 @@ export class QueryParamSelectorComponent {
return params && key ? params[key] || '' : '';
});
+ _urlValues = computed(() => {
+ const raw = this._urlValue();
+ return raw
+ ? raw
+ .split(',')
+ .map((value) => value.trim())
+ .filter(Boolean)
+ : [];
+ });
+
+ _value = computed(() =>
+ this.multiple()
+ ? (this.pendingValues() ?? this._urlValues())
+ : this._urlValue(),
+ );
+
_handleSelectionChange(event: MatSelectChange): void {
- const newValue = event.value;
-
- this.router.navigate([], {
- queryParams: { [this.queryParamKey()]: newValue },
- queryParamsHandling: 'merge',
- });
+ if (this.multiple()) {
+ this.pendingValues.set(event.value ?? []);
+ return;
+ }
+ this.commit(event.value || null);
this.handleSelectionChange.emit(event);
}
+
+ _handleOpenedChange(opened: boolean): void {
+ if (opened || !this.multiple()) {
+ return;
+ }
+
+ const pending = this.pendingValues();
+ this.pendingValues.set(null);
+
+ if (pending !== null) {
+ this.commit(pending.length > 0 ? pending.join(',') : null);
+ }
+ }
+
+ private commit(value: string | null): void {
+ const pageKey = this.pageQueryParamKey();
+
+ this.router.navigate([], {
+ queryParams: {
+ [this.queryParamKey()]: value,
+ ...(pageKey ? { [pageKey]: 0 } : {}),
+ },
+ queryParamsHandling: 'merge',
+ });
+ }
}