WIP: Multi select
This commit is contained in:
@@ -10,10 +10,15 @@
|
||||
hideIcon="pi pi-times">
|
||||
</p-speedDial>
|
||||
</div>
|
||||
|
||||
<div *ngIf="isAnyBookSelected()">
|
||||
<p-button icon="pi pi-ellipsis-v" label="Options" severity="primary" [rounded]="true" [outlined]="true" (click)="menu.toggle($event)"></p-button>
|
||||
<p-menu #menu [model]="items" [popup]="true" appendTo="body"></p-menu>
|
||||
<p-button icon="pi pi-times" label="Deselect All" severity="warning" [rounded]="true" [outlined]="true" (click)="deselectAllBooks()"></p-button>
|
||||
</div>
|
||||
|
||||
<div class="library-header-right">
|
||||
<p-dropdown
|
||||
optionLabel="name"
|
||||
placeholder="Select Sorting"/>
|
||||
<p-dropdown optionLabel="name" placeholder="Select Sorting" />
|
||||
<div class="zoom-controls">
|
||||
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
@@ -26,7 +31,10 @@
|
||||
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card [book]="book"></app-book-card>
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[onBookSelect]="handleBookSelect.bind(this)">
|
||||
</app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
gap: 2rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.library-name {
|
||||
margin: 0;
|
||||
color: var(--text-color);
|
||||
|
||||
@@ -9,6 +9,8 @@ import {Book} from '../../model/book.model';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {Shelf} from '../../model/book.model';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-books-browser',
|
||||
@@ -17,11 +19,12 @@ import {ShelfService} from '../../service/shelf.service';
|
||||
styleUrls: ['./books-browser.component.scss']
|
||||
})
|
||||
export class BooksBrowserComponent implements OnInit {
|
||||
|
||||
books$: Observable<Book[]> | undefined;
|
||||
entity$: Observable<Library | Shelf | null> | undefined;
|
||||
entityType$: Observable<string | null> | undefined;
|
||||
items: MenuItem[] | undefined;
|
||||
selectedBooks: Set<number> = new Set();
|
||||
book: Book | undefined;
|
||||
|
||||
constructor(
|
||||
private activatedRoute: ActivatedRoute,
|
||||
@@ -30,7 +33,8 @@ export class BooksBrowserComponent implements OnInit {
|
||||
private messageService: MessageService,
|
||||
private libraryService: LibraryService,
|
||||
private bookService: BookService,
|
||||
private shelfService: ShelfService
|
||||
private shelfService: ShelfService,
|
||||
private dialogService: DialogService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -84,75 +88,58 @@ export class BooksBrowserComponent implements OnInit {
|
||||
return of(null);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
//this.initializeMenuItems();
|
||||
}
|
||||
|
||||
/*private initializeMenuItems(): void {
|
||||
handleBookSelect(book: Book, selected: boolean): void {
|
||||
if (selected) {
|
||||
this.selectedBooks.add(book.id);
|
||||
this.book = book; // Set the selected book
|
||||
this.setupMenu();
|
||||
} else {
|
||||
this.selectedBooks.delete(book.id);
|
||||
this.book = undefined; // Clear the selected book
|
||||
}
|
||||
}
|
||||
|
||||
setupMenu(): void {
|
||||
this.items = [
|
||||
{
|
||||
icon: 'pi pi-trash',
|
||||
tooltipOptions: {
|
||||
tooltipLabel: 'Delete',
|
||||
tooltipPosition: 'top'
|
||||
},
|
||||
command: () => {
|
||||
this.entity$?.subscribe(entity => {
|
||||
if (entity) {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete ${entity.name}?`,
|
||||
header: 'Confirmation',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'none',
|
||||
rejectIcon: 'none',
|
||||
rejectButtonStyleClass: 'p-button-text',
|
||||
accept: () => {
|
||||
if ('libraryId' in entity) { // Check if it's a Library
|
||||
this.libraryService.deleteLibrary(entity.id).subscribe({
|
||||
complete: () => {
|
||||
this.router.navigate(['/']);
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: 'Success',
|
||||
detail: 'Library was deleted'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed',
|
||||
detail: 'Failed to delete library',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if ('id' in entity) { // Check if it's a Shelf
|
||||
this.shelfService.deleteShelf(entity.id).subscribe({
|
||||
complete: () => {
|
||||
this.router.navigate(['/']);
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: 'Success',
|
||||
detail: 'Shelf was deleted'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed',
|
||||
detail: 'Failed to delete shelf',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
label: 'Options',
|
||||
items: [
|
||||
{
|
||||
label: 'Edit shelf',
|
||||
icon: 'pi pi-folder',
|
||||
command: () => this.openShelfDialog(),
|
||||
}
|
||||
],
|
||||
},
|
||||
];
|
||||
}*/
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
this.selectedBooks.clear();
|
||||
this.books$?.subscribe(books => {
|
||||
books.forEach(book => book.selected = false);
|
||||
});
|
||||
}
|
||||
|
||||
isAnyBookSelected(): boolean {
|
||||
return this.selectedBooks.size > 0;
|
||||
}
|
||||
|
||||
openShelfDialog(): void {
|
||||
this.dialogService.open(ShelfAssignerComponent, {
|
||||
header: `Update Books Shelves`,
|
||||
modal: true,
|
||||
width: '30%',
|
||||
height: '70%',
|
||||
contentStyle: {overflow: 'auto'},
|
||||
baseZIndex: 10,
|
||||
data: {
|
||||
isMultiBooks: true,
|
||||
book: this.book,
|
||||
bookIds: this.selectedBooks
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user