Feature: add table column visibility configuration

- Introduced a multi-select dropdown for customizing visible columns in the book browser table
- Implemented per-user persistence using UserService settings
- Saved preferences include visibility and column order
- Ensured all available columns are listed even when hidden
This commit is contained in:
aditya.chandel
2025-07-08 15:20:32 -06:00
committed by Aditya Chandel
parent d0edf800c7
commit 2c72790334
11 changed files with 325 additions and 115 deletions
@@ -41,6 +41,8 @@ import {Slider} from 'primeng/slider';
import {Select} from 'primeng/select';
import {FilterSortPreferenceService} from './filters/filter-sorting-preferences.service';
import {Divider} from 'primeng/divider';
import {MultiSelect} from 'primeng/multiselect';
import {TableColumnPreferenceService} from './table-column-preference-service';
export enum EntityType {
LIBRARY = 'Library',
@@ -73,7 +75,7 @@ const SORT_DIRECTION = {
standalone: true,
templateUrl: './book-browser.component.html',
styleUrls: ['./book-browser.component.scss'],
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select, Divider],
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select, Divider, MultiSelect],
providers: [SeriesCollapseFilter],
animations: [
trigger('slideInOut', [
@@ -113,6 +115,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
@ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent;
visibleColumns: { field: string; header: string }[] = [];
selectedFilter = new BehaviorSubject<Record<string, any> | null>(null);
selectedFilterMode = new BehaviorSubject<'and' | 'or'>('and');
protected resetFilterSubject = new Subject<void>();
@@ -122,6 +126,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
protected userService = inject(UserService);
protected coverScalePreferenceService = inject(CoverScalePreferenceService);
protected filterSortPreferenceService = inject(FilterSortPreferenceService);
protected columnPreferenceService = inject(TableColumnPreferenceService);
private activatedRoute = inject(ActivatedRoute);
private messageService = inject(MessageService);
@@ -142,7 +147,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
currentViewMode: string | undefined = undefined;
lastAppliedSort: SortOption | null = null;
filterVisibility = true;
private settingFiltersFromUrl = false;
protected metadataMenuItems: MenuItem[] | undefined;
currentBooks: Book[] = [];
@@ -161,6 +165,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.coverScalePreferenceService.setScale(this.coverScalePreferenceService.scaleFactor);
}
onVisibleColumnsChange(selected: any[]) {
const allFields = this.bookTableComponent.allColumns.map(col => col.field);
this.visibleColumns = selected.sort(
(a, b) => allFields.indexOf(a.field) - allFields.indexOf(b.field)
);
}
ngOnInit(): void {
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
@@ -218,6 +229,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
}
ngAfterViewInit() {
combineLatest({
paramMap: this.activatedRoute.queryParamMap,
user: this.userService.userState$.pipe(
@@ -229,7 +241,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
const viewParam = paramMap.get(QUERY_PARAMS.VIEW);
const sortParam = paramMap.get(QUERY_PARAMS.SORT);
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
const sidebarParam = paramMap.get(QUERY_PARAMS.SIDEBAR);
const filterParams = paramMap.get(QUERY_PARAMS.FILTER);
const parsedFilters: Record<string, string[]> = {};
@@ -270,6 +281,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined;
this.coverScalePreferenceService.initScaleValue(user?.userSettings?.entityViewPreferences?.global?.coverSize);
this.filterSortPreferenceService.initValue(user?.userSettings?.filterSortingMode);
this.columnPreferenceService.initPreferences(user.userSettings?.tableColumnPreference);
this.visibleColumns = this.columnPreferenceService.visibleColumns;
const override = this.entityViewPreferences?.overrides?.find(o =>
o.entityType?.toUpperCase() === currentEntityTypeStr &&