WPI: Add table for display books

This commit is contained in:
aditya.chandel
2025-01-06 15:18:14 -07:00
parent 7e748bb79a
commit 65b7e6df8d
9 changed files with 98 additions and 9 deletions
@@ -30,6 +30,9 @@ public class JobSchedulerService {
scheduler.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
if(e.getMessage().contains("already exists")) {
throw ApiError.ANOTHER_METADATA_JOB_RUNNING.createException();
}
throw ApiError.SCHEDULE_REFRESH_ERROR.createException(e.getMessage());
}
}
@@ -26,16 +26,21 @@ public class FileService {
private final AppProperties appProperties;
public Resource getBookCover(String thumbnailPath) {
Path filePath = Paths.get(thumbnailPath);
Path thumbPath;
if (thumbnailPath == null || thumbnailPath.isEmpty()) {
thumbPath = Paths.get(getMissingThumbnailPath());
} else {
thumbPath = Paths.get(thumbnailPath);
}
try {
Resource resource = new UrlResource(filePath.toUri());
Resource resource = new UrlResource(thumbPath.toUri());
if (resource.exists() && resource.isReadable()) {
return resource;
} else {
throw ApiError.IMAGE_NOT_FOUND.createException(filePath);
throw ApiError.IMAGE_NOT_FOUND.createException(thumbPath);
}
} catch (IOException e) {
throw ApiError.IMAGE_NOT_FOUND.createException(filePath);
throw ApiError.IMAGE_NOT_FOUND.createException(thumbPath);
}
}
@@ -75,4 +80,8 @@ public class FileService {
return appProperties.getPathConfig() + "/thumbs/" + bookId + "/";
}
public String getMissingThumbnailPath() {
return appProperties.getPathConfig() + "/thumbs/missing/m.jpg";
}
}
+2 -1
View File
@@ -4,6 +4,7 @@ import {PdfViewerComponent} from './book/component/pdf-viewer/pdf-viewer.compone
import {DashboardComponent} from './book/component/dashboard/dashboard.component';
import {BookBrowserComponent} from './book/component/book-browser/book-browser.component';
import {AppLayoutComponent} from './book/component/layout/app.layout.component';
import {BookTableComponent} from './book/component/book-table/book-table.component';
const routes: Routes = [
{
@@ -13,7 +14,7 @@ const routes: Routes = [
path: '', component: DashboardComponent,
},
{
path: 'all-books', component: BookBrowserComponent,
path: 'all-books', component: BookTableComponent,
},
{
path: 'library/:libraryId/books', component: BookBrowserComponent,
-1
View File
@@ -1,4 +1,3 @@
<p-confirmDialog />
<p-toast></p-toast>
<app-loading-overlay></app-loading-overlay>
<router-outlet></router-outlet>
@@ -37,7 +37,7 @@
<div class="flex flex-row gap-4 justify-between">
<p class="font-bold">{{ truncateText(book['title'], 90) }}</p>
<div class="flex gap-4">
<p>ISBN: {{ book['isbn13'] }}</p>
<p>ISBN: {{ book['isbn10'] }}</p>
<p> | </p>
<p>Published: {{ book['publishedDate'] }}</p>
</div>
@@ -53,8 +53,7 @@ export class BookBrowserComponent implements OnInit {
private shelfService: ShelfService,
private dialogService: DialogService,
private sortService: SortService,
private libraryShelfMenuService: LibraryShelfMenuService
) {
private libraryShelfMenuService: LibraryShelfMenuService) {
}
ngOnInit(): void {
@@ -0,0 +1,43 @@
<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/12 max-w-40 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 class="w-6 h-6">
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="size-7"/>
</td>
<td 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/12 max-w-40 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>
@@ -0,0 +1,35 @@
import { Component } from '@angular/core';
import {Observable} from 'rxjs';
import {BookState} from '../../model/state/book-state.model';
import {TableModule} from 'primeng/table';
import {AsyncPipe, NgIf} from '@angular/common';
import {ProgressSpinner} from 'primeng/progressspinner';
import {BookService} from '../../service/book.service';
import {Rating} from 'primeng/rating';
import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-book-table',
standalone: true,
templateUrl: './book-table.component.html',
imports: [
TableModule,
AsyncPipe,
NgIf,
ProgressSpinner,
Rating,
FormsModule
],
styleUrl: './book-table.component.scss'
})
export class BookTableComponent {
bookState$: Observable<BookState>;
constructor(private bookService: BookService) {
this.bookState$ = this.bookService.bookState$;
}
getBookCoverUrl(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
}