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
@@ -29,6 +29,16 @@
}
}
</ul>
<ul class="layout-menu">
@if (magicShelfMenu$ | async; as shelfMenu) {
@for (item of shelfMenu; track item; let i = $index) {
@if (!item.separator) {
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
}
}
}
</ul>
</div>
@if (versionInfo) {
@@ -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],
},
];
@@ -1,9 +1,20 @@
<ng-container>
@if (root) {
@if (item.hasDropDown) {
<div class="flex items-center justify-between layout-menuitem-root-text cursor-pointer pt-4" (click)="toggleExpand(key)">
<div>{{ item.label }}</div>
<i [ngClass]="{
<div class=" flex items-center justify-between layout-menuitem-root-text cursor-pointer pt-4">
<div class="flex items-center justify-between gap-2 cursor-pointer">
<div>{{ item.label }}</div>
@if (item.hasCreate) {
<i
class="pi pi-plus text-surface-500 hover:text-surface-200"
style="font-size: 0.8rem"
(click)="openDialog(item)"
></i>
}
</div>
<i
(click)="toggleExpand(key)"
[ngClass]="{
'pi': true,
'pi-angle-up': isExpanded(key),
'pi-angle-down': !isExpanded(key),
@@ -39,7 +50,7 @@
</a>
}
<span>
@if (item.type === 'Library' || item.type === 'Shelf') {
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved') {
<p-button
(click)="entitymenu.toggle($event)"
@@ -9,6 +9,7 @@ import {Ripple} from 'primeng/ripple';
import {Button} from 'primeng/button';
import {Menu} from 'primeng/menu';
import {UserService} from '../../../settings/user-management/user.service';
import {DialogLauncherService} from '../../../dialog-launcher.service';
@Component({
selector: '[app-menuitem]',
@@ -22,7 +23,7 @@ import {UserService} from '../../../settings/user-management/user.service';
AsyncPipe,
Button,
Menu
],
],
animations: [
trigger('children', [
state('collapsed', style({
@@ -65,7 +66,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
return this.expandedItems.has(key);
}
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
constructor(public router: Router, private menuService: MenuService, private userService: UserService, private dialogLauncher: DialogLauncherService) {
this.userService.userState$.subscribe(userData => {
if (userData) {
this.canManipulateLibrary = userData.permissions.canManipulateLibrary;
@@ -143,4 +144,13 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
this.menuResetSubscription.unsubscribe();
}
}
openDialog(item: any) {
if (item.type === 'library' && this.canManipulateLibrary) {
this.dialogLauncher.openLibraryCreatorDialog();
}
if (item.type === 'magicShelf') {
this.dialogLauncher.openMagicShelfDialog();
}
}
}
@@ -3,7 +3,6 @@ import {MenuItem} from 'primeng/api';
import {LayoutService} from '../layout-main/service/app.layout.service';
import {Router, RouterLink} from '@angular/router';
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryCreatorComponent} from '../../../book/components/library-creator/library-creator.component';
import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
@@ -14,11 +13,8 @@ import {Button} from 'primeng/button';
import {StyleClass} from 'primeng/styleclass';
import {Divider} from 'primeng/divider';
import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurator.component';
import {BookUploaderComponent} from '../../../utilities/component/book-uploader/book-uploader.component';
import {AuthService} from '../../../core/service/auth.service';
import {UserService} from '../../../settings/user-management/user.service';
import {UserProfileDialogComponent} from '../../../settings/global-preferences/user-profile-dialog/user-profile-dialog.component';
import {GithubSupportDialog} from '../../../utilities/component/github-support-dialog/github-support-dialog';
import {Popover} from 'primeng/popover';
import {MetadataProgressService} from '../../../core/service/metadata-progress-service';
import {takeUntil} from 'rxjs/operators';
@@ -26,6 +22,7 @@ import {Subject} from 'rxjs';
import {MetadataBatchProgressNotification} from '../../../core/model/metadata-batch-progress.model';
import {UnifiedNotificationBoxComponent} from '../../../core/component/unified-notification-popover-component/unified-notification-popover-component';
import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
import {DialogLauncherService} from '../../../dialog-launcher.service';
@Component({
selector: 'app-topbar',
@@ -79,7 +76,8 @@ export class AppTopBarComponent implements OnDestroy {
private authService: AuthService,
protected userService: UserService,
private metadataProgressService: MetadataProgressService,
private bookdropFileService: BookdropFileService
private bookdropFileService: BookdropFileService,
private dialogLauncher: DialogLauncherService
) {
this.subscribeToMetadataProgress();
this.subscribeToNotifications();
@@ -116,19 +114,19 @@ export class AppTopBarComponent implements OnDestroy {
}
openGithubSupportDialog(): void {
this.openDialog(GithubSupportDialog, 'Support BookLore on GitHub', '25%');
this.dialogLauncher.openGithubSupportDialog();
}
openLibraryCreatorDialog(): void {
this.openDialog(LibraryCreatorComponent, 'Create New Library', '15%');
this.dialogLauncher.openLibraryCreatorDialog();
}
openFileUploadDialog(): void {
this.openDialog(BookUploaderComponent, 'Book Uploader', '10%');
this.dialogLauncher.openFileUploadDialog();
}
openUserProfileDialog(): void {
this.openDialog(UserProfileDialogComponent, 'User Profile Information', '10%');
this.dialogLauncher.openUserProfileDialog();
}
navigateToSettings() {
@@ -139,24 +137,6 @@ export class AppTopBarComponent implements OnDestroy {
this.authService.logout();
}
private openDialog(component: any, header: string, top: string) {
const isMobile = window.innerWidth <= 768;
this.ref = this.dialogService.open(component, {
header,
modal: true,
closable: true,
style: {
position: 'absolute',
top,
...(isMobile && {
width: '90vw',
maxWidth: '90vw',
minWidth: '90vw',
}),
},
});
}
private subscribeToMetadataProgress() {
this.metadataProgressService.progressUpdates$
.pipe(takeUntil(this.destroy$))