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
+37
@@ -0,0 +1,37 @@
|
||||
<div class="rounded-xl overflow-hidden">
|
||||
<p-tabs [value]="tab" lazy="true" scrollable >
|
||||
<p-tablist>
|
||||
<p-tab value="view">
|
||||
<i [class]="'pi pi-book'"></i>
|
||||
Book Details
|
||||
</p-tab>
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tab value="edit">
|
||||
<i [class]="'pi pi-pencil'"></i>
|
||||
Edit Metadata
|
||||
</p-tab>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tab value="match">
|
||||
<i [class]="'pi pi-search'"></i>
|
||||
Search Metadata
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="overflow-auto" style="height: calc(100vh - 9.7rem);">
|
||||
<p-tabpanel value="view">
|
||||
<app-metadata-viewer [book$]="book$" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
|
||||
</p-tabpanel>
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tabpanel value="edit">
|
||||
<app-metadata-editor [book$]="book$"></app-metadata-editor>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tabpanel value="match">
|
||||
<app-metadata-searcher [book$]="book$"></app-metadata-searcher>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
+1
@@ -0,0 +1 @@
|
||||
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
import { Component, inject, OnDestroy, OnInit, Optional } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { UserService } from '../../settings/user-management/user.service';
|
||||
import { Book, BookRecommendation } from '../../book/model/book.model';
|
||||
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
||||
import {
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
map,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
takeUntil,
|
||||
tap,
|
||||
take,
|
||||
} from 'rxjs/operators';
|
||||
import { BookService } from '../../book/service/book.service';
|
||||
import { AppSettingsService } from '../../core/service/app-settings.service';
|
||||
import {
|
||||
Tab,
|
||||
TabList,
|
||||
TabPanel,
|
||||
TabPanels,
|
||||
Tabs,
|
||||
} from 'primeng/tabs';
|
||||
import { MetadataViewerComponent } from './metadata-viewer/metadata-viewer.component';
|
||||
import { MetadataEditorComponent } from './metadata-editor/metadata-editor.component';
|
||||
import { MetadataSearcherComponent } from './metadata-searcher/metadata-searcher.component';
|
||||
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||
import { BookMetadataHostService } from '../../book-metadata-host-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-metadata-center',
|
||||
standalone: true,
|
||||
templateUrl: './book-metadata-center.component.html',
|
||||
imports: [
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
MetadataViewerComponent,
|
||||
MetadataEditorComponent,
|
||||
MetadataSearcherComponent,
|
||||
],
|
||||
styleUrls: ['./book-metadata-center.component.scss'],
|
||||
})
|
||||
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private metadataHostService = inject(BookMetadataHostService);
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
book$!: Observable<Book>;
|
||||
recommendedBooks: BookRecommendation[] = [];
|
||||
tab: string = 'view';
|
||||
canEditMetadata: boolean = false;
|
||||
admin: boolean = false;
|
||||
|
||||
private appSettings$ = this.appSettingsService.appSettings$;
|
||||
private currentBookId$ = new BehaviorSubject<number | null>(null);
|
||||
|
||||
constructor(
|
||||
@Optional() private config?: DynamicDialogConfig,
|
||||
@Optional() private ref?: DynamicDialogRef
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.loadBooks();
|
||||
const bookIdFromDialog: number | undefined = this.config?.data?.bookId;
|
||||
if (bookIdFromDialog != null) {
|
||||
this.currentBookId$.next(bookIdFromDialog);
|
||||
} else {
|
||||
this.route.paramMap
|
||||
.pipe(
|
||||
map(params => Number(params.get('bookId'))),
|
||||
filter(bookId => !isNaN(bookId)),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(bookId => this.currentBookId$.next(bookId));
|
||||
}
|
||||
|
||||
this.metadataHostService.bookSwitches$
|
||||
.pipe(
|
||||
filter((bookId): bookId is number => !!bookId),
|
||||
distinctUntilChanged(),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(bookId => {
|
||||
this.currentBookId$.next(bookId);
|
||||
});
|
||||
|
||||
this.book$ = this.currentBookId$.pipe(
|
||||
filter((bookId): bookId is number => bookId != null),
|
||||
distinctUntilChanged(),
|
||||
switchMap(bookId =>
|
||||
this.bookService.bookState$.pipe(
|
||||
map(state => state.books?.find(b => b.id === bookId)),
|
||||
filter((book): book is Book => !!book && !!book.metadata),
|
||||
switchMap(book =>
|
||||
this.bookService.getBookByIdFromAPI(book.id, true)
|
||||
)
|
||||
)
|
||||
),
|
||||
takeUntil(this.destroy$),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
this.currentBookId$
|
||||
.pipe(
|
||||
filter((id): id is number => id != null),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(bookId => this.fetchBookRecommendationsIfNeeded(bookId));
|
||||
|
||||
this.route.queryParamMap
|
||||
.pipe(
|
||||
map(params => params.get('tab') ?? 'view'),
|
||||
distinctUntilChanged(),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(tab => {
|
||||
const validTabs = ['view', 'edit', 'match'];
|
||||
this.tab = validTabs.includes(tab) ? tab : 'view';
|
||||
});
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(userData => {
|
||||
this.canEditMetadata = userData?.permissions?.canEditMetadata ?? false;
|
||||
this.admin = userData?.permissions?.admin ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
||||
this.appSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(settings => {
|
||||
if (settings!.similarBookRecommendation ?? false) {
|
||||
this.bookService
|
||||
.getBookRecommendations(bookId)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(recommendations => {
|
||||
this.recommendedBooks = recommendations.sort(
|
||||
(a, b) => (b.similarityScore ?? 0) - (a.similarityScore ?? 0)
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+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();
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
@if (book$ | async; as book) {
|
||||
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" class="flex flex-col h-full w-full">
|
||||
<div class="flex-grow overflow-auto p-0 md:p-4">
|
||||
<div class="flex justify-center items-center" [ngStyle]="{'padding-bottom': '0.75rem', 'padding-left': '7.6rem'}">
|
||||
<p class="ml-3 text-lg">Current Metadata</p>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon='pi pi-angle-left'
|
||||
[ngStyle]="{'padding-left': '3rem', 'padding-right': '0.5rem'}"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all missing fields" tooltipPosition="bottom"
|
||||
(onClick)="copyMissing()"></p-button>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon='pi pi-angle-double-left'
|
||||
[ngStyle]="{'padding-left': '0.5rem', 'padding-right': '2rem'}"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all fields" tooltipPosition="bottom"
|
||||
(onClick)="copyAll()"></p-button>
|
||||
<p class="text-lg">Fetched Metadata</p>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label class="label"></label>
|
||||
<div class="input-container">
|
||||
@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>
|
||||
}
|
||||
<img [src]="metadataForm.get('thumbnailUrl')?.value" alt="Book Thumbnail" class="thumbnail"/>
|
||||
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl" class="input"/>
|
||||
<p-button
|
||||
[icon]="isValueSaved('thumbnailUrl') ? 'pi pi-check' : (hoveredFields['thumbnailUrl'] && isValueCopied('thumbnailUrl') ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueSaved('thumbnailUrl'),
|
||||
'yellow-outlined-button': isValueCopied('thumbnailUrl') && !hoveredFields['thumbnailUrl'],
|
||||
'red-outlined-button': isValueCopied('thumbnailUrl') && hoveredFields['thumbnailUrl']
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields['thumbnailUrl'] && isValueCopied('thumbnailUrl') ? resetField('thumbnailUrl') : copyFetchedToCurrent('thumbnailUrl')"
|
||||
(mouseenter)="onMouseEnter('thumbnailUrl')"
|
||||
(mouseleave)="onMouseLeave('thumbnailUrl')"/>
|
||||
<input type="hidden" [value]="fetchedMetadata.thumbnailUrl" class="input" readonly/>
|
||||
<img [src]="fetchedMetadata.thumbnailUrl ?? null" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||
</div>
|
||||
</div>
|
||||
@for (field of metadataFieldsTop; track field) {
|
||||
<div class="form-row">
|
||||
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
|
||||
<div class="input-container">
|
||||
@if (!book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
|
||||
}
|
||||
<input pSize="small" fluid pInputText id="{{field.controlName}}" formControlName="{{field.controlName}}" class="input"/>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueSaved(field.controlName),
|
||||
'yellow-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<input pSize="small" pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="input" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataChips; track field) {
|
||||
<div class="form-row">
|
||||
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
|
||||
<div class="input-container">
|
||||
@if (!book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
|
||||
}
|
||||
<div class="w-full px-4">
|
||||
<p-chips formControlName="{{field.controlName}}" addOnBlur="true"></p-chips>
|
||||
</div>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueSaved(field.controlName),
|
||||
'yellow-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
|
||||
<div class="w-full px-4">
|
||||
<p-chips
|
||||
[ngModel]="fetchedMetadata[field.fetchedKey] ?? []"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
[disabled]="true">
|
||||
</p-chips>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataDescription; track field) {
|
||||
<div class="form-row">
|
||||
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
|
||||
<div class="input-container">
|
||||
@if (!book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
|
||||
}
|
||||
<textarea rows="3" pTextarea id="{{field.controlName}}" formControlName="{{field.controlName}}" class="input"></textarea>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueSaved(field.controlName),
|
||||
'yellow-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<textarea rows="3" pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="input" readonly></textarea>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataFieldsBottom; track field) {
|
||||
<div class="form-row">
|
||||
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
|
||||
<div class="input-container">
|
||||
@if (!book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
|
||||
}
|
||||
@if (book.metadata![field.lockedKey]) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
|
||||
}
|
||||
<input pInputText pSize="small" id="{{field.controlName}}" formControlName="{{field.controlName}}" class="input"/>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueSaved(field.controlName),
|
||||
'yellow-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<input pInputText pSize="small" [value]="fetchedMetadata[field.fetchedKey] ?? null" class="input" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="flex justify-center items-center" [ngStyle]="{'padding-bottom': '0.75rem', 'padding-left': '7.6rem'}">
|
||||
<p class="ml-3 text-lg">Current Metadata</p>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon='pi pi-angle-left'
|
||||
[ngStyle]="{'padding-left': '3rem', 'padding-right': '0.5rem'}"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all missing fields" tooltipPosition="bottom"
|
||||
(onClick)="copyMissing()"></p-button>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon='pi pi-angle-double-left'
|
||||
[ngStyle]="{'padding-left': '0.5rem', 'padding-right': '2rem'}"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all fields" tooltipPosition="bottom"
|
||||
(onClick)="copyAll()"></p-button>
|
||||
<p class="text-lg">Fetched Metadata</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if (!reviewMode) {
|
||||
<div class="mt-auto">
|
||||
<p-divider></p-divider>
|
||||
<div class="flex justify-between px-2 pt-4">
|
||||
<p-button label="To Metadata List" icon="pi pi-arrow-left" severity="info" (onClick)="goBackClick()"></p-button>
|
||||
<div class="flex gap-x-4 justify-end">
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button
|
||||
label="Save"
|
||||
[icon]="isSaving ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[loading]="isSaving"
|
||||
[disabled]="isSaving"
|
||||
type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
.form-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.label {
|
||||
width: 7rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.input-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 50%;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 15.625rem;
|
||||
height: 21.875rem;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
margin-left: 2.5rem;
|
||||
margin-right: 2.5rem;
|
||||
}
|
||||
|
||||
.arrow-button {
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.yellow-outlined-button {
|
||||
--p-button-outlined-primary-border-color: yellow;
|
||||
--p-button-outlined-primary-color: yellow;
|
||||
}
|
||||
|
||||
.green-outlined-button {
|
||||
--p-button-outlined-primary-border-color: limegreen;
|
||||
--p-button-outlined-primary-color: limegreen;
|
||||
}
|
||||
|
||||
.red-outlined-button {
|
||||
--p-button-outlined-primary-border-color: #E32636;
|
||||
--p-button-outlined-primary-color: #E32636;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100% !important;
|
||||
}
|
||||
+540
@@ -0,0 +1,540 @@
|
||||
import {Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
|
||||
import {Book, BookMetadata, MetadataClearFlags, MetadataUpdateWrapper} from '../../../book/model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {AsyncPipe, NgClass, NgStyle} from '@angular/common';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {filter, map} from 'rxjs/operators';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Chips} from 'primeng/chips';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-picker',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-picker.component.html',
|
||||
styleUrls: ['./metadata-picker.component.scss'],
|
||||
imports: [
|
||||
Button,
|
||||
FormsModule,
|
||||
InputText,
|
||||
Divider,
|
||||
ReactiveFormsModule,
|
||||
NgClass,
|
||||
NgStyle,
|
||||
Tooltip,
|
||||
AsyncPipe,
|
||||
Textarea,
|
||||
Chips
|
||||
]
|
||||
})
|
||||
export class MetadataPickerComponent implements OnInit {
|
||||
|
||||
metadataFieldsTop = [
|
||||
{label: 'Title', controlName: 'title', lockedKey: 'titleLocked', fetchedKey: 'title'},
|
||||
{label: 'Publisher', controlName: 'publisher', lockedKey: 'publisherLocked', fetchedKey: 'publisher'},
|
||||
{label: 'Published', controlName: 'publishedDate', lockedKey: 'publishedDateLocked', fetchedKey: 'publishedDate'}
|
||||
];
|
||||
|
||||
metadataChips = [
|
||||
{label: 'Authors', controlName: 'authors', lockedKey: 'authorsLocked', fetchedKey: 'authors'},
|
||||
{label: 'Categories', controlName: 'categories', lockedKey: 'categoriesLocked', fetchedKey: 'categories'}
|
||||
];
|
||||
|
||||
metadataDescription = [
|
||||
{label: 'Description', controlName: 'description', lockedKey: 'descriptionLocked', fetchedKey: 'description'},
|
||||
];
|
||||
|
||||
metadataFieldsBottom = [
|
||||
{label: 'Series', controlName: 'seriesName', lockedKey: 'seriesNameLocked', fetchedKey: 'seriesName'},
|
||||
{label: 'Book #', controlName: 'seriesNumber', lockedKey: 'seriesNumberLocked', fetchedKey: 'seriesNumber'},
|
||||
{label: 'Total Books', controlName: 'seriesTotal', lockedKey: 'seriesTotalLocked', fetchedKey: 'seriesTotal'},
|
||||
{label: 'Language', controlName: 'language', lockedKey: 'languageLocked', fetchedKey: 'language'},
|
||||
{label: 'ISBN-10', controlName: 'isbn10', lockedKey: 'isbn10Locked', fetchedKey: 'isbn10'},
|
||||
{label: 'ISBN-13', controlName: 'isbn13', lockedKey: 'isbn13Locked', fetchedKey: 'isbn13'},
|
||||
{label: 'ASIN', controlName: 'asin', lockedKey: 'asinLocked', fetchedKey: 'asin'},
|
||||
{label: 'Amz Reviews', controlName: 'amazonReviewCount', lockedKey: 'amazonReviewCountLocked', fetchedKey: 'amazonReviewCount'},
|
||||
{label: 'Amz Rating', controlName: 'amazonRating', lockedKey: 'amazonRatingLocked', fetchedKey: 'amazonRating'},
|
||||
{label: 'GR ID', controlName: 'goodreadsId', lockedKey: 'goodreadsIdLocked', fetchedKey: 'goodreadsId'},
|
||||
{label: 'GR Reviews', controlName: 'goodreadsReviewCount', lockedKey: 'goodreadsReviewCountLocked', fetchedKey: 'goodreadsReviewCount'},
|
||||
{label: 'GR Rating', controlName: 'goodreadsRating', lockedKey: 'goodreadsRatingLocked', fetchedKey: 'goodreadsRating'},
|
||||
{label: 'HC ID', controlName: 'hardcoverId', lockedKey: 'hardcoverIdLocked', fetchedKey: 'hardcoverId'},
|
||||
{label: 'HC Reviews', controlName: 'hardcoverReviewCount', lockedKey: 'hardcoverReviewCountLocked', fetchedKey: 'hardcoverReviewCount'},
|
||||
{label: 'HC Rating', controlName: 'hardcoverRating', lockedKey: 'hardcoverRatingLocked', fetchedKey: 'hardcoverRating'},
|
||||
{label: 'Google ID', controlName: 'googleId', lockedKey: 'googleIdLocked', fetchedKey: 'googleIdRating'},
|
||||
{label: 'Pages', controlName: 'pageCount', lockedKey: 'pageCountLocked', fetchedKey: 'pageCount'}
|
||||
];
|
||||
|
||||
@Input() reviewMode!: boolean;
|
||||
@Input() fetchedMetadata!: BookMetadata;
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@Output() goBack = new EventEmitter<boolean>();
|
||||
|
||||
metadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
copiedFields: Record<string, boolean> = {};
|
||||
savedFields: Record<string, boolean> = {};
|
||||
originalMetadata!: BookMetadata;
|
||||
isSaving = false;
|
||||
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
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(''),
|
||||
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(''),
|
||||
thumbnailUrl: 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(false),
|
||||
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(
|
||||
filter((book): book is Book => !!book && !!book.metadata),
|
||||
map(book => book.metadata),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe((metadata) => {
|
||||
|
||||
this.metadataForm.reset();
|
||||
this.copiedFields = {};
|
||||
this.savedFields = {};
|
||||
this.hoveredFields = {};
|
||||
|
||||
if (metadata) {
|
||||
this.originalMetadata = metadata;
|
||||
this.originalMetadata.thumbnailUrl = this.urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn);
|
||||
this.currentBookId = metadata.bookId;
|
||||
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,
|
||||
asin: metadata.asin || 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,
|
||||
thumbnailUrl: this.urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn),
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
if (metadata.titleLocked) this.metadataForm.get('title')?.disable();
|
||||
if (metadata.subtitleLocked) this.metadataForm.get('subtitle')?.disable();
|
||||
if (metadata.authorsLocked) this.metadataForm.get('authors')?.disable();
|
||||
if (metadata.categoriesLocked) this.metadataForm.get('categories')?.disable();
|
||||
if (metadata.publisherLocked) this.metadataForm.get('publisher')?.disable();
|
||||
if (metadata.publishedDateLocked) this.metadataForm.get('publishedDate')?.disable();
|
||||
if (metadata.languageLocked) this.metadataForm.get('language')?.disable();
|
||||
if (metadata.isbn10Locked) this.metadataForm.get('isbn10')?.disable();
|
||||
if (metadata.isbn13Locked) this.metadataForm.get('isbn13')?.disable();
|
||||
if (metadata.asinLocked) this.metadataForm.get('asin')?.disable();
|
||||
if (metadata.personalRatingLocked) this.metadataForm.get('personalRating')?.disable();
|
||||
if (metadata.amazonReviewCountLocked) this.metadataForm.get('amazonReviewCount')?.disable();
|
||||
if (metadata.amazonRatingLocked) this.metadataForm.get('amazonRating')?.disable();
|
||||
if (metadata.googleIdLocked) this.metadataForm.get('googleIdCount')?.disable();
|
||||
if (metadata.goodreadsReviewCountLocked) this.metadataForm.get('goodreadsReviewCount')?.disable();
|
||||
if (metadata.goodreadsRatingLocked) this.metadataForm.get('goodreadsRating')?.disable();
|
||||
if (metadata.hardcoverIdLocked) this.metadataForm.get('hardcoverId')?.disable();
|
||||
if (metadata.hardcoverReviewCountLocked) this.metadataForm.get('hardcoverReviewCount')?.disable();
|
||||
if (metadata.hardcoverRatingLocked) this.metadataForm.get('hardcoverRating')?.disable();
|
||||
if (metadata.googleIdLocked) this.metadataForm.get('googleId')?.disable();
|
||||
if (metadata.pageCountLocked) this.metadataForm.get('pageCount')?.disable();
|
||||
if (metadata.descriptionLocked) this.metadataForm.get('description')?.disable();
|
||||
if (metadata.seriesNameLocked) this.metadataForm.get('seriesName')?.disable();
|
||||
if (metadata.seriesNumberLocked) this.metadataForm.get('seriesNumber')?.disable();
|
||||
if (metadata.seriesTotalLocked) this.metadataForm.get('seriesTotal')?.disable();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
this.isSaving = true;
|
||||
const updatedBookMetadata = this.buildMetadataWrapper(undefined);
|
||||
this.bookService.updateBookMetadata(this.currentBookId, updatedBookMetadata, false).subscribe({
|
||||
next: (bookMetadata) => {
|
||||
this.isSaving = false;
|
||||
Object.keys(this.copiedFields).forEach((field) => {
|
||||
if (this.copiedFields[field]) {
|
||||
this.savedFields[field] = true;
|
||||
}
|
||||
});
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
},
|
||||
error: () => {
|
||||
this.isSaving = false;
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private buildMetadataWrapper(shouldLockAllFields: boolean | undefined): MetadataUpdateWrapper {
|
||||
const updatedBookMetadata: BookMetadata = {
|
||||
bookId: this.currentBookId,
|
||||
title: this.metadataForm.get('title')?.value || this.copiedFields['title'] ? this.getValueOrCopied('title') : '',
|
||||
subtitle: this.metadataForm.get('subtitle')?.value || this.copiedFields['subtitle'] ? this.getValueOrCopied('subtitle') : '',
|
||||
authors: this.metadataForm.get('authors')?.value || this.copiedFields['authors'] ? this.getArrayFromFormField('authors', this.fetchedMetadata.authors) : [],
|
||||
categories: this.metadataForm.get('categories')?.value || this.copiedFields['categories'] ? this.getArrayFromFormField('categories', this.fetchedMetadata.categories) : [],
|
||||
publisher: this.metadataForm.get('publisher')?.value || this.copiedFields['publisher'] ? this.getValueOrCopied('publisher') : '',
|
||||
publishedDate: this.metadataForm.get('publishedDate')?.value || this.copiedFields['publishedDate'] ? this.getValueOrCopied('publishedDate') : '',
|
||||
isbn10: this.metadataForm.get('isbn10')?.value || this.copiedFields['isbn10'] ? this.getValueOrCopied('isbn10') : '',
|
||||
isbn13: this.metadataForm.get('isbn13')?.value || this.copiedFields['isbn13'] ? this.getValueOrCopied('isbn13') : '',
|
||||
description: this.metadataForm.get('description')?.value || this.copiedFields['description'] ? this.getValueOrCopied('description') : '',
|
||||
pageCount: this.metadataForm.get('pageCount')?.value || this.copiedFields['pageCount'] ? this.getPageCountOrCopied() : null,
|
||||
language: this.metadataForm.get('language')?.value || this.copiedFields['language'] ? this.getValueOrCopied('language') : '',
|
||||
asin: this.metadataForm.get('asin')?.value || this.copiedFields['asin'] ? this.getValueOrCopied('asin') : '',
|
||||
personalRating: this.metadataForm.get('personalRating')?.value || this.copiedFields['personalRating'] ? this.getNumberOrCopied('personalRating') : null,
|
||||
amazonRating: this.metadataForm.get('amazonRating')?.value || this.copiedFields['amazonRating'] ? this.getNumberOrCopied('amazonRating') : null,
|
||||
amazonReviewCount: this.metadataForm.get('amazonReviewCount')?.value || this.copiedFields['amazonReviewCount'] ? this.getNumberOrCopied('amazonReviewCount') : null,
|
||||
goodreadsId: this.metadataForm.get('goodreadsId')?.value || this.copiedFields['goodreadsId'] ? this.getValueOrCopied('goodreadsId') : '',
|
||||
goodreadsRating: this.metadataForm.get('goodreadsRating')?.value || this.copiedFields['goodreadsRating'] ? this.getNumberOrCopied('goodreadsRating') : null,
|
||||
goodreadsReviewCount: this.metadataForm.get('goodreadsReviewCount')?.value || this.copiedFields['goodreadsReviewCount'] ? this.getNumberOrCopied('goodreadsReviewCount') : null,
|
||||
hardcoverId: this.metadataForm.get('hardcoverId')?.value || this.copiedFields['hardcoverId'] ? this.getValueOrCopied('hardcoverId') : '',
|
||||
hardcoverRating: this.metadataForm.get('hardcoverRating')?.value || this.copiedFields['hardcoverRating'] ? this.getNumberOrCopied('hardcoverRating') : null,
|
||||
hardcoverReviewCount: this.metadataForm.get('hardcoverReviewCount')?.value || this.copiedFields['hardcoverReviewCount'] ? this.getNumberOrCopied('hardcoverReviewCount') : null,
|
||||
googleId: this.metadataForm.get('googleId')?.value || this.copiedFields['googleId'] ? this.getValueOrCopied('googleId') : '',
|
||||
seriesName: this.metadataForm.get('seriesName')?.value || this.copiedFields['seriesName'] ? this.getValueOrCopied('seriesName') : '',
|
||||
seriesNumber: this.metadataForm.get('seriesNumber')?.value || this.copiedFields['seriesNumber'] ? this.getNumberOrCopied('seriesNumber') : null,
|
||||
seriesTotal: this.metadataForm.get('seriesTotal')?.value || this.copiedFields['seriesTotal'] ? this.getNumberOrCopied('seriesTotal') : null,
|
||||
thumbnailUrl: this.getThumbnail(),
|
||||
|
||||
titleLocked: this.metadataForm.get('titleLocked')?.value,
|
||||
subtitleLocked: this.metadataForm.get('subtitleLocked')?.value,
|
||||
authorsLocked: this.metadataForm.get('authorsLocked')?.value,
|
||||
categoriesLocked: this.metadataForm.get('categoriesLocked')?.value,
|
||||
publisherLocked: this.metadataForm.get('publisherLocked')?.value,
|
||||
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
|
||||
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
|
||||
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
|
||||
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
|
||||
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
|
||||
languageLocked: this.metadataForm.get('languageLocked')?.value,
|
||||
asinLocked: this.metadataForm.get('asinLocked')?.value,
|
||||
personalRatingLocked: this.metadataForm.get('personalRatingLocked')?.value,
|
||||
amazonRatingLocked: this.metadataForm.get('amazonRatingLocked')?.value,
|
||||
amazonReviewCountLocked: this.metadataForm.get('amazonReviewCountLocked')?.value,
|
||||
goodreadsIdLocked: this.metadataForm.get('goodreadsIdLocked')?.value,
|
||||
goodreadsRatingLocked: this.metadataForm.get('goodreadsRatingLocked')?.value,
|
||||
goodreadsReviewCountLocked: this.metadataForm.get('goodreadsReviewCountLocked')?.value,
|
||||
hardcoverIdLocked: this.metadataForm.get('hardcoverIdLocked')?.value,
|
||||
hardcoverRatingLocked: this.metadataForm.get('hardcoverRatingLocked')?.value,
|
||||
hardcoverReviewCountLocked: this.metadataForm.get('hardcoverReviewCountLocked')?.value,
|
||||
googleIdLocked: this.metadataForm.get('googleIdLocked')?.value,
|
||||
seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value,
|
||||
seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value,
|
||||
seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value,
|
||||
coverLocked: this.metadataForm.get('thumbnailUrlLocked')?.value,
|
||||
|
||||
...(shouldLockAllFields !== undefined && {allFieldsLocked: shouldLockAllFields}),
|
||||
};
|
||||
|
||||
const clearFlags: MetadataClearFlags = this.inferClearFlags(updatedBookMetadata, this.originalMetadata);
|
||||
|
||||
return {
|
||||
metadata: updatedBookMetadata,
|
||||
clearFlags: clearFlags
|
||||
};
|
||||
}
|
||||
|
||||
private inferClearFlags(current: BookMetadata, original: BookMetadata): MetadataClearFlags {
|
||||
return {
|
||||
title: !current.title && !!original.title,
|
||||
subtitle: !current.subtitle && !!original.subtitle,
|
||||
authors: current.authors?.length === 0 && original.authors?.length! > 0,
|
||||
categories: current.categories?.length === 0 && original.categories?.length! > 0,
|
||||
publisher: !current.publisher && !!original.publisher,
|
||||
publishedDate: !current.publishedDate && !!original.publishedDate,
|
||||
isbn10: !current.isbn10 && !!original.isbn10,
|
||||
isbn13: !current.isbn13 && !!original.isbn13,
|
||||
description: !current.description && !!original.description,
|
||||
pageCount: current.pageCount === null && original.pageCount !== null,
|
||||
language: !current.language && !!original.language,
|
||||
asin: !current.asin && !!original.asin,
|
||||
amazonRating: current.amazonRating === null && original.amazonRating !== null,
|
||||
amazonReviewCount: current.amazonReviewCount === null && original.amazonReviewCount !== null,
|
||||
goodreadsId: !current.goodreadsId && !!original.goodreadsId,
|
||||
goodreadsRating: current.goodreadsRating === null && original.goodreadsRating !== null,
|
||||
goodreadsReviewCount: current.goodreadsReviewCount === null && original.goodreadsReviewCount !== null,
|
||||
hardcoverId: !current.hardcoverId && !!original.hardcoverId,
|
||||
hardcoverRating: current.hardcoverRating === null && original.hardcoverRating !== null,
|
||||
hardcoverReviewCount: current.hardcoverReviewCount === null && original.hardcoverReviewCount !== null,
|
||||
googleId: !current.googleId && !!original.googleId,
|
||||
seriesName: !current.seriesName && !!original.seriesName,
|
||||
seriesNumber: current.seriesNumber === null && original.seriesNumber !== null,
|
||||
seriesTotal: current.seriesTotal === null && original.seriesTotal !== null,
|
||||
cover: !current.thumbnailUrl && !!original.thumbnailUrl,
|
||||
personalRating: current.personalRating === null && original.personalRating !== null,
|
||||
};
|
||||
}
|
||||
|
||||
getThumbnail() {
|
||||
const thumbnailUrl = this.metadataForm.get('thumbnailUrl')?.value;
|
||||
if (thumbnailUrl?.includes('api/v1')) {
|
||||
return null;
|
||||
}
|
||||
return this.copiedFields['thumbnailUrl'] ? this.getValueOrCopied('thumbnailUrl') : null;
|
||||
}
|
||||
|
||||
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadataWrapper(shouldLockAllFields), 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',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
copyMissing(): void {
|
||||
Object.keys(this.fetchedMetadata).forEach((field) => {
|
||||
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
||||
if (!isLocked && !this.metadataForm.get(field)?.value && this.fetchedMetadata[field]) {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
copyAll() {
|
||||
Object.keys(this.fetchedMetadata).forEach((field) => {
|
||||
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
||||
if (!isLocked && this.fetchedMetadata[field] && field !== 'thumbnailUrl') {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
copyFetchedToCurrent(field: string): void {
|
||||
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
||||
if (isLocked) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Action Blocked',
|
||||
detail: `${field} is locked and cannot be updated.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
const value = this.fetchedMetadata[field];
|
||||
if (value) {
|
||||
this.metadataForm.get(field)?.setValue(value);
|
||||
this.copiedFields[field] = true;
|
||||
this.highlightCopiedInput(field);
|
||||
}
|
||||
}
|
||||
|
||||
private getNumberOrCopied(field: string): number | null {
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || null;
|
||||
}
|
||||
return Number(formValue);
|
||||
}
|
||||
|
||||
private getPageCountOrCopied(): number | null {
|
||||
const formValue = this.metadataForm.get('pageCount')?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields['pageCount'] = true;
|
||||
return this.fetchedMetadata.pageCount || null;
|
||||
}
|
||||
return Number(formValue);
|
||||
}
|
||||
|
||||
private getValueOrCopied(field: string): string {
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (!formValue || formValue === '') {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || '';
|
||||
}
|
||||
return formValue;
|
||||
}
|
||||
|
||||
getArrayFromFormField(field: string, fallbackValue: any): any[] {
|
||||
const fieldValue = this.metadataForm.get(field)?.value;
|
||||
if (!fieldValue) {
|
||||
return fallbackValue ? (Array.isArray(fallbackValue) ? fallbackValue : [fallbackValue]) : [];
|
||||
}
|
||||
if (typeof fieldValue === 'string') {
|
||||
return fieldValue.split(',').map(item => item.trim());
|
||||
}
|
||||
return Array.isArray(fieldValue) ? fieldValue : [];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
highlightCopiedInput(field: string): void {
|
||||
this.copiedFields = {...this.copiedFields, [field]: true};
|
||||
}
|
||||
|
||||
isValueCopied(field: string): boolean {
|
||||
return this.copiedFields[field];
|
||||
}
|
||||
|
||||
isValueSaved(field: string): boolean {
|
||||
return this.savedFields[field];
|
||||
}
|
||||
|
||||
goBackClick() {
|
||||
this.goBack.emit(true);
|
||||
}
|
||||
|
||||
hoveredFields: { [key: string]: boolean } = {};
|
||||
|
||||
onMouseEnter(controlName: string): void {
|
||||
if (this.isValueCopied(controlName) && !this.isValueSaved(controlName)) {
|
||||
this.hoveredFields[controlName] = true;
|
||||
}
|
||||
}
|
||||
|
||||
onMouseLeave(controlName: string): void {
|
||||
this.hoveredFields[controlName] = false;
|
||||
}
|
||||
|
||||
resetField(field: string) {
|
||||
this.metadataForm.get(field)?.setValue(this.originalMetadata[field]);
|
||||
this.copiedFields[field] = false;
|
||||
this.hoveredFields[field] = false;
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
@if (selectedFetchedMetadata$ | async; as selectedFetchedMetadata) {
|
||||
<div class="h-full w-full flex-auto min-w-[80rem]">
|
||||
<app-metadata-picker
|
||||
[fetchedMetadata]="selectedFetchedMetadata"
|
||||
[book$]="book$"
|
||||
(goBack)="onGoBack()">
|
||||
</app-metadata-picker>
|
||||
</div>
|
||||
} @else {
|
||||
<form class="flex flex-col w-full h-full pt-2 min-w-full md:min-w-[60rem] pr-0 md:pr-2 pl-0 md:pl-2" [formGroup]="form" (ngSubmit)="onSubmit()">
|
||||
|
||||
<div class="grid grid-cols-1 md:flex md:flex-row w-full gap-4 md:items-end">
|
||||
|
||||
<div class="flex flex-col gap-1 w-full max-w-full md:w-3/12">
|
||||
<label for="provider">Providers</label>
|
||||
<p-multiselect
|
||||
id="provider"
|
||||
class="w-full"
|
||||
[filter]="false"
|
||||
showToggleAll="false"
|
||||
[options]="providers"
|
||||
formControlName="provider"
|
||||
placeholder="Select Providers">
|
||||
</p-multiselect>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 w-full max-w-full md:w-5/12">
|
||||
<label for="title">Title</label>
|
||||
<input pInputText formControlName="title" id="title" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 w-full max-w-full md:w-4/12">
|
||||
<label for="author">Author</label>
|
||||
<input pInputText formControlName="author" id="author" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 w-full sm:w-fit md:w-auto">
|
||||
<label class="invisible md:visible h-0 md:h-auto">Search</label>
|
||||
<div class="flex justify-center md:justify-start">
|
||||
<p-button
|
||||
label="Search"
|
||||
type="submit"
|
||||
outlined="true"
|
||||
[disabled]="!isSearchEnabled || loading"
|
||||
class="w-full sm:w-fit md:w-auto">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@if (loading) {
|
||||
<div class="flex justify-center items-center mt-8">
|
||||
<p-progress-spinner ariaLabel="loading"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading) {
|
||||
<div class="mt-4 md:mt-8 flex-1 overflow-y-auto">
|
||||
@for (metadata of allFetchedMetadata; track metadata) {
|
||||
<div class="book-item flex flex-col w-full">
|
||||
<div class="flex flex-row w-full book-item-content cursor-pointer" (click)="onBookClick(metadata)">
|
||||
<img [src]="metadata.thumbnailUrl || 'assets/images/missing-cover.jpg'" alt="Image" class="img-fixed-dimensions pr-0 md:pr-2 md:py-3 self-center md:self-start"/>
|
||||
<div class="flex flex-col w-full m-2">
|
||||
<div class="flex flex-col md:flex-row gap-2 md:gap-4 justify-between">
|
||||
<p class="font-bold">{{ truncateText(metadata['title']!, 90) }}</p>
|
||||
<div class="flex flex-wrap gap-2 text-sm">
|
||||
<p>ISBN: {{ metadata['isbn10'] || metadata['asin'] }}</p>
|
||||
<span class="hidden md:inline">|</span>
|
||||
<p>Published: {{ metadata['publishedDate'] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 text-sm">
|
||||
<p>by {{ truncateText(metadata['authors']!.join(', '), 70) }}</p>
|
||||
<span class="hidden md:inline">|</span>
|
||||
<p>Source: <span [innerHTML]="buildProviderLink(metadata)"></span></p>
|
||||
</div>
|
||||
<p class="mt-4 truncate-text p-secondary">
|
||||
{{ sanitizeHtml(metadata['description']) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
.truncate-text {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.img-fixed-dimensions {
|
||||
height: 150px;
|
||||
width: 100px;
|
||||
object-fit: fill;
|
||||
}
|
||||
|
||||
.book-item {
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.book-item-content {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.book-item:hover .book-item-content::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(255, 255, 255, 0.075);
|
||||
}
|
||||
|
||||
.book-item:hover .book-item-content {
|
||||
box-shadow: 0 0 0 rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {MultiSelect} from 'primeng/multiselect';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
import {FetchMetadataRequest} from '../../model/request/fetch-metadata-request.model';
|
||||
import {MetadataPickerComponent} from '../metadata-picker/metadata-picker.component';
|
||||
import {Book, BookMetadata} from '../../../book/model/book.model';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
|
||||
import {BehaviorSubject, combineLatest, Observable, Subject, Subscription, takeUntil} from 'rxjs';
|
||||
import {distinctUntilChanged, filter, switchMap} from 'rxjs/operators';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-searcher',
|
||||
templateUrl: './metadata-searcher.component.html',
|
||||
styleUrls: ['./metadata-searcher.component.scss'],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Divider,
|
||||
ProgressSpinner,
|
||||
MetadataPickerComponent,
|
||||
MultiSelect,
|
||||
AsyncPipe
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class MetadataSearcherComponent implements OnInit, OnDestroy {
|
||||
form: FormGroup;
|
||||
providers: string[] = [];
|
||||
allFetchedMetadata: BookMetadata[] = [];
|
||||
bookId!: number;
|
||||
loading: boolean = false;
|
||||
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
|
||||
selectedFetchedMetadata$ = new BehaviorSubject<BookMetadata | null>(null);
|
||||
|
||||
private formBuilder = inject(FormBuilder);
|
||||
private bookService = inject(BookService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private route = inject(ActivatedRoute);
|
||||
|
||||
private subscription: Subscription = new Subscription();
|
||||
private cancelRequest$ = new Subject<void>();
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
constructor() {
|
||||
this.form = this.formBuilder.group({
|
||||
provider: null,
|
||||
title: [''],
|
||||
author: ['']
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.subscription.add(
|
||||
this.route.paramMap
|
||||
.pipe(
|
||||
switchMap(params => {
|
||||
const bookId = +params.get('id')!;
|
||||
if (this.bookId !== bookId) {
|
||||
this.bookId = bookId;
|
||||
this.cancelRequest$.next();
|
||||
this.loading = false;
|
||||
this.allFetchedMetadata = [];
|
||||
this.selectedFetchedMetadata$.next(null);
|
||||
}
|
||||
return combineLatest([this.book$, this.appSettings$]);
|
||||
}),
|
||||
filter(([book, settings]) => !!book && !!settings),
|
||||
distinctUntilChanged(([prevBook], [currBook]) => prevBook?.id === currBook?.id)
|
||||
)
|
||||
.subscribe(([book, settings]) => {
|
||||
this.providers = Object.entries(settings!.metadataProviderSettings)
|
||||
.filter(([_, value]) => value.enabled)
|
||||
.map(([key]) => key.charAt(0).toUpperCase() + key.slice(1));
|
||||
|
||||
this.resetFormFromBook(book!);
|
||||
|
||||
if (settings!.autoBookSearch) {
|
||||
this.onSubmit();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private resetFormFromBook(book: Book): void {
|
||||
this.selectedFetchedMetadata$.next(null);
|
||||
this.allFetchedMetadata = [];
|
||||
this.bookId = book.id;
|
||||
|
||||
this.form.patchValue({
|
||||
provider: this.providers,
|
||||
title: book.metadata?.title ?? '',
|
||||
author: book.metadata?.authors?.[0] ?? ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.cancelRequest$.next();
|
||||
this.subscription.unsubscribe();
|
||||
this.selectedFetchedMetadata$.complete();
|
||||
}
|
||||
|
||||
get isSearchEnabled(): boolean {
|
||||
const providerSelected = !!this.form.get('provider')?.value;
|
||||
const title = this.form.get('title')?.value;
|
||||
return providerSelected && title;
|
||||
}
|
||||
|
||||
onSubmit(): void {
|
||||
if (this.form.valid) {
|
||||
const providerKeys = this.form.get('provider')?.value;
|
||||
if (!providerKeys) return;
|
||||
|
||||
const fetchRequest: FetchMetadataRequest = {
|
||||
bookId: this.bookId,
|
||||
providers: providerKeys,
|
||||
title: this.form.get('title')?.value,
|
||||
author: this.form.get('author')?.value
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
this.cancelRequest$.next();
|
||||
|
||||
this.bookService.fetchBookMetadata(fetchRequest.bookId, fetchRequest)
|
||||
.pipe(takeUntil(this.cancelRequest$))
|
||||
.subscribe({
|
||||
next: (fetchedMetadata) => {
|
||||
this.loading = false;
|
||||
this.allFetchedMetadata = fetchedMetadata.map(m => ({
|
||||
...m,
|
||||
thumbnailUrl: m.thumbnailUrl
|
||||
}));
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.warn('Form is invalid. Please fill in all required fields.');
|
||||
}
|
||||
}
|
||||
|
||||
onBookClick(fetchedMetadata: BookMetadata) {
|
||||
this.selectedFetchedMetadata$.next(fetchedMetadata);
|
||||
}
|
||||
|
||||
onGoBack() {
|
||||
this.selectedFetchedMetadata$.next(null);
|
||||
}
|
||||
|
||||
sanitizeHtml(htmlString: string | null | undefined): string {
|
||||
if (!htmlString) return '';
|
||||
return htmlString.replace(/<\/?[^>]+(>|$)/g, '').trim();
|
||||
}
|
||||
|
||||
truncateText(text: string | null, length: number): string {
|
||||
const safeText = text ?? '';
|
||||
return safeText.length > length ? safeText.substring(0, length) + '...' : safeText;
|
||||
}
|
||||
|
||||
buildProviderLink(metadata: BookMetadata): string {
|
||||
if (metadata.asin) {
|
||||
return `<a href="https://www.amazon.com/dp/${metadata.asin}" target="_blank">Amazon</a>`;
|
||||
} else if (metadata.goodreadsId) {
|
||||
return `<a href="https://www.goodreads.com/book/show/${metadata.goodreadsId}" target="_blank">Goodreads</a>`;
|
||||
} else if (metadata.googleId) {
|
||||
return `<a href="https://books.google.com/books?id=${metadata.googleId}" target="_blank">Google</a>`;
|
||||
} else if (metadata.hardcoverId) {
|
||||
return `<a href="https://hardcover.app/books/${metadata.hardcoverId}" target="_blank">Hardcover</a>`;
|
||||
}
|
||||
|
||||
throw new Error("No provider ID found in metadata.");
|
||||
}
|
||||
}
|
||||
+417
@@ -0,0 +1,417 @@
|
||||
<div class="p-0 md:p-2 flex flex-col h-full w-full rounded-xl">
|
||||
@if (book$ | async; as book) {
|
||||
<div class="flex flex-col md:flex-row gap-6 pb-8">
|
||||
|
||||
<div class="flex justify-center md:justify-start">
|
||||
<div class="relative w-[250px] min-w-[250px] md:w-[250px]">
|
||||
<img
|
||||
[attr.src]="urlHelper.getCoverUrl(book?.metadata!.bookId, book?.metadata!.coverUpdatedOn)"
|
||||
class="rounded-xl w-full object-cover"
|
||||
alt="Cover of {{ book?.metadata!.title }}"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
@if (book?.metadata!.seriesNumber != null) {
|
||||
<div class="absolute top-2 left-2 bg-black/60 text-white px-2 py-0.5 rounded-lg text-xs font-semibold">
|
||||
#{{ book?.metadata!.seriesNumber }}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (getProgressPercent(book) !== null) {
|
||||
<div class="absolute bottom-0 left-0 right-0">
|
||||
<p-progressBar
|
||||
[value]="getProgressPercent(book)"
|
||||
[showValue]="false"
|
||||
[ngClass]="{
|
||||
'rounded-b-xl': true,
|
||||
'progress-complete': getProgressPercent(book) === 100,
|
||||
'progress-incomplete': getProgressPercent(book)! < 100
|
||||
}"
|
||||
[style]="{ height: '8px' }">
|
||||
</p-progressBar>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col justify-between flex-grow">
|
||||
<div class="space-y-4">
|
||||
|
||||
<div class="flex items-start justify-between">
|
||||
<div class="flex flex-col text-center md:text-left w-full">
|
||||
@if (book?.metadata?.seriesName) {
|
||||
<p
|
||||
class="text-blue-600 cursor-pointer hover:underline"
|
||||
(click)="goToSeries(book?.metadata?.seriesName!)"
|
||||
>
|
||||
{{ book?.metadata?.seriesName }}
|
||||
@if (book?.metadata?.seriesNumber) {
|
||||
#{{ book?.metadata?.seriesNumber }}
|
||||
}
|
||||
</p>
|
||||
}
|
||||
|
||||
<div class="flex flex-col items-center md:items-start gap-1">
|
||||
<div class="flex items-center gap-2 justify-center md:justify-start flex-wrap text-center md:text-left">
|
||||
<h2 class="text-3xl font-extrabold text-gray-900 dark:text-white leading-tight">
|
||||
{{ book?.metadata!.title }}
|
||||
</h2>
|
||||
<i
|
||||
class="pi align-middle"
|
||||
[ngClass]="isMetadataFullyLocked(book?.metadata!) ? 'pi-lock text-red-500' : 'pi-lock-open text-green-500'"
|
||||
[title]="isMetadataFullyLocked(book?.metadata!) ? 'Metadata is locked' : 'Metadata is unlocked'"
|
||||
pTooltip="{{ isMetadataFullyLocked(book?.metadata!) ? 'This book metadata is locked.' : 'This book metadata is unlocked.' }}"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
</div>
|
||||
|
||||
<p class="text-gray-600 dark:text-gray-300 text-lg">
|
||||
@for (author of book?.metadata!.authors; track author; let isLast = $last) {
|
||||
<a class="hover:underline dark:text-blue-400 cursor-pointer" (click)="goToAuthorBooks(author)">
|
||||
{{ author }}
|
||||
</a>
|
||||
@if (!isLast) {
|
||||
<span>, </span>
|
||||
}
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-start text-sm w-full">
|
||||
|
||||
<div class="flex justify-center sm:justify-start">
|
||||
<div class="flex items-center gap-2">
|
||||
<i class="pi pi-thumbs-up-fill text-yellow-500" pTooltip="Personal Rating" tooltipPosition="top"></i>
|
||||
<p-rating
|
||||
[ngModel]="book?.metadata!.personalRating"
|
||||
(onRate)="onPersonalRatingChange(book, $event)"
|
||||
stars="10"
|
||||
[style.--p-rating-icon-active-color]="getStarColorScaled(book?.metadata!.personalRating, 10)">
|
||||
</p-rating>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (book?.metadata?.amazonRating || book?.metadata?.goodreadsRating || book?.metadata?.hardcoverRating || book?.metadata?.googleId) {
|
||||
<span class="hidden sm:inline text-gray-400 text-xl px-1 leading-none">|</span>
|
||||
}
|
||||
|
||||
<div class="flex flex-wrap justify-center sm:justify-start gap-4 pt-1">
|
||||
@if (book?.metadata?.amazonRating) {
|
||||
<a
|
||||
class="flex items-center gap-1"
|
||||
[href]="'https://www.amazon.com/dp/' + (book.metadata?.asin ?? '')"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
[pTooltip]="getRatingTooltip(book, 'amazon')"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
<img
|
||||
src="https://www.amazon.com/favicon.ico"
|
||||
alt="Amazon"
|
||||
class="w-5 h-5 object-contain transform transition duration-200 hover:scale-125 hover:drop-shadow-lg"
|
||||
/>
|
||||
<span class="font-semibold">
|
||||
{{ getRatingPercent(book.metadata!.amazonRating) }}%
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (book?.metadata?.goodreadsRating) {
|
||||
<a
|
||||
class="flex items-center gap-1"
|
||||
[href]="'https://www.goodreads.com/book/show/' + (book.metadata?.goodreadsId ?? '')"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
[pTooltip]="getRatingTooltip(book, 'goodreads')"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
<img
|
||||
src="https://www.goodreads.com/favicon.ico"
|
||||
alt="Goodreads"
|
||||
class="w-5 h-5 object-contain transform transition duration-200 hover:scale-125 hover:drop-shadow-lg"
|
||||
/>
|
||||
<span class="font-semibold">
|
||||
{{ getRatingPercent(book.metadata!.goodreadsRating) }}%
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (book?.metadata?.hardcoverRating) {
|
||||
<a
|
||||
class="flex items-center gap-1"
|
||||
[href]="'https://hardcover.app/books/' + (book.metadata?.hardcoverId ?? '')"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
[pTooltip]="getRatingTooltip(book, 'hardcover')"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
<img
|
||||
src="https://assets.hardcover.app/static/favicon.ico"
|
||||
alt="Hardcover"
|
||||
class="w-5 h-5 object-contain transform transition duration-200 hover:scale-125 hover:drop-shadow-lg"
|
||||
/>
|
||||
<span class="font-semibold">
|
||||
{{ getRatingPercent(book.metadata!.hardcoverRating) }}%
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (book?.metadata?.googleId) {
|
||||
<a
|
||||
class="flex items-center gap-1"
|
||||
[href]="'https://books.google.com/books?id=' + book.metadata!.googleId"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<img
|
||||
src="https://books.google.com/favicon.ico"
|
||||
alt="Google Books"
|
||||
class="w-5 h-5 object-contain transform transition duration-200 hover:scale-125 hover:drop-shadow-lg"
|
||||
/>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (book?.metadata?.categories?.length) {
|
||||
<div class="overflow-x-auto scrollbar-hide max-w-7xl pt-2 md:pt-0">
|
||||
<div class="flex gap-2 w-max max-w-[1150px]">
|
||||
@for (category of book.metadata!.categories; track category) {
|
||||
<a (click)="goToCategory(category)" class="shrink-0 no-underline cursor-pointer">
|
||||
<p-tag [value]="category"></p-tag>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="grid md:grid-cols-3 gap-y-2.5 text-sm pt-2 md:pt-4 text-gray-700 dark:text-gray-300 max-w-5xl">
|
||||
<p class="whitespace-nowrap max-w-[250px] overflow-hidden text-ellipsis">
|
||||
<span class="font-bold">Publisher: </span>
|
||||
@if (book?.metadata?.publisher) {
|
||||
<span class="underline hover:opacity-80 cursor-pointer" (click)="goToPublisher(book?.metadata?.publisher!)">
|
||||
{{ book?.metadata?.publisher }}
|
||||
</span>
|
||||
} @else {
|
||||
<span>-</span>
|
||||
}
|
||||
</p>
|
||||
<p><strong>Published:</strong> {{ book?.metadata!.publishedDate || '-' }}</p>
|
||||
<p><strong>Language:</strong> {{ book?.metadata!.language || '-' }}</p>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">File Type:</span>
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200"
|
||||
[ngClass]="getFileTypeColorClass(getFileExtension(book?.filePath))">
|
||||
{{ getFileExtension(book?.filePath) || '-' }}
|
||||
</span>
|
||||
</p>
|
||||
<p><strong>File Size:</strong> {{ getFileSizeInMB(book) }}</p>
|
||||
<p>
|
||||
<strong>ISBN:</strong>
|
||||
@if (book?.metadata?.isbn13 || book?.metadata?.isbn10) {
|
||||
{{ book.metadata!.isbn13 }}
|
||||
@if (book?.metadata?.isbn13 && book?.metadata?.isbn10) {
|
||||
/
|
||||
}
|
||||
{{ book.metadata!.isbn10 }}
|
||||
} @else {
|
||||
<span>-</span>
|
||||
}
|
||||
</p>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Read Status:</span>
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white cursor-pointer"
|
||||
[ngClass]="getStatusSeverityClass(selectedReadStatus)"
|
||||
(click)="menu.toggle($event)">
|
||||
{{ getStatusLabel(selectedReadStatus) }}
|
||||
</span>
|
||||
<p-menu #menu [popup]="true" [model]="readStatusMenuItems"></p-menu>
|
||||
</p>
|
||||
<p class="whitespace-nowrap flex items-center">
|
||||
<span class="font-bold mr-2">Progress:</span>
|
||||
<span class="inline-flex items-center">
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white"
|
||||
[ngClass]="getProgressColorClass(getProgressPercent(book))">
|
||||
{{ getProgressPercent(book) !== null ? getProgressPercent(book) + '%' : 'N/A' }}
|
||||
</span>
|
||||
@if (getProgressPercent(book) !== null) {
|
||||
<p-button
|
||||
pTooltip="Reset progress"
|
||||
tooltipPosition="bottom"
|
||||
icon="pi pi-refresh"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
class="ml-1 custom-button-padding"
|
||||
(onClick)="resetProgress(book)">
|
||||
</p-button>
|
||||
}
|
||||
</span>
|
||||
</p>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Metadata Match:</span>
|
||||
@if (book?.metadataMatchScore != null) {
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200 border"
|
||||
[ngClass]="getMatchScoreColorClass(book?.metadataMatchScore!)">
|
||||
{{ (book?.metadataMatchScore! * 100) | number:'1.0-0' }}%
|
||||
</span>
|
||||
} @else {
|
||||
<span>-</span>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-semibold text-sm">File Path:</span>
|
||||
<i
|
||||
class="pi cursor-pointer text-sm"
|
||||
[ngClass]="showFilePath ? 'pi-eye-slash' : 'pi-eye'"
|
||||
(click)="showFilePath = !showFilePath"
|
||||
></i>
|
||||
@if (showFilePath) {
|
||||
<code class="text-xs font-mono truncate text-gray-300">{{ book?.filePath }}</code>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (userService.userState$ | async; as userData) {
|
||||
<div class="flex flex-wrap gap-3 pt-6">
|
||||
@if (book!.bookType === 'PDF') {
|
||||
@if (readMenuItems$ | async; as readItems) {
|
||||
<p-splitbutton
|
||||
label="Read"
|
||||
icon="pi pi-book"
|
||||
[model]="readItems"
|
||||
(onClick)="read(book.id, 'ngx')"
|
||||
severity="primary"/>
|
||||
}
|
||||
}
|
||||
@if (book!.bookType !== 'PDF') {
|
||||
<p-button
|
||||
label="Read"
|
||||
icon="pi pi-book"
|
||||
(onClick)="read(book?.metadata!.bookId, undefined)"
|
||||
severity="primary"/>
|
||||
}
|
||||
<p-button
|
||||
label="Shelf"
|
||||
icon="pi pi-folder"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="assignShelf(book.id)">
|
||||
</p-button>
|
||||
@if (userData.permissions.canDownload || userData.permissions.admin) {
|
||||
<p-button
|
||||
label="Download"
|
||||
icon="pi pi-download"
|
||||
severity="success"
|
||||
outlined
|
||||
(onClick)="download(book.id)">
|
||||
</p-button>
|
||||
}
|
||||
@if (userData.permissions.canEmailBook || userData.permissions.admin) {
|
||||
@if (emailMenuItems$ | async; as emailItems) {
|
||||
<p-splitbutton
|
||||
label="Quick Send"
|
||||
icon="pi pi-send"
|
||||
[model]="emailItems"
|
||||
(onClick)="quickSend(book.id)"
|
||||
outlined
|
||||
severity="info">
|
||||
</p-splitbutton>
|
||||
}
|
||||
}
|
||||
@if (userData.permissions.canEditMetadata || userData.permissions.admin) {
|
||||
@if (refreshMenuItems$ | async; as refreshItems) {
|
||||
<p-splitbutton
|
||||
[label]="isAutoFetching ? 'Fetching...' : 'Auto Fetch'"
|
||||
[icon]="isAutoFetching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
[outlined]="true"
|
||||
[model]="refreshItems"
|
||||
severity="warn"
|
||||
(onClick)="quickRefresh(book.id)"
|
||||
[disabled]="isAutoFetching"
|
||||
pTooltip="Automatically fetch metadata using default sources"
|
||||
tooltipPosition="top">
|
||||
</p-splitbutton>
|
||||
}
|
||||
}
|
||||
@if (userData.permissions.canDeleteBook || userData.permissions.admin) {
|
||||
@if (otherItems$ | async; as otherItems) {
|
||||
<p-button icon="pi pi-ellipsis-v" outlined severity="danger" (click)="entitymenu.toggle($event)"></p-button>
|
||||
<p-menu #entitymenu [model]="otherItems" [popup]="true" appendTo="body"></p-menu>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-4 pb-2 pt-4 border border-[var(--border-color)] rounded-xl">
|
||||
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }" class="transition-all duration-300 overflow-hidden description-container">
|
||||
<div class="readonly-editor px-2">
|
||||
<p-editor #quillEditor [readonly]="true" [style]="{height: '225px'}" [(ngModel)]="book.metadata!.description">
|
||||
<ng-template #header>
|
||||
</ng-template>
|
||||
</p-editor>
|
||||
</div>
|
||||
</div>
|
||||
@if (book.metadata!.description && book.metadata!.description.length > 500) {
|
||||
<p-button
|
||||
[label]="isExpanded ? 'Show less' : 'Show more'"
|
||||
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
|
||||
iconPos="right"
|
||||
size="small"
|
||||
text
|
||||
(click)="toggleExpand()">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="pt-4 space-y-4 pb-6">
|
||||
@if (bookInSeries.length > 0) {
|
||||
<div>
|
||||
<h3 class="text-xl font-semibold pt-2">More in the Series</h3>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of bookInSeries; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component
|
||||
[book]="book"
|
||||
></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
}
|
||||
@if (recommendedBooks.length > 0) {
|
||||
<div>
|
||||
<h3 class="text-xl font-semibold">Similar Books</h3>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of recommendedBooks; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component
|
||||
[book]="book.book"
|
||||
></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
::ng-deep .readonly-editor .p-editor {
|
||||
.p-editor-toolbar.ql-snow {
|
||||
padding: 0 !important;
|
||||
border: none !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.p-editor-content.ql-snow {
|
||||
border: none !important;
|
||||
border-end-end-radius: 0 !important;
|
||||
border-end-start-radius: 0 !important;
|
||||
}
|
||||
|
||||
.ql-editor {
|
||||
padding: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .readonly-editor .ql-container {
|
||||
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;
|
||||
}
|
||||
|
||||
.scrollbar-hide {
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none; /* for IE 10+ */
|
||||
}
|
||||
|
||||
.dashboard-scroller-infinite {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 0.25rem;
|
||||
gap: 1.25rem;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
width: 101px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
flex-basis: 101px;
|
||||
}
|
||||
|
||||
.description-container {
|
||||
max-height: 58px;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.description-container .description-content {
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.line-clamp-none {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.series-number-overlay {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
font-size: 0.8rem;
|
||||
padding: 1px 3px;
|
||||
border-radius: 3px;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
::ng-deep .custom-button-padding .p-button {
|
||||
padding-block: 0rem !important;
|
||||
}
|
||||
|
||||
::ng-deep .custom-tag-padding {
|
||||
padding: 0.1rem !important;
|
||||
}
|
||||
|
||||
+535
@@ -0,0 +1,535 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, Optional, SimpleChanges, ViewChild} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AsyncPipe, DecimalPipe, NgClass} from '@angular/common';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Rating, RatingRateEvent} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Book, BookMetadata, BookRecommendation, ReadStatus} from '../../../book/model/book.model';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
import {BookSenderComponent} from '../../../book/components/book-sender/book-sender.component';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {EmailService} from '../../../settings/email/email.service';
|
||||
import {ShelfAssignerComponent} from '../../../book/components/shelf-assigner/shelf-assigner.component';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Editor} from 'primeng/editor';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||
import {Router} from '@angular/router';
|
||||
import {filter, map, take} from 'rxjs/operators';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {BookCardLiteComponent} from '../../../book/components/book-card-lite/book-card-lite-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, Editor, ProgressBar, Menu, InfiniteScrollDirective, BookCardLiteComponent]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@Input() recommendedBooks: BookRecommendation[] = [];
|
||||
@ViewChild(Editor) quillEditor!: Editor;
|
||||
private originalRecommendedBooks: BookRecommendation[] = [];
|
||||
|
||||
private dialogService = inject(DialogService);
|
||||
private emailService = inject(EmailService);
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
protected userService = inject(UserService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private router = inject(Router);
|
||||
|
||||
private dialogRef?: DynamicDialogRef;
|
||||
|
||||
constructor(@Optional() dialogRef?: DynamicDialogRef) {
|
||||
this.dialogRef = dialogRef;
|
||||
}
|
||||
|
||||
emailMenuItems$!: Observable<MenuItem[]>;
|
||||
readMenuItems$!: Observable<MenuItem[]>;
|
||||
refreshMenuItems$!: Observable<MenuItem[]>;
|
||||
otherItems$!: Observable<MenuItem[]>;
|
||||
bookInSeries: Book[] = [];
|
||||
|
||||
isExpanded = false;
|
||||
showFilePath = false;
|
||||
isAutoFetching = false;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
|
||||
readStatusOptions = [
|
||||
{label: 'Unread', value: ReadStatus.UNREAD},
|
||||
{label: 'Reading', value: ReadStatus.READING},
|
||||
{label: 'Re-reading', value: ReadStatus.RE_READING},
|
||||
{label: 'Partially Read', value: ReadStatus.PARTIALLY_READ},
|
||||
{label: 'Paused', value: ReadStatus.PAUSED},
|
||||
{label: 'Read', value: ReadStatus.READ},
|
||||
{label: 'Won’t Read', value: ReadStatus.WONT_READ},
|
||||
{label: 'Abandoned', value: ReadStatus.ABANDONED}
|
||||
];
|
||||
|
||||
selectedReadStatus: ReadStatus = ReadStatus.UNREAD;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.emailMenuItems$ = this.book$.pipe(
|
||||
map(book => book?.metadata ?? null),
|
||||
filter((metadata): metadata is BookMetadata => metadata != null),
|
||||
map((metadata): MenuItem[] => [
|
||||
{
|
||||
label: 'Custom Send',
|
||||
command: () => {
|
||||
this.dialogService.open(BookSenderComponent, {
|
||||
header: 'Send Book to Email',
|
||||
modal: true,
|
||||
closable: true,
|
||||
style: {position: 'absolute', top: '20%'},
|
||||
data: {bookId: metadata.bookId}
|
||||
});
|
||||
}
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
this.refreshMenuItems$ = this.book$.pipe(
|
||||
filter((book): book is Book => book !== null),
|
||||
map((book): MenuItem[] => [
|
||||
{
|
||||
label: 'Granular Refresh',
|
||||
icon: 'pi pi-database',
|
||||
command: () => {
|
||||
this.dialogService.open(MetadataFetchOptionsComponent, {
|
||||
header: 'Metadata Refresh Options',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
bookIds: [book.id],
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
this.readMenuItems$ = this.book$.pipe(
|
||||
filter((book): book is Book => book !== null),
|
||||
map((book): MenuItem[] => [
|
||||
{
|
||||
label: 'Streaming Reader',
|
||||
command: () => this.read(book.id, 'streaming')
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
this.otherItems$ = this.book$.pipe(
|
||||
filter((book): book is Book => book !== null),
|
||||
map((book): MenuItem[] => [
|
||||
{
|
||||
label: 'Delete Book',
|
||||
icon: 'pi pi-trash',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete "${book.metadata?.title}"?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([book.id])).subscribe({
|
||||
next: () => {
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
this.dialogRef?.close();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(
|
||||
filter(user => !!user),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(user => {
|
||||
this.metadataCenterViewMode = user?.userSettings.metadataCenterViewMode ?? 'route';
|
||||
});
|
||||
|
||||
this.book$
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
filter((book): book is Book => book != null && book.metadata != null)
|
||||
)
|
||||
.subscribe(book => {
|
||||
const metadata = book.metadata;
|
||||
this.isAutoFetching = false;
|
||||
this.loadBooksInSeriesAndFilterRecommended(metadata!.bookId);
|
||||
if (this.quillEditor?.quill) {
|
||||
this.quillEditor.quill.root.innerHTML = metadata!.description;
|
||||
}
|
||||
this.selectedReadStatus = book.readStatus ?? ReadStatus.UNREAD;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['recommendedBooks']) {
|
||||
this.originalRecommendedBooks = [...this.recommendedBooks];
|
||||
this.book$.pipe(take(1)).subscribe(book => this.filterRecommendations(book));
|
||||
}
|
||||
}
|
||||
|
||||
private loadBooksInSeriesAndFilterRecommended(bookId: number): void {
|
||||
this.bookService.getBooksInSeries(bookId).subscribe(bookInSeries => {
|
||||
bookInSeries.sort((a, b) => (a.metadata?.seriesNumber ?? 0) - (b.metadata?.seriesNumber ?? 0));
|
||||
this.bookInSeries = bookInSeries;
|
||||
this.originalRecommendedBooks = [...this.recommendedBooks];
|
||||
this.book$.pipe(take(1)).subscribe(book => this.filterRecommendations(book));
|
||||
});
|
||||
}
|
||||
|
||||
private filterRecommendations(book: Book | null): void {
|
||||
if (!this.originalRecommendedBooks) return;
|
||||
const bookInSeriesIds = new Set(this.bookInSeries.map(book => book.id));
|
||||
this.recommendedBooks = this.originalRecommendedBooks.filter(
|
||||
rec => !bookInSeriesIds.has(rec.book.id)
|
||||
);
|
||||
}
|
||||
|
||||
toggleExpand(): void {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
read(bookId: number | undefined, reader: "ngx" | "streaming" | undefined): void {
|
||||
if (bookId) this.bookService.readBook(bookId, reader);
|
||||
}
|
||||
|
||||
download(bookId: number) {
|
||||
this.bookService.downloadFile(bookId);
|
||||
}
|
||||
|
||||
quickRefresh(bookId: number) {
|
||||
this.isAutoFetching = true;
|
||||
const request: MetadataRefreshRequest = {
|
||||
quick: true,
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: [bookId],
|
||||
};
|
||||
this.bookService.autoRefreshMetadata(request).subscribe();
|
||||
setTimeout(() => {
|
||||
this.isAutoFetching = false;
|
||||
}, 15000);
|
||||
}
|
||||
|
||||
quickSend(bookId: number) {
|
||||
this.emailService.emailBookQuick(bookId).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: 'Success',
|
||||
detail: 'The book sending has been scheduled.',
|
||||
}),
|
||||
error: (err) => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err?.error?.message || 'An error occurred while sending the book.',
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
assignShelf(bookId: number) {
|
||||
this.dialogService.open(ShelfAssignerComponent, {
|
||||
header: `Update Book's Shelves`,
|
||||
modal: true,
|
||||
closable: true,
|
||||
contentStyle: {overflow: 'auto'},
|
||||
baseZIndex: 10,
|
||||
style: {position: 'absolute', top: '15%'},
|
||||
data: {book: this.bookService.getBookByIdFromState(bookId)}
|
||||
});
|
||||
}
|
||||
|
||||
isMetadataFullyLocked(metadata: BookMetadata): boolean {
|
||||
const lockedKeys = Object.keys(metadata).filter(k => k.endsWith('Locked'));
|
||||
return lockedKeys.length > 0 && lockedKeys.every(k => metadata[k] === true);
|
||||
}
|
||||
|
||||
getFileSizeInMB(book: Book | null): string {
|
||||
const sizeKb = book?.fileSizeKb;
|
||||
return sizeKb != null ? `${(sizeKb / 1024).toFixed(2)} MB` : '-';
|
||||
}
|
||||
|
||||
getProgressPercent(book: Book | null): number | undefined {
|
||||
if (!book) return;
|
||||
return book.bookType === 'PDF' ? book.pdfProgress?.percentage
|
||||
: book.bookType === 'CBX' ? book.cbxProgress?.percentage
|
||||
: book.epubProgress?.percentage;
|
||||
}
|
||||
|
||||
getFileExtension(filePath?: string): string | null {
|
||||
if (!filePath) return null;
|
||||
const parts = filePath.split('.');
|
||||
if (parts.length < 2) return null;
|
||||
return parts.pop()?.toUpperCase() || null;
|
||||
}
|
||||
|
||||
getFileTypeColorClass(fileType: string | null | undefined): string {
|
||||
if (!fileType) return 'bg-gray-600 text-white';
|
||||
switch (fileType.toLowerCase()) {
|
||||
case 'pdf':
|
||||
return 'bg-pink-700 text-white';
|
||||
case 'epub':
|
||||
return 'bg-indigo-600 text-white';
|
||||
case 'cbz':
|
||||
return 'bg-teal-600 text-white';
|
||||
case 'cbr':
|
||||
return 'bg-purple-700 text-white';
|
||||
case 'cb7':
|
||||
return 'bg-blue-700 text-white';
|
||||
default:
|
||||
return 'bg-gray-600 text-white';
|
||||
}
|
||||
}
|
||||
|
||||
getStarColorScaled(rating?: number | null, maxScale: number = 5): string {
|
||||
if (rating == null) {
|
||||
return 'rgb(203, 213, 225)';
|
||||
}
|
||||
const normalized = rating / maxScale;
|
||||
if (normalized >= 0.9) {
|
||||
return 'rgb(34, 197, 94)';
|
||||
} else if (normalized >= 0.75) {
|
||||
return 'rgb(52, 211, 153)';
|
||||
} else if (normalized >= 0.6) {
|
||||
return 'rgb(234, 179, 8)';
|
||||
} else if (normalized >= 0.4) {
|
||||
return 'rgb(249, 115, 22)';
|
||||
} else {
|
||||
return 'rgb(239, 68, 68)';
|
||||
}
|
||||
}
|
||||
|
||||
getMatchScoreColorClass(score: number): string {
|
||||
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';
|
||||
}
|
||||
|
||||
getStatusSeverityClass(status: string): string {
|
||||
const normalized = status?.toUpperCase();
|
||||
switch (normalized) {
|
||||
case 'UNREAD':
|
||||
return 'bg-gray-500';
|
||||
case 'PAUSED':
|
||||
return 'bg-zinc-600';
|
||||
case 'READING':
|
||||
return 'bg-blue-600';
|
||||
case 'RE_READING':
|
||||
return 'bg-indigo-600';
|
||||
case 'READ':
|
||||
return 'bg-green-600';
|
||||
case 'PARTIALLY_READ':
|
||||
return 'bg-yellow-600';
|
||||
case 'ABANDONED':
|
||||
return 'bg-red-600';
|
||||
case 'WONT_READ':
|
||||
return 'bg-pink-700';
|
||||
default:
|
||||
return 'bg-gray-600';
|
||||
}
|
||||
}
|
||||
|
||||
getProgressColorClass(progress: number | null | undefined): string {
|
||||
if (progress == null) return 'bg-gray-600';
|
||||
return 'bg-blue-500';
|
||||
}
|
||||
|
||||
onPersonalRatingChange(book: Book, {value: personalRating}: RatingRateEvent): void {
|
||||
if (!book?.metadata) return;
|
||||
|
||||
const updatedMetadata = {...book.metadata, personalRating};
|
||||
|
||||
this.bookService.updateBookMetadata(book.id, {
|
||||
metadata: updatedMetadata,
|
||||
clearFlags: {personalRating: false}
|
||||
}, false).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Rating Saved',
|
||||
detail: 'Personal rating updated successfully'
|
||||
});
|
||||
},
|
||||
error: err => {
|
||||
console.error('Failed to update personal rating:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: 'Could not update personal rating'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
goToAuthorBooks(author: string): void {
|
||||
this.handleMetadataClick('author', author);
|
||||
}
|
||||
|
||||
goToCategory(category: string): void {
|
||||
this.handleMetadataClick('category', category);
|
||||
}
|
||||
|
||||
goToSeries(seriesName: string): void {
|
||||
this.handleMetadataClick('series', seriesName);
|
||||
}
|
||||
|
||||
goToPublisher(publisher: string): void {
|
||||
this.handleMetadataClick('publisher', publisher);
|
||||
}
|
||||
|
||||
private navigateToFilteredBooks(filterKey: string, filterValue: string): void {
|
||||
this.router.navigate(['/all-books'], {
|
||||
queryParams: {
|
||||
view: 'grid',
|
||||
sort: 'title',
|
||||
direction: 'asc',
|
||||
sidebar: true,
|
||||
filter: `${filterKey}:${filterValue}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private handleMetadataClick(filterKey: string, filterValue: string): void {
|
||||
if (this.metadataCenterViewMode === 'dialog') {
|
||||
this.dialogRef?.close();
|
||||
setTimeout(() => this.navigateToFilteredBooks(filterKey, filterValue), 200);
|
||||
} else {
|
||||
this.navigateToFilteredBooks(filterKey, filterValue);
|
||||
}
|
||||
}
|
||||
|
||||
getRatingTooltip(book: Book, source: 'amazon' | 'goodreads' | 'hardcover'): string {
|
||||
const meta = book?.metadata;
|
||||
if (!meta) return '';
|
||||
|
||||
switch (source) {
|
||||
case 'amazon':
|
||||
return meta.amazonRating != null
|
||||
? `★ ${meta.amazonRating} | ${meta.amazonReviewCount?.toLocaleString() ?? '0'} reviews`
|
||||
: '';
|
||||
case 'goodreads':
|
||||
return meta.goodreadsRating != null
|
||||
? `★ ${meta.goodreadsRating} | ${meta.goodreadsReviewCount?.toLocaleString() ?? '0'} reviews`
|
||||
: '';
|
||||
case 'hardcover':
|
||||
return meta.hardcoverRating != null
|
||||
? `★ ${meta.hardcoverRating} | ${meta.hardcoverReviewCount?.toLocaleString() ?? '0'} reviews`
|
||||
: '';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
getRatingPercent(rating: number | null | undefined): number {
|
||||
if (rating == null) return 0;
|
||||
return Math.round((rating / 5) * 100);
|
||||
}
|
||||
|
||||
readStatusMenuItems = this.readStatusOptions.map(option => ({
|
||||
label: option.label,
|
||||
command: () => this.updateReadStatus(option.value)
|
||||
}));
|
||||
|
||||
getStatusLabel(value: string): string {
|
||||
return this.readStatusOptions.find(o => o.value === value)?.label.toUpperCase() ?? 'UNSET';
|
||||
}
|
||||
|
||||
updateReadStatus(status: ReadStatus): void {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.book$.pipe(take(1)).subscribe(book => {
|
||||
if (!book || !book.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookService.updateBookReadStatus(book.id, status).subscribe({
|
||||
next: () => {
|
||||
this.selectedReadStatus = status;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Read Status Updated',
|
||||
detail: `Marked as "${this.getStatusLabel(status)}"`,
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to update read status:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: 'Could not update read status.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
resetProgress(book: Book): void {
|
||||
this.confirmationService.confirm({
|
||||
message: `Reset reading progress for "${book.metadata?.title}"?`,
|
||||
header: 'Confirm Reset',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'Cancel',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookService.resetProgress(book.id).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Progress Reset',
|
||||
detail: 'Reading progress has been reset.',
|
||||
life: 1500
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed',
|
||||
detail: 'Could not reset progress.',
|
||||
life: 1500
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user