selected filters component added to classified pages table
This commit is contained in:
@@ -24,16 +24,17 @@
|
||||
|
||||
<div class="ucs-table-toolbar">
|
||||
<div class="ucs-table-toolbar-left">
|
||||
@if (selectedCategory(); as cat) {
|
||||
<mat-chip-set>
|
||||
<mat-chip (removed)="clearCategoryFilter()">
|
||||
Gefiltert: {{ categoryMeta(cat).label }}
|
||||
<button matChipRemove (click)="clearCategoryFilter()">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
</button>
|
||||
</mat-chip>
|
||||
</mat-chip-set>
|
||||
@if (selectedCategory()) {
|
||||
<app-selected-filters [observers]="observers()"></app-selected-filters>
|
||||
}
|
||||
<!-- <app-searchable-select
|
||||
[label]="'Kategorie filtern'"
|
||||
[selectedElements]="selectedCategoryOptions()"
|
||||
(handleSelectChange)="selectCategory($event.id)"
|
||||
[fetchElements]="fetchPageCategories"
|
||||
[getSelectLabel]="getCategoryLabel"
|
||||
[getSelectValue]="getCategoryValue"
|
||||
class="ucs-searchable-select"></app-searchable-select> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.ucs-stat-chip {
|
||||
|
||||
@@ -34,12 +34,22 @@ import type { ClassifiedPage } from '../../../api/model/classifiedPage';
|
||||
import type { ClassifiedPageResponse } from '../../../api/model/classifiedPageResponse';
|
||||
import { CategoryBucket } from '../../../api/model/categoryBucket';
|
||||
import { QueryParamPaginatorComponent } from '../../../shared/ui/query-param-paginator/query-param-paginator.component';
|
||||
import {
|
||||
SelectedFiltersComponent,
|
||||
FilterObserver,
|
||||
} from '../../../shared/ui/selected-filters/selected-filters.component';
|
||||
import { CATEGORY_ICON } from '../../../shared/ui/icons';
|
||||
interface CategoryMeta {
|
||||
label: string;
|
||||
icon: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
interface CategoryOption {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface CategoryStat extends CategoryMeta {
|
||||
key: string;
|
||||
count: number;
|
||||
@@ -82,6 +92,7 @@ const CLASSIFIED_SIZE_PARAM = 'size';
|
||||
MatProgressBarModule,
|
||||
DataTableComponent,
|
||||
QueryParamPaginatorComponent,
|
||||
SelectedFiltersComponent,
|
||||
ChipComponent,
|
||||
],
|
||||
templateUrl: './classified-pages.component.html',
|
||||
@@ -109,6 +120,51 @@ export class ClassifiedPagesComponent implements OnInit {
|
||||
this.buckets().reduce((sum, b) => sum + b.count, 0),
|
||||
);
|
||||
|
||||
readonly pageCategories = computed<CategoryOption[]>(() => {
|
||||
const categories: CategoryOption[] = [];
|
||||
this.buckets().forEach((bucket) => {
|
||||
const meta = CATEGORY_META[bucket.category] ?? FALLBACK_META;
|
||||
categories.push({
|
||||
id: bucket.category,
|
||||
name: meta.label,
|
||||
});
|
||||
});
|
||||
return categories;
|
||||
});
|
||||
readonly selectedCategoryOptions = computed<CategoryOption[]>(() => {
|
||||
const selected = this.pageCategories().find(
|
||||
(category) => category.id === this.selectedCategory(),
|
||||
);
|
||||
return selected ? [selected] : [];
|
||||
});
|
||||
readonly fetchPageCategories = (searchTerm: string) => {
|
||||
const normalizedSearchTerm = searchTerm.trim().toLowerCase();
|
||||
return of({
|
||||
elements: this.pageCategories().filter((category) =>
|
||||
`${category.name} ${category.id}`
|
||||
.toLowerCase()
|
||||
.includes(normalizedSearchTerm),
|
||||
),
|
||||
});
|
||||
};
|
||||
readonly getCategoryLabel = (category: CategoryOption): string => {
|
||||
return category.name;
|
||||
};
|
||||
readonly getCategoryValue = (category: CategoryOption): string => {
|
||||
return category.id;
|
||||
};
|
||||
observers = computed<FilterObserver[]>(() => {
|
||||
const observers: FilterObserver[] = [
|
||||
{
|
||||
id: 'search',
|
||||
queryParamKey: CLASSIFIED_CATEGORY_PARAM,
|
||||
icon: CATEGORY_ICON,
|
||||
removable: true,
|
||||
},
|
||||
];
|
||||
|
||||
return observers;
|
||||
});
|
||||
readonly stats = computed<CategoryStat[]>(() => {
|
||||
const total = this.totalClassifiedPages() || 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user