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}`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user