diff --git a/booklore-ui/src/app/book/component/layout/app.menu.component.ts b/booklore-ui/src/app/book/component/layout/app.menu.component.ts index 2d5fca183..900690508 100644 --- a/booklore-ui/src/app/book/component/layout/app.menu.component.ts +++ b/booklore-ui/src/app/book/component/layout/app.menu.component.ts @@ -3,7 +3,7 @@ import {AppMenuitemComponent} from './app.menuitem.component'; import {AsyncPipe, NgForOf, NgIf} from '@angular/common'; import {MenuModule} from 'primeng/menu'; import {LibraryService} from '../../service/library.service'; -import {Observable} from 'rxjs'; +import {async, Observable} from 'rxjs'; import {map} from 'rxjs/operators'; import {ShelfService} from '../../service/shelf.service'; @@ -30,6 +30,7 @@ export class AppMenuComponent implements OnInit { label: library.name, icon: 'pi pi-' + library.icon, routerLink: [`/library/${library.id}/books`], + bookCount$: this.libraryService.getBookCount(library.id ?? 0), })), }, ]) @@ -44,10 +45,11 @@ export class AppMenuComponent implements OnInit { label: shelf.name, icon: 'pi pi-' + shelf.icon, routerLink: [`/shelf/${shelf.id}/books`], + bookCount$: this.shelfService.getBookCount(shelf.id ?? 0), })), }, ]) - ) + ); this.populateHome(); } diff --git a/booklore-ui/src/app/book/component/layout/app.menuitem.component.ts b/booklore-ui/src/app/book/component/layout/app.menuitem.component.ts index 5bd7ff150..629dab858 100644 --- a/booklore-ui/src/app/book/component/layout/app.menuitem.component.ts +++ b/booklore-ui/src/app/book/component/layout/app.menuitem.component.ts @@ -5,7 +5,7 @@ import {Subscription} from 'rxjs'; import {filter} from 'rxjs/operators'; import {MenuService} from './app.menu.service'; import {LayoutService} from './service/app.layout.service'; -import {NgClass, NgForOf, NgIf} from '@angular/common'; +import {AsyncPipe, NgClass, NgForOf, NgIf} from '@angular/common'; import {Ripple} from 'primeng/ripple'; @Component({ @@ -19,7 +19,9 @@ import {Ripple} from 'primeng/ripple'; (click)="itemClick($event)" [ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple> - {{ item.label }} + + {{ item.label }} + @@ -33,7 +35,12 @@ import {Ripple} from 'primeng/ripple'; [queryParams]="item.queryParams" [attr.target]="item.target" tabindex="0" pRipple> - {{ item.label }} + + {{ item.label }} + + {{ bookCount }} + + @@ -50,7 +57,8 @@ import {Ripple} from 'primeng/ripple'; NgClass, NgForOf, Ripple, - NgIf + NgIf, + AsyncPipe ], animations: [ trigger('children', [ diff --git a/booklore-ui/src/app/book/service/library.service.ts b/booklore-ui/src/app/book/service/library.service.ts index fcb7875a8..9b1c09a0a 100644 --- a/booklore-ui/src/app/book/service/library.service.ts +++ b/booklore-ui/src/app/book/service/library.service.ts @@ -76,4 +76,10 @@ export class LibraryService { return this.http.get(`${this.url}/${libraryId}/book/${bookId}/withNeighbors`); } + getBookCount(libraryId: number): Observable { + return this.bookService.books$.pipe( + map(books => books.filter(book => book.libraryId === libraryId).length) + ); + } + } diff --git a/booklore-ui/src/app/book/service/shelf.service.ts b/booklore-ui/src/app/book/service/shelf.service.ts index a9eb24e1a..11777c941 100644 --- a/booklore-ui/src/app/book/service/shelf.service.ts +++ b/booklore-ui/src/app/book/service/shelf.service.ts @@ -66,4 +66,10 @@ export class ShelfService { }) ); } + + getBookCount(shelfId: number): Observable { + return this.bookService.books$.pipe( + map(books => books.filter(book => book.shelves?.some(shelf => shelf.id === shelfId)).length) + ); + } }