Add “Unassigned” shelf view for books not in any shelf
This commit is contained in:
committed by
Aditya Chandel
parent
22f10d0475
commit
4cb82d2ba7
@@ -38,6 +38,7 @@ export const routes: Routes = [
|
|||||||
{path: 'settings', component: SettingsComponent, canActivate: [AuthGuard]},
|
{path: 'settings', component: SettingsComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
{path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
{path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||||
|
{path: 'unshelved-books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]}
|
{path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,14 +3,17 @@
|
|||||||
<div class="flex justify-between items-center p-2 rounded-t-xl mb-4 bg-[var(--card-background)]">
|
<div class="flex justify-between items-center p-2 rounded-t-xl mb-4 bg-[var(--card-background)]">
|
||||||
<div class="flex items-center pl-2">
|
<div class="flex items-center pl-2">
|
||||||
<ng-container *ngIf="entityType$ | async as entityType">
|
<ng-container *ngIf="entityType$ | async as entityType">
|
||||||
<p *ngIf="entityType !== EntityType.ALL_BOOKS" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
<p *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
||||||
{{ entityType }}: {{ (entity$ | async)?.name }}
|
{{ entityType }}: {{ (entity$ | async)?.name }}
|
||||||
</p>
|
</p>
|
||||||
<p *ngIf="entityType === EntityType.ALL_BOOKS" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
<p *ngIf="entityType === EntityType.ALL_BOOKS" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
||||||
All Books
|
All Books
|
||||||
</p>
|
</p>
|
||||||
|
<p *ngIf="entityType === EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
||||||
|
Unshelved Books
|
||||||
|
</p>
|
||||||
<div *ngIf="userService.userData$ | async as userData">
|
<div *ngIf="userService.userData$ | async as userData">
|
||||||
<div *ngIf="entityType !== EntityType.ALL_BOOKS && userData.permissions.canManipulateLibrary">
|
<div *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && userData.permissions.canManipulateLibrary">
|
||||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
||||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||||
</div>
|
</div>
|
||||||
@@ -126,7 +129,7 @@
|
|||||||
<div class="flex justify-between gap-8">
|
<div class="flex justify-between gap-8">
|
||||||
<ng-container *ngIf="entityType$ | async as entityType">
|
<ng-container *ngIf="entityType$ | async as entityType">
|
||||||
<p-button
|
<p-button
|
||||||
*ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS"
|
*ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS || entityType === EntityType.UNSHELVED"
|
||||||
icon="pi pi-bookmark-fill"
|
icon="pi pi-bookmark-fill"
|
||||||
outlined="true"
|
outlined="true"
|
||||||
severity="info"
|
severity="info"
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/l
|
|||||||
export enum EntityType {
|
export enum EntityType {
|
||||||
LIBRARY = 'Library',
|
LIBRARY = 'Library',
|
||||||
SHELF = 'Shelf',
|
SHELF = 'Shelf',
|
||||||
ALL_BOOKS = 'All Books'
|
ALL_BOOKS = 'All Books',
|
||||||
|
UNSHELVED = 'Unshelved Books',
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUERY_PARAMS = {
|
const QUERY_PARAMS = {
|
||||||
@@ -137,21 +138,21 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.bookService.loadBooks();
|
this.bookService.loadBooks();
|
||||||
|
|
||||||
const isAllBooksRoute = this.activatedRoute.snapshot.routeConfig?.path === 'all-books';
|
const currentPath = this.activatedRoute.snapshot.routeConfig?.path;
|
||||||
|
|
||||||
if (isAllBooksRoute) {
|
if (currentPath === 'all-books') {
|
||||||
this.entityType = EntityType.ALL_BOOKS;
|
this.entityType = EntityType.ALL_BOOKS;
|
||||||
this.entityType$ = of(EntityType.ALL_BOOKS);
|
this.entityType$ = of(EntityType.ALL_BOOKS);
|
||||||
this.entity$ = of(null);
|
this.entity$ = of(null);
|
||||||
this.bookState$ = this.fetchAllBooks();
|
|
||||||
|
} else if (currentPath === 'unshelved-books') {
|
||||||
|
this.entityType = EntityType.UNSHELVED;
|
||||||
|
this.entityType$ = of(EntityType.UNSHELVED);
|
||||||
|
this.entity$ = of(null);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const routeEntityInfo$ = this.getEntityInfoFromRoute();
|
const routeEntityInfo$ = this.getEntityInfoFromRoute();
|
||||||
|
|
||||||
this.bookState$ = routeEntityInfo$.pipe(
|
|
||||||
switchMap(({entityId, entityType}) => this.fetchBooksByEntity(entityId, entityType)),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.entity$ = routeEntityInfo$.pipe(
|
this.entity$ = routeEntityInfo$.pipe(
|
||||||
switchMap(({entityId, entityType}) => this.fetchEntity(entityId, entityType))
|
switchMap(({entityId, entityType}) => this.fetchEntity(entityId, entityType))
|
||||||
);
|
);
|
||||||
@@ -255,6 +256,23 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fetchUnshelvedBooks(): Observable<BookState> {
|
||||||
|
return this.bookService.bookState$.pipe(
|
||||||
|
map(bookState => {
|
||||||
|
const unshelvedBooks = (bookState.books || []).filter(book =>
|
||||||
|
!book.shelves || book.shelves.length === 0
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
...bookState,
|
||||||
|
books: unshelvedBooks
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
map(bookState => this.processBookState(bookState)),
|
||||||
|
switchMap(bookState => this.headerFilter(bookState)),
|
||||||
|
switchMap(bookState => this.sideBarFilter(bookState))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private sideBarFilter(bookState: BookState): Observable<BookState> {
|
private sideBarFilter(bookState: BookState): Observable<BookState> {
|
||||||
return this.selectedFilter.pipe(
|
return this.selectedFilter.pipe(
|
||||||
map((activeFilters: Record<string, any[]> | null) => {
|
map((activeFilters: Record<string, any[]> | null) => {
|
||||||
@@ -397,6 +415,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
applySortOption(sortOption: SortOption): void {
|
applySortOption(sortOption: SortOption): void {
|
||||||
if (this.entityType === EntityType.ALL_BOOKS) {
|
if (this.entityType === EntityType.ALL_BOOKS) {
|
||||||
this.bookState$ = this.fetchAllBooks();
|
this.bookState$ = this.fetchAllBooks();
|
||||||
|
} else if (this.entityType === EntityType.UNSHELVED) {
|
||||||
|
this.bookState$ = this.fetchUnshelvedBooks();
|
||||||
} else {
|
} else {
|
||||||
const routeParam$ = this.getEntityInfoFromRoute();
|
const routeParam$ = this.getEntityInfoFromRoute();
|
||||||
this.bookState$ = routeParam$.pipe(
|
this.bookState$ = routeParam$.pipe(
|
||||||
|
|||||||
@@ -106,4 +106,12 @@ export class ShelfService {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUnshelvedBookCount(): Observable<number> {
|
||||||
|
return this.bookService.bookState$.pipe(
|
||||||
|
map(state =>
|
||||||
|
(state.books || []).filter(book => !book.shelves || book.shelves.length === 0).length
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,20 +57,32 @@ export class AppMenuComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
|
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
|
||||||
map((state) => [
|
map((state) => {
|
||||||
{
|
const shelves = state.shelves?.map((shelf) => ({
|
||||||
label: 'Shelves',
|
|
||||||
separator: false,
|
|
||||||
items: state.shelves?.map((shelf) => ({
|
|
||||||
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
||||||
label: shelf.name,
|
label: shelf.name,
|
||||||
type: 'Shelf',
|
type: 'Shelf',
|
||||||
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),
|
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||||
})) || [],
|
})) || [];
|
||||||
|
|
||||||
|
const unshelvedItem = {
|
||||||
|
label: 'Unshelved',
|
||||||
|
type: 'Shelf',
|
||||||
|
icon: 'pi pi-inbox',
|
||||||
|
routerLink: ['/unshelved-books'],
|
||||||
|
bookCount$: this.shelfService.getUnshelvedBookCount?.() ?? of(0),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Shelves',
|
||||||
|
separator: false,
|
||||||
|
items: [unshelvedItem, ...shelves],
|
||||||
},
|
},
|
||||||
])
|
];
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.homeMenu$ = this.bookService.bookState$.pipe(
|
this.homeMenu$ = this.bookService.bookState$.pipe(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false">
|
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false">
|
||||||
<ng-container *ngIf="item.type === 'Library' || item.type === 'Shelf'">
|
<ng-container *ngIf="item.type === 'Library' || item.type === 'Shelf'">
|
||||||
<p-button
|
<p-button
|
||||||
*ngIf="item.type !== 'Library' || canManipulateLibrary"
|
*ngIf="(item.type !== 'Library' || canManipulateLibrary) && item.label !== 'Unshelved'"
|
||||||
(click)="entitymenu.toggle($event)"
|
(click)="entitymenu.toggle($event)"
|
||||||
(mouseover)="hovered = true"
|
(mouseover)="hovered = true"
|
||||||
(mouseleave)="hovered = false"
|
(mouseleave)="hovered = false"
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container *ngIf="item.type === 'Library' && !canManipulateLibrary || item.type === 'All Books'">
|
<ng-container *ngIf="item.type === 'Library' && !canManipulateLibrary || item.type === 'All Books' || item.label === 'Unshelved'">
|
||||||
<p class="text-[var(--primary-color)] pr-1">
|
<p class="text-[var(--primary-color)] pr-1">
|
||||||
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user