Implement magic shelves with dynamic rule-based filters

This commit is contained in:
aditya.chandel
2025-07-28 07:59:00 -06:00
committed by Aditya Chandel
parent 0777d473dc
commit 63518b7eb8
36 changed files with 1767 additions and 65 deletions
@@ -12,6 +12,7 @@ import {AppVersion, VersionService} from '../../../core/service/version.service'
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {VersionChangelogDialogComponent} from './version-changelog-dialog/version-changelog-dialog.component';
import {UserService} from '../../../settings/user-management/user.service';
import {MagicShelf, MagicShelfService, MagicShelfState} from '../../../magic-shelf-service';
@Component({
selector: 'app-menu',
@@ -23,6 +24,7 @@ export class AppMenuComponent implements OnInit {
libraryMenu$: Observable<any> | undefined;
shelfMenu$: Observable<any> | undefined;
homeMenu$: Observable<any> | undefined;
magicShelfMenu$: Observable<any> | undefined;
versionInfo: AppVersion | null = null;
dynamicDialogRef: DynamicDialogRef | undefined;
@@ -34,6 +36,7 @@ export class AppMenuComponent implements OnInit {
private libraryShelfMenuService = inject(LibraryShelfMenuService);
private dialogService = inject(DialogService);
private userService = inject(UserService);
private magicShelfService = inject(MagicShelfService);
librarySortField: 'name' | 'id' = 'name';
librarySortOrder: 'asc' | 'desc' = 'desc';
@@ -41,7 +44,6 @@ export class AppMenuComponent implements OnInit {
shelfSortOrder: 'asc' | 'desc' = 'asc';
ngOnInit(): void {
this.versionService.getVersion().subscribe((data) => {
this.versionInfo = data;
@@ -91,8 +93,10 @@ export class AppMenuComponent implements OnInit {
const sortedLibraries = this.sortArray(libraries, this.librarySortField, this.librarySortOrder);
return [
{
label: 'Library',
label: 'Libraries',
type: 'library',
hasDropDown: true,
hasCreate: true,
items: sortedLibraries.map((library) => ({
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library),
label: library.name,
@@ -106,6 +110,29 @@ export class AppMenuComponent implements OnInit {
})
);
this.magicShelfMenu$ = this.magicShelfService.shelvesState$.pipe(
map((state: MagicShelfState) => {
const shelves = state.shelves ?? [];
const sortedShelves = this.sortArray(shelves, 'name', 'asc');
return [
{
label: 'Magic Shelves',
type: 'magicShelf',
hasDropDown: true,
hasCreate: true,
items: sortedShelves.map((shelf) => ({
label: shelf.name,
type: 'magicShelfItem',
icon: 'pi pi-' + shelf.icon,
menu: this.libraryShelfMenuService.initializeMagicShelfMenuItems(shelf),
routerLink: [`/magic-shelf/${shelf.id}/books`],
bookCount$: this.magicShelfService.getBookCount(shelf.id ?? 0),
})),
},
];
})
);
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
map((state) => {
const shelves = state.shelves ?? [];
@@ -130,8 +157,10 @@ export class AppMenuComponent implements OnInit {
return [
{
type: 'shelf',
label: 'Shelves',
hasDropDown: true,
hasCreate: false,
items: [unshelvedItem, ...shelfItems],
},
];