Add book count to menu
This commit is contained in:
@@ -3,7 +3,7 @@ import {AppMenuitemComponent} from './app.menuitem.component';
|
|||||||
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
||||||
import {MenuModule} from 'primeng/menu';
|
import {MenuModule} from 'primeng/menu';
|
||||||
import {LibraryService} from '../../service/library.service';
|
import {LibraryService} from '../../service/library.service';
|
||||||
import {Observable} from 'rxjs';
|
import {async, Observable} from 'rxjs';
|
||||||
import {map} from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import {ShelfService} from '../../service/shelf.service';
|
import {ShelfService} from '../../service/shelf.service';
|
||||||
|
|
||||||
@@ -30,6 +30,7 @@ export class AppMenuComponent implements OnInit {
|
|||||||
label: library.name,
|
label: library.name,
|
||||||
icon: 'pi pi-' + library.icon,
|
icon: 'pi pi-' + library.icon,
|
||||||
routerLink: [`/library/${library.id}/books`],
|
routerLink: [`/library/${library.id}/books`],
|
||||||
|
bookCount$: this.libraryService.getBookCount(library.id ?? 0),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
@@ -44,10 +45,11 @@ export class AppMenuComponent implements OnInit {
|
|||||||
label: shelf.name,
|
label: shelf.name,
|
||||||
icon: 'pi pi-' + shelf.icon,
|
icon: 'pi pi-' + shelf.icon,
|
||||||
routerLink: [`/shelf/${shelf.id}/books`],
|
routerLink: [`/shelf/${shelf.id}/books`],
|
||||||
|
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
)
|
);
|
||||||
|
|
||||||
this.populateHome();
|
this.populateHome();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {Subscription} from 'rxjs';
|
|||||||
import {filter} from 'rxjs/operators';
|
import {filter} from 'rxjs/operators';
|
||||||
import {MenuService} from './app.menu.service';
|
import {MenuService} from './app.menu.service';
|
||||||
import {LayoutService} from './service/app.layout.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';
|
import {Ripple} from 'primeng/ripple';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -19,7 +19,9 @@ import {Ripple} from 'primeng/ripple';
|
|||||||
(click)="itemClick($event)"
|
(click)="itemClick($event)"
|
||||||
[ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple>
|
[ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple>
|
||||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||||
<span class="layout-menuitem-text">{{ item.label }}</span>
|
<span class="layout-menuitem-text">
|
||||||
|
{{ item.label }}
|
||||||
|
</span>
|
||||||
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -33,7 +35,12 @@ import {Ripple} from 'primeng/ripple';
|
|||||||
[queryParams]="item.queryParams"
|
[queryParams]="item.queryParams"
|
||||||
[attr.target]="item.target" tabindex="0" pRipple>
|
[attr.target]="item.target" tabindex="0" pRipple>
|
||||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||||
<span class="layout-menuitem-text">{{ item.label }}</span>
|
<span class="layout-menuitem-text flex justify-content-between w-full">
|
||||||
|
{{ item.label }}
|
||||||
|
<span *ngIf="item.bookCount$ | async as bookCount">
|
||||||
|
{{ bookCount }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -50,7 +57,8 @@ import {Ripple} from 'primeng/ripple';
|
|||||||
NgClass,
|
NgClass,
|
||||||
NgForOf,
|
NgForOf,
|
||||||
Ripple,
|
Ripple,
|
||||||
NgIf
|
NgIf,
|
||||||
|
AsyncPipe
|
||||||
],
|
],
|
||||||
animations: [
|
animations: [
|
||||||
trigger('children', [
|
trigger('children', [
|
||||||
|
|||||||
@@ -76,4 +76,10 @@ export class LibraryService {
|
|||||||
return this.http.get<BookWithNeighborsDTO>(`${this.url}/${libraryId}/book/${bookId}/withNeighbors`);
|
return this.http.get<BookWithNeighborsDTO>(`${this.url}/${libraryId}/book/${bookId}/withNeighbors`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBookCount(libraryId: number): Observable<number> {
|
||||||
|
return this.bookService.books$.pipe(
|
||||||
|
map(books => books.filter(book => book.libraryId === libraryId).length)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,4 +66,10 @@ export class ShelfService {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBookCount(shelfId: number): Observable<number> {
|
||||||
|
return this.bookService.books$.pipe(
|
||||||
|
map(books => books.filter(book => book.shelves?.some(shelf => shelf.id === shelfId)).length)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user