feat(viewer): add context-aware series collapse functionality (#2073)
- Introduced support for context-specific series collapse preferences for libraries, shelves, and magic shelves. - Improved backward compatibility with legacy preference structures. - Added JSON aliasing for `seriesCollapse` to maintain API compatibility. - Extended entity selection in view preferences to include magic shelves. - Enhanced error handling in app settings service to filter null values. - Optimized series collapse preference management, ensuring local and global overrides persist accurately. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package com.adityachandel.booklore.model.dto;
|
|||||||
|
|
||||||
import com.adityachandel.booklore.model.dto.settings.SidebarSortOption;
|
import com.adityachandel.booklore.model.dto.settings.SidebarSortOption;
|
||||||
import com.adityachandel.booklore.model.enums.*;
|
import com.adityachandel.booklore.model.enums.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -93,6 +94,7 @@ public class BookLoreUser {
|
|||||||
private String sortDir;
|
private String sortDir;
|
||||||
private String view;
|
private String view;
|
||||||
private Float coverSize;
|
private Float coverSize;
|
||||||
|
@JsonAlias("seriesCollapse")
|
||||||
private Boolean seriesCollapsed;
|
private Boolean seriesCollapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +116,8 @@ public class BookLoreUser {
|
|||||||
private String sortKey;
|
private String sortKey;
|
||||||
private String sortDir;
|
private String sortDir;
|
||||||
private String view;
|
private String view;
|
||||||
private Boolean seriesCollapse;
|
@JsonAlias("seriesCollapse")
|
||||||
|
private Boolean seriesCollapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
+3
-1
@@ -95,7 +95,9 @@ public class AppSettingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getSettingsMap() {
|
private Map<String, String> getSettingsMap() {
|
||||||
return settingPersistenceHelper.appSettingsRepository.findAll().stream().collect(Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal));
|
return settingPersistenceHelper.appSettingsRepository.findAll().stream()
|
||||||
|
.filter(entity -> entity.getName() != null && entity.getVal() != null)
|
||||||
|
.collect(Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PublicAppSetting buildPublicSetting() {
|
private PublicAppSetting buildPublicSetting() {
|
||||||
|
|||||||
+1
-1
@@ -261,7 +261,7 @@
|
|||||||
class="grid"
|
class="grid"
|
||||||
#container
|
#container
|
||||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||||
@for (book of scroll.viewPortItems; let i = $index; track book) {
|
@for (book of scroll.viewPortItems; let i = $index; track book.id) {
|
||||||
<div
|
<div
|
||||||
class="virtual-scroller-item relative"
|
class="virtual-scroller-item relative"
|
||||||
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
|
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.entityType$ = of(entityType);
|
this.entityType$ = of(entityType);
|
||||||
this.entity$ = of(null);
|
this.entity$ = of(null);
|
||||||
|
this.seriesCollapseFilter.setContext(null, null);
|
||||||
|
|
||||||
this.pageTitle.setPageTitle(currentPath === 'all-books' ? 'All Books' : 'Unshelved Books');
|
this.pageTitle.setPageTitle(currentPath === 'all-books' ? 'All Books' : 'Unshelved Books');
|
||||||
} else {
|
} else {
|
||||||
@@ -235,6 +236,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.pageTitle.setPageTitle(entity.name);
|
this.pageTitle.setPageTitle(entity.name);
|
||||||
}
|
}
|
||||||
this.entity = entity ?? null;
|
this.entity = entity ?? null;
|
||||||
|
this.updateSeriesCollapseContext();
|
||||||
this.entityOptions = entity
|
this.entityOptions = entity
|
||||||
? this.isLibrary(entity)
|
? this.isLibrary(entity)
|
||||||
? this.libraryShelfMenuService.initializeLibraryMenuItems(entity)
|
? this.libraryShelfMenuService.initializeLibraryMenuItems(entity)
|
||||||
@@ -711,6 +713,30 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.dialogHelperService.openFileMoverDialog(this.selectedBooks);
|
this.dialogHelperService.openFileMoverDialog(this.selectedBooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateSeriesCollapseContext() {
|
||||||
|
let type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF' | null = null;
|
||||||
|
let id: number | null = null;
|
||||||
|
|
||||||
|
if (this.entity && this.entityType) {
|
||||||
|
switch (this.entityType) {
|
||||||
|
case EntityType.LIBRARY:
|
||||||
|
type = 'LIBRARY';
|
||||||
|
id = this.entity.id ?? 0;
|
||||||
|
break;
|
||||||
|
case EntityType.SHELF:
|
||||||
|
type = 'SHELF';
|
||||||
|
id = this.entity.id ?? 0;
|
||||||
|
break;
|
||||||
|
case EntityType.MAGIC_SHELF:
|
||||||
|
type = 'MAGIC_SHELF';
|
||||||
|
id = this.entity.id ?? 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.seriesCollapseFilter.setContext(type, id);
|
||||||
|
}
|
||||||
|
|
||||||
private isLibrary(entity: Library | Shelf | MagicShelf): entity is Library {
|
private isLibrary(entity: Library | Shelf | MagicShelf): entity is Library {
|
||||||
return (entity as Library).paths !== undefined;
|
return (entity as Library).paths !== undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
+83
-11
@@ -1,7 +1,7 @@
|
|||||||
import {BookFilter} from './BookFilter';
|
import {BookFilter} from './BookFilter';
|
||||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||||
import {BookState} from '../../../model/state/book-state.model';
|
import {BookState} from '../../../model/state/book-state.model';
|
||||||
import {debounceTime, filter, map, take, takeUntil} from 'rxjs/operators';
|
import {debounceTime, filter, map, takeUntil} from 'rxjs/operators';
|
||||||
import {Book} from '../../../model/book.model';
|
import {Book} from '../../../model/book.model';
|
||||||
import {inject, Injectable, OnDestroy} from '@angular/core';
|
import {inject, Injectable, OnDestroy} from '@angular/core';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
@@ -17,18 +17,16 @@ export class SeriesCollapseFilter implements BookFilter, OnDestroy {
|
|||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
private hasUserToggled = false;
|
private hasUserToggled = false;
|
||||||
|
private currentContext: { type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF', id: number } | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.userService.userState$
|
this.userService.userState$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(userState => !!userState?.user && userState.loaded),
|
filter(userState => !!userState?.user && userState.loaded),
|
||||||
take(1),
|
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
)
|
)
|
||||||
.subscribe(user => {
|
.subscribe(() => {
|
||||||
const prefs = user.user?.userSettings?.entityViewPreferences;
|
this.applyPreference();
|
||||||
const initialCollapsed = prefs?.global?.seriesCollapsed ?? false;
|
|
||||||
this.seriesCollapseSubject.next(initialCollapsed);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.seriesCollapse$
|
this.seriesCollapse$
|
||||||
@@ -40,6 +38,15 @@ export class SeriesCollapseFilter implements BookFilter, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setContext(type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF' | null, id: number | null): void {
|
||||||
|
if (type && id) {
|
||||||
|
this.currentContext = {type, id};
|
||||||
|
} else {
|
||||||
|
this.currentContext = null;
|
||||||
|
}
|
||||||
|
this.applyPreference();
|
||||||
|
}
|
||||||
|
|
||||||
get isSeriesCollapsed(): boolean {
|
get isSeriesCollapsed(): boolean {
|
||||||
return this.seriesCollapseSubject.value;
|
return this.seriesCollapseSubject.value;
|
||||||
}
|
}
|
||||||
@@ -49,6 +56,38 @@ export class SeriesCollapseFilter implements BookFilter, OnDestroy {
|
|||||||
this.seriesCollapseSubject.next(value);
|
this.seriesCollapseSubject.next(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private applyPreference(): void {
|
||||||
|
const user = this.userService.getCurrentUser();
|
||||||
|
const prefs = user?.userSettings?.entityViewPreferences;
|
||||||
|
|
||||||
|
let collapsed = false;
|
||||||
|
|
||||||
|
if (prefs) {
|
||||||
|
// Backward compatibility: check for old 'seriesCollapse' field
|
||||||
|
const globalAny = prefs.global as any;
|
||||||
|
collapsed = prefs.global?.seriesCollapsed ?? globalAny?.seriesCollapse ?? false;
|
||||||
|
|
||||||
|
if (this.currentContext) {
|
||||||
|
const override = prefs.overrides?.find(o =>
|
||||||
|
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||||
|
);
|
||||||
|
if (override) {
|
||||||
|
const prefAny = override.preferences as any;
|
||||||
|
if (override.preferences.seriesCollapsed !== undefined) {
|
||||||
|
collapsed = override.preferences.seriesCollapsed;
|
||||||
|
} else if (prefAny?.seriesCollapse !== undefined) {
|
||||||
|
collapsed = prefAny.seriesCollapse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hasUserToggled = false;
|
||||||
|
if (this.seriesCollapseSubject.value !== collapsed) {
|
||||||
|
this.seriesCollapseSubject.next(collapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filter(bookState: BookState, forceExpandSeries?: boolean): Observable<BookState> {
|
filter(bookState: BookState, forceExpandSeries?: boolean): Observable<BookState> {
|
||||||
return this.seriesCollapse$.pipe(
|
return this.seriesCollapse$.pipe(
|
||||||
map(isCollapsed => {
|
map(isCollapsed => {
|
||||||
@@ -93,18 +132,51 @@ export class SeriesCollapseFilter implements BookFilter, OnDestroy {
|
|||||||
|
|
||||||
private persistCollapsePreference(isCollapsed: boolean): void {
|
private persistCollapsePreference(isCollapsed: boolean): void {
|
||||||
const user = this.userService.getCurrentUser();
|
const user = this.userService.getCurrentUser();
|
||||||
const prefs = user?.userSettings?.entityViewPreferences;
|
if (!user) return;
|
||||||
if (!user || !prefs) return;
|
|
||||||
|
|
||||||
prefs.global = prefs.global ?? {};
|
const prefs = structuredClone(user.userSettings.entityViewPreferences ?? {
|
||||||
prefs.global.seriesCollapsed = isCollapsed;
|
global: {
|
||||||
|
sortKey: 'addedOn',
|
||||||
|
sortDir: 'DESC',
|
||||||
|
view: 'GRID',
|
||||||
|
coverSize: 1.0,
|
||||||
|
seriesCollapsed: false
|
||||||
|
},
|
||||||
|
overrides: []
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!prefs.overrides) {
|
||||||
|
prefs.overrides = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.currentContext) {
|
||||||
|
let override = prefs.overrides.find(o =>
|
||||||
|
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!override) {
|
||||||
|
override = {
|
||||||
|
entityType: this.currentContext.type,
|
||||||
|
entityId: this.currentContext.id,
|
||||||
|
preferences: {
|
||||||
|
...prefs.global,
|
||||||
|
seriesCollapsed: isCollapsed
|
||||||
|
}
|
||||||
|
};
|
||||||
|
prefs.overrides.push(override);
|
||||||
|
} else {
|
||||||
|
override.preferences.seriesCollapsed = isCollapsed;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prefs.global.seriesCollapsed = isCollapsed;
|
||||||
|
}
|
||||||
|
|
||||||
this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs);
|
this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs);
|
||||||
|
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Preference Saved',
|
summary: 'Preference Saved',
|
||||||
detail: `Series collapse set to ${isCollapsed ? 'enabled' : 'disabled'}.`,
|
detail: `Series collapse set to ${isCollapsed ? 'enabled' : 'disabled'}${this.currentContext ? ' for this view' : ' globally'}.`,
|
||||||
life: 1500
|
life: 1500
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export interface EntityViewPreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityViewPreferenceOverride {
|
export interface EntityViewPreferenceOverride {
|
||||||
entityType: 'LIBRARY' | 'SHELF';
|
entityType: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF';
|
||||||
entityId: number;
|
entityId: number;
|
||||||
preferences: EntityViewPreference;
|
preferences: EntityViewPreference;
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-7
@@ -7,6 +7,7 @@ import {TableModule} from 'primeng/table';
|
|||||||
import {User, UserService} from '../../user-management/user.service';
|
import {User, UserService} from '../../user-management/user.service';
|
||||||
import {LibraryService} from '../../../book/service/library.service';
|
import {LibraryService} from '../../../book/service/library.service';
|
||||||
import {ShelfService} from '../../../book/service/shelf.service';
|
import {ShelfService} from '../../../book/service/shelf.service';
|
||||||
|
import {MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service';
|
||||||
import {combineLatest, Subject} from 'rxjs';
|
import {combineLatest, Subject} from 'rxjs';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {ToastModule} from 'primeng/toast';
|
import {ToastModule} from 'primeng/toast';
|
||||||
@@ -52,7 +53,8 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
entityTypeOptions = [
|
entityTypeOptions = [
|
||||||
{label: 'Library', value: 'LIBRARY'},
|
{label: 'Library', value: 'LIBRARY'},
|
||||||
{label: 'Shelf', value: 'SHELF'}
|
{label: 'Shelf', value: 'SHELF'},
|
||||||
|
{label: 'Magic Shelf', value: 'MAGIC_SHELF'}
|
||||||
];
|
];
|
||||||
|
|
||||||
sortDirectionOptions = [
|
sortDirectionOptions = [
|
||||||
@@ -67,13 +69,14 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
libraryOptions: { label: string; value: number }[] = [];
|
libraryOptions: { label: string; value: number }[] = [];
|
||||||
shelfOptions: { label: string; value: number }[] = [];
|
shelfOptions: { label: string; value: number }[] = [];
|
||||||
|
magicShelfOptions: { label: string; value: number }[] = [];
|
||||||
|
|
||||||
selectedSort: string = 'title';
|
selectedSort: string = 'title';
|
||||||
selectedSortDir: 'ASC' | 'DESC' = 'ASC';
|
selectedSortDir: 'ASC' | 'DESC' = 'ASC';
|
||||||
selectedView: 'GRID' | 'TABLE' = 'GRID';
|
selectedView: 'GRID' | 'TABLE' = 'GRID';
|
||||||
|
|
||||||
overrides: {
|
overrides: {
|
||||||
entityType: 'LIBRARY' | 'SHELF';
|
entityType: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF';
|
||||||
library: number;
|
library: number;
|
||||||
sort: string;
|
sort: string;
|
||||||
sortDir: 'ASC' | 'DESC';
|
sortDir: 'ASC' | 'DESC';
|
||||||
@@ -85,6 +88,7 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private libraryService = inject(LibraryService);
|
private libraryService = inject(LibraryService);
|
||||||
private shelfService = inject(ShelfService);
|
private shelfService = inject(ShelfService);
|
||||||
|
private magicShelfService = inject(MagicShelfService);
|
||||||
private userService = inject(UserService);
|
private userService = inject(UserService);
|
||||||
private messageService = inject(MessageService);
|
private messageService = inject(MessageService);
|
||||||
|
|
||||||
@@ -93,9 +97,10 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
this.userService.userState$.pipe(filter(userState => !!userState?.user && userState.loaded), take(1)),
|
this.userService.userState$.pipe(filter(userState => !!userState?.user && userState.loaded), take(1)),
|
||||||
this.libraryService.libraryState$.pipe(filter(libraryState => !!libraryState?.libraries && libraryState.loaded), take(1)),
|
this.libraryService.libraryState$.pipe(filter(libraryState => !!libraryState?.libraries && libraryState.loaded), take(1)),
|
||||||
this.shelfService.shelfState$.pipe(filter(shelfState => !!shelfState?.shelves && shelfState.loaded), take(1)),
|
this.shelfService.shelfState$.pipe(filter(shelfState => !!shelfState?.shelves && shelfState.loaded), take(1)),
|
||||||
|
this.magicShelfService.shelvesState$.pipe(filter(magicState => !!magicState?.shelves && magicState.loaded), take(1))
|
||||||
]).pipe(
|
]).pipe(
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
).subscribe(([userState, librariesState, shelfState]) => {
|
).subscribe(([userState, librariesState, shelfState, magicState]) => {
|
||||||
|
|
||||||
this.user = userState.user;
|
this.user = userState.user;
|
||||||
const prefs = userState.user?.userSettings?.entityViewPreferences;
|
const prefs = userState.user?.userSettings?.entityViewPreferences;
|
||||||
@@ -121,6 +126,11 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
label: s.name,
|
label: s.name,
|
||||||
value: s.id!
|
value: s.id!
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.magicShelfOptions = (magicState?.shelves ?? []).filter(s => s.id !== undefined).map(s => ({
|
||||||
|
label: s.name,
|
||||||
|
value: s.id!
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,19 +139,34 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
|||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
getAvailableEntities(index: number, type: 'LIBRARY' | 'SHELF') {
|
getAvailableEntities(index: number, type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF') {
|
||||||
const selected = this.overrides.map((o, i) => i !== index ? o.library : null);
|
const selected = this.overrides.map((o, i) => i !== index ? o.library : null);
|
||||||
const source = type === 'LIBRARY' ? this.libraryOptions : this.shelfOptions;
|
let source: { label: string; value: number }[];
|
||||||
|
switch (type) {
|
||||||
|
case 'LIBRARY':
|
||||||
|
source = this.libraryOptions;
|
||||||
|
break;
|
||||||
|
case 'SHELF':
|
||||||
|
source = this.shelfOptions;
|
||||||
|
break;
|
||||||
|
case 'MAGIC_SHELF':
|
||||||
|
source = this.magicShelfOptions;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
source = [];
|
||||||
|
}
|
||||||
return source.filter(opt => !selected.includes(opt.value) || this.overrides[index]?.library === opt.value);
|
return source.filter(opt => !selected.includes(opt.value) || this.overrides[index]?.library === opt.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get availableLibraries() {
|
get availableLibraries() {
|
||||||
const used = new Set(this.overrides.map(o => `${o.entityType}_${o.library}`));
|
const used = new Set(this.overrides.map(o => `${o.entityType}_${o.library}`));
|
||||||
|
|
||||||
const withEntityType = (options: { label: string; value: number }[], entityType: 'LIBRARY' | 'SHELF') =>
|
const withEntityType = (options: { label: string; value: number }[], entityType: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF') =>
|
||||||
options.map(opt => ({...opt, entityType}));
|
options.map(opt => ({...opt, entityType}));
|
||||||
|
|
||||||
return [...withEntityType(this.libraryOptions, 'LIBRARY'), ...withEntityType(this.shelfOptions, 'SHELF')]
|
return [...withEntityType(this.libraryOptions, 'LIBRARY'),
|
||||||
|
...withEntityType(this.shelfOptions, 'SHELF'),
|
||||||
|
...withEntityType(this.magicShelfOptions, 'MAGIC_SHELF')]
|
||||||
.filter(opt => !used.has(`${opt.entityType}_${opt.value}`));
|
.filter(opt => !used.has(`${opt.entityType}_${opt.value}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user