Add all books menu item
This commit is contained in:
@@ -13,6 +13,9 @@ const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: '', component: DashboardComponent,
|
path: '', component: DashboardComponent,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'all-books', component: BookBrowserComponent,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'library/:libraryId/books', component: BookBrowserComponent,
|
path: 'library/:libraryId/books', component: BookBrowserComponent,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="book-browser-header">
|
<div class="book-browser-header">
|
||||||
<div class="left-items">
|
<div class="left-items">
|
||||||
<p class="entity-name text-2xl">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</p>
|
|
||||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"/>
|
<ng-container *ngIf="entityType$ | async as entityType">
|
||||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
<p *ngIf="entityType !== 'all-books'" class="entity-name text-2xl">
|
||||||
|
{{ entityType }}: {{ (entity$ | async)?.name }}
|
||||||
|
</p>
|
||||||
|
<p *ngIf="entityType === 'all-books'" class="entity-name text-2xl">
|
||||||
|
All Books
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div *ngIf="entityType !== 'all-books'">
|
||||||
|
<p-button
|
||||||
|
icon="pi pi-ellipsis-v"
|
||||||
|
[rounded]="true"
|
||||||
|
[text]="true"
|
||||||
|
severity="info"
|
||||||
|
(click)="entitymenu.toggle($event)" />
|
||||||
|
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="header-right-items">
|
<div class="header-right-items">
|
||||||
@@ -53,12 +70,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||||
<div class="footer-items-container">
|
<div class="footer-items-container">
|
||||||
<!--<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="info" (click)="menu.toggle($event)"></p-button>-->
|
<ng-container *ngIf="entityType$ | async as entityType">
|
||||||
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-book" label="Assign Shelf" severity="info" (onClick)="openShelfAssigner()"></p-button>
|
<p-button *ngIf="entityType === 'Library' || entityType ==='all-books'" icon="pi pi-book" label="Assign Shelf" severity="info" (onClick)="openShelfAssigner()"></p-button>
|
||||||
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="info" (click)="unshelfBooks()"></p-button>
|
<p-button *ngIf="entityType === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="info" (click)="unshelfBooks()"></p-button>
|
||||||
<p-button icon="pi pi-times" label="Deselect" severity="warn" (click)="deselectAllBooks()"></p-button>
|
<p-button icon="pi pi-times" label="Deselect" severity="warn" (click)="deselectAllBooks()"></p-button>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
<!--<p-menu #menu [model]="multiSelectItems" [popup]="true" appendTo="body"></p-menu>-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
entityType: string = '';
|
entityType: string = '';
|
||||||
bookTitle: string = '';
|
bookTitle: string = '';
|
||||||
entityOptions: MenuItem[] | undefined;
|
entityOptions: MenuItem[] | undefined;
|
||||||
multiSelectItems: MenuItem[] | undefined;
|
|
||||||
selectedBooks: Set<number> = new Set();
|
selectedBooks: Set<number> = new Set();
|
||||||
selectedSort: SortOption | null = null;
|
selectedSort: SortOption | null = null;
|
||||||
sortOptions: SortOption[] = [];
|
sortOptions: SortOption[] = [];
|
||||||
@@ -54,31 +53,43 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.sortOptions = SortOptionsHelper.generateSortOptions();
|
this.sortOptions = SortOptionsHelper.generateSortOptions();
|
||||||
const routeParam$ = this.getRouteParams();
|
const isAllBooksRoute = this.activatedRoute.snapshot.routeConfig?.path === 'all-books';
|
||||||
|
|
||||||
this.bookState$ = routeParam$.pipe(
|
if (isAllBooksRoute) {
|
||||||
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)),
|
this.entityType$ = this.activatedRoute.url.pipe(
|
||||||
);
|
map(segments => {
|
||||||
|
const fullPath = segments.map(segment => segment.path).join('/');
|
||||||
|
return fullPath === 'all-books' ? 'all-books' : null;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.bookState$ = this.fetchAllBooks();
|
||||||
|
} else {
|
||||||
|
|
||||||
this.entity$ = routeParam$.pipe(
|
const routeParam$ = this.getRouteParams();
|
||||||
switchMap(({libraryId, shelfId}) => this.fetchEntity(libraryId, shelfId))
|
|
||||||
);
|
|
||||||
|
|
||||||
this.entityType$ = routeParam$.pipe(
|
this.bookState$ = routeParam$.pipe(
|
||||||
map(({libraryId, shelfId}) => libraryId ? 'Library' : shelfId ? 'Shelf' : null)
|
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entity$.subscribe(entity => {
|
this.entity$ = routeParam$.pipe(
|
||||||
this.entity = entity;
|
switchMap(({libraryId, shelfId}) => this.fetchEntity(libraryId, shelfId))
|
||||||
this.setSelectedSortFromEntity(entity);
|
);
|
||||||
});
|
|
||||||
|
this.entityType$ = routeParam$.pipe(
|
||||||
|
map(({libraryId, shelfId}) => libraryId ? 'Library' : shelfId ? 'Shelf' : null)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.entity$.subscribe(entity => {
|
||||||
|
this.entity = entity;
|
||||||
|
this.setSelectedSortFromEntity(entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.activatedRoute.paramMap.subscribe(() => {
|
this.activatedRoute.paramMap.subscribe(() => {
|
||||||
this.bookTitle$.next('');
|
this.bookTitle$.next('');
|
||||||
this.bookTitle = '';
|
this.bookTitle = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
//this.setupMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRouteParams(): Observable<{ libraryId: number; shelfId: number }> {
|
private getRouteParams(): Observable<{ libraryId: number; shelfId: number }> {
|
||||||
@@ -127,15 +138,12 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBooks(bookFilter: (book: Book) => boolean): Observable<BookState> {
|
private fetchAllBooks(): Observable<BookState> {
|
||||||
return this.bookService.bookState$.pipe(
|
return this.bookService.bookState$.pipe(
|
||||||
map(bookState => {
|
map(bookState => {
|
||||||
if (bookState.loaded && !bookState.error) {
|
if (bookState.loaded && !bookState.error) {
|
||||||
const filteredBooks = bookState.books!.filter(book => {
|
const sortedBooks = this.sortService.applySort(bookState.books || [], this.selectedSort);
|
||||||
return bookFilter(book);
|
return {...bookState, books: sortedBooks};
|
||||||
});
|
|
||||||
const sortedBooks = this.sortService.applySort(filteredBooks, this.selectedSort);
|
|
||||||
return { ...bookState, books: sortedBooks };
|
|
||||||
} else {
|
} else {
|
||||||
return bookState;
|
return bookState;
|
||||||
}
|
}
|
||||||
@@ -145,7 +153,34 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
map(title => {
|
map(title => {
|
||||||
if (title && title.trim() !== '') {
|
if (title && title.trim() !== '') {
|
||||||
const filteredBooks = bookState.books?.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase())) || null;
|
const filteredBooks = bookState.books?.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase())) || null;
|
||||||
return { ...bookState, books: filteredBooks };
|
return {...bookState, books: filteredBooks};
|
||||||
|
}
|
||||||
|
return bookState;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchBooks(bookFilter: (book: Book) => boolean): Observable<BookState> {
|
||||||
|
return this.bookService.bookState$.pipe(
|
||||||
|
map(bookState => {
|
||||||
|
if (bookState.loaded && !bookState.error) {
|
||||||
|
const filteredBooks = bookState.books!.filter(book => {
|
||||||
|
return bookFilter(book);
|
||||||
|
});
|
||||||
|
const sortedBooks = this.sortService.applySort(filteredBooks, this.selectedSort);
|
||||||
|
return {...bookState, books: sortedBooks};
|
||||||
|
} else {
|
||||||
|
return bookState;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
switchMap(bookState =>
|
||||||
|
this.bookTitle$.pipe(
|
||||||
|
map(title => {
|
||||||
|
if (title && title.trim() !== '') {
|
||||||
|
const filteredBooks = bookState.books?.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase())) || null;
|
||||||
|
return {...bookState, books: filteredBooks};
|
||||||
}
|
}
|
||||||
return bookState;
|
return bookState;
|
||||||
})
|
})
|
||||||
@@ -253,23 +288,6 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*setupMenu(): void {
|
|
||||||
this.multiSelectItems = [
|
|
||||||
{
|
|
||||||
label: 'Options',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
label: 'Edit shelf',
|
|
||||||
icon: 'pi pi-folder',
|
|
||||||
command: () => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private initializeLibraryMenuItems(): void {
|
private initializeLibraryMenuItems(): void {
|
||||||
this.entityOptions = [
|
this.entityOptions = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<ul class="layout-menu">
|
<ul class="layout-menu">
|
||||||
<ng-container *ngFor="let item of home; let i = index;">
|
<ng-container *ngIf="homeMenu$ | async as homeMenu">
|
||||||
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
<ng-container *ngFor="let item of homeMenu; let i = index;">
|
||||||
<li *ngIf="item.separator" class="menu-separator"></li>
|
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||||
|
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||||
|
</ng-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import { AppMenuitemComponent } from './app.menuitem.component';
|
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 {Observable, of} from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import { ShelfService } from '../../service/shelf.service';
|
import {ShelfService} from '../../service/shelf.service';
|
||||||
|
import {BookService} from '../../service/book.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-menu',
|
selector: 'app-menu',
|
||||||
@@ -13,11 +14,12 @@ import { ShelfService } from '../../service/shelf.service';
|
|||||||
templateUrl: './app.menu.component.html',
|
templateUrl: './app.menu.component.html',
|
||||||
})
|
})
|
||||||
export class AppMenuComponent implements OnInit {
|
export class AppMenuComponent implements OnInit {
|
||||||
home: any[] = [];
|
|
||||||
libraryMenu$: Observable<any> | undefined;
|
libraryMenu$: Observable<any> | undefined;
|
||||||
shelfMenu$: Observable<any> | undefined;
|
shelfMenu$: Observable<any> | undefined;
|
||||||
|
homeMenu$: Observable<any> | undefined;
|
||||||
|
|
||||||
constructor(private libraryService: LibraryService, private shelfService: ShelfService) {}
|
constructor(private libraryService: LibraryService, private shelfService: ShelfService, private bookService: BookService) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
|
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
|
||||||
@@ -50,17 +52,29 @@ export class AppMenuComponent implements OnInit {
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
this.populateHome();
|
this.homeMenu$ = this.bookService.bookState$.pipe(
|
||||||
|
map((bookState) => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Home',
|
||||||
|
separator: false,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: 'Dashboard',
|
||||||
|
icon: 'pi pi-fw pi-home',
|
||||||
|
routerLink: ['/'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'All Books',
|
||||||
|
icon: 'pi pi-fw pi-book',
|
||||||
|
routerLink: ['/all-books'],
|
||||||
|
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
populateHome(): void {
|
|
||||||
this.home = [
|
|
||||||
{
|
|
||||||
label: 'Home',
|
|
||||||
items: [
|
|
||||||
{ label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/'] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { RxStompService } from './rx-stomp.service';
|
import { RxStompService } from './rx-stomp.service';
|
||||||
import { myRxStompConfig } from './my-rx-stomp.config';
|
import { rxStompConfig } from './rx-stomp.config';
|
||||||
|
|
||||||
export function rxStompServiceFactory() {
|
export function rxStompServiceFactory() {
|
||||||
const rxStomp = new RxStompService();
|
const rxStomp = new RxStompService();
|
||||||
rxStomp.configure(myRxStompConfig);
|
rxStomp.configure(rxStompConfig);
|
||||||
rxStomp.activate();
|
rxStomp.activate();
|
||||||
return rxStomp;
|
return rxStomp;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { RxStompConfig } from '@stomp/rx-stomp';
|
import { RxStompConfig } from '@stomp/rx-stomp';
|
||||||
|
|
||||||
export const myRxStompConfig: RxStompConfig = {
|
export const rxStompConfig: RxStompConfig = {
|
||||||
// Which server?
|
// Which server?
|
||||||
brokerURL: 'ws://localhost:8080/ws',
|
brokerURL: 'ws://localhost:8080/ws',
|
||||||
|
|
||||||
Reference in New Issue
Block a user