Implement interactive metadata review for batch updates, with progress tracking and a unified notification system
This commit is contained in:
committed by
Aditya Chandel
parent
6576f3351a
commit
116f0c950e
+487
@@ -0,0 +1,487 @@
|
||||
@if (book$ | async; as book) {
|
||||
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" class="flex flex-col h-full md:min-w-[80rem]">
|
||||
@if (isLoading) {
|
||||
<div class="absolute inset-0 bg-black opacity-25 z-10 "></div>
|
||||
}
|
||||
@if (isLoading) {
|
||||
<p-progressSpinner [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
|
||||
}
|
||||
<div class="flex-grow overflow-auto md:py-2 md:px-2 ">
|
||||
<div class="flex flex-col md:flex-row w-full gap-4">
|
||||
<div class="flex flex-col items-center gap-4 relative">
|
||||
<img
|
||||
[attr.src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
alt="Image"
|
||||
width="250"
|
||||
[ngClass]="{ 'brightness-50': isUploading }"
|
||||
class="transition-all duration-300 ease-in-out"/>
|
||||
@if (isUploading) {
|
||||
<p-progressSpinner
|
||||
class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-10">
|
||||
</p-progressSpinner>
|
||||
}
|
||||
<div class="flex items-center gap-6">
|
||||
<p-button
|
||||
icon="pi pi-refresh"
|
||||
(onClick)="regenerateCover(book.id)"
|
||||
pTooltip="Regenerate cover"
|
||||
tooltipPosition="top"
|
||||
[outlined]="true"
|
||||
severity="warn"
|
||||
[disabled]="book.metadata!['coverLocked']">
|
||||
</p-button>
|
||||
<p-fileupload
|
||||
pTooltip="Upload cover"
|
||||
tooltipPosition="top"
|
||||
[disabled]="book.metadata!['coverLocked']"
|
||||
name="file"
|
||||
[url]="getUploadCoverUrl()"
|
||||
mode="basic"
|
||||
chooseIcon="pi pi-upload"
|
||||
accept="image/jpeg,image/png"
|
||||
maxFileSize="5000000"
|
||||
chooseLabel="Cover"
|
||||
(onUpload)="onUpload($event)"
|
||||
(onError)="onUploadError($event)"
|
||||
[auto]="true"
|
||||
(onBeforeUpload)="onBeforeSend()">
|
||||
</p-fileupload>
|
||||
@if (!book.metadata!['coverLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['coverLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col flex-grow pl-2">
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 pb-1">
|
||||
<div class="flex flex-col gap-1 md:w-2/3">
|
||||
<label for="title">Title</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="title" formControlName="title" class="w-full"/>
|
||||
@if (!book.metadata!['titleLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('title')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['titleLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('title')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/3">
|
||||
<label for="subtitle">Subtitle</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
|
||||
@if (!book.metadata!['subtitleLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['subtitleLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 md:basis-[71%]">
|
||||
<label for="authors">Authors</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<div class="w-full">
|
||||
<p-chips formControlName="authors" addOnBlur="true"></p-chips>
|
||||
</div>
|
||||
@if (!book.metadata!['authorsLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('authors')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['authorsLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('authors')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:basis-[20%]">
|
||||
<label for="publisher">Publisher</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
|
||||
@if (!book.metadata!['publisherLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publisher')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['publisherLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publisher')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:basis-[14%]">
|
||||
<label for="language">Language</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="language" formControlName="language" class="w-full"/>
|
||||
@if (!book.metadata!['languageLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('language')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['languageLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<label for="categories">Categories</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<div class="w-full">
|
||||
<p-chips formControlName="categories" addOnBlur="true"></p-chips>
|
||||
</div>
|
||||
@if (!book.metadata!['categoriesLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('categories')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['categoriesLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('categories')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 md:basis-[75%]">
|
||||
<label for="seriesName">Series Name</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
|
||||
@if (!book.metadata!['seriesNameLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesName')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['seriesNameLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesName')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 md:basis-[10%]">
|
||||
<label for="seriesNumber">Book #</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="seriesNumber" formControlName="seriesNumber" class="w-full"/>
|
||||
@if (!book.metadata!['seriesNumberLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesNumber')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['seriesNumberLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesNumber')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 md:basis-[10%]">
|
||||
<label for="seriesTotal">Total Books</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="seriesTotal" formControlName="seriesTotal" class="w-full"/>
|
||||
@if (!book.metadata!['seriesTotalLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesTotal')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['seriesTotalLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesTotal')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 md:basis-[15%]">
|
||||
<label for="publishedDate">Publish Date</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
|
||||
@if (!book.metadata!['publishedDateLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['publishedDateLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="isbn10">ISBN 10</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
|
||||
@if (!book.metadata!['isbn10Locked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['isbn10Locked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="isbn13">ISBN 13</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
|
||||
@if (!book.metadata!['isbn13Locked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['isbn13Locked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="asin">ASIN (Amazon ID)</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="asin" formControlName="asin" class="w-full"/>
|
||||
@if (!book.metadata!['asinLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('asin')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['asinLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('asin')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="amazonRating">Amazon ★</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="amazonRating" formControlName="amazonRating" class="w-full"/>
|
||||
@if (!book.metadata!['amazonRatingLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('amazonRating')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['amazonRatingLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('amazonRating')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="amazonRatingCount">Amazon Reviews</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="amazonRatingCount" formControlName="amazonReviewCount" class="w-full"/>
|
||||
@if (!book.metadata!['amazonReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('amazonReviewCount')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['amazonReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('amazonReviewCount')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="googleId">Google Books ID</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="googleId" formControlName="googleId" class="w-full"/>
|
||||
@if (!book.metadata!['googleIdLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('googleId')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['googleIdLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('googleId')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="goodreadsId">Goodreads ID</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="goodreadsId" formControlName="goodreadsId" class="w-full"/>
|
||||
@if (!book.metadata!['goodreadsIdLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('goodreadsId')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['goodreadsIdLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('goodreadsId')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="goodreadsRating">Goodreads ★</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="goodreadsRating" formControlName="goodreadsRating" class="w-full"/>
|
||||
@if (!book.metadata!['goodreadsRatingLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('goodreadsRating')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['goodreadsRatingLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('goodreadsRating')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="goodreadsReviewCount">Goodreads Reviews</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="goodreadsReviewCount" formControlName="goodreadsReviewCount" class="w-full"/>
|
||||
@if (!book.metadata!['goodreadsReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('goodreadsReviewCount')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['goodreadsReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('goodreadsReviewCount')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="hardcoverId">Hardcover ID</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="hardcoverId" formControlName="hardcoverId" class="w-full"/>
|
||||
@if (!book.metadata!['hardcoverIdLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('hardcoverId')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['hardcoverIdLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('hardcoverId')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="hardcoverRating">Hardcover ★</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="hardcoverRating" formControlName="hardcoverRating" class="w-full"/>
|
||||
@if (!book.metadata!['hardcoverRatingLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('hardcoverRating')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['hardcoverRatingLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('hardcoverRating')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 md:w-1/6">
|
||||
<label for="hardcoverReviewCount">Hardcover Reviews</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="hardcoverReviewCount" formControlName="hardcoverReviewCount" class="w-full"/>
|
||||
@if (!book.metadata!['hardcoverReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('hardcoverReviewCount')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['hardcoverReviewCountLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('hardcoverReviewCount')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row w-full pb-1">
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<p-tabs value="editor" class="w-full">
|
||||
<p-tablist>
|
||||
<p-tab value="editor">WYSIWYG Editor</p-tab>
|
||||
<p-tab value="html">HTML Editor</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels class="custom-tab-padding">
|
||||
<p-tabpanel value="editor">
|
||||
<form [formGroup]="metadataForm">
|
||||
<p-editor #quillEditor formControlName="description" [readonly]="quillDisabled()" [style]="{ height: '200px' }">
|
||||
<ng-template #header>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-bold" aria-label="Bold"></button>
|
||||
<button class="ql-italic" aria-label="Italic"></button>
|
||||
<button class="ql-underline" aria-label="Underline"></button>
|
||||
<button class="ql-strike" aria-label="Strikethrough"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<select class="ql-size" aria-label="Font Size">
|
||||
<option value="small">Small</option>
|
||||
<option selected>Normal</option>
|
||||
<option value="large">Large</option>
|
||||
<option value="huge">Huge</option>
|
||||
</select>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-list" value="ordered" aria-label="Numbered List"></button>
|
||||
<button class="ql-list" value="bullet" aria-label="Bullet List"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<select class="ql-color" aria-label="Text Color"></select>
|
||||
<select class="ql-background" aria-label="Background Color"></select>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-clean" aria-label="Remove Formatting"></button>
|
||||
</span>
|
||||
</ng-template>
|
||||
</p-editor>
|
||||
</form>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel value="html" class="w-full">
|
||||
<textarea
|
||||
class="w-full p-4"
|
||||
rows="9"
|
||||
[disabled]="quillDisabled()"
|
||||
[ngModel]="htmlTextarea"
|
||||
(ngModelChange)="onHtmlTextareaChange($event)"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
placeholder="Edit raw HTML here">
|
||||
</textarea>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
@if (!book.metadata!['descriptionLocked']) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata!['descriptionLocked']) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-auto">
|
||||
<p-divider></p-divider>
|
||||
<div class="flex flex-col gap-2 px-2 pt-4 md:pb-4 z-10">
|
||||
|
||||
<!-- Desktop Buttons -->
|
||||
<div class="hidden sm:flex justify-between w-full gap-4">
|
||||
@if (showNavigationButtons) {
|
||||
<div class="flex gap-x-4">
|
||||
<p-button label="Close" icon="pi pi-times" [outlined]="true" severity="danger" (onClick)="closeDialog()"></p-button>
|
||||
<p-divider layout="vertical" />
|
||||
<p-button label="Previous Book" [disabled]="disablePrevious" icon="pi pi-arrow-left" [outlined]="true" severity="info" (onClick)="onPrevious()"></p-button>
|
||||
<p-button label="Next Book" [disabled]="disableNext" icon="pi pi-arrow-right" iconPos="right" [outlined]="true" severity="info" (onClick)="onNext()"></p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex gap-x-4 items-center ml-auto">
|
||||
<p-button
|
||||
[label]="isAutoFetching ? 'Fetching…' : 'Auto Fetch'"
|
||||
[icon]="isAutoFetching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
[outlined]="true"
|
||||
severity="info"
|
||||
(onClick)="autoFetch(book.id)"
|
||||
[disabled]="isAutoFetching"
|
||||
pTooltip="Automatically fetch metadata using default sources"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
@if (book.bookType === 'PDF' || book.bookType === 'EPUB') {
|
||||
<p-button label="Restore" icon="pi pi-refresh" [outlined]="true" severity="danger" (onClick)="restoreMetadata()" pTooltip="Revert all changes to original metadata" tooltipPosition="top"></p-button>
|
||||
<p-divider layout="vertical" />
|
||||
}
|
||||
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()" pTooltip="Unlock all metadata fields for editing" tooltipPosition="top"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()" pTooltip="Lock all metadata fields to prevent changes" tooltipPosition="top"></p-button>
|
||||
<p-divider layout="vertical" />
|
||||
<p-button label="Save" icon="pi pi-check" [loading]="isSaving" [disabled]="isSaving" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mobile Buttons -->
|
||||
<div class="flex sm:hidden justify-between w-full flex-wrap">
|
||||
@if (showNavigationButtons) {
|
||||
<div class="flex gap-2 flex-wrap">
|
||||
<p-button icon="pi pi-times" [outlined]="true" severity="danger" (onClick)="closeDialog()" pTooltip="Close" tooltipPosition="top"></p-button>
|
||||
<p-button icon="pi pi-arrow-left" [disabled]="disablePrevious" [outlined]="true" severity="info" (onClick)="onPrevious()" pTooltip="Previous Book" tooltipPosition="top"></p-button>
|
||||
<p-button icon="pi pi-arrow-right" [disabled]="disableNext" iconPos="right" [outlined]="true" severity="info" (onClick)="onNext()" pTooltip="Next Book" tooltipPosition="top"></p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex gap-4 items-center flex-wrap ml-auto">
|
||||
<p-button
|
||||
icon="pi pi-bolt"
|
||||
[outlined]="true"
|
||||
severity="info"
|
||||
(onClick)="autoFetch(book.id)"
|
||||
[disabled]="isAutoFetching"
|
||||
pTooltip="Auto Fetch"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
@if (book.bookType === 'PDF' || book.bookType === 'EPUB') {
|
||||
<p-button icon="pi pi-refresh" [outlined]="true" severity="danger" (onClick)="restoreMetadata()" pTooltip="Restore" tooltipPosition="top"></p-button>
|
||||
}
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()" pTooltip="Unlock All" tooltipPosition="top"></p-button>
|
||||
<p-button icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()" pTooltip="Lock All" tooltipPosition="top"></p-button>
|
||||
<p-divider layout="vertical" />
|
||||
<p-button label="Save" icon="pi pi-check" [loading]="isSaving" [disabled]="isSaving" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
::ng-deep .p-tabpanels .custom-tab-padding {
|
||||
padding: 1rem 0rem 0rem 0.5rem !important;
|
||||
|
||||
@media (min-width: 640px) {
|
||||
padding: var(--p-tabs-tabpanel-padding) !important;
|
||||
}
|
||||
}
|
||||
+550
@@ -0,0 +1,550 @@
|
||||
import {Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output, ViewChild} from '@angular/core';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AsyncPipe, NgClass} from '@angular/common';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Book, BookMetadata, MetadataClearFlags, MetadataUpdateWrapper} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {FileUpload, FileUploadErrorEvent, FileUploadEvent} from 'primeng/fileupload';
|
||||
import {HttpResponse} from '@angular/common/http';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Editor} from 'primeng/editor';
|
||||
import {debounceTime} from 'rxjs/operators';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {MetadataRestoreDialogComponent} from '../../../book/components/book-browser/metadata-restore-dialog-component/metadata-restore-dialog-component';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {Chips} from 'primeng/chips';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-editor',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-editor.component.html',
|
||||
styleUrls: ['./metadata-editor.component.scss'],
|
||||
imports: [
|
||||
InputText,
|
||||
Button,
|
||||
Divider,
|
||||
FormsModule,
|
||||
AsyncPipe,
|
||||
ReactiveFormsModule,
|
||||
FileUpload,
|
||||
ProgressSpinner,
|
||||
NgClass,
|
||||
Tooltip,
|
||||
Editor,
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
Chips
|
||||
]
|
||||
})
|
||||
export class MetadataEditorComponent implements OnInit {
|
||||
|
||||
@ViewChild(Editor) quillEditor!: Editor;
|
||||
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@Output() nextBookClicked = new EventEmitter<void>();
|
||||
@Output() previousBookClicked = new EventEmitter<void>();
|
||||
@Output() closeDialogButtonClicked = new EventEmitter<void>();
|
||||
|
||||
@Input() disableNext = false;
|
||||
@Input() disablePrevious = false;
|
||||
@Input() showNavigationButtons = false;
|
||||
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private dialogService = inject(DialogService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
metadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
isUploading = false;
|
||||
isLoading = false;
|
||||
htmlTextarea = '';
|
||||
isSaving = false;
|
||||
|
||||
refreshingBookIds = new Set<number>();
|
||||
isAutoFetching = false;
|
||||
|
||||
originalMetadata!: BookMetadata;
|
||||
|
||||
constructor() {
|
||||
this.metadataForm = new FormGroup({
|
||||
title: new FormControl(''),
|
||||
subtitle: new FormControl(''),
|
||||
authors: new FormControl(''),
|
||||
categories: new FormControl(''),
|
||||
publisher: new FormControl(''),
|
||||
publishedDate: new FormControl(''),
|
||||
isbn10: new FormControl(''),
|
||||
isbn13: new FormControl(''),
|
||||
description: new FormControl(''),
|
||||
pageCount: new FormControl(''),
|
||||
language: new FormControl(''),
|
||||
asin: new FormControl(''),
|
||||
personalRating: new FormControl(''),
|
||||
amazonRating: new FormControl(''),
|
||||
amazonReviewCount: new FormControl(''),
|
||||
goodreadsId: new FormControl(''),
|
||||
goodreadsRating: new FormControl(''),
|
||||
goodreadsReviewCount: new FormControl(''),
|
||||
hardcoverId: new FormControl(''),
|
||||
hardcoverRating: new FormControl(''),
|
||||
hardcoverReviewCount: new FormControl(''),
|
||||
googleId: new FormControl(''),
|
||||
seriesName: new FormControl(''),
|
||||
seriesNumber: new FormControl(''),
|
||||
seriesTotal: new FormControl(''),
|
||||
|
||||
titleLocked: new FormControl(false),
|
||||
subtitleLocked: new FormControl(false),
|
||||
authorsLocked: new FormControl(false),
|
||||
categoriesLocked: new FormControl(false),
|
||||
publisherLocked: new FormControl(false),
|
||||
publishedDateLocked: new FormControl(false),
|
||||
isbn10Locked: new FormControl(false),
|
||||
isbn13Locked: new FormControl(false),
|
||||
descriptionLocked: new FormControl(false),
|
||||
pageCountLocked: new FormControl(false),
|
||||
languageLocked: new FormControl(false),
|
||||
asinLocked: new FormControl(false),
|
||||
personalRatingLocked: new FormControl(false),
|
||||
amazonRatingLocked: new FormControl(false),
|
||||
amazonReviewCountLocked: new FormControl(false),
|
||||
goodreadsIdLocked: new FormControl(''),
|
||||
goodreadsRatingLocked: new FormControl(false),
|
||||
goodreadsReviewCountLocked: new FormControl(false),
|
||||
hardcoverIdLocked: new FormControl(false),
|
||||
hardcoverRatingLocked: new FormControl(false),
|
||||
hardcoverReviewCountLocked: new FormControl(false),
|
||||
googleIdLocked: new FormControl(false),
|
||||
seriesNameLocked: new FormControl(false),
|
||||
seriesNumberLocked: new FormControl(false),
|
||||
seriesTotalLocked: new FormControl(false),
|
||||
thumbnailUrlLocked: new FormControl(false),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.book$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(book => {
|
||||
const metadata = book?.metadata;
|
||||
if (!metadata) return;
|
||||
|
||||
this.currentBookId = metadata.bookId;
|
||||
|
||||
if (this.refreshingBookIds.has(book.id)) {
|
||||
this.refreshingBookIds.delete(book.id);
|
||||
this.isAutoFetching = false;
|
||||
}
|
||||
|
||||
this.originalMetadata = structuredClone(metadata);
|
||||
|
||||
if (this.quillEditor?.quill) {
|
||||
this.quillEditor.quill.root.innerHTML = metadata.description;
|
||||
this.quillDisabled();
|
||||
}
|
||||
|
||||
this.populateFormFromMetadata(metadata);
|
||||
});
|
||||
|
||||
this.metadataForm.get('description')?.valueChanges
|
||||
.pipe(debounceTime(100), takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(value => {
|
||||
if (this.htmlTextarea !== value) {
|
||||
this.htmlTextarea = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private populateFormFromMetadata(metadata: BookMetadata): void {
|
||||
this.metadataForm.patchValue({
|
||||
title: metadata.title ?? null,
|
||||
subtitle: metadata.subtitle ?? null,
|
||||
authors: [...(metadata.authors ?? [])].sort(),
|
||||
categories: [...(metadata.categories ?? [])].sort(),
|
||||
publisher: metadata.publisher ?? null,
|
||||
publishedDate: metadata.publishedDate ?? null,
|
||||
isbn10: metadata.isbn10 ?? null,
|
||||
isbn13: metadata.isbn13 ?? null,
|
||||
description: metadata.description ?? null,
|
||||
pageCount: metadata.pageCount ?? null,
|
||||
language: metadata.language ?? null,
|
||||
rating: metadata.rating ?? null,
|
||||
reviewCount: metadata.reviewCount ?? null,
|
||||
asin: metadata.asin ?? null,
|
||||
personalRating: metadata.personalRating ?? null,
|
||||
amazonRating: metadata.amazonRating ?? null,
|
||||
amazonReviewCount: metadata.amazonReviewCount ?? null,
|
||||
goodreadsId: metadata.goodreadsId ?? null,
|
||||
goodreadsRating: metadata.goodreadsRating ?? null,
|
||||
goodreadsReviewCount: metadata.goodreadsReviewCount ?? null,
|
||||
hardcoverId: metadata.hardcoverId ?? null,
|
||||
hardcoverRating: metadata.hardcoverRating ?? null,
|
||||
hardcoverReviewCount: metadata.hardcoverReviewCount ?? null,
|
||||
googleId: metadata.googleId ?? null,
|
||||
seriesName: metadata.seriesName ?? null,
|
||||
seriesNumber: metadata.seriesNumber ?? null,
|
||||
seriesTotal: metadata.seriesTotal ?? null,
|
||||
titleLocked: metadata.titleLocked ?? false,
|
||||
subtitleLocked: metadata.subtitleLocked ?? false,
|
||||
authorsLocked: metadata.authorsLocked ?? false,
|
||||
categoriesLocked: metadata.categoriesLocked ?? false,
|
||||
publisherLocked: metadata.publisherLocked ?? false,
|
||||
publishedDateLocked: metadata.publishedDateLocked ?? false,
|
||||
isbn10Locked: metadata.isbn10Locked ?? false,
|
||||
isbn13Locked: metadata.isbn13Locked ?? false,
|
||||
descriptionLocked: metadata.descriptionLocked ?? false,
|
||||
pageCountLocked: metadata.pageCountLocked ?? false,
|
||||
languageLocked: metadata.languageLocked ?? false,
|
||||
asinLocked: metadata.asinLocked ?? false,
|
||||
personalRatingLocked: metadata.personalRatingLocked ?? false,
|
||||
amazonRatingLocked: metadata.amazonRatingLocked ?? false,
|
||||
amazonReviewCountLocked: metadata.amazonReviewCountLocked ?? false,
|
||||
goodreadsIdLocked: metadata.goodreadsIdLocked ?? false,
|
||||
goodreadsRatingLocked: metadata.goodreadsRatingLocked ?? false,
|
||||
goodreadsReviewCountLocked: metadata.goodreadsReviewCountLocked ?? false,
|
||||
hardcoverIdLocked: metadata.hardcoverIdLocked ?? false,
|
||||
hardcoverRatingLocked: metadata.hardcoverRatingLocked ?? false,
|
||||
hardcoverReviewCountLocked: metadata.hardcoverReviewCountLocked ?? false,
|
||||
googleIdLocked: metadata.googleIdLocked ?? false,
|
||||
seriesNameLocked: metadata.seriesNameLocked ?? false,
|
||||
seriesNumberLocked: metadata.seriesNumberLocked ?? false,
|
||||
seriesTotalLocked: metadata.seriesTotalLocked ?? false,
|
||||
thumbnailUrlLocked: metadata.coverLocked ?? false,
|
||||
});
|
||||
|
||||
const lockableFields: { key: keyof BookMetadata; control: string }[] = [
|
||||
{key: 'titleLocked', control: 'title'},
|
||||
{key: 'subtitleLocked', control: 'subtitle'},
|
||||
{key: 'authorsLocked', control: 'authors'},
|
||||
{key: 'categoriesLocked', control: 'categories'},
|
||||
{key: 'publisherLocked', control: 'publisher'},
|
||||
{key: 'publishedDateLocked', control: 'publishedDate'},
|
||||
{key: 'languageLocked', control: 'language'},
|
||||
{key: 'isbn10Locked', control: 'isbn10'},
|
||||
{key: 'isbn13Locked', control: 'isbn13'},
|
||||
{key: 'asinLocked', control: 'asin'},
|
||||
{key: 'amazonReviewCountLocked', control: 'amazonReviewCount'},
|
||||
{key: 'amazonRatingLocked', control: 'amazonRating'},
|
||||
{key: 'personalRatingLocked', control: 'personalRating'},
|
||||
{key: 'goodreadsIdLocked', control: 'goodreadsId'},
|
||||
{key: 'goodreadsReviewCountLocked', control: 'goodreadsReviewCount'},
|
||||
{key: 'goodreadsRatingLocked', control: 'goodreadsRating'},
|
||||
{key: 'hardcoverIdLocked', control: 'hardcoverId'},
|
||||
{key: 'hardcoverReviewCountLocked', control: 'hardcoverReviewCount'},
|
||||
{key: 'hardcoverRatingLocked', control: 'hardcoverRating'},
|
||||
{key: 'googleIdLocked', control: 'googleId'},
|
||||
{key: 'pageCountLocked', control: 'pageCount'},
|
||||
{key: 'descriptionLocked', control: 'description'},
|
||||
{key: 'seriesNameLocked', control: 'seriesName'},
|
||||
{key: 'seriesNumberLocked', control: 'seriesNumber'},
|
||||
{key: 'seriesTotalLocked', control: 'seriesTotal'}
|
||||
];
|
||||
|
||||
for (const {key, control} of lockableFields) {
|
||||
const isLocked = metadata[key] === true;
|
||||
const formControl = this.metadataForm.get(control);
|
||||
if (formControl) {
|
||||
isLocked ? formControl.disable() : formControl.enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
this.isSaving = true;
|
||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadataWrapper(undefined), false).subscribe({
|
||||
next: (response) => {
|
||||
this.isSaving = false;
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
},
|
||||
error: (err) => {
|
||||
this.isSaving = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err?.error?.message || 'Failed to update book metadata'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleLock(field: string): void {
|
||||
const isLocked = this.metadataForm.get(field + 'Locked')?.value;
|
||||
const updatedLockedState = !isLocked;
|
||||
this.metadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
|
||||
if (updatedLockedState) {
|
||||
this.metadataForm.get(field)?.disable();
|
||||
} else {
|
||||
this.metadataForm.get(field)?.enable();
|
||||
}
|
||||
this.updateMetadata(undefined);
|
||||
}
|
||||
|
||||
lockAll(): void {
|
||||
Object.keys(this.metadataForm.controls).forEach((key) => {
|
||||
if (key.endsWith('Locked')) {
|
||||
this.metadataForm.get(key)?.setValue(true);
|
||||
const fieldName = key.replace('Locked', '');
|
||||
this.metadataForm.get(fieldName)?.disable();
|
||||
}
|
||||
});
|
||||
this.updateMetadata(true);
|
||||
}
|
||||
|
||||
unlockAll(): void {
|
||||
Object.keys(this.metadataForm.controls).forEach((key) => {
|
||||
if (key.endsWith('Locked')) {
|
||||
this.metadataForm.get(key)?.setValue(false);
|
||||
const fieldName = key.replace('Locked', '');
|
||||
this.metadataForm.get(fieldName)?.enable();
|
||||
}
|
||||
});
|
||||
this.updateMetadata(false);
|
||||
}
|
||||
|
||||
quillDisabled(): boolean {
|
||||
return this.metadataForm.get('descriptionLocked')?.value === true;
|
||||
}
|
||||
|
||||
onHtmlTextareaChange(value: string): void {
|
||||
this.htmlTextarea = value;
|
||||
const control = this.metadataForm.get('description');
|
||||
if (control?.value !== value) {
|
||||
control?.patchValue(value, {emitEvent: false});
|
||||
if (this.quillEditor && this.quillEditor.quill) {
|
||||
this.quillEditor.quill.root.innerHTML = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private buildMetadataWrapper(shouldLockAllFields?: boolean): MetadataUpdateWrapper {
|
||||
const form = this.metadataForm;
|
||||
|
||||
const metadata: BookMetadata = {
|
||||
bookId: this.currentBookId,
|
||||
title: form.get('title')?.value,
|
||||
subtitle: form.get('subtitle')?.value,
|
||||
authors: form.get('authors')?.value ?? [],
|
||||
categories: form.get('categories')?.value ?? [],
|
||||
publisher: form.get('publisher')?.value,
|
||||
publishedDate: form.get('publishedDate')?.value,
|
||||
isbn10: form.get('isbn10')?.value,
|
||||
isbn13: form.get('isbn13')?.value,
|
||||
description: form.get('description')?.value,
|
||||
pageCount: form.get('pageCount')?.value,
|
||||
rating: form.get('rating')?.value,
|
||||
reviewCount: form.get('reviewCount')?.value,
|
||||
asin: form.get('asin')?.value,
|
||||
personalRating: form.get('personalRating')?.value,
|
||||
amazonRating: form.get('amazonRating')?.value,
|
||||
amazonReviewCount: form.get('amazonReviewCount')?.value,
|
||||
goodreadsId: form.get('goodreadsId')?.value,
|
||||
goodreadsRating: form.get('goodreadsRating')?.value,
|
||||
goodreadsReviewCount: form.get('goodreadsReviewCount')?.value,
|
||||
hardcoverId: form.get('hardcoverId')?.value,
|
||||
hardcoverRating: form.get('hardcoverRating')?.value,
|
||||
hardcoverReviewCount: form.get('hardcoverReviewCount')?.value,
|
||||
googleId: form.get('googleId')?.value,
|
||||
language: form.get('language')?.value,
|
||||
seriesName: form.get('seriesName')?.value,
|
||||
seriesNumber: form.get('seriesNumber')?.value,
|
||||
seriesTotal: form.get('seriesTotal')?.value,
|
||||
|
||||
// Locks
|
||||
titleLocked: form.get('titleLocked')?.value,
|
||||
subtitleLocked: form.get('subtitleLocked')?.value,
|
||||
authorsLocked: form.get('authorsLocked')?.value,
|
||||
categoriesLocked: form.get('categoriesLocked')?.value,
|
||||
publisherLocked: form.get('publisherLocked')?.value,
|
||||
publishedDateLocked: form.get('publishedDateLocked')?.value,
|
||||
isbn10Locked: form.get('isbn10Locked')?.value,
|
||||
isbn13Locked: form.get('isbn13Locked')?.value,
|
||||
descriptionLocked: form.get('descriptionLocked')?.value,
|
||||
pageCountLocked: form.get('pageCountLocked')?.value,
|
||||
languageLocked: form.get('languageLocked')?.value,
|
||||
asinLocked: form.get('asinLocked')?.value,
|
||||
amazonRatingLocked: form.get('amazonRatingLocked')?.value,
|
||||
personalRatingLocked: form.get('personalRatingLocked')?.value,
|
||||
amazonReviewCountLocked: form.get('amazonReviewCountLocked')?.value,
|
||||
goodreadsIdLocked: form.get('goodreadsIdLocked')?.value,
|
||||
goodreadsRatingLocked: form.get('goodreadsRatingLocked')?.value,
|
||||
goodreadsReviewCountLocked: form.get('goodreadsReviewCountLocked')?.value,
|
||||
hardcoverIdLocked: form.get('hardcoverIdLocked')?.value,
|
||||
hardcoverRatingLocked: form.get('hardcoverRatingLocked')?.value,
|
||||
hardcoverReviewCountLocked: form.get('hardcoverReviewCountLocked')?.value,
|
||||
googleIdLocked: form.get('googleIdLocked')?.value,
|
||||
seriesNameLocked: form.get('seriesNameLocked')?.value,
|
||||
seriesNumberLocked: form.get('seriesNumberLocked')?.value,
|
||||
seriesTotalLocked: form.get('seriesTotalLocked')?.value,
|
||||
coverLocked: form.get('thumbnailUrlLocked')?.value,
|
||||
|
||||
...(shouldLockAllFields !== undefined && {allFieldsLocked: shouldLockAllFields})
|
||||
};
|
||||
|
||||
const original = this.originalMetadata;
|
||||
|
||||
const wasCleared = (key: keyof BookMetadata): boolean => {
|
||||
const current = (metadata[key] as any) ?? null;
|
||||
const prev = (original[key] as any) ?? null;
|
||||
|
||||
const isEmpty = (val: any): boolean =>
|
||||
val === null || val === '' || (Array.isArray(val) && val.length === 0);
|
||||
|
||||
return isEmpty(current) && !isEmpty(prev);
|
||||
};
|
||||
|
||||
const clearFlags: MetadataClearFlags = {
|
||||
title: wasCleared('title'),
|
||||
subtitle: wasCleared('subtitle'),
|
||||
authors: wasCleared('authors'),
|
||||
categories: wasCleared('categories'),
|
||||
publisher: wasCleared('publisher'),
|
||||
publishedDate: wasCleared('publishedDate'),
|
||||
isbn10: wasCleared('isbn10'),
|
||||
isbn13: wasCleared('isbn13'),
|
||||
description: wasCleared('description'),
|
||||
pageCount: wasCleared('pageCount'),
|
||||
language: wasCleared('language'),
|
||||
asin: wasCleared('asin'),
|
||||
personalRating: wasCleared('personalRating'),
|
||||
amazonRating: wasCleared('personalRating'),
|
||||
amazonReviewCount: wasCleared('amazonReviewCount'),
|
||||
goodreadsId: wasCleared('goodreadsId'),
|
||||
goodreadsRating: wasCleared('goodreadsRating'),
|
||||
goodreadsReviewCount: wasCleared('goodreadsReviewCount'),
|
||||
hardcoverId: wasCleared('hardcoverId'),
|
||||
hardcoverRating: wasCleared('hardcoverRating'),
|
||||
hardcoverReviewCount: wasCleared('hardcoverReviewCount'),
|
||||
googleId: wasCleared('googleId'),
|
||||
seriesName: wasCleared('seriesName'),
|
||||
seriesNumber: wasCleared('seriesNumber'),
|
||||
seriesTotal: wasCleared('seriesTotal'),
|
||||
cover: false
|
||||
};
|
||||
|
||||
return {metadata, clearFlags};
|
||||
}
|
||||
|
||||
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
||||
let metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
|
||||
this.bookService.updateBookMetadata(this.currentBookId, metadataUpdateWrapper, false).subscribe({
|
||||
next: (response) => {
|
||||
if (shouldLockAllFields !== undefined) {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: shouldLockAllFields ? 'Metadata Locked' : 'Metadata Unlocked',
|
||||
detail: shouldLockAllFields
|
||||
? 'All fields have been successfully locked.'
|
||||
: 'All fields have been successfully unlocked.',
|
||||
});
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update lock state',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getUploadCoverUrl(): string {
|
||||
return this.bookService.getUploadCoverUrl(this.currentBookId);
|
||||
}
|
||||
|
||||
onBeforeSend(): void {
|
||||
this.isUploading = true;
|
||||
}
|
||||
|
||||
onUpload(event: FileUploadEvent): void {
|
||||
const response: HttpResponse<any> = event.originalEvent as HttpResponse<any>;
|
||||
if (response && response.status === 200) {
|
||||
const bookMetadata: BookMetadata = response.body as BookMetadata;
|
||||
this.bookService.handleBookMetadataUpdate(this.currentBookId, bookMetadata);
|
||||
this.isUploading = false;
|
||||
} else {
|
||||
this.isUploading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error', summary: 'Upload Failed', detail: 'An error occurred while uploading the cover', life: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onUploadError($event: FileUploadErrorEvent) {
|
||||
this.isUploading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error', summary: 'Upload Error', detail: 'An error occurred while uploading the cover', life: 3000
|
||||
});
|
||||
}
|
||||
|
||||
regenerateCover(bookId: number) {
|
||||
this.bookService.regenerateCover(bookId).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Book cover regenerated successfully. Refresh page to see the new cover.'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to start cover regeneration'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
restoreMetadata() {
|
||||
this.dialogService.open(MetadataRestoreDialogComponent, {
|
||||
header: 'Restore Metadata from Backup',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
bookId: [this.currentBookId]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
autoFetch(bookId: number) {
|
||||
this.refreshingBookIds.add(bookId);
|
||||
this.isAutoFetching = true;
|
||||
const request: MetadataRefreshRequest = {
|
||||
quick: true,
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: [bookId],
|
||||
};
|
||||
this.bookService.autoRefreshMetadata(request).subscribe();
|
||||
setTimeout(() => {
|
||||
this.isAutoFetching = false;
|
||||
this.refreshingBookIds.delete(bookId);
|
||||
}, 15000);
|
||||
}
|
||||
|
||||
onNext() {
|
||||
this.nextBookClicked.emit();
|
||||
}
|
||||
|
||||
onPrevious() {
|
||||
this.previousBookClicked.emit();
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.closeDialogButtonClicked.emit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user