diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.html b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.html index 520689368..317bf4f9c 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.html +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.html @@ -6,9 +6,6 @@ @if (!item.separator) {
  • } - @if (item.separator) { - - } } } @@ -19,9 +16,6 @@ @if (!item.separator) {
  • } - @if (item.separator) { - - } } } @@ -32,9 +26,6 @@ @if (!item.separator) {
  • } - @if (item.separator) { - - } } } diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts index 62fccd6b4..c6430362f 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts @@ -11,7 +11,6 @@ import {LibraryShelfMenuService} from '../../../book/service/library-shelf-menu. 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 {AppSettingsService} from '../../../core/service/app-settings.service'; import {UserService} from '../../../settings/user-management/user.service'; @Component({ @@ -41,6 +40,8 @@ export class AppMenuComponent implements OnInit { shelfSortField: 'name' | 'id' = 'name'; shelfSortOrder: 'asc' | 'desc' = 'asc'; + + ngOnInit(): void { this.versionService.getVersion().subscribe((data) => { this.versionInfo = data; @@ -64,7 +65,6 @@ export class AppMenuComponent implements OnInit { map((bookState) => [ { label: 'Home', - separator: false, items: [ { label: 'Dashboard', @@ -89,11 +89,10 @@ export class AppMenuComponent implements OnInit { map((state) => { const libraries = state.libraries ?? []; const sortedLibraries = this.sortArray(libraries, this.librarySortField, this.librarySortOrder); - return [ { label: 'Library', - separator: false, + hasDropDown: true, items: sortedLibraries.map((library) => ({ menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library), label: library.name, @@ -132,7 +131,7 @@ export class AppMenuComponent implements OnInit { return [ { label: 'Shelves', - separator: false, + hasDropDown: true, items: [unshelvedItem, ...shelfItems], }, ]; diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html index 9c26ed900..a74f505fe 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html @@ -1,43 +1,43 @@ - @if (root && item.visible !== false) { -
    {{ item.label }}
    - } - - @if ((!item.routerLink || item.items) && item.visible !== false) { - - - - {{ item.label }} - - @if (item.items) { - - } - - } - -
    - @if ((item.routerLink && !item.items) && item.visible !== false) { - - - - {{ item.label }} - - @if (item.items) { - - } - + @if (root) { + @if (item.hasDropDown) { +
    +
    {{ item.label }}
    + +
    + } @else { +
    +
    {{ item.label }}
    +
    } - @if ((item.routerLink && !item.items) && item.visible !== false) { + } + +
    +
    + @if ((item.routerLink && !item.items)) { + + + + {{ item.label }} + + + } @if (item.type === 'Library' || item.type === 'Shelf') { @if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved') { @@ -56,20 +56,23 @@ } } + @if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.label === 'Unshelved') {

    {{ (item.bookCount$ | async)?.toString() || '0' }}

    }
    - } -
    +
    - @if (item.items && item.visible !== false) { - - } +
    +
    diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts index fe07f5821..e5d4827f0 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts @@ -4,11 +4,10 @@ import {animate, state, style, transition, trigger} from '@angular/animations'; import {Subscription} from 'rxjs'; import {filter} from 'rxjs/operators'; import {MenuService} from './service/app.menu.service'; -import { AsyncPipe, NgClass } from '@angular/common'; +import {AsyncPipe, NgClass} from '@angular/common'; import {Ripple} from 'primeng/ripple'; import {Button} from 'primeng/button'; import {Menu} from 'primeng/menu'; -import {MenuItem} from 'primeng/api'; import {UserService} from '../../../settings/user-management/user.service'; @Component({ @@ -52,6 +51,20 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { menuSourceSubscription: Subscription; menuResetSubscription: Subscription; + expandedItems = new Set(); + + toggleExpand(key: string) { + if (this.expandedItems.has(key)) { + this.expandedItems.delete(key); + } else { + this.expandedItems.add(key); + } + } + + isExpanded(key: string): boolean { + return this.expandedItems.has(key); + } + constructor(public router: Router, private menuService: MenuService, private userService: UserService) { this.userService.userState$.subscribe(userData => { if (userData) { @@ -85,6 +98,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { ngOnInit() { this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index); + this.expandedItems.add(this.key); if (this.item.routerLink) { this.updateActiveStateFromRoute(); } @@ -116,10 +130,6 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { this.menuService.onMenuStateChange({key: this.key}); } - get submenuAnimation() { - return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed'); - } - @HostBinding('class.active-menuitem') get activeClass() { return this.active && !this.root;