Add an option to save metadata directly into the EPUB file, along with the ability to back up and restore the original metadata.
This commit is contained in:
committed by
Aditya Chandel
parent
faae595ef6
commit
03ce268d8e
@@ -32,6 +32,7 @@
|
||||
[(ngModel)]="isSelected"
|
||||
binary="true"
|
||||
id="select-checkbox-{{book.id}}"
|
||||
name="select-checkbox-{{book.id}}"
|
||||
class="select-checkbox"
|
||||
(ngModelChange)="toggleSelection(isSelected || false)">
|
||||
</p-checkbox>
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
<div class="p-4 w-[54rem]">
|
||||
<p class="mb-4 text-gray-300">
|
||||
This will restore the embedded metadata and cover (if available) from a saved backup for the selected book.
|
||||
</p>
|
||||
|
||||
@if (book) {
|
||||
<div class="mb-4">
|
||||
<p class="font-semibold text-gray-300 pb-2">Book to Restore:</p>
|
||||
<div class="border p-3 rounded space-y-1 custom-table">
|
||||
<div><strong>ID:</strong> {{ book.id }}</div>
|
||||
<div><strong>Current Title:</strong> {{ book.metadata?.title }}</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (backupMetadata) {
|
||||
<div class="mb-4">
|
||||
<p class="font-semibold text-gray-300 pb-2">Backup Metadata Preview:</p>
|
||||
<div class="p-6 rounded custom-table text-sm text-gray-400 flex flex-col gap-6">
|
||||
|
||||
<div class="flex">
|
||||
<div class="flex-1 space-y-1">
|
||||
@if (backupMetadata.title) {
|
||||
<div><strong>Title:</strong> {{ backupMetadata.title }}</div>
|
||||
}
|
||||
@if (backupMetadata.subtitle) {
|
||||
<div><strong>Subtitle:</strong> {{ backupMetadata.subtitle }}</div>
|
||||
}
|
||||
@if (backupMetadata.authors.length) {
|
||||
<div><strong>Authors:</strong> {{ backupMetadata.authors.join(', ') }}</div>
|
||||
}
|
||||
@if (backupMetadata.publisher) {
|
||||
<div><strong>Publisher:</strong> {{ backupMetadata.publisher }}</div>
|
||||
}
|
||||
@if (backupMetadata.publishedDate) {
|
||||
<div><strong>Published Date:</strong> {{ backupMetadata.publishedDate }}</div>
|
||||
}
|
||||
@if (backupMetadata.seriesName) {
|
||||
<div><strong>Series Name:</strong> {{ backupMetadata.seriesName }}</div>
|
||||
}
|
||||
@if (backupMetadata.seriesNumber !== null) {
|
||||
<div><strong>Series Number:</strong> {{ backupMetadata.seriesNumber }}</div>
|
||||
}
|
||||
@if (backupMetadata.seriesTotal !== null) {
|
||||
<div><strong>Series Total:</strong> {{ backupMetadata.seriesTotal }}</div>
|
||||
}
|
||||
@if (backupMetadata.isbn13) {
|
||||
<div><strong>ISBN-13:</strong> {{ backupMetadata.isbn13 }}</div>
|
||||
}
|
||||
@if (backupMetadata.isbn10) {
|
||||
<div><strong>ISBN-10:</strong> {{ backupMetadata.isbn10 }}</div>
|
||||
}
|
||||
@if (backupMetadata.pageCount !== null) {
|
||||
<div><strong>Page Count:</strong> {{ backupMetadata.pageCount }}</div>
|
||||
}
|
||||
@if (backupMetadata.language) {
|
||||
<div><strong>Language:</strong> {{ backupMetadata.language }}</div>
|
||||
}
|
||||
@if (backupMetadata.asin) {
|
||||
<div><strong>ASIN:</strong> {{ backupMetadata.asin }}</div>
|
||||
}
|
||||
@if (backupMetadata.amazonRating !== null) {
|
||||
<div><strong>Amazon Rating:</strong> {{ backupMetadata.amazonRating }}</div>
|
||||
}
|
||||
@if (backupMetadata.amazonReviewCount !== null) {
|
||||
<div><strong>Amazon Review Count:</strong> {{ backupMetadata.amazonReviewCount }}</div>
|
||||
}
|
||||
@if (backupMetadata.goodreadsId) {
|
||||
<div><strong>Goodreads ID:</strong> {{ backupMetadata.goodreadsId }}</div>
|
||||
}
|
||||
@if (backupMetadata.goodreadsRating !== null) {
|
||||
<div><strong>Goodreads Rating:</strong> {{ backupMetadata.goodreadsRating }}</div>
|
||||
}
|
||||
@if (backupMetadata.goodreadsReviewCount !== null) {
|
||||
<div><strong>Goodreads Review Count:</strong> {{ backupMetadata.goodreadsReviewCount }}</div>
|
||||
}
|
||||
@if (backupMetadata.hardcoverId) {
|
||||
<div><strong>Hardcover ID:</strong> {{ backupMetadata.hardcoverId }}</div>
|
||||
}
|
||||
@if (backupMetadata.hardcoverRating !== null) {
|
||||
<div><strong>Hardcover Rating:</strong> {{ backupMetadata.hardcoverRating }}</div>
|
||||
}
|
||||
@if (backupMetadata.hardcoverReviewCount !== null) {
|
||||
<div><strong>Hardcover Review Count:</strong> {{ backupMetadata.hardcoverReviewCount }}</div>
|
||||
}
|
||||
@if (backupMetadata.googleId) {
|
||||
<div><strong>Google Books ID:</strong> {{ backupMetadata.googleId }}</div>
|
||||
}
|
||||
@if (backupMetadata.categories.length) {
|
||||
<div><strong>Categories:</strong> {{ backupMetadata.categories.join(', ') }}</div>
|
||||
}
|
||||
</div>
|
||||
<div class="w-48 flex-shrink-0">
|
||||
<div class="font-semibold text-gray-300 pb-2">Backup Cover Preview:</div>
|
||||
<div class="bg-gray-900 border p-2 rounded flex justify-center">
|
||||
<img
|
||||
[src]="urlHelperService.getBackupCoverUrl(book?.id!)"
|
||||
alt="Backup Cover"
|
||||
class="max-h-80 object-contain rounded shadow"
|
||||
onerror="this.src='assets/images/missing-cover.jpg'"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (backupMetadata.description) {
|
||||
<div class="text-sm text-gray-400">
|
||||
<div class="font-semibold text-gray-300 pb-1">Description:</div>
|
||||
{{ backupMetadata.description }}
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!backupMetadata) {
|
||||
<div class="mb-4">
|
||||
<div class="p-4 border border-yellow-700 rounded bg-yellow-900 text-yellow-300 text-sm shadow-sm">
|
||||
<p class="font-medium mb-1 text-yellow-200">No backup available</p>
|
||||
<p>We couldn't find a saved backup for this book. Metadata and cover cannot be restored.</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex justify-end gap-3 mt-6">
|
||||
<p-button
|
||||
severity="info"
|
||||
outlined
|
||||
label="Cancel"
|
||||
(onClick)="dynamicDialogRef.close()"
|
||||
icon="pi pi-times">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
severity="danger"
|
||||
label="Restore"
|
||||
(onClick)="onRestore()"
|
||||
icon="pi pi-refresh"
|
||||
[disabled]="!backupMetadata">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.custom-table {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--card-border);
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {Book, BookMetadata} from '../../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-restore-dialog-component',
|
||||
standalone: true,
|
||||
imports: [Button],
|
||||
templateUrl: './metadata-restore-dialog-component.html',
|
||||
styleUrl: './metadata-restore-dialog-component.scss'
|
||||
})
|
||||
export class MetadataRestoreDialogComponent implements OnInit {
|
||||
|
||||
bookId!: number;
|
||||
book!: Book | undefined;
|
||||
backupMetadata: BookMetadata | null = null;
|
||||
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
protected dynamicDialogRef = inject(DynamicDialogRef);
|
||||
protected bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
protected urlHelperService = inject(UrlHelperService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookId = this.dynamicDialogConfig.data.bookId;
|
||||
this.book = this.bookService.getBookByIdFromState(this.bookId);
|
||||
|
||||
this.bookService.getBackupMetadata(this.bookId).subscribe({
|
||||
next: (data) => {
|
||||
this.backupMetadata = data;
|
||||
},
|
||||
error: err => {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'No Backup Found',
|
||||
detail: err?.error?.message || 'Backup metadata could not be retrieved.'
|
||||
});
|
||||
this.backupMetadata = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onRestore(): void {
|
||||
this.bookService.restoreMetadata(this.bookId).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Restore Successful',
|
||||
detail: `Metadata restored for book ID ${this.bookId}`
|
||||
});
|
||||
this.dynamicDialogRef.close({ action: 'restore', bookId: this.bookId });
|
||||
},
|
||||
error: err => {
|
||||
const errorMessage = err?.error?.message || err?.message || 'Unknown error';
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Restore Failed',
|
||||
detail: `Failed to restore metadata: ${errorMessage}`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+18
-3
@@ -191,7 +191,14 @@
|
||||
</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Page Count:</span> {{ metadata.pageCount || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB() }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Progress:</span> {{ getProgressPercent() !== null ? getProgressPercent() + '%' : '-' }}</p>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Progress:</span>
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white"
|
||||
[ngClass]="getProgressColorClass(getProgressPercent())">
|
||||
{{ getProgressPercent() !== null ? getProgressPercent() + '%' : 'N/A' }}
|
||||
</span>
|
||||
</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 13:</span> {{ metadata.isbn13 || '-' }}</p>
|
||||
</div>
|
||||
<div class="pt-2 flex items-center gap-2 w-full">
|
||||
@@ -203,7 +210,7 @@
|
||||
onLabel=""
|
||||
offLabel=""
|
||||
size="small"
|
||||
class="flex-shrink-0"></p-toggleButton>
|
||||
class="flex-shrink-0 my-visibility-toggle"></p-toggleButton>
|
||||
@if (showFilePath) {
|
||||
<div
|
||||
class="flex items-center gap-4 flex-grow"
|
||||
@@ -235,7 +242,7 @@
|
||||
severity="info"/>
|
||||
}
|
||||
<p-button
|
||||
label="Assign Shelf"
|
||||
label="Shelf"
|
||||
icon="pi pi-folder"
|
||||
severity="info"
|
||||
outlined
|
||||
@@ -269,6 +276,14 @@
|
||||
outlined
|
||||
severity="info">
|
||||
</p-splitbutton>
|
||||
<p-button
|
||||
outlined
|
||||
label="More"
|
||||
severity="info"
|
||||
(click)="menu.toggle($event)"
|
||||
icon="pi pi-plus">
|
||||
</p-button>
|
||||
<p-tieredmenu #menu [model]="moreItems" [popup]="true" appendTo="body"></p-tieredmenu>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
+5
@@ -20,6 +20,11 @@
|
||||
font-size: 14px !important;
|
||||
}
|
||||
|
||||
::ng-deep p-togglebutton.my-visibility-toggle span[data-pc-section="label"] {
|
||||
display: none;
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.scrollbar-hide::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
+34
-10
@@ -28,13 +28,15 @@ import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metad
|
||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {MetadataRestoreDialogComponent} from '../../../components/book-browser/metadata-restore-dialog-component/metadata-restore-dialog-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor, ProgressBar, ToggleButton, RouterLink]
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor, ProgressBar, ToggleButton, RouterLink, TieredMenu]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
|
||||
@@ -57,6 +59,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
emailMenuItems: MenuItem[] | undefined;
|
||||
readMenuItems: MenuItem[] | undefined;
|
||||
refreshMenuItems: MenuItem[] | undefined;
|
||||
moreItems: MenuItem[] | undefined;
|
||||
bookInSeries: Book[] = [];
|
||||
isExpanded = false;
|
||||
showFilePath = false;
|
||||
@@ -113,6 +116,22 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
}
|
||||
];
|
||||
|
||||
this.moreItems = [
|
||||
{
|
||||
label: 'Restore Metadata',
|
||||
command: () => {
|
||||
this.dialogService.open(MetadataRestoreDialogComponent, {
|
||||
header: 'Restore Metadata from Backup',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
bookId: [this.book!.id]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
this.metadata$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((metadata) => {
|
||||
@@ -288,14 +307,19 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
getMatchScoreColorClass(score: number): string {
|
||||
if (score >= 0.95) return 'bg-green-900 border-green-950';
|
||||
if (score >= 0.90) return 'bg-green-800 border-green-900';
|
||||
if (score >= 0.80) return 'bg-green-700 border-green-800';
|
||||
if (score >= 0.70) return 'bg-yellow-700 border-yellow-800';
|
||||
if (score >= 0.60) return 'bg-yellow-600 border-yellow-700';
|
||||
if (score >= 0.50) return 'bg-yellow-500 border-yellow-600';
|
||||
if (score >= 0.40) return 'bg-red-500 border-red-600';
|
||||
if (score >= 0.30) return 'bg-red-600 border-red-700';
|
||||
return 'bg-red-700 border-red-800';
|
||||
if (score >= 0.95) return 'bg-green-800 border-green-900';
|
||||
if (score >= 0.90) return 'bg-green-700 border-green-800';
|
||||
if (score >= 0.80) return 'bg-green-600 border-green-700';
|
||||
if (score >= 0.70) return 'bg-yellow-600 border-yellow-700';
|
||||
if (score >= 0.60) return 'bg-yellow-500 border-yellow-600';
|
||||
if (score >= 0.50) return 'bg-yellow-400 border-yellow-500';
|
||||
if (score >= 0.40) return 'bg-red-400 border-red-500';
|
||||
if (score >= 0.30) return 'bg-red-500 border-red-600';
|
||||
return 'bg-red-600 border-red-700';
|
||||
}
|
||||
|
||||
getProgressColorClass(progress: number | null | undefined): string {
|
||||
if (progress == null) return 'bg-gray-600';
|
||||
return 'bg-blue-500';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export class BookService {
|
||||
|
||||
getBookByIdFromState(bookId: number): Book | undefined {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
return currentState.books?.find(book => book.id === bookId);
|
||||
return currentState.books?.find(book => +book.id === +bookId);
|
||||
}
|
||||
|
||||
updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | undefined>, shelvesToUnassign: Set<number | undefined>): Observable<Book[]> {
|
||||
@@ -413,4 +413,16 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
restoreMetadata(bookId: number) {
|
||||
return this.http.post<BookMetadata>(`${this.url}/${bookId}/metadata/restore`, null).pipe(
|
||||
map(updatedMetadata => {
|
||||
this.handleBookMetadataUpdate(bookId, updatedMetadata);
|
||||
return updatedMetadata;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getBackupMetadata(bookId: number) {
|
||||
return this.http.get<any>(`${this.url}/${bookId}/metadata/restore`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user