Allow metadata fields to be explicitly cleared

This commit is contained in:
aditya.chandel
2025-06-28 14:12:48 -06:00
committed by Aditya Chandel
parent df233d8f95
commit e8cd58cd42
28 changed files with 1044 additions and 612 deletions
@@ -283,7 +283,7 @@ export class BookCardComponent implements OnInit, OnDestroy {
});
} else {
this.dialogService.open(BookMetadataCenterComponent, {
width: '95%',
width: '85%',
data: {bookId: book.id},
modal: true,
dismissableMask: true,
@@ -194,8 +194,8 @@ export class BookFilterComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(([sortMode]) => {
this.filterStreams = {
author: this.getFilterStream((book: Book) => book.metadata?.authors.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
category: this.getFilterStream((book: Book) => book.metadata?.categories.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
author: this.getFilterStream((book: Book) => book.metadata?.authors!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
category: this.getFilterStream((book: Book) => book.metadata?.categories!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name', sortMode),
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
readStatus: this.getFilterStream((book: Book) => [{id: book.readStatus ?? ReadStatus.UNREAD, name: getReadStatusName(book.readStatus)}], 'id', 'name', sortMode),
@@ -15,7 +15,7 @@ export class HeaderFilter implements BookFilter {
const filteredBooks = bookState.books?.filter(book => {
const matchesTitle = book.metadata?.title?.toLowerCase().includes(term.toLowerCase());
const matchesSeries = book.metadata?.seriesName?.toLowerCase().includes(term.toLowerCase());
const matchesAuthor = book.metadata?.authors.some(author =>
const matchesAuthor = book.metadata?.authors?.some(author =>
author.toLowerCase().includes(term.toLowerCase())
);
return matchesTitle || matchesSeries || matchesAuthor;
@@ -26,8 +26,8 @@
@if (backupMetadata.subtitle) {
<div><strong>Subtitle:</strong> {{ backupMetadata.subtitle }}</div>
}
@if (backupMetadata.authors.length) {
<div><strong>Authors:</strong> {{ backupMetadata.authors.join(', ') }}</div>
@if (backupMetadata.authors!.length) {
<div><strong>Authors:</strong> {{ backupMetadata.authors!.join(', ') }}</div>
}
@if (backupMetadata.publisher) {
<div><strong>Publisher:</strong> {{ backupMetadata.publisher }}</div>
@@ -6,7 +6,7 @@
@if (isLoading) {
<p-progressSpinner [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
}
<div class="flex-grow overflow-auto p-4">
<div class="flex-grow overflow-auto py-2 px-2">
<div class="flex flex-row w-full gap-4">
<div class="flex flex-col items-center gap-2 relative">
<img
@@ -6,7 +6,7 @@ import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular
import {Observable} from 'rxjs';
import {AsyncPipe, NgClass} from '@angular/common';
import {MessageService} from 'primeng/api';
import {Book, BookMetadata} from '../../../model/book.model';
import {Book, BookMetadata, MetadataClearFlags, MetadataUpdateWrapper} from '../../../model/book.model';
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
import {FileUpload, FileUploadErrorEvent, FileUploadEvent} from 'primeng/fileupload';
import {HttpResponse} from '@angular/common/http';
@@ -77,6 +77,8 @@ export class MetadataEditorComponent implements OnInit {
refreshingBookIds = new Set<number>();
isAutoFetching = false;
originalMetadata!: BookMetadata;
constructor() {
this.metadataForm = new FormGroup({
title: new FormControl(''),
@@ -90,9 +92,8 @@ export class MetadataEditorComponent implements OnInit {
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
asin: new FormControl(''),
personalRating: new FormControl(''),
amazonRating: new FormControl(''),
amazonReviewCount: new FormControl(''),
goodreadsId: new FormControl(''),
@@ -118,6 +119,7 @@ export class MetadataEditorComponent implements OnInit {
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(''),
@@ -148,6 +150,8 @@ export class MetadataEditorComponent implements OnInit {
this.isAutoFetching = false;
}
this.originalMetadata = structuredClone(metadata);
if (this.quillEditor?.quill) {
this.quillEditor.quill.root.innerHTML = metadata.description;
this.quillDisabled();
@@ -181,6 +185,7 @@ export class MetadataEditorComponent implements OnInit {
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,
@@ -205,6 +210,7 @@ export class MetadataEditorComponent implements OnInit {
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,
@@ -233,6 +239,7 @@ export class MetadataEditorComponent implements OnInit {
{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'},
@@ -254,21 +261,17 @@ export class MetadataEditorComponent implements OnInit {
isLocked ? formControl.disable() : formControl.enable();
}
}
this.metadataForm.get('reviewCount')?.disable();
this.metadataForm.get('rating')?.disable();
}
onSave(): void {
this.isSaving = true;
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
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;
console.error('Update metadata failed:', err);
this.messageService.add({
severity: 'error',
summary: 'Error',
@@ -327,69 +330,117 @@ export class MetadataEditorComponent implements OnInit {
}
}
private buildMetadata(shouldLockAllFields: boolean | undefined) {
const updatedBookMetadata: BookMetadata = {
private buildMetadataWrapper(shouldLockAllFields?: boolean): MetadataUpdateWrapper {
const form = this.metadataForm;
const metadata: BookMetadata = {
bookId: this.currentBookId,
title: this.metadataForm.get('title')?.value,
subtitle: this.metadataForm.get('subtitle')?.value,
authors: this.metadataForm.get('authors')?.value ?? [],
categories: this.metadataForm.get('categories')?.value ?? [],
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,
asin: this.metadataForm.get('asin')?.value,
amazonRating: this.metadataForm.get('amazonRating')?.value,
amazonReviewCount: this.metadataForm.get('amazonReviewCount')?.value,
goodreadsId: this.metadataForm.get('goodreadsId')?.value,
goodreadsRating: this.metadataForm.get('goodreadsRating')?.value,
goodreadsReviewCount: this.metadataForm.get('goodreadsReviewCount')?.value,
hardcoverId: this.metadataForm.get('hardcoverId')?.value,
hardcoverRating: this.metadataForm.get('hardcoverRating')?.value,
hardcoverReviewCount: this.metadataForm.get('hardcoverReviewCount')?.value,
googleId: this.metadataForm.get('googleId')?.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,
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,
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,
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,
// 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}),
...(shouldLockAllFields !== undefined && {allFieldsLocked: shouldLockAllFields})
};
return updatedBookMetadata;
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 {
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
let metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
this.bookService.updateBookMetadata(this.currentBookId, metadataUpdateWrapper, false).subscribe({
next: (response) => {
if (shouldLockAllFields !== undefined) {
this.messageService.add({
@@ -1,5 +1,5 @@
import {Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
import {Book, BookMetadata} from '../../../model/book.model';
import {Book, BookMetadata, MetadataClearFlags, MetadataUpdateWrapper} from '../../../model/book.model';
import {MessageService} from 'primeng/api';
import {Button} from 'primeng/button';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
@@ -127,6 +127,7 @@ export class MetadataPickerComponent implements OnInit {
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),
@@ -193,6 +194,7 @@ export class MetadataPickerComponent implements OnInit {
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,
@@ -218,6 +220,7 @@ export class MetadataPickerComponent implements OnInit {
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();
@@ -238,7 +241,7 @@ export class MetadataPickerComponent implements OnInit {
onSave(): void {
this.isSaving = true;
const updatedBookMetadata = this.buildMetadata(undefined);
const updatedBookMetadata = this.buildMetadataWrapper(undefined);
this.bookService.updateBookMetadata(this.currentBookId, updatedBookMetadata, false).subscribe({
next: (bookMetadata) => {
this.isSaving = false;
@@ -256,7 +259,7 @@ export class MetadataPickerComponent implements OnInit {
});
}
private buildMetadata(shouldLockAllFields: boolean | undefined) {
private buildMetadataWrapper(shouldLockAllFields: boolean | undefined): MetadataUpdateWrapper {
const updatedBookMetadata: BookMetadata = {
bookId: this.currentBookId,
title: this.metadataForm.get('title')?.value || this.copiedFields['title'] ? this.getValueOrCopied('title') : '',
@@ -271,6 +274,7 @@ export class MetadataPickerComponent implements OnInit {
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') : '',
@@ -297,6 +301,7 @@ export class MetadataPickerComponent implements OnInit {
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,
@@ -313,7 +318,44 @@ export class MetadataPickerComponent implements OnInit {
...(shouldLockAllFields !== undefined && {allFieldsLocked: shouldLockAllFields}),
};
return updatedBookMetadata;
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() {
@@ -325,7 +367,7 @@ export class MetadataPickerComponent implements OnInit {
}
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadataWrapper(shouldLockAllFields), false).subscribe({
next: (response) => {
if (shouldLockAllFields !== undefined) {
this.messageService.add({
@@ -39,7 +39,7 @@
<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>
<p class="font-bold">{{ truncateText(metadata['title']!, 90) }}</p>
<div class="flex gap-2">
<p>ISBN: {{ metadata['isbn10'] || metadata['asin'] }}</p>
<p> | </p>
@@ -47,7 +47,7 @@
</div>
</div>
<div class="flex gap-2">
<p>by {{ truncateText(metadata['authors'].join(', '), 70) }}</p>
<p>by {{ truncateText(metadata['authors']!.join(', '), 70) }}</p>
<p> | </p>
<p>Source: <span [innerHTML]="buildProviderLink(metadata)"></span></p>
</div>
@@ -1,4 +1,4 @@
<div class="pt-2 flex flex-col h-full">
<div class="pt-2 flex flex-col h-full px-2 w-full">
@if (book$ | async; as book) {
<div>
<div class="flex flex-row">
@@ -26,7 +26,7 @@
}
</div>
<div class="flex flex-col justify-between">
<div class="pl-6 flex flex-col w-full">
<div class="pl-6 flex flex-col">
<div class="flex flex-row items-center justify-between">
<div>
@if (book?.metadata!.seriesName) {
@@ -55,7 +55,6 @@
</p>
</div>
</div>
<div class="flex items-center gap-2 pt-2">
<div class="flex items-center gap-2">
<i class="pi pi-thumbs-up-fill"
@@ -142,12 +141,14 @@
}
}
</div>
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
@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 class="overflow-x-auto pt-4 scrollbar-hide max-w-full w-full">
<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 gap-x-20 gap-y-2 pt-6" style="grid-template-columns: repeat(5, max-content);">
<div>
@@ -162,7 +163,7 @@
<p-menu #menu [popup]="true" [model]="readStatusMenuItems"></p-menu>
</p>
</div>
<p class="whitespace-nowrap"><span class="font-bold">Publisher:</span> {{ book?.metadata!.publisher || '-' }}</p>
<p class="whitespace-nowrap max-w-[250px] overflow-hidden text-ellipsis"><span class="font-bold">Publisher:</span> {{ book?.metadata!.publisher || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">Published:</span> {{ book?.metadata!.publishedDate || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ book?.metadata!.language || '-' }}</p>
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ book?.metadata!.isbn10 || '-' }}</p>
@@ -199,7 +200,7 @@
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB(book) }}</p>
<p class="whitespace-nowrap"><span class="font-bold">ISBN 13:</span> {{ book?.metadata!.isbn13 || '-' }}</p>
</div>
<div class="pt-2 flex items-center gap-2 w-full">
<div class="pt-2 flex items-center gap-2">
<span class="font-semibold flex-shrink-0">File Path:</span>
<p-toggleButton
[(ngModel)]="showFilePath"
@@ -214,7 +215,7 @@
class="flex items-center gap-4 flex-grow"
style="min-width: 0;">
<p
class="font-mono text-sm text-gray-400 overflow-x-auto whitespace-nowrap flex-grow"
class="font-mono text-sm text-gray-400 whitespace-nowrap flex-grow"
style="min-width: 0;">
{{ book?.filePath }}
</p>
@@ -298,7 +299,6 @@
<p-divider></p-divider>
<div class="flex-1 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">
@@ -311,12 +311,12 @@
@if (book.metadata!.description && book.metadata!.description.length > 100) {
<div 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()">
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>
}
@@ -6,7 +6,7 @@ import {BookService} from '../../../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 '../../../model/book.model';
import {Book, BookMetadata, BookRecommendation, MetadataClearFlags, MetadataUpdateWrapper, ReadStatus} from '../../../model/book.model';
import {Divider} from 'primeng/divider';
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
import {UserService} from '../../../../settings/user-management/user.service';
@@ -346,17 +346,29 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
return 'bg-blue-500';
}
onPersonalRatingChange(book: Book, event: RatingRateEvent): void {
const rating = event.value;
if (!book || !book.metadata) return;
const updatedMetadata = {
...book.metadata,
personalRating: rating
};
this.bookService.updateBookMetadata(book.id, updatedMetadata, false).subscribe({
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) => {
error: err => {
console.error('Failed to update personal rating:', err);
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'Could not update personal rating'
});
}
});
}
@@ -4,6 +4,7 @@
<p-progressSpinner></p-progressSpinner>
</div>
}
<div class="p-4 border border-gray-700 rounded-md mb-4 bg-gray-900 text-gray-200">
<div class="flex justify-between items-center mb-2">
<p class="text-base font-semibold">
@@ -12,16 +13,13 @@
<button
type="button"
(click)="showBookList = !showBookList"
class="text-sm text-sky-400 hover:underline"
>
class="text-sm text-sky-400 hover:underline">
{{ showBookList ? 'Hide' : 'Show' }} Titles
</button>
</div>
@if (showBookList) {
<div
class="max-h-48 overflow-y-auto border-t border-gray-700 pt-2 pl-1 text-sm text-gray-300"
>
<div class="max-h-48 overflow-y-auto border-t border-gray-700 pt-2 pl-1 text-sm text-gray-300">
<ul class="list-disc pl-5 space-y-1">
@for (book of books; track book) {
<li>{{ book.metadata?.title || 'Untitled Book' }}</li>
@@ -31,84 +29,118 @@
}
</div>
<div class="px-4 text-sm text-yellow-500 mb-2">
<i class="pi pi-exclamation-triangle mr-1"></i>
Checking <strong>Clear</strong> will remove that field’s metadata from <strong>all selected books</strong>.
</div>
<form [formGroup]="metadataForm" (ngSubmit)="onSubmit()" class="flex flex-col gap-4 w-full p-4">
<div class="flex flex-col gap-2">
<label for="authors" class="flex items-center gap-2">
Author(s)
<i
class="pi pi-info-circle text-sky-600"
pTooltip="Enter multiple authors. Press Enter after typing each name."
tooltipPosition="right"
style="cursor: pointer"
></i>
<label for="authors" class="flex items-center justify-between gap-2">
<span class="flex items-center gap-2">
Author(s)
<i class="pi pi-info-circle text-sky-600"
pTooltip="Enter multiple authors. Press Enter after typing each name."
tooltipPosition="right"
style="cursor: pointer"></i>
</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.authors" [ngModelOptions]="{standalone: true}" (onChange)="onFieldClearToggle('authors')" binary="true" inputId="clearAuthors"/>
<label for="clearAuthors" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<div class="w-full">
<p-chips
formControlName="authors"
addOnBlur="true"
></p-chips>
</div>
<p-chips formControlName="authors" [disabled]="clearFields.authors" addOnBlur="true"></p-chips>
</div>
<!-- Publisher -->
<div class="flex flex-col gap-2">
<label for="publisher">Publisher</label>
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
</div>
<div class="flex flex-row flex-wrap gap-4">
<div class="flex flex-col gap-2 w-1/3">
<label for="language">Language</label>
<input pInputText id="language" formControlName="language" fluid/>
</div>
<div class="flex flex-col gap-2 w-1/3">
<label for="seriesTotal">Total Books in Series</label>
<input
pInputText
id="seriesTotal"
type="number"
min="1"
formControlName="seriesTotal"
fluid
/>
</div>
<div class="flex flex-col gap-2 w-1/4">
<label for="publishedDate">Published Date</label>
<p-datepicker
id="publishedDate"
formControlName="publishedDate"
dateFormat="yy-mm-dd"
showIcon
appendTo="body"
fluid></p-datepicker>
</div>
</div>
<div class="flex flex-col gap-2">
<label for="seriesName">Series Name</label>
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
</div>
<div class="flex flex-col gap-2">
<label for="genres" class="flex items-center gap-2">
Genre(s)
<i
class="pi pi-info-circle text-sky-600"
pTooltip="Enter multiple genres. Press Enter after typing each genre."
tooltipPosition="right"
style="cursor: pointer"
></i>
<label for="publisher" class="flex items-center justify-between gap-2">
<span>Publisher</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.publisher" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('publisher')" binary="true" inputId="clearPublisher"/>
<label for="clearPublisher" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<input pInputText id="publisher" formControlName="publisher" [disabled]="clearFields.publisher" class="w-full"/>
</div>
<div class="w-full">
<p-chips
formControlName="genres"
addOnBlur="true"
></p-chips>
<!-- Language + Series Total + Published Date -->
<div class="flex justify-between gap-7">
<!-- Language -->
<div class="flex flex-col gap-2 w-full">
<label for="language" class="flex items-center justify-between gap-2">
<span>Language</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.language" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('language')" binary="true" inputId="clearLanguage"/>
<label for="clearLanguage" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<input pInputText id="language" formControlName="language" [disabled]="clearFields.language" class="w-full"/>
</div>
<!-- Published Date -->
<div class="flex flex-col gap-2 w-96">
<label for="publishedDate" class="flex items-center justify-between gap-2">
<span>Published Date</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.publishedDate" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('publishedDate')" binary="true" inputId="clearPublishedDate"/>
<label for="clearPublishedDate" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<p-datepicker id="publishedDate" formControlName="publishedDate" [disabled]="clearFields.publishedDate" dateFormat="yy-mm-dd" showIcon></p-datepicker>
</div>
<!-- Series Total -->
<div class="flex flex-col gap-2 min-w-56">
<label for="seriesTotal" class="flex items-center justify-between gap-2">
<span>Total Books in Series</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.seriesTotal" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('seriesTotal')" binary="true" inputId="clearSeriesTotal"/>
<label for="clearSeriesTotal" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<input pInputText id="seriesTotal" type="number" min="1" formControlName="seriesTotal"
[disabled]="clearFields.seriesTotal" class="w-full"/>
</div>
</div>
<!-- Series Name -->
<div class="flex flex-col gap-2">
<label for="seriesName" class="flex items-center justify-between gap-2">
<span>Series Name</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.seriesName" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('seriesName')" binary="true" inputId="clearSeriesName"/>
<label for="clearSeriesName" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<input pInputText id="seriesName" formControlName="seriesName" [disabled]="clearFields.seriesName" class="w-full"/>
</div>
<!-- Genres -->
<div class="flex flex-col gap-2">
<label for="genres" class="flex items-center justify-between gap-2">
<span class="flex items-center gap-2">
Genre(s)
<i class="pi pi-info-circle text-sky-600"
pTooltip="Enter multiple genres. Press Enter after typing each genre."
tooltipPosition="right"
style="cursor: pointer"></i>
</span>
<div class="flex items-center gap-1">
<p-checkbox [(ngModel)]="clearFields.genres" [ngModelOptions]="{standalone: true}"
(onChange)="onFieldClearToggle('genres')" binary="true" inputId="clearGenres"/>
<label for="clearGenres" class="text-sm text-gray-300 cursor-pointer">Clear</label>
</div>
</label>
<p-chips formControlName="genres" addOnBlur="true" [disabled]="clearFields.genres"></p-chips>
<div class="flex items-center gap-2 mt-2">
<p-checkbox
inputId="mergeCategories"
@@ -116,7 +148,6 @@
[(ngModel)]="mergeCategories"
[ngModelOptions]="{ standalone: true }"
binary="true"
class="text-sm"
/>
<label for="mergeCategories" class="text-sm text-gray-300 cursor-pointer">
Keep existing categories and add new ones (uncheck to remove all existing categories)
@@ -8,7 +8,6 @@ import {Chips} from 'primeng/chips';
import {DatePicker} from 'primeng/datepicker';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {MessageService} from 'primeng/api';
import {BookService} from '../../service/book.service';
import {Book, BulkMetadataUpdateRequest} from '../../model/book.model';
import {Checkbox} from 'primeng/checkbox';
@@ -20,12 +19,12 @@ import {ProgressSpinner} from 'primeng/progressspinner';
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
InputText,
Button,
Tooltip,
Chips,
DatePicker,
FormsModule,
Checkbox,
ProgressSpinner
],
@@ -41,6 +40,16 @@ export class BulkMetadataUpdateComponent implements OnInit {
mergeCategories = true;
loading = false;
clearFields = {
authors: false,
publisher: false,
language: false,
seriesName: false,
seriesTotal: false,
publishedDate: false,
genres: false,
};
private readonly config = inject(DynamicDialogConfig);
private readonly ref = inject(DynamicDialogRef);
private readonly fb = inject(FormBuilder);
@@ -62,43 +71,70 @@ export class BulkMetadataUpdateComponent implements OnInit {
});
}
onSubmit(): void {
if (this.metadataForm.valid) {
const formValue = this.metadataForm.value;
onFieldClearToggle(field: keyof typeof this.clearFields): void {
const control = this.metadataForm.get(field);
if (!control) return;
const payload: BulkMetadataUpdateRequest = {
bookIds: this.bookIds,
authors: formValue.authors?.length ? formValue.authors : undefined,
publisher: formValue.publisher?.trim() || undefined,
language: formValue.language?.trim() || undefined,
seriesName: formValue.seriesName?.trim() || undefined,
seriesTotal: formValue.seriesTotal || undefined,
publishedDate: formValue.publishedDate
? new Date(formValue.publishedDate).toISOString().split('T')[0]
: undefined,
genres: formValue.genres?.length ? formValue.genres : undefined
};
this.loading = true;
this.bookService.updateBooksMetadata(payload, this.mergeCategories).subscribe({
next: (updatedBooks) => {
this.loading = false;
this.messageService.add({
severity: 'success',
summary: 'Metadata Updated',
detail: `${updatedBooks.length} book${updatedBooks.length > 1 ? 's' : ''} updated successfully`,
});
this.ref.close(true);
},
error: (error) => {
console.error('Bulk metadata update failed:', error);
this.loading = false;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'An error occurred while updating book metadata',
});
}
});
if (this.clearFields[field]) {
control.disable();
control.setValue(null);
} else {
control.enable();
}
}
onSubmit(): void {
if (!this.metadataForm.valid) return;
const formValue = this.metadataForm.value;
const payload: BulkMetadataUpdateRequest = {
bookIds: this.bookIds,
authors: this.clearFields.authors ? [] : (formValue.authors?.length ? formValue.authors : undefined),
clearAuthors: this.clearFields.authors,
publisher: this.clearFields.publisher ? '' : (formValue.publisher?.trim() || undefined),
clearPublisher: this.clearFields.publisher,
language: this.clearFields.language ? '' : (formValue.language?.trim() || undefined),
clearLanguage: this.clearFields.language,
seriesName: this.clearFields.seriesName ? '' : (formValue.seriesName?.trim() || undefined),
clearSeriesName: this.clearFields.seriesName,
seriesTotal: this.clearFields.seriesTotal ? null : (formValue.seriesTotal || undefined),
clearSeriesTotal: this.clearFields.seriesTotal,
publishedDate: this.clearFields.publishedDate
? null
: (formValue.publishedDate ? new Date(formValue.publishedDate).toISOString().split('T')[0] : undefined),
clearPublishedDate: this.clearFields.publishedDate,
genres: this.clearFields.genres ? [] : (formValue.genres?.length ? formValue.genres : undefined),
clearGenres: this.clearFields.genres
};
this.loading = true;
this.bookService.updateBooksMetadata(payload, this.mergeCategories).subscribe({
next: updatedBooks => {
this.loading = false;
this.messageService.add({
severity: 'success',
summary: 'Metadata Updated',
detail: `${updatedBooks.length} book${updatedBooks.length > 1 ? 's' : ''} updated successfully`
});
this.ref.close(true);
},
error: err => {
console.error('Bulk metadata update failed:', err);
this.loading = false;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'An error occurred while updating book metadata'
});
}
});
}
}
+47 -5
View File
@@ -38,7 +38,7 @@ export interface CbxProgress {
export interface BookMetadata {
bookId: number;
title: string;
title?: string;
subtitle?: string;
publisher?: string;
publishedDate?: string;
@@ -64,8 +64,8 @@ export interface BookMetadata {
hardcoverReviewCount?: number | null;
personalRating?: number | null;
coverUpdatedOn?: string;
authors: string[];
categories: string[];
authors?: string[];
categories?: string[];
provider?: string;
providerBookId?: string;
thumbnailUrl?: string | null;
@@ -86,6 +86,7 @@ export interface BookMetadata {
googleIdLocked?: boolean;
pageCountLocked?: boolean;
languageLocked?: boolean;
personalRatingLocked?: boolean;
amazonRatingLocked?: boolean;
amazonReviewCountLocked?: boolean;
goodreadsRatingLocked?: boolean;
@@ -100,6 +101,40 @@ export interface BookMetadata {
[key: string]: any;
}
export interface MetadataClearFlags {
title?: boolean;
subtitle?: boolean;
publisher?: boolean;
publishedDate?: boolean;
description?: boolean;
seriesName?: boolean;
seriesNumber?: boolean;
seriesTotal?: boolean;
isbn13?: boolean;
isbn10?: boolean;
asin?: boolean;
goodreadsId?: boolean;
hardcoverId?: boolean;
googleId?: boolean;
pageCount?: boolean;
language?: boolean;
amazonRating?: boolean;
amazonReviewCount?: boolean;
goodreadsRating?: boolean;
goodreadsReviewCount?: boolean;
hardcoverRating?: boolean;
hardcoverReviewCount?: boolean;
personalRating?: boolean;
authors?: boolean;
categories?: boolean;
cover?: boolean;
}
export interface MetadataUpdateWrapper {
metadata: BookMetadata;
clearFlags: MetadataClearFlags;
}
export interface PdfViewerSetting {
zoom: string | number;
spread: 'off' | 'even' | 'odd';
@@ -156,12 +191,19 @@ export const enum PdfPageSpread {
export interface BulkMetadataUpdateRequest {
bookIds: number[];
authors?: string[];
clearAuthors?: boolean;
publisher?: string;
clearPublisher?: boolean;
language?: string;
clearLanguage?: boolean;
seriesName?: string;
seriesTotal?: number;
publishedDate?: string;
clearSeriesName?: boolean;
seriesTotal?: number | null;
clearSeriesTotal?: boolean;
publishedDate?: string | null;
clearPublishedDate?: boolean;
genres?: string[];
clearGenres?: boolean;
}
export interface BookDeletionResponse {
@@ -2,7 +2,7 @@ import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, first, Observable, of, throwError} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http';
import {catchError, filter, map, tap} from 'rxjs/operators';
import {Book, BookDeletionResponse, BookMetadata, BookRecommendation, BookSetting, BulkMetadataUpdateRequest, ReadStatus} from '../model/book.model';
import {Book, BookDeletionResponse, BookMetadata, BookRecommendation, BookSetting, BulkMetadataUpdateRequest, MetadataUpdateWrapper, ReadStatus} from '../model/book.model';
import {BookState} from '../model/state/book-state.model';
import {API_CONFIG} from '../../config/api-config';
import {FetchMetadataRequest} from '../metadata/model/request/fetch-metadata-request.model';
@@ -160,7 +160,7 @@ export class BookService {
const state = this.bookStateSubject.value;
return (state.books || []).filter(book =>
book.metadata?.title?.toLowerCase().includes(query.toLowerCase()) ||
book.metadata?.authors.some(author => author.toLowerCase().includes(query.toLowerCase()))
book.metadata?.authors?.some(author => author.toLowerCase().includes(query.toLowerCase()))
);
}
@@ -292,9 +292,9 @@ export class BookService {
return this.http.post<BookMetadata[]>(`${this.url}/${bookId}/metadata/prospective`, request);
}
updateBookMetadata(bookId: number | undefined, bookMetadata: BookMetadata, mergeCategories: boolean): Observable<BookMetadata> {
updateBookMetadata(bookId: number | undefined, wrapper: MetadataUpdateWrapper, mergeCategories: boolean): Observable<BookMetadata> {
const params = new HttpParams().set('mergeCategories', mergeCategories.toString());
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadata, {params}).pipe(
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, wrapper, {params}).pipe(
map(updatedMetadata => {
this.handleBookMetadataUpdate(bookId!, updatedMetadata);
return updatedMetadata;