WIP: Buggy big table to small to big switching
This commit is contained in:
Generated
+4
-4
@@ -24,7 +24,7 @@
|
||||
"ngx-extended-pdf-viewer": "^22.0.0",
|
||||
"ngx-infinite-scroll": "^19.0.0",
|
||||
"primeicons": "^7.0.0",
|
||||
"primeng": "19.0.2",
|
||||
"primeng": "19.0.3",
|
||||
"quill": "^2.0.3",
|
||||
"rxjs": "~7.8.0",
|
||||
"tailwindcss-primeui": "^0.3.4",
|
||||
@@ -12037,9 +12037,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/primeng": {
|
||||
"version": "19.0.2",
|
||||
"resolved": "https://registry.npmjs.org/primeng/-/primeng-19.0.2.tgz",
|
||||
"integrity": "sha512-7vizB1ynvvADjZBE9/Ks/YFwbY/d2tKYo+8Uq3OsBq9+rf9pIwKQIhd9GKkpe1gXx5Ig2SOFVeTp1Ru4H/vlVA==",
|
||||
"version": "19.0.3",
|
||||
"resolved": "https://registry.npmjs.org/primeng/-/primeng-19.0.3.tgz",
|
||||
"integrity": "sha512-cv15SG37WcMFlGZY9cyMULM8l91PTYRONdvMoDECNnH7LV0EkG1jvrsAezn8c4IsoJheofnoZez9D6Z9TpS4PQ==",
|
||||
"license": "SEE LICENSE IN LICENSE.md",
|
||||
"dependencies": {
|
||||
"@primeuix/styled": "^0.3.2",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"ngx-extended-pdf-viewer": "^22.0.0",
|
||||
"ngx-infinite-scroll": "^19.0.0",
|
||||
"primeicons": "^7.0.0",
|
||||
"primeng": "19.0.2",
|
||||
"primeng": "19.0.3",
|
||||
"quill": "^2.0.3",
|
||||
"rxjs": "~7.8.0",
|
||||
"tailwindcss-primeui": "^0.3.4",
|
||||
|
||||
@@ -14,7 +14,7 @@ const routes: Routes = [
|
||||
path: '', component: DashboardComponent,
|
||||
},
|
||||
{
|
||||
path: 'all-books', component: BookTableComponent,
|
||||
path: 'all-books', component: BookBrowserComponent,
|
||||
},
|
||||
{
|
||||
path: 'library/:libraryId/books', component: BookBrowserComponent,
|
||||
|
||||
@@ -43,6 +43,9 @@ import Aura from '@primeng/themes/aura';
|
||||
import {IftaLabel} from 'primeng/iftalabel';
|
||||
import {LoadingOverlayComponent} from './loading-overlay/loading-overlay.component';
|
||||
import {MultiSelectModule} from 'primeng/multiselect';
|
||||
import {SelectButton} from "primeng/selectbutton";
|
||||
import {BookTableComponent} from './book/component/book-table/book-table.component';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -52,38 +55,41 @@ import {MultiSelectModule} from 'primeng/multiselect';
|
||||
ShelfAssignerComponent,
|
||||
BookBrowserComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule,
|
||||
AppLayoutModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
TableModule,
|
||||
Button,
|
||||
StepperModule,
|
||||
IconFieldModule,
|
||||
InputIconModule,
|
||||
ToggleButtonModule,
|
||||
PasswordModule,
|
||||
ToastModule,
|
||||
InfiniteScrollDirective,
|
||||
SearchComponent,
|
||||
DropdownModule,
|
||||
VirtualScrollerModule,
|
||||
LazyLoadImageModule,
|
||||
ConfirmDialogModule,
|
||||
CheckboxModule,
|
||||
DividerModule,
|
||||
DialogModule,
|
||||
BookCardComponent,
|
||||
SpeedDialModule,
|
||||
MenuModule,
|
||||
IconPickerComponent,
|
||||
ProgressSpinnerModule,
|
||||
IftaLabel,
|
||||
LoadingOverlayComponent,
|
||||
MultiSelectModule
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule,
|
||||
AppLayoutModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
TableModule,
|
||||
Button,
|
||||
StepperModule,
|
||||
IconFieldModule,
|
||||
InputIconModule,
|
||||
ToggleButtonModule,
|
||||
PasswordModule,
|
||||
ToastModule,
|
||||
InfiniteScrollDirective,
|
||||
SearchComponent,
|
||||
DropdownModule,
|
||||
VirtualScrollerModule,
|
||||
LazyLoadImageModule,
|
||||
ConfirmDialogModule,
|
||||
CheckboxModule,
|
||||
DividerModule,
|
||||
DialogModule,
|
||||
BookCardComponent,
|
||||
SpeedDialModule,
|
||||
MenuModule,
|
||||
IconPickerComponent,
|
||||
ProgressSpinnerModule,
|
||||
IftaLabel,
|
||||
LoadingOverlayComponent,
|
||||
MultiSelectModule,
|
||||
SelectButton,
|
||||
BookTableComponent,
|
||||
RadioButton
|
||||
],
|
||||
providers: [
|
||||
DialogService,
|
||||
MessageService,
|
||||
|
||||
-1
@@ -19,7 +19,6 @@ import {MultiSelect} from 'primeng/multiselect';
|
||||
templateUrl: './metadata-searcher.component.html',
|
||||
styleUrls: ['./metadata-searcher.component.scss'],
|
||||
imports: [
|
||||
Select,
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
|
||||
+2
-2
@@ -4,10 +4,10 @@
|
||||
|
||||
<img [src]="coverImageSrc(bookMetadata.bookId)" class="book-cover placeholder" alt="Cover of {{ bookMetadata.title }}" loading="lazy" width="225"/>
|
||||
|
||||
<div class="pl-4 flex flex-col w-full space-y-4">
|
||||
<div class="pl-6 flex flex-col w-full space-y-4">
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<div>
|
||||
<p class="text-xl font-bold">{{ bookMetadata.title }}</p>
|
||||
<p class="text-lg font-bold">{{ bookMetadata.title }}</p>
|
||||
<div class="flex items-center gap-4 pt-1">
|
||||
<p-rating [(ngModel)]="bookMetadata.rating" readonly stars="5"></p-rating>
|
||||
<p class="font-semibold">({{ bookMetadata.reviewCount || 0 }} Reviews)</p>
|
||||
|
||||
@@ -7,15 +7,8 @@
|
||||
<p *ngIf="entityType === EntityType.ALL_BOOKS" class="entity-name text-2xl">
|
||||
All Books
|
||||
</p>
|
||||
|
||||
<div *ngIf="entityType !== EntityType.ALL_BOOKS">
|
||||
<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>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -23,74 +16,69 @@
|
||||
|
||||
<div class="header-right-items">
|
||||
<input type="text" pInputText placeholder="Search by title..." [(ngModel)]="bookTitle" (ngModelChange)="onBookTitleChange($event)"/>
|
||||
|
||||
<p-dropdown
|
||||
[options]="sortOptions"
|
||||
optionLabel="label"
|
||||
placeholder="Select Sorting"
|
||||
[(ngModel)]="selectedSort"
|
||||
(onChange)="updateSortOption($event.value)">
|
||||
</p-dropdown>
|
||||
|
||||
<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>
|
||||
<p-dropdown [options]="sortOptions" optionLabel="label" placeholder="Select Sorting" [(ngModel)]="selectedSort" (onChange)="updateSortOption($event.value)"></p-dropdown>
|
||||
<div class="state-options">
|
||||
<p-radioButton *ngFor="let option of stateOptions" [value]="option.value" [(ngModel)]="value" (onClick)="viewChanged($event)"></p-radioButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!(bookState$ | async)?.loaded && !(bookState$ | async)?.error">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div class="virtual-scroller-container">
|
||||
<div class="no-books-container" *ngIf="(bookState$ | async)?.error">
|
||||
<p class="no-books-text">
|
||||
{{ entityType === EntityType.LIBRARY ? "Failed to load library's books!" : "Failed to load shelf's books!" }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0">
|
||||
<p class="no-books-text">
|
||||
{{ entityType === EntityType.LIBRARY ? "This library has no books!" : "This shelf has no books!" }}
|
||||
</p>
|
||||
<div *ngIf="bookState$ | async as bookState">
|
||||
<div *ngIf="!bookState?.loaded && !bookState?.error">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div class="book-card-container" *ngIf="(bookState$ | async)?.books as books">
|
||||
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid grid-cols-12 gap-4" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSelected]="selectedBooks.has(book.id)">
|
||||
</app-book-card>
|
||||
<div class="virtual-scroller-container">
|
||||
<div class="no-books-container" *ngIf="bookState?.error">
|
||||
<p class="no-books-text">
|
||||
{{ entityType === EntityType.LIBRARY ? "Failed to load library's books!" : "Failed to load shelf's books!" }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="no-books-container" *ngIf="!bookState?.error && bookState?.loaded && bookState?.books?.length === 0">
|
||||
<p class="no-books-text">
|
||||
{{ entityType === EntityType.LIBRARY ? "This library has no books!" : "This shelf has no books!" }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="book-card-container" *ngIf="bookState?.books as books">
|
||||
<app-book-table *ngIf="value === 'table'" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"></app-book-table>
|
||||
|
||||
<virtual-scroller *ngIf="value === 'grid'" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid grid-cols-12 gap-4" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSelected]="selectedBooks.has(book.id)">
|
||||
</app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
</div>
|
||||
|
||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||
<div class="footer-items-container">
|
||||
<ng-container *ngIf="entityType$ | async as entityType">
|
||||
<p-button *ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS"
|
||||
icon="pi pi-book"
|
||||
label="Assign Shelf"
|
||||
severity="info"
|
||||
(onClick)="openShelfAssigner()">
|
||||
</p-button>
|
||||
<p-button *ngIf="entityType === 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>
|
||||
</ng-container>
|
||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||
<div class="footer-items-container">
|
||||
<ng-container *ngIf="entityType$ | async as entityType">
|
||||
<p-button *ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS"
|
||||
icon="pi pi-book"
|
||||
label="Assign Shelf"
|
||||
severity="info"
|
||||
(onClick)="openShelfAssigner()">
|
||||
</p-button>
|
||||
<p-button *ngIf="entityType === 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>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -23,12 +23,6 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.zoom-controls {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.virtual-scroller-container {
|
||||
position: relative;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {MenuItem, MessageService} from 'primeng/api';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
@@ -16,6 +16,8 @@ import {SortOption} from '../../model/sort.model';
|
||||
import {BookState} from '../../model/state/book-state.model';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {LibraryShelfMenuService} from '../../service/library-shelf-menu.service';
|
||||
import {SelectButtonChangeEvent} from 'primeng/selectbutton';
|
||||
import {BookTableComponent} from '../book-table/book-table.component';
|
||||
|
||||
export enum EntityType {
|
||||
LIBRARY = 'Library',
|
||||
@@ -44,6 +46,12 @@ export class BookBrowserComponent implements OnInit {
|
||||
sortOptions: SortOption[] = [];
|
||||
isDrawerVisible: boolean = false;
|
||||
dynamicDialogRef: DynamicDialogRef | undefined;
|
||||
EntityType = EntityType;
|
||||
|
||||
stateOptions: any[] = [{ label: 'Grid', value: 'grid' },{ label: 'Table', value: 'table' }];
|
||||
value: string = 'table';
|
||||
|
||||
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
||||
|
||||
constructor(
|
||||
private activatedRoute: ActivatedRoute,
|
||||
@@ -91,7 +99,6 @@ export class BookBrowserComponent implements OnInit {
|
||||
this.bookTitle$.next('');
|
||||
this.bookTitle = '';
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private getEntityInfoFromRoute(): Observable<{ entityId: number; entityType: EntityType }> {
|
||||
@@ -214,9 +221,20 @@ export class BookBrowserComponent implements OnInit {
|
||||
this.isDrawerVisible = this.selectedBooks.size > 0;
|
||||
}
|
||||
|
||||
onSelectedBooksChange(selectedBookIds: Set<number>): void {
|
||||
this.selectedBooks = new Set(selectedBookIds);
|
||||
this.isDrawerVisible = this.selectedBooks.size > 0;
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
this.selectedBooks.clear();
|
||||
this.isDrawerVisible = false;
|
||||
this.bookTableComponent.clearSelectedBooks();
|
||||
}
|
||||
|
||||
viewChanged(event : SelectButtonChangeEvent) {
|
||||
this.selectedBooks.clear();
|
||||
this.isDrawerVisible = false;
|
||||
}
|
||||
|
||||
unshelfBooks() {
|
||||
@@ -285,6 +303,4 @@ export class BookBrowserComponent implements OnInit {
|
||||
this.selectedBooks.clear();
|
||||
});
|
||||
}
|
||||
|
||||
protected readonly EntityType = EntityType;
|
||||
}
|
||||
|
||||
@@ -34,11 +34,7 @@ export class BookCardComponent implements OnInit {
|
||||
items: MenuItem[] | undefined;
|
||||
isHovered: boolean = false;
|
||||
|
||||
constructor(
|
||||
private bookService: BookService,
|
||||
private router: Router,
|
||||
private dialogService: DialogService
|
||||
) {
|
||||
constructor(private bookService: BookService, private dialogService: DialogService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
@@ -1,41 +1,36 @@
|
||||
<div *ngIf="!(bookState$ | async)?.loaded && !(bookState$ | async)?.error">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div *ngIf="(bookState$ | async)?.books as book">
|
||||
<p-table [value]="book" [resizableColumns]="true" showGridlines stripedRows [scrollable]="true"
|
||||
scrollHeight="900px" [virtualScroll]="true" [virtualScrollItemSize]="46">
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th class="max-w-16">Cover</th>
|
||||
<th class="w-1/2 max-w-52 overflow-hidden truncate" pResizableColumn>Title</th>
|
||||
<th class="w-1/6 max-w-48 overflow-hidden truncate">Publisher</th>
|
||||
<th class="w-1/8 max-w-44 overflow-hidden truncate" pResizableColumn>Subtitle</th>
|
||||
<th class="w-1/8 max-w-36 overflow-hidden truncate">ISBN</th>
|
||||
<th class="w-1/8 max-w-32 overflow-hidden truncate">Language</th>
|
||||
<th class="w-1/8 max-w-36 overflow-hidden truncate">Rating</th>
|
||||
<th class="max-w-16">
|
||||
<p-tableHeaderCheckbox/>
|
||||
</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-book>
|
||||
<tr style="height:46px">
|
||||
<td (click)="openMetadataCenter(book.id)" class="w-6 h-6"><img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="size-7"/></td>
|
||||
<td (click)="openMetadataCenter(book.id)" class="w-1/2 max-w-52 overflow-hidden truncate" [title]="book.metadata?.title">{{ book.metadata?.title }} </td>
|
||||
<td class="w-1/6 max-w-48 overflow-hidden truncate">{{ book.metadata?.publisher }}</td>
|
||||
<td class="w-1/8 max-w-44 overflow-hidden truncate">{{ book.metadata?.subtitle }}</td>
|
||||
<td class="w-1/8 max-w-36 overflow-hidden truncate">{{ book.metadata?.isbn10 }}</td>
|
||||
<td class="w-1/8 max-w-32 overflow-hidden truncate">{{ book.metadata?.language }}</td>
|
||||
<td class="w-1/8 max-w-36 overflow-hidden truncate">
|
||||
<ng-container *ngIf="book.metadata">
|
||||
<p-rating [(ngModel)]="book.metadata.rating" readonly stars="5"></p-rating>
|
||||
</ng-container>
|
||||
</td>
|
||||
<td class="max-w-16">
|
||||
<p-tableCheckbox [value]="book"/>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
<p-table [value]="books" [resizableColumns]="true" showGridlines stripedRows [scrollable]="true" [scrollHeight]="'calc(100vh - 160px)'"
|
||||
[virtualScroll]="true" [virtualScrollItemSize]="46" [(selection)]="selectedBooks" (onHeaderCheckboxToggle)="onHeaderCheckboxToggle($event)"
|
||||
(onRowSelect)="onRowSelect($event)" (onRowUnselect)="onRowUnselect($event)">
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th class="max-w-16">Cover</th>
|
||||
<th class="w-1/2 max-w-52 overflow-hidden truncate" pResizableColumn>Title</th>
|
||||
<th class="w-1/6 max-w-48 overflow-hidden truncate">Publisher</th>
|
||||
<th class="w-1/8 max-w-44 overflow-hidden truncate" pResizableColumn>Subtitle</th>
|
||||
<th class="w-1/8 max-w-36 overflow-hidden truncate">ISBN</th>
|
||||
<th class="w-1/8 max-w-32 overflow-hidden truncate">Language</th>
|
||||
<th class="w-1/8 max-w-36 overflow-hidden truncate">Rating</th>
|
||||
<th class="max-w-16">
|
||||
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
|
||||
</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-book>
|
||||
<tr style="height:46px">
|
||||
<td (click)="openMetadataCenter(book.id)" class="w-6 h-6"><img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="size-7"/></td>
|
||||
<td (click)="openMetadataCenter(book.id)" class="w-1/2 max-w-52 overflow-hidden truncate" [title]="book.metadata?.title">{{ book.metadata?.title }}</td>
|
||||
<td class="w-1/6 max-w-48 overflow-hidden truncate">{{ book.metadata?.publisher }}</td>
|
||||
<td class="w-1/8 max-w-44 overflow-hidden truncate">{{ book.metadata?.subtitle }}</td>
|
||||
<td class="w-1/8 max-w-36 overflow-hidden truncate">{{ book.metadata?.isbn10 }}</td>
|
||||
<td class="w-1/8 max-w-32 overflow-hidden truncate">{{ book.metadata?.language }}</td>
|
||||
<td class="w-1/8 max-w-36 overflow-hidden truncate">
|
||||
<ng-container *ngIf="book.metadata">
|
||||
<p-rating [(ngModel)]="book.metadata.rating" readonly stars="5"></p-rating>
|
||||
</ng-container>
|
||||
</td>
|
||||
<td class="max-w-16">
|
||||
<p-tableCheckbox [value]="book"></p-tableCheckbox>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
.p-datatable-flex-scrollable .p-datatable-wrapper {
|
||||
flex-basis: auto !important;
|
||||
height: 0 !important;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookState} from '../../model/state/book-state.model';
|
||||
import {ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges} from '@angular/core';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {BookMetadataCenterComponent} from '../../../book-metadata-center/book-metadata-center.component';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {Book} from '../../model/book.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-table',
|
||||
@@ -16,31 +14,58 @@ import {DialogService} from 'primeng/dynamicdialog';
|
||||
templateUrl: './book-table.component.html',
|
||||
imports: [
|
||||
TableModule,
|
||||
AsyncPipe,
|
||||
NgIf,
|
||||
ProgressSpinner,
|
||||
Rating,
|
||||
FormsModule
|
||||
],
|
||||
styleUrl: './book-table.component.scss'
|
||||
})
|
||||
export class BookTableComponent {
|
||||
bookState$: Observable<BookState>;
|
||||
selectedBooks: Book[] = [];
|
||||
selectedBookIds: Set<number> = new Set();
|
||||
|
||||
constructor(private bookService: BookService, private dialogService: DialogService) {
|
||||
this.bookState$ = this.bookService.bookState$;
|
||||
@Output() selectedBooksChange = new EventEmitter<Set<number>>();
|
||||
@Input() books: Book[] = [];
|
||||
|
||||
constructor(private bookService: BookService, private dialogService: DialogService, private zone: NgZone) {
|
||||
}
|
||||
|
||||
clearSelectedBooks(): void {
|
||||
this.selectedBookIds.clear();
|
||||
this.selectedBooks = [];
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
onRowSelect(event: any): void {
|
||||
this.selectedBookIds.add(event.data.id);
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
onRowUnselect(event: any): void {
|
||||
this.selectedBookIds.delete(event.data.id);
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
onHeaderCheckboxToggle(event: any): void {
|
||||
if (event.checked) {
|
||||
this.selectedBooks = [...this.books];
|
||||
this.selectedBookIds = new Set(this.books.map(book => book.id));
|
||||
} else {
|
||||
this.clearSelectedBooks();
|
||||
}
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
return this.bookService.getBookCoverUrl(bookId);
|
||||
}
|
||||
|
||||
openMetadataCenter(id: number) {
|
||||
openMetadataCenter(id: number): void {
|
||||
this.openBookDetailsDialog(id);
|
||||
}
|
||||
|
||||
openBookDetailsDialog(bookId: number): void {
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe({
|
||||
next: (book) => {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
header: 'Open book details',
|
||||
@@ -59,6 +84,6 @@ export class BookTableComponent {
|
||||
error: (error) => {
|
||||
console.error('Error fetching book:', error);
|
||||
}
|
||||
}))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user