- Add option to sort sidebar shelf and library

- Move user settings to a separate table
- Make settings tabs' elements more consistent
This commit is contained in:
adityachandelgit
2025-05-16 20:34:05 -06:00
committed by Aditya Chandel
parent 4cb82d2ba7
commit 5d1dd1576c
95 changed files with 1161 additions and 746 deletions
@@ -1,20 +0,0 @@
<div class="rounded-xl overflow-hidden">
<p-tabs [value]="tab" lazy="true">
<p-tablist>
<p-tab value="view">Book Details</p-tab>
<p-tab *ngIf="canEditMetadata" value="edit">Edit Metadata</p-tab>
<p-tab *ngIf="canEditMetadata" value="match">Search Metadata</p-tab>
</p-tablist>
<p-tabpanels class="h-[calc(100vh-10rem)]">
<p-tabpanel value="view">
<app-metadata-viewer [book]="book" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
</p-tabpanel>
<p-tabpanel *ngIf="canEditMetadata" value="edit">
<app-metadata-editor></app-metadata-editor>
</p-tabpanel>
<p-tabpanel *ngIf="canEditMetadata" value="match">
<app-metadata-searcher></app-metadata-searcher>
</p-tabpanel>
</p-tabpanels>
</p-tabs>
</div>
@@ -1,106 +0,0 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {BookMetadataCenterService} from './book-metadata-center.service';
import {UserService} from '../../settings/user-management/user.service';
import {Book, BookRecommendation} from '../../book/model/book.model';
import {Subscription} from 'rxjs';
import {distinctUntilChanged, filter, map, switchMap, 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 {NgIf} from '@angular/common';
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
@Component({
selector: 'app-book-metadata-center',
standalone: true,
templateUrl: './book-metadata-center.component.html',
styleUrl: './book-metadata-center.component.scss',
imports: [
TabList,
Tabs,
Tab,
NgIf,
TabPanels,
MetadataViewerComponent,
TabPanel,
MetadataEditorComponent,
MetadataSearcherComponent
]
})
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
private route = inject(ActivatedRoute);
private bookService = inject(BookService);
private metadataCenterService = inject(BookMetadataCenterService);
private userService = inject(UserService);
private appSettingsService = inject(AppSettingsService);
book: Book | undefined;
recommendedBooks: BookRecommendation[] = [];
tab: string = 'view';
canEditMetadata: boolean = false;
private userSubscription: Subscription = Subscription.EMPTY;
private routeSubscription: Subscription = Subscription.EMPTY;
private appSettings$ = this.appSettingsService.appSettings$;
ngOnInit(): void {
this.bookService.loadBooks();
this.routeSubscription = this.route.paramMap.pipe(
switchMap(params => {
const bookId = Number(params.get('bookId'));
if (isNaN(bookId)) throw new Error('Invalid book ID');
return this.route.queryParamMap.pipe(
map(queryParams => ({
bookId,
tab: queryParams.get('tab') ?? 'view'
}))
);
}),
switchMap(({bookId, tab}) => {
const validTabs = ['view', 'edit', 'match'];
this.tab = validTabs.includes(tab) ? tab : 'view';
return this.bookService.getBookByIdFromAPI(bookId, true);
}),
filter(book => !!book && !!book.metadata),
distinctUntilChanged((prev, curr) => prev.id === curr.id)
).subscribe(book => {
this.book = book;
this.metadataCenterService.emitBookChanged(book);
this.metadataCenterService.emitMetadata(book.metadata!);
this.fetchBookRecommendationsIfNeeded(book.metadata!.bookId);
});
this.userSubscription = this.userService.userData$.subscribe(userData => {
const userPermissions = userData?.permissions;
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
});
}
ngOnDestroy(): void {
this.userSubscription.unsubscribe();
this.routeSubscription.unsubscribe();
this.metadataCenterService.emitBookChanged(null);
}
private fetchBookRecommendationsIfNeeded(bookId: number): void {
this.appSettings$
.pipe(
filter(settings => settings != null),
take(1)
)
.subscribe(settings => {
const similarBookRecommendation = settings!.similarBookRecommendation ?? false;
if (similarBookRecommendation) {
this.bookService.getBookRecommendations(bookId).subscribe(recommendations => {
this.recommendedBooks = recommendations;
});
}
});
}
}
@@ -1,24 +0,0 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {Book, BookMetadata} from '../../book/model/book.model';
@Injectable({
providedIn: 'root'
})
export class BookMetadataCenterService {
private bookMetadataSubject = new BehaviorSubject<BookMetadata | null>(null);
currentMetadata$ = this.bookMetadataSubject.asObservable();
emitMetadata(bookMetadata: BookMetadata) {
this.bookMetadataSubject.next(bookMetadata);
}
bookChangedSubject = new BehaviorSubject<Book | null>(null);
bookChanged$ = this.bookChangedSubject.asObservable();
emitBookChanged(book: Book | null) {
this.bookChangedSubject.next(book);
}
}
@@ -1,315 +0,0 @@
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<div *ngIf="isLoading" class="absolute inset-0 bg-black opacity-25 z-10"></div>
<p-progressSpinner *ngIf="isLoading" [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
<div class="overflow-y-scroll flex-1">
<div class="flex flex-row w-full gap-4">
<div class="flex flex-col items-center gap-2 relative">
<img
[attr.src]="urlHelper.getCoverUrl(metadata.bookId, metadata?.coverUpdatedOn)"
alt="Image"
width="250"
[ngClass]="{ 'brightness-50': isUploading }"
class="transition-all duration-300 ease-in-out"/>
<p-progressSpinner
*ngIf="isUploading"
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(metadata.bookId)"
pTooltip="Regenerate cover"
tooltipPosition="top"
[outlined]="true"
[disabled]="metadata['coverLocked']">
</p-button>
<p-fileupload
pTooltip="Upload cover"
tooltipPosition="top"
[disabled]="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>
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
<p-button *ngIf="metadata['coverLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col flex-grow pl-2">
<!-- Title and Subtitle -->
<div class="flex flex-row w-full gap-4 pb-1">
<div class="flex flex-col gap-1 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"/>
<p-button *ngIf="!metadata['titleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('title')" severity="success"></p-button>
<p-button *ngIf="metadata['titleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('title')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 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"/>
<p-button *ngIf="!metadata['subtitleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="success"></p-button>
<p-button *ngIf="metadata['subtitleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Authors and Publisher -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-2/3">
<label for="authors">Authors</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="authors" formControlName="authors" class="w-full"/>
<p-button *ngIf="!metadata['authorsLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('authors')" severity="success"></p-button>
<p-button *ngIf="metadata['authorsLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('authors')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="publisher">Publisher</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
<p-button *ngIf="!metadata['publisherLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publisher')" severity="success"></p-button>
<p-button *ngIf="metadata['publisherLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publisher')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Categories and Published Date -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-2/3">
<label for="categories">Categories</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="categories" formControlName="categories" class="w-full"/>
<p-button *ngIf="!metadata['categoriesLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('categories')" severity="success"></p-button>
<p-button *ngIf="metadata['categoriesLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('categories')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="publishedDate">Publish Date</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
<p-button *ngIf="!metadata['publishedDateLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="success"></p-button>
<p-button *ngIf="metadata['publishedDateLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="warn"></p-button>
</div>
</div>
</div>
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 basis-2/6">
<label for="seriesName">Series Name</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
<p-button *ngIf="!metadata['seriesNameLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesName')" severity="success"></p-button>
<p-button *ngIf="metadata['seriesNameLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesName')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 basis-1/6">
<label for="seriesNumber">Book Number</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="seriesNumber" formControlName="seriesNumber" class="w-full"/>
<p-button *ngIf="!metadata['seriesNumberLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesNumber')" severity="success"></p-button>
<p-button *ngIf="metadata['seriesNumberLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesNumber')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 basis-1/6">
<label for="seriesTotal">Books in Series</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="seriesTotal" formControlName="seriesTotal" class="w-full"/>
<p-button *ngIf="!metadata['seriesTotalLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('seriesTotal')" severity="success"></p-button>
<p-button *ngIf="metadata['seriesTotalLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('seriesTotal')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 basis-1/6">
<label for="language">Language</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="language" formControlName="language" class="w-full"/>
<p-button *ngIf="!metadata['languageLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('language')" severity="success"></p-button>
<p-button *ngIf="metadata['languageLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 basis-1/6">
<label for="pageCount">Page Count</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
<p-button *ngIf="!metadata['pageCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="success"></p-button>
<p-button *ngIf="metadata['pageCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- ISBN, Language, Review Count -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-1/4">
<label for="isbn10">ISBN 10</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
<p-button *ngIf="!metadata['isbn10Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="success"></p-button>
<p-button *ngIf="metadata['isbn10Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="isbn13">ISBN 13</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
<p-button *ngIf="!metadata['isbn13Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="success"></p-button>
<p-button *ngIf="metadata['isbn13Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="reviewCount">Rating Count (Legacy)</label>
<div class="flex justify-between items-center gap-2">
<input [disabled]="true" pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
<p-button disabled icon="pi pi-lock" [outlined]="true" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="rating">Rating (Legacy)</label>
<div class="flex justify-between items-center gap-2">
<input [disabled]="true" pInputText id="rating" formControlName="rating" class="w-full"/>
<p-button disabled icon="pi pi-lock" [outlined]="true" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Review Count, Rating, Page Count -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-1/4">
<label for="amazonRatingCount">Amazon Rating Count</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="amazonRatingCount" formControlName="amazonReviewCount" class="w-full"/>
<p-button *ngIf="!metadata['amazonReviewCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('amazonReviewCount')" severity="success"></p-button>
<p-button *ngIf="metadata['amazonReviewCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('amazonReviewCount')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="amazonRating">Amazon Rating</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="amazonRating" formControlName="amazonRating" class="w-full"/>
<p-button *ngIf="!metadata['amazonRatingLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('amazonRating')" severity="success"></p-button>
<p-button *ngIf="metadata['amazonRatingLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('amazonRating')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="goodreadsReviewCount">Goodreads Rating Count</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="goodreadsReviewCount" formControlName="goodreadsReviewCount" class="w-full"/>
<p-button *ngIf="!metadata['goodreadsReviewCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('goodreadsReviewCount')" severity="success"></p-button>
<p-button *ngIf="metadata['goodreadsReviewCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('goodreadsReviewCount')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="goodreadsRating">Goodreads Rating</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="goodreadsRating" formControlName="goodreadsRating" class="w-full"/>
<p-button *ngIf="!metadata['goodreadsRatingLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('goodreadsRating')" severity="success"></p-button>
<p-button *ngIf="metadata['goodreadsRatingLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('goodreadsRating')" 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>
<p-tabpanel value="editor">
<form [formGroup]="metadataForm">
<p-editor #quillEditor formControlName="description" [readonly]="quillDisabled()" [style]="{ height: '215px' }">
<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="10"
[disabled]="quillDisabled()"
[ngModel]="htmlTextarea"
(ngModelChange)="onHtmlTextareaChange($event)"
[ngModelOptions]="{ standalone: true }"
placeholder="Edit raw HTML here">
</textarea>
</p-tabpanel>
</p-tabpanels>
</p-tabs>
<p-button *ngIf="!metadata['descriptionLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
<p-button *ngIf="metadata['descriptionLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
</div>
</div>
</div>
</div>
<div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider>
<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="pi pi-check" type="submit"></p-button>
</div>
</div>
</form>
@@ -1,392 +0,0 @@
import {Component, inject, OnInit, 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 {BookMetadataCenterService} from '../book-metadata-center.service';
import {AsyncPipe, NgClass, NgIf} from '@angular/common';
import {MessageService} from 'primeng/api';
import {BookMetadata} 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';
@Component({
selector: 'app-metadata-editor',
standalone: true,
templateUrl: './metadata-editor.component.html',
styleUrls: ['./metadata-editor.component.scss'],
imports: [
InputText,
Button,
Divider,
FormsModule,
AsyncPipe,
NgIf,
ReactiveFormsModule,
FileUpload,
ProgressSpinner,
NgClass,
Tooltip,
Editor,
Tabs,
TabList,
Tab,
TabPanels,
TabPanel
]
})
export class MetadataEditorComponent implements OnInit {
@ViewChild(Editor) quillEditor!: Editor;
private metadataCenterService = inject(BookMetadataCenterService);
private messageService = inject(MessageService);
private bookService = inject(BookService);
protected urlHelper = inject(UrlHelperService);
bookMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
metadataForm: FormGroup;
currentBookId!: number;
isUploading = false;
isLoading = false;
htmlTextarea = '';
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(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
amazonRating: new FormControl(''),
amazonReviewCount: new FormControl(''),
goodreadsRating: new FormControl(''),
goodreadsReviewCount: 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),
ratingLocked: new FormControl(false),
reviewCountLocked: new FormControl(false),
amazonRatingLocked: new FormControl(false),
amazonReviewCountLocked: new FormControl(false),
goodreadsRatingLocked: new FormControl(false),
goodreadsReviewCountLocked: new FormControl(false),
seriesNameLocked: new FormControl(false),
seriesNumberLocked: new FormControl(false),
seriesTotalLocked: new FormControl(false),
thumbnailUrlLocked: new FormControl(false),
});
}
ngOnInit(): void {
this.bookMetadata$.subscribe((metadata) => {
if (metadata) {
this.currentBookId = metadata.bookId;
if (this.quillEditor && this.quillEditor.quill) {
this.quillEditor.quill.root.innerHTML = metadata.description;
this.quillDisabled();
}
this.metadataForm.patchValue({
title: metadata.title || null,
subtitle: metadata.subtitle || null,
authors: (metadata.authors || []).sort().join(', '),
categories: (metadata.categories || []).sort().join(', '),
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,
amazonRating: metadata.amazonRating || null,
amazonReviewCount: metadata.amazonReviewCount || null,
goodreadsRating: metadata.goodreadsRating || null,
goodreadsReviewCount: metadata.goodreadsReviewCount || 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,
ratingLocked: metadata.ratingLocked || false,
reviewCountLocked: metadata.reviewCountLocked || false,
amazonRatingLocked: metadata.amazonRatingLocked || false,
amazonReviewCountLocked: metadata.amazonReviewCountLocked || false,
goodreadsRatingLocked: metadata.goodreadsRatingLocked || false,
goodreadsReviewCountLocked: metadata.goodreadsReviewCountLocked || 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: 'amazonReviewCountLocked', control: 'amazonReviewCount' },
{ key: 'amazonRatingLocked', control: 'amazonRating' },
{ key: 'goodreadsReviewCountLocked', control: 'goodreadsReviewCount' },
{ key: 'goodreadsRatingLocked', control: 'goodreadsRating' },
{ key: 'pageCountLocked', control: 'pageCount' },
{ key: 'descriptionLocked', control: 'description' },
{ key: 'seriesNameLocked', control: 'seriesName' },
{ key: 'seriesNumberLocked', control: 'seriesNumber' },
{ key: 'seriesTotalLocked', control: 'seriesTotal' }
];
lockableFields.forEach(({ key, control }) => {
const isLocked = metadata[key] === true;
const formControl = this.metadataForm.get(control);
if (formControl) {
isLocked ? formControl.disable() : formControl.enable();
}
});
this.metadataForm.get('reviewCount')?.disable();
this.metadataForm.get('rating')?.disable();
}
this.metadataForm.get('description')?.valueChanges
.pipe(debounceTime(100))
.subscribe(value => {
if (this.htmlTextarea !== value) {
this.htmlTextarea = value;
}
});
});
}
onSave(): void {
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
next: (response) => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.metadataCenterService.emitMetadata(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: '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 buildMetadata(shouldLockAllFields: boolean | undefined) {
const updatedBookMetadata: BookMetadata = {
bookId: this.currentBookId,
title: this.metadataForm.get('title')?.value,
subtitle: this.metadataForm.get('subtitle')?.value,
authors: this.metadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()),
categories: this.metadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()),
publisher: this.metadataForm.get('publisher')?.value,
publishedDate: this.metadataForm.get('publishedDate')?.value,
isbn10: this.metadataForm.get('isbn10')?.value,
isbn13: this.metadataForm.get('isbn13')?.value,
description: this.metadataForm.get('description')?.value,
pageCount: this.metadataForm.get('pageCount')?.value,
rating: this.metadataForm.get('rating')?.value,
reviewCount: this.metadataForm.get('reviewCount')?.value,
amazonRating: this.metadataForm.get('amazonRating')?.value,
amazonReviewCount: this.metadataForm.get('amazonReviewCount')?.value,
goodreadsRating: this.metadataForm.get('goodreadsRating')?.value,
goodreadsReviewCount: this.metadataForm.get('goodreadsReviewCount')?.value,
language: this.metadataForm.get('language')?.value,
seriesName: this.metadataForm.get('seriesName')?.value,
seriesNumber: this.metadataForm.get('seriesNumber')?.value,
seriesTotal: this.metadataForm.get('seriesTotal')?.value,
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,
ratingLocked: this.metadataForm.get('ratingLocked')?.value,
reviewCountLocked: this.metadataForm.get('reviewCountLocked')?.value,
amazonRatingLocked: this.metadataForm.get('amazonRatingLocked')?.value,
amazonReviewCountLocked: this.metadataForm.get('amazonReviewCountLocked')?.value,
goodreadsRatingLocked: this.metadataForm.get('goodreadsRatingLocked')?.value,
goodreadsReviewCountLocked: this.metadataForm.get('goodreadsReviewCountLocked')?.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}),
};
return updatedBookMetadata;
}
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
next: (response) => {
this.metadataCenterService.emitMetadata(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.metadataCenterService.emitMetadata(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'
});
}
});
}
}
@@ -1,148 +0,0 @@
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="h-full flex pt-1 flex-col">
<div class="overflow-y-scroll flex-1">
<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="info"
icon='pi pi-angle-left'
[ngStyle]="{'padding-left': '2rem', 'padding-right': '0.5rem'}"
[outlined]="true"
pTooltip="Move all missing fields" tooltipPosition="bottom"
(onClick)="copyMissing()"></p-button>
<p-button
severity="info"
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">
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
<p-button *ngIf="metadata['coverLocked']" 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>
<div *ngFor="let field of metadataFieldsTop" class="form-row">
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
<div class="input-container">
<p-button *ngIf="!metadata[field.lockedKey]" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
<p-button *ngIf="metadata[field.lockedKey]" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
<input 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 pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="input" readonly/>
</div>
</div>
<div *ngFor="let field of metadataDescription" class="form-row">
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
<div class="input-container">
<p-button *ngIf="!metadata[field.lockedKey]" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
<p-button *ngIf="metadata[field.lockedKey]" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
<textarea rows="6" 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="6" pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="input" readonly></textarea>
</div>
</div>
<div *ngFor="let field of metadataFieldsBottom" class="form-row">
<label for="{{field.controlName}}" class="label">{{ field.label }}</label>
<div class="input-container">
<p-button *ngIf="!metadata[field.lockedKey]" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="success"></p-button>
<p-button *ngIf="metadata[field.lockedKey]" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock(field.controlName)" severity="warn"></p-button>
<input 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 pInputText [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="info"
icon='pi pi-angle-left'
[ngStyle]="{'padding-left': '2rem', 'padding-right': '0.5rem'}"
[outlined]="true"
pTooltip="Move all missing fields" tooltipPosition="bottom"
(onClick)="copyMissing()"></p-button>
<p-button
severity="info"
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>
<div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider>
<div class="flex justify-between">
<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="pi pi-check" type="submit"></p-button>
</div>
</div>
</div>
</form>
@@ -1,55 +0,0 @@
.form-row {
display: flex;
align-items: center;
margin-bottom: 0.75rem;
width: 100%;
justify-content: flex-start;
}
.label {
width: 6rem;
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 0.5rem;
}
.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;
}
@@ -1,434 +0,0 @@
import {Component, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
import {BookMetadata} 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, NgForOf, NgIf, NgStyle} from '@angular/common';
import {Divider} from 'primeng/divider';
import {BookMetadataCenterService} from '../book-metadata-center.service';
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';
@Component({
selector: 'app-metadata-picker',
standalone: true,
templateUrl: './metadata-picker.component.html',
styleUrls: ['./metadata-picker.component.scss'],
imports: [
Button,
FormsModule,
InputText,
NgIf,
Divider,
ReactiveFormsModule,
NgClass,
NgStyle,
Tooltip,
AsyncPipe,
NgForOf,
Textarea
]
})
export class MetadataPickerComponent implements OnInit {
metadataFieldsTop = [
{label: 'Title', controlName: 'title', lockedKey: 'titleLocked', fetchedKey: 'title'},
{label: 'Authors', controlName: 'authors', lockedKey: 'authorsLocked', fetchedKey: 'authors'},
{label: 'Categories', controlName: 'categories', lockedKey: 'categoriesLocked', fetchedKey: 'categories'},
{label: 'Publisher', controlName: 'publisher', lockedKey: 'publisherLocked', fetchedKey: 'publisher'},
{label: 'Published', controlName: 'publishedDate', lockedKey: 'publishedDateLocked', fetchedKey: 'publishedDate'},
{label: 'ISBN-10', controlName: 'isbn10', lockedKey: 'isbn10Locked', fetchedKey: 'isbn10'},
{label: 'Language', controlName: 'language', lockedKey: 'languageLocked', fetchedKey: 'language'}
];
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: 'ISBN-13', controlName: 'isbn13', lockedKey: 'isbn13Locked', fetchedKey: 'isbn13'},
{label: 'Amazon Reviews', controlName: 'amazonReviewCount', lockedKey: 'amazonReviewCountLocked', fetchedKey: 'amazonReviewCount'},
{label: 'Amazon Rating', controlName: 'amazonRating', lockedKey: 'amazonRatingLocked', fetchedKey: 'amazonRating'},
{label: 'Goodreads Reviews', controlName: 'goodreadsReviewCount', lockedKey: 'goodreadsReviewCountLocked', fetchedKey: 'goodreadsReviewCount'},
{label: 'Goodreads Rating', controlName: 'goodreadsRating', lockedKey: 'goodreadsRatingLocked', fetchedKey: 'goodreadsRating'},
{label: 'Pages', controlName: 'pageCount', lockedKey: 'pageCountLocked', fetchedKey: 'pageCount'}
];
@Input() fetchedMetadata!: BookMetadata;
@Output() goBack = new EventEmitter<boolean>();
metadataForm: FormGroup;
currentBookId!: number;
copiedFields: Record<string, boolean> = {};
savedFields: Record<string, boolean> = {};
originalMetadata!: BookMetadata;
private metadataCenterService = inject(BookMetadataCenterService);
private messageService = inject(MessageService);
private bookService = inject(BookService);
protected urlHelper = inject(UrlHelperService);
bookMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
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(''),
amazonRating: new FormControl(''),
amazonReviewCount: new FormControl(''),
goodreadsRating: new FormControl(''),
goodreadsReviewCount: 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),
amazonRatingLocked: new FormControl(false),
amazonReviewCountLocked: new FormControl(false),
goodreadsRatingLocked: new FormControl(false),
goodreadsReviewCountLocked: new FormControl(false),
seriesNameLocked: new FormControl(false),
seriesNumberLocked: new FormControl(false),
seriesTotalLocked: new FormControl(false),
thumbnailUrlLocked: new FormControl(false),
});
}
ngOnInit(): void {
this.bookMetadata$.subscribe((metadata) => {
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().join(', '),
categories: (metadata.categories || []).sort().join(', '),
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,
amazonRating: metadata.amazonRating || null,
amazonReviewCount: metadata.amazonReviewCount || null,
goodreadsRating: metadata.goodreadsRating || null,
goodreadsReviewCount: metadata.goodreadsReviewCount || 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,
amazonRatingLocked: metadata.amazonRatingLocked || false,
amazonReviewCountLocked: metadata.amazonReviewCountLocked || false,
goodreadsRatingLocked: metadata.goodreadsRatingLocked || false,
goodreadsReviewCountLocked: metadata.goodreadsReviewCountLocked || 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.amazonReviewCountLocked) this.metadataForm.get('amazonReviewCount')?.disable();
if (metadata.amazonRatingLocked) this.metadataForm.get('amazonRating')?.disable();
if (metadata.goodreadsReviewCountLocked) this.metadataForm.get('goodreadsReviewCount')?.disable();
if (metadata.goodreadsRatingLocked) this.metadataForm.get('goodreadsRating')?.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 {
const updatedBookMetadata = this.buildMetadata(undefined);
this.bookService.updateBookMetadata(this.currentBookId, updatedBookMetadata, false).subscribe({
next: (bookMetadata) => {
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'});
this.metadataCenterService.emitMetadata(bookMetadata);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
});
}
private buildMetadata(shouldLockAllFields: boolean | undefined) {
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') : '',
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,
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,
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,
amazonRatingLocked: this.metadataForm.get('amazonRatingLocked')?.value,
amazonReviewCountLocked: this.metadataForm.get('amazonReviewCountLocked')?.value,
goodreadsRatingLocked: this.metadataForm.get('goodreadsRatingLocked')?.value,
goodreadsReviewCountLocked: this.metadataForm.get('goodreadsReviewCountLocked')?.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}),
};
return updatedBookMetadata;
}
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.buildMetadata(shouldLockAllFields), false).subscribe({
next: (response) => {
this.metadataCenterService.emitMetadata(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;
}
}
@@ -1,57 +0,0 @@
<form *ngIf="!selectedFetchedMetadata" class="flex flex-col w-full h-full pt-2" [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="flex w-full gap-x-4 items-end">
<div class="flex flex-col gap-1 w-3/12">
<label>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-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-4/12">
<label for="author">Author</label>
<input pInputText formControlName="author" id="author" class="w-full"/>
</div>
<div>
<p-button label="Search" type="submit" outlined="true" [disabled]="!isSearchEnabled || loading"></p-button>
</div>
</div>
<div *ngIf="loading" class="flex justify-center items-center">
<p-progress-spinner ariaLabel="loading"/>
</div>
<div *ngIf="!loading" class="mt-8 flex-1 overflow-y-auto">
<div *ngFor="let metadata of allFetchedMetadata" class="book-item flex flex-col w-full">
<div class="flex w-full flex-row book-item-content" (click)="onBookClick(metadata)">
<img [src]="metadata.thumbnailUrl || 'assets/images/missing-cover.jpg'" alt="Image" class="img-fixed-dimensions pr-2"/>
<div class=" flex flex-col w-full m-2">
<div class="flex flex-row gap-4 justify-between">
<p class="font-bold">{{ truncateText(metadata['title'], 90) }}</p>
<div class="flex gap-2">
<p>ISBN: {{ metadata['isbn10'] || metadata['asin'] }}</p>
<p> | </p>
<p>Published: {{ metadata['publishedDate'] }}</p>
</div>
</div>
<div class="flex gap-2">
<p>by {{ truncateText(metadata['authors'].join(', '), 70) }}</p>
<p> | </p>
<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>
<div *ngIf="selectedFetchedMetadata" class="h-full flex-auto">
<app-metadata-picker [fetchedMetadata]="selectedFetchedMetadata" (goBack)="onGoBack()"></app-metadata-picker>
</div>
@@ -1,36 +0,0 @@
.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);
}
@@ -1,182 +0,0 @@
import {Component, inject, 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 {NgForOf, NgIf} from '@angular/common';
import {MetadataProvider} from '../../model/provider.model';
import {FetchMetadataRequest} from '../../model/request/fetch-metadata-request.model';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MetadataPickerComponent} from '../metadata-picker/metadata-picker.component';
import {BookMetadataCenterService} from '../book-metadata-center.service';
import {MultiSelect} from 'primeng/multiselect';
import {Book, BookMetadata} from '../../../book/model/book.model';
import {BookService} from '../../../book/service/book.service';
import {combineLatest, Observable, Subscription, Subject, takeUntil} from 'rxjs';
import {AppSettings} from '../../../core/model/app-settings.model';
import {AppSettingsService} from '../../../core/service/app-settings.service';
import {distinctUntilChanged, filter, switchMap} from 'rxjs/operators';
import {ActivatedRoute, Router} from '@angular/router';
@Component({
selector: 'app-metadata-searcher',
templateUrl: './metadata-searcher.component.html',
styleUrls: ['./metadata-searcher.component.scss'],
imports: [ReactiveFormsModule, Button, InputText, Divider, NgForOf, NgIf, ProgressSpinner, MetadataPickerComponent, MultiSelect],
standalone: true
})
export class MetadataSearcherComponent implements OnInit, OnDestroy {
form: FormGroup;
providers = Object.values(MetadataProvider);
allFetchedMetadata: BookMetadata[] = [];
selectedFetchedMetadata!: BookMetadata | null;
bookId!: number;
loading: boolean = false;
private formBuilder = inject(FormBuilder);
private metadataCenterService = inject(BookMetadataCenterService);
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$;
bookChanged$: Observable<Book | null> = this.metadataCenterService.bookChanged$;
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.selectedFetchedMetadata = null;
this.allFetchedMetadata = [];
this.form.patchValue({
provider: Object.values(MetadataProvider),
title: '',
author: '',
});
}
return combineLatest([this.bookChanged$, this.appSettings$]);
}),
filter(([book, settings]) => !!book && !!settings),
distinctUntilChanged(([prevBook], [currBook]) => prevBook?.id === currBook?.id)
).subscribe(([book, settings]) => {
const autoBookSearchEnabled = settings!.autoBookSearch ?? false;
if (book) {
this.selectedFetchedMetadata = null;
this.allFetchedMetadata = [];
this.bookId = book.id;
this.form.patchValue({
provider: Object.values(MetadataProvider),
title: book.metadata?.title || null,
author: book.metadata?.authors?.length ? book.metadata.authors[0] : ''
});
if (autoBookSearchEnabled) {
this.onSubmit();
}
}
})
);
}
ngOnDestroy(): void {
this.cancelRequest$.next();
this.subscription.unsubscribe();
this.allFetchedMetadata = [];
this.selectedFetchedMetadata = null;
}
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 = Object.keys(MetadataProvider).filter(key =>
(this.form.get('provider')?.value as string[]).includes(MetadataProvider[key as keyof typeof MetadataProvider])
);
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((fetchedMetadata) => ({
...fetchedMetadata,
thumbnailUrl: fetchedMetadata.thumbnailUrl
}));
},
error: () => {
this.loading = false;
}
});
} else {
console.warn('Form is invalid. Please fill in all required fields.');
}
}
buildProviderLink(metadata: BookMetadata): string {
if (!metadata.provider || !metadata.providerBookId) {
throw new Error("Invalid metadata: 'provider' or 'providerBookId' is missing.");
}
switch (metadata.provider) {
case "Amazon":
return `<a href="https://www.amazon.com/dp/${metadata.providerBookId}" target="_blank">Amazon</a>`;
case "GoodReads":
return `<a href="https://www.goodreads.com/book/show/${metadata.providerBookId}" target="_blank">Goodreads</a>`;
case "Google":
return `<a href="https://books.google.com/books?id=${metadata.providerBookId}" target="_blank">Google</a>`;
default:
throw new Error(`Unsupported provider: ${metadata.provider}`);
}
}
truncateText(text: string | null, length: number): string {
const safeText = text ?? '';
return safeText.length > length ? safeText.substring(0, length) + '...' : safeText;
}
onBookClick(fetchedMetadata: BookMetadata) {
this.selectedFetchedMetadata = fetchedMetadata;
}
onGoBack() {
this.selectedFetchedMetadata = null;
}
sanitizeHtml(htmlString: string | null | undefined): string {
if (!htmlString) {
return '';
}
return htmlString.replace(/<\/?[^>]+(>|$)/g, '').trim();
}
}
@@ -1,161 +0,0 @@
<div class="pt-2 flex flex-col h-full overflow-hidden">
<div *ngIf="metadata$ | async as metadata">
<div class="flex flex-row">
<img [attr.src]="urlHelper.getCoverUrl(metadata.bookId, metadata?.coverUpdatedOn)"
class="book-cover placeholder"
alt="Cover of {{ metadata.title }}"
loading="lazy"
width="225"/>
<div class="flex flex-col justify-between">
<div class="pl-6 flex flex-col w-full">
<div class="flex flex-row items-center justify-between">
<div>
<p *ngIf="metadata.seriesName" class="italic">{{ metadata.seriesName }} #{{ metadata.seriesNumber }}</p>
<div class="flex items-center gap-2">
<p class="text-2xl font-bold m-0">{{ metadata.title }}</p>
<i
class="pi"
[ngClass]="isMetadataFullyLocked(metadata) ? 'pi-lock text-red-500' : 'pi-lock-open text-green-500'"
[title]="isMetadataFullyLocked(metadata) ? 'Metadata is locked' : 'Metadata is unlocked'"
style="font-size: 1.25rem;"
pTooltip="{{ isMetadataFullyLocked(metadata) ? 'This book metadata is locked.' : 'This book metadata is unlocked.' }}"
tooltipPosition="top">
</i>
</div>
<p class="text-xl">{{ getAuthorNames(metadata?.authors || []) }}</p>
</div>
</div>
<div class="flex items-center gap-2 pt-2">
<ng-container *ngIf="metadata.amazonRating || metadata.goodreadsRating; else legacyRating">
<p *ngIf="metadata.amazonRating" class="font-semibold">Amazon: {{ metadata.amazonRating }}</p>
<p-rating
[(ngModel)]="metadata.amazonRating"
readonly
stars="5"
[style.--p-rating-icon-active-color]="getStarColor(metadata.amazonRating)">
</p-rating>
<p *ngIf="metadata.amazonRating" class="font-semibold"> ({{ metadata.amazonReviewCount | number:'1.0-0' }})</p>
<p *ngIf="metadata.amazonRating && metadata.goodreadsRating">|</p>
<p *ngIf="metadata.goodreadsRating" class="font-semibold">Goodreads: {{ metadata.goodreadsRating }}</p>
<p-rating
[(ngModel)]="metadata.goodreadsRating"
readonly
stars="5"
[style.--p-rating-icon-active-color]="getStarColor(metadata.goodreadsRating)">
</p-rating>
<p *ngIf="metadata.goodreadsRating" class="font-semibold"> ({{ metadata.goodreadsReviewCount | number:'1.0-0' }})</p>
</ng-container>
<ng-template #legacyRating>
<p-rating
[(ngModel)]="metadata.rating"
readonly
stars="5"
[style.--p-rating-icon-active-color]="getStarColor(metadata.rating)">
</p-rating>
<p class="font-semibold">
{{ metadata?.reviewCount ? '(' + (metadata?.reviewCount | number:'1.0-0') + ' Ratings)' : 'No Ratings' }}
</p>
</ng-template>
</div>
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
<p-tag *ngFor="let category of metadata.categories" [value]="category" class="shrink-0"></p-tag>
</div>
<div class="grid gap-x-20 gap-y-2 pt-6" style="grid-template-columns: repeat(4, max-content);">
<p class="whitespace-nowrap"><span class="font-bold">Publisher:</span> {{ metadata.publisher || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">Published:</span> {{ metadata.publishedDate || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ metadata.language || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ metadata.isbn10 || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">ISBN 13:</span> {{ metadata.isbn13 || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">Page Count:</span> {{ metadata.pageCount || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB() }}</p>
</div>
<p class="pt-2"><span class="font-bold">File Path:</span> {{ book?.filePath }}</p>
</div>
<div *ngIf="userService.userData$ | async as userData" class="pl-6 pt-4 flex flex-row w-full gap-4">
<p-button label="Read" icon="pi pi-book" severity="info" (onClick)="read(metadata.bookId)"></p-button>
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
<p-button *ngIf="userData.permissions.canDownload" label="Download" icon="pi pi-download" severity="info" outlined (onClick)="download(metadata.bookId)"></p-button>
<p-splitbutton *ngIf="userData.permissions.canEmailBook" label="Quick Send" icon="pi pi-send" [model]="items" (onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
</div>
</div>
</div>
</div>
<p-divider></p-divider>
<div *ngIf="metadata$ | async as metadata" class="flex-1 overflow-auto space-y-2 px-2">
<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: '260px'}" [(ngModel)]="metadata.description">
<ng-template #header>
</ng-template>
</p-editor>
</div>
</div>
<div *ngIf="metadata.description && metadata.description.length > 100" class="text-left">
<button pButton
type="button"
[label]="isExpanded ? 'Show less' : 'Show more'"
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
iconPos="right"
class="p-button-text p-button-sm"
(click)="toggleExpand()">
</button>
</div>
<p-divider></p-divider>
<ng-container *ngIf="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">
<div class="dashboard-scroller-card" *ngFor="let book of recommendedBooks">
<app-book-card
[book]="book.book"
[isCheckboxEnabled]="false"
[readButtonHidden]="true"
[bottomBarHidden]="true">
</app-book-card>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="bookInSeries.length > 0">
<p-divider></p-divider>
<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">
<div class="dashboard-scroller-card" *ngFor="let book of bookInSeries">
<app-book-card
[book]="book"
[isCheckboxEnabled]="false"
[readButtonHidden]="true"
[bottomBarHidden]="true">
</app-book-card>
</div>
</div>
</div>
<p-divider></p-divider>
</ng-container>
</div>
</div>
@@ -1,64 +0,0 @@
::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;
}
.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;
}
@@ -1,182 +0,0 @@
import {Component, DestroyRef, inject, Input, OnInit, ViewChild} from '@angular/core';
import {Button, ButtonDirective} from 'primeng/button';
import {AsyncPipe, DecimalPipe, NgClass, NgForOf, NgIf} from '@angular/common';
import {first, Observable} from 'rxjs';
import {BookService} from '../../../book/service/book.service';
import {BookMetadataCenterService} from '../book-metadata-center.service';
import {Rating} from 'primeng/rating';
import {FormsModule} from '@angular/forms';
import {Tag} from 'primeng/tag';
import {Book, BookMetadata, BookRecommendation} 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 {MenuItem, MessageService} from 'primeng/api';
import {BookSenderComponent} from '../../../book/components/book-sender/book-sender.component';
import {DialogService} 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 {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Editor} from 'primeng/editor';
@Component({
selector: 'app-metadata-viewer',
standalone: true,
templateUrl: './metadata-viewer.component.html',
styleUrl: './metadata-viewer.component.scss',
imports: [Button, NgForOf, NgIf, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor]
})
export class MetadataViewerComponent implements OnInit {
@Input() book: Book | undefined;
@Input() recommendedBooks: BookRecommendation[] = [];
@ViewChild(Editor) quillEditor!: Editor;
private dialogService = inject(DialogService);
private emailService = inject(EmailService);
private messageService = inject(MessageService);
private bookService = inject(BookService);
private metadataCenterService = inject(BookMetadataCenterService);
protected urlHelper = inject(UrlHelperService);
protected userService = inject(UserService);
private destroyRef = inject(DestroyRef);
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
items: MenuItem[] | undefined;
bookInSeries: Book[] = [];
isExpanded = false;
ngOnInit(): void {
this.items = [
{
label: 'Custom Send',
command: () => {
this.metadata$.pipe(first()).subscribe((metadata) => {
if (metadata) {
this.dialogService.open(BookSenderComponent, {
header: 'Send Book to Email',
modal: true,
closable: true,
style: {
position: 'absolute',
top: '15%',
},
data: {
bookId: metadata.bookId,
}
});
}
});
}
}
];
this.metadata$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((metadata) => {
if (metadata) {
this.getBooksInSeries(metadata.bookId);
if (this.quillEditor && this.quillEditor.quill) {
this.quillEditor.quill.root.innerHTML = metadata.description;
}
}
});
}
toggleExpand(): void {
this.isExpanded = !this.isExpanded;
}
getBooksInSeries(bookId: number): void {
this.bookService.getBooksInSeries(bookId).subscribe((bookInSeries) => {
this.bookInSeries = bookInSeries;
});
}
read(bookId: number): void {
this.bookService.readBook(bookId);
}
getAuthorNames(authors: string[]): string {
return authors.join(', ');
}
download(bookId: number) {
this.bookService.downloadFile(bookId);
}
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) => {
const errorMessage = err?.error?.message || 'An error occurred while sending the book.';
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: errorMessage,
});
},
});
}
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(key => key.endsWith('Locked'));
if (lockedKeys.length === 0) {
return false;
}
return lockedKeys.every(key => metadata[key] === true);
}
getFileSizeInMB(): string {
const sizeKb = this.book?.fileSizeKb;
if (sizeKb != null) {
const sizeMb = sizeKb / 1024;
return `${sizeMb.toFixed(2)} MB`;
}
return '-';
}
getStarColor(rating?: number | null): string {
if (rating == null) {
return 'rgb(203, 213, 225)';
} else if (rating >= 4.5) {
return 'rgb(34, 197, 94)';
} else if (rating >= 4) {
return 'rgb(52, 211, 153)';
} else if (rating >= 3.5) {
return 'rgb(234, 179, 8)';
} else if (rating >= 2.5) {
return 'rgb(249, 115, 22)';
} else {
return 'rgb(239, 68, 68)';
}
}
}
@@ -1,79 +0,0 @@
<div class="flex flex-col space-y-6 p-4">
<table class="min-w-full table-auto border-collapse custom-table">
<thead>
<tr>
<th class="px-4 py-2 text-left font-semibold text-gray-300">Book Field</th>
<th class="px-4 py-2 text-left font-semibold text-gray-300">3rd Priority</th>
<th class="px-4 py-2 text-left font-semibold text-gray-300">2nd Priority</th>
<th class="px-4 py-2 text-left font-semibold text-gray-300">1st Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td class="px-4 py-2 text-gray-300">All Other Fields</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="allP3.value"
(onChange)="syncProvider($event, 'p3')"
placeholder="Select All"
class="w-full">
</p-select>
</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="allP2.value"
(onChange)="syncProvider($event, 'p2')"
placeholder="Select All"
class="w-full">
</p-select>
</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="allP1.value"
(onChange)="syncProvider($event, 'p1')"
placeholder="Select All"
class="w-full">
</p-select>
</td>
</tr>
<tr *ngFor="let field of fields" [hidden]="field === 'cover' && !refreshCovers">
<td class="px-4 py-2 text-gray-300">{{ field | titlecase }}</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p3"
placeholder="Unset"
class="w-full">
</p-select>
</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p2"
placeholder="Unset"
class="w-full">
</p-select>
</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p1"
placeholder="Unset"
class="w-full">
</p-select>
</td>
</tr>
</tbody>
</table>
<div class="flex flex-row items-center justify-between">
<div class="flex gap-10">
<div class="flex flex-row items-center gap-4 justify-start">
<p>Refresh covers: </p>
<p-checkbox [(ngModel)]="refreshCovers" [binary]="true"></p-checkbox>
</div>
<div class="flex flex-row items-center gap-4 justify-start">
<p>Merge categories: </p>
<p-checkbox [(ngModel)]="mergeCategories" [binary]="true"></p-checkbox>
</div>
</div>
<div class="flex flex-row gap-6">
<p-button severity="warn" outlined="true" label="Reset" (onClick)="reset()"></p-button>
<p-button label="Save" outlined="true" (onClick)="submit()"></p-button>
</div>
</div>
</div>
@@ -1,4 +0,0 @@
.custom-table {
border: 1px solid var(--border-color);
border-radius: var(--card-border);
}
@@ -1,97 +0,0 @@
import {Component, Output, EventEmitter, inject, Input, OnInit, OnChanges, SimpleChanges} from '@angular/core';
import {Select, SelectChangeEvent} from 'primeng/select';
import {FormsModule} from '@angular/forms';
import {NgForOf, TitleCasePipe} from '@angular/common';
import {Checkbox} from 'primeng/checkbox';
import {Button} from 'primeng/button';
import {MessageService} from 'primeng/api';
import {FieldOptions, FieldProvider, MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
@Component({
selector: 'app-metadata-advanced-fetch-options',
templateUrl: './metadata-advanced-fetch-options.component.html',
imports: [Select, FormsModule, NgForOf, Checkbox, Button, TitleCasePipe],
styleUrl: './metadata-advanced-fetch-options.component.scss',
standalone: true
})
export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
@Output() metadataOptionsSubmitted: EventEmitter<MetadataRefreshOptions> = new EventEmitter<MetadataRefreshOptions>();
fields: (keyof FieldOptions)[] = ['title', 'description', 'authors', 'categories', 'cover'];
providers: string[] = ['Amazon', 'Google', 'GoodReads'];
refreshCovers: boolean = false;
mergeCategories: boolean = false;
allP3 = {placeholder: 'Set All', value: null as string | null};
allP2 = {placeholder: 'Set All', value: null as string | null};
allP1 = {placeholder: 'Set All', value: null as string | null};
fieldOptions: FieldOptions = {
title: {p3: null, p2: null, p1: null},
description: {p3: null, p2: null, p1: null},
authors: {p3: null, p2: null, p1: null},
categories: {p3: null, p2: null, p1: null},
cover: {p3: null, p2: null, p1: null}
};
private messageService = inject(MessageService);
@Input() currentMetadataOptions!: MetadataRefreshOptions;
ngOnChanges(changes: SimpleChanges): void {
if (changes['currentMetadataOptions'] && this.currentMetadataOptions) {
this.refreshCovers = this.currentMetadataOptions.refreshCovers || false;
this.mergeCategories = this.currentMetadataOptions.mergeCategories || false;
this.fieldOptions = this.currentMetadataOptions.fieldOptions || this.fieldOptions;
this.allP3.value = this.currentMetadataOptions.allP3 || null;
this.allP2.value = this.currentMetadataOptions.allP2 || null;
this.allP1.value = this.currentMetadataOptions.allP1 || null;
}
}
syncProvider(event: SelectChangeEvent, providerType: keyof FieldProvider) {
for (const field of Object.keys(this.fieldOptions)) {
this.fieldOptions[field as keyof FieldOptions][providerType] = event.value;
}
}
submit() {
const allP3Selected = Object.keys(this.fieldOptions).every(field => {
return this.fieldOptions[field as keyof FieldOptions].p3 !== null;
});
if (allP3Selected) {
const metadataRefreshOptions: MetadataRefreshOptions = {
allP1: this.allP1.value,
allP2: this.allP2.value,
allP3: this.allP3.value,
refreshCovers: this.refreshCovers,
mergeCategories: this.mergeCategories,
fieldOptions: this.fieldOptions
};
this.metadataOptionsSubmitted.emit(metadataRefreshOptions);
} else {
this.messageService.add({
severity: 'error',
summary: 'Error',
life: 5000,
detail: 'At least one provider must be selected for all the book fields.'
});
}
}
reset() {
this.allP3.value = null;
this.allP2.value = null;
this.allP1.value = null;
for (const field of Object.keys(this.fieldOptions)) {
this.fieldOptions[field as keyof FieldOptions] = {
p3: null,
p2: null,
p1: null
};
}
}
}
@@ -1,5 +0,0 @@
<div class="flex flex-col space-y-6">
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)"></app-metadata-advanced-fetch-options>
</div>
@@ -1,43 +0,0 @@
import {Component, inject} from '@angular/core';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
import {BookService} from '../../../book/service/book.service';
@Component({
selector: 'app-metadata-fetch-options',
standalone: true,
templateUrl: './metadata-fetch-options.component.html',
imports: [
MetadataAdvancedFetchOptionsComponent
],
styleUrl: './metadata-fetch-options.component.scss'
})
export class MetadataFetchOptionsComponent {
libraryId!: number;
bookIds!: number[];
metadataRefreshType!: MetadataRefreshType;
private dynamicDialogConfig = inject(DynamicDialogConfig);
private dynamicDialogRef = inject(DynamicDialogRef);
private bookService = inject(BookService);
constructor() {
this.libraryId = this.dynamicDialogConfig.data.libraryId;
this.bookIds = this.dynamicDialogConfig.data.bookIds;
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
}
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) {
const metadataRefreshRequest: MetadataRefreshRequest = {
refreshType: this.metadataRefreshType,
refreshOptions: metadataRefreshOptions,
bookIds: this.bookIds,
libraryId: this.libraryId
};
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
this.dynamicDialogRef.close();
}
}
@@ -1,5 +0,0 @@
export enum MetadataProvider {
Amazon = "Amazon",
Google = "Google",
GoodReads = "GoodReads"
}
@@ -1,6 +0,0 @@
export interface FetchMetadataRequest {
bookId: number,
providers: string[],
title: string,
author: string
}
@@ -1,22 +0,0 @@
export interface MetadataRefreshOptions {
allP3: string | null;
allP2: string | null;
allP1: string | null;
refreshCovers: boolean;
mergeCategories: boolean;
fieldOptions?: FieldOptions;
}
export interface FieldProvider {
p3: string | null;
p2: string | null;
p1: string | null;
}
export interface FieldOptions {
title: FieldProvider;
description: FieldProvider;
authors: FieldProvider;
categories: FieldProvider;
cover: FieldProvider;
}
@@ -1,10 +0,0 @@
import {MetadataRefreshType} from './metadata-refresh-type.enum';
import {MetadataRefreshOptions} from './metadata-refresh-options.model';
export interface MetadataRefreshRequest {
quick?: boolean;
refreshType: MetadataRefreshType;
libraryId?: number;
bookIds?: number[];
refreshOptions?: MetadataRefreshOptions;
}
@@ -1,4 +0,0 @@
export enum MetadataRefreshType {
BOOKS = 'BOOKS',
LIBRARY = 'LIBRARY'
}