feat(filters): add customizable visible filters setting (#2625)
This commit is contained in:
@@ -166,6 +166,44 @@ export interface TableColumnPreference {
|
||||
order: number;
|
||||
}
|
||||
|
||||
export type VisibleFilterType =
|
||||
| 'author' | 'category' | 'series' | 'bookType' | 'readStatus'
|
||||
| 'personalRating' | 'publisher' | 'matchScore' | 'library' | 'shelf'
|
||||
| 'shelfStatus' | 'tag' | 'publishedDate' | 'fileSize' | 'amazonRating'
|
||||
| 'goodreadsRating' | 'hardcoverRating' | 'language' | 'pageCount' | 'mood'
|
||||
| 'ageRating' | 'contentRating';
|
||||
|
||||
export const DEFAULT_VISIBLE_FILTERS: VisibleFilterType[] = [
|
||||
'author', 'category', 'series', 'bookType', 'readStatus',
|
||||
'personalRating', 'library', 'tag', 'ageRating', 'contentRating',
|
||||
'matchScore', 'publisher', 'publishedDate', 'fileSize'
|
||||
];
|
||||
|
||||
export const ALL_FILTER_OPTIONS: { label: string; value: VisibleFilterType }[] = [
|
||||
{label: 'Author', value: 'author'},
|
||||
{label: 'Genre', value: 'category'},
|
||||
{label: 'Series', value: 'series'},
|
||||
{label: 'Book Type', value: 'bookType'},
|
||||
{label: 'Read Status', value: 'readStatus'},
|
||||
{label: 'Personal Rating', value: 'personalRating'},
|
||||
{label: 'Library', value: 'library'},
|
||||
{label: 'Tag', value: 'tag'},
|
||||
{label: 'Age Rating', value: 'ageRating'},
|
||||
{label: 'Content Rating', value: 'contentRating'},
|
||||
{label: 'Metadata Match Score', value: 'matchScore'},
|
||||
{label: 'Publisher', value: 'publisher'},
|
||||
{label: 'Published Year', value: 'publishedDate'},
|
||||
{label: 'File Size', value: 'fileSize'},
|
||||
{label: 'Shelf', value: 'shelf'},
|
||||
{label: 'Shelf Status', value: 'shelfStatus'},
|
||||
{label: 'Language', value: 'language'},
|
||||
{label: 'Page Count', value: 'pageCount'},
|
||||
{label: 'Mood', value: 'mood'},
|
||||
{label: 'Amazon Rating', value: 'amazonRating'},
|
||||
{label: 'Goodreads Rating', value: 'goodreadsRating'},
|
||||
{label: 'Hardcover Rating', value: 'hardcoverRating'}
|
||||
];
|
||||
|
||||
export interface UserSettings {
|
||||
perBookSetting: PerBookSetting;
|
||||
pdfReaderSetting: PdfReaderSetting;
|
||||
@@ -177,6 +215,7 @@ export interface UserSettings {
|
||||
sidebarShelfSorting: SidebarShelfSorting;
|
||||
sidebarMagicShelfSorting: SidebarMagicShelfSorting;
|
||||
filterMode: BookFilterMode;
|
||||
visibleFilters?: VisibleFilterType[];
|
||||
metadataCenterViewMode: 'route' | 'dialog';
|
||||
enableSeriesView: boolean;
|
||||
entityViewPreferences: EntityViewPreferences;
|
||||
|
||||
+28
@@ -26,5 +26,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header-standalone">
|
||||
<label class="setting-label">Visible Filters</label>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Select which filters appear in the filter sidebar. Choose between {{ minFilters }} and {{ maxFilters }} filters.
|
||||
<span class="filter-count">({{ selectionCountText }})</span>
|
||||
</p>
|
||||
<div class="setting-options">
|
||||
<p-multiselect
|
||||
[options]="allFilterOptions"
|
||||
[(ngModel)]="selectedVisibleFilters"
|
||||
(ngModelChange)="onVisibleFiltersChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[showClear]="false"
|
||||
[filter]="true"
|
||||
filterPlaceHolder="Search filters..."
|
||||
placeholder="Select filters"
|
||||
display="chip"
|
||||
appendTo="body"
|
||||
[maxSelectedLabels]="5"
|
||||
selectedItemsLabel="{0} filters selected"
|
||||
styleClass="visible-filters-select">
|
||||
</p-multiselect>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+15
@@ -47,4 +47,19 @@
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
p-multiselect {
|
||||
min-width: 300px;
|
||||
max-width: 100%;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter-count {
|
||||
font-weight: 500;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
+49
-3
@@ -1,16 +1,30 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Select} from 'primeng/select';
|
||||
import {BookFilterMode, User, UserService, UserSettings, UserState} from '../../user-management/user.service';
|
||||
import {
|
||||
ALL_FILTER_OPTIONS,
|
||||
BookFilterMode,
|
||||
DEFAULT_VISIBLE_FILTERS,
|
||||
User,
|
||||
UserService,
|
||||
UserSettings,
|
||||
UserState,
|
||||
VisibleFilterType
|
||||
} from '../../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {filter, takeUntil} from 'rxjs/operators';
|
||||
import {MultiSelect} from 'primeng/multiselect';
|
||||
|
||||
const MIN_VISIBLE_FILTERS = 5;
|
||||
const MAX_VISIBLE_FILTERS = 15;
|
||||
|
||||
@Component({
|
||||
selector: 'app-filter-preferences',
|
||||
imports: [
|
||||
Select,
|
||||
FormsModule
|
||||
FormsModule,
|
||||
MultiSelect
|
||||
],
|
||||
templateUrl: './filter-preferences.component.html',
|
||||
styleUrl: './filter-preferences.component.scss'
|
||||
@@ -23,7 +37,12 @@ export class FilterPreferencesComponent implements OnInit, OnDestroy {
|
||||
{label: 'Single', value: 'single'},
|
||||
];
|
||||
|
||||
readonly allFilterOptions = ALL_FILTER_OPTIONS;
|
||||
readonly minFilters = MIN_VISIBLE_FILTERS;
|
||||
readonly maxFilters = MAX_VISIBLE_FILTERS;
|
||||
|
||||
selectedFilterMode: BookFilterMode = 'and';
|
||||
selectedVisibleFilters: VisibleFilterType[] = [...DEFAULT_VISIBLE_FILTERS];
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
@@ -49,6 +68,7 @@ export class FilterPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
private loadPreferences(settings: UserSettings): void {
|
||||
this.selectedFilterMode = settings.filterMode ?? 'and';
|
||||
this.selectedVisibleFilters = settings.visibleFilters ?? [...DEFAULT_VISIBLE_FILTERS];
|
||||
}
|
||||
|
||||
private updatePreference(path: string[], value: unknown): void {
|
||||
@@ -71,7 +91,33 @@ export class FilterPreferencesComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
onFilterModeChange() {
|
||||
onFilterModeChange(): void {
|
||||
this.updatePreference(['filterMode'], this.selectedFilterMode);
|
||||
}
|
||||
|
||||
onVisibleFiltersChange(): void {
|
||||
if (this.selectedVisibleFilters.length < MIN_VISIBLE_FILTERS) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Minimum Filters Required',
|
||||
detail: `Please select at least ${MIN_VISIBLE_FILTERS} filters.`,
|
||||
life: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (this.selectedVisibleFilters.length > MAX_VISIBLE_FILTERS) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Maximum Filters Exceeded',
|
||||
detail: `Please select at most ${MAX_VISIBLE_FILTERS} filters.`,
|
||||
life: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.updatePreference(['visibleFilters'], this.selectedVisibleFilters);
|
||||
}
|
||||
|
||||
get selectionCountText(): string {
|
||||
return `${this.selectedVisibleFilters.length} of ${this.allFilterOptions.length} selected`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user