From c049c2bbc0a937d372b6819b55e582192faad74f Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Sun, 26 Jan 2025 10:33:12 -0700 Subject: [PATCH] WIP: Enhance book metadata picker --- .../controller/MetadataController.java | 5 - .../service/metadata/BookMetadataUpdater.java | 125 ------------- .../metadata-editor.component.html | 6 +- .../metadata-editor.component.ts | 122 ++++++------ .../metadata-picker.component.html | 77 +++++++- .../metadata-picker.component.ts | 174 ++++++++++++++---- ...tadata-advanced-fetch-options.component.ts | 18 +- .../request/metadata-refresh-options.model.ts | 6 +- .../service/metadata-dialog.service.ts | 4 +- 9 files changed, 295 insertions(+), 242 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/controller/MetadataController.java b/booklore-api/src/main/java/com/adityachandel/booklore/controller/MetadataController.java index bf6150c57..700937b6e 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/controller/MetadataController.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/controller/MetadataController.java @@ -37,11 +37,6 @@ public class MetadataController { return ResponseEntity.ok(bookMetadata); } - /*@PutMapping("/update/{bookId}") - public ResponseEntity updateMetadata(@PathVariable long bookId, @RequestBody BookMetadata bookMetadata) { - return ResponseEntity.ok(bookMetadataUpdater.updateMetadata(bookId, bookMetadata)); - }*/ - @PutMapping(path = "/refreshV2") public ResponseEntity scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) { jobSchedulerService.scheduleMetadataRefreshV2(request); diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/metadata/BookMetadataUpdater.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/metadata/BookMetadataUpdater.java index f094a81d9..a0ae8cd3f 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/metadata/BookMetadataUpdater.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/metadata/BookMetadataUpdater.java @@ -1,10 +1,6 @@ package com.adityachandel.booklore.service.metadata; import com.adityachandel.booklore.exception.ApiError; -import com.adityachandel.booklore.mapper.AuthorMapper; -import com.adityachandel.booklore.mapper.BookMetadataMapper; -import com.adityachandel.booklore.mapper.CategoryMapper; -import com.adityachandel.booklore.model.dto.BookMetadata; import com.adityachandel.booklore.model.entity.*; import com.adityachandel.booklore.repository.*; import com.adityachandel.booklore.service.metadata.model.FetchedBookMetadata; @@ -20,7 +16,6 @@ import java.time.Instant; import java.time.ZoneId; import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -34,9 +29,6 @@ public class BookMetadataUpdater { private BookMetadataRepository bookMetadataRepository; private CategoryRepository categoryRepository; private FileService fileService; - private BookMetadataMapper bookMetadataMapper; - private AuthorMapper authorMapper; - private CategoryMapper categoryMapper; private BookAwardRepository bookAwardRepository; @@ -249,121 +241,4 @@ public class BookMetadataUpdater { } } - - public BookMetadata updateMetadata(long bookId, BookMetadata updatedMetadata) { - BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId)); - BookMetadataEntity metadata = bookEntity.getMetadata(); - - List lockedFields = new ArrayList<>(); - - if (metadata.getAllFieldsLocked() != null && metadata.getAllFieldsLocked()) { - log.warn("Attempted to update metadata for book with ID {}, but all fields are locked. No update performed.", bookId); - throw ApiError.METADATA_LOCKED.createException(bookId); - } - - if (metadata.getTitleLocked() && updatedMetadata.getTitle() != null) { - lockedFields.add("Title"); - } else if (!metadata.getTitleLocked() && updatedMetadata.getTitle() != null) { - metadata.setTitle(updatedMetadata.getTitle()); - } - - if (metadata.getSubtitleLocked() && updatedMetadata.getSubtitle() != null) { - lockedFields.add("Subtitle"); - } else if (!metadata.getSubtitleLocked() && updatedMetadata.getSubtitle() != null) { - metadata.setSubtitle(updatedMetadata.getSubtitle()); - } - - if (metadata.getPublisherLocked() && updatedMetadata.getPublisher() != null) { - lockedFields.add("Publisher"); - } else if (!metadata.getPublisherLocked() && updatedMetadata.getPublisher() != null) { - metadata.setPublisher(updatedMetadata.getPublisher()); - } - - if (metadata.getSeriesNameLocked() && updatedMetadata.getSeriesName() != null) { - lockedFields.add("Series Name"); - } else if (!metadata.getSeriesNameLocked() && updatedMetadata.getSeriesName() != null) { - metadata.setSeriesName(updatedMetadata.getSeriesName()); - } - - if (metadata.getSeriesNumberLocked() && updatedMetadata.getSeriesNumber() != null) { - lockedFields.add("Series Number"); - } else if (!metadata.getSeriesNumberLocked() && updatedMetadata.getSeriesNumber() != null) { - metadata.setSeriesNumber(updatedMetadata.getSeriesNumber()); - } - - if (metadata.getSeriesTotalLocked() && updatedMetadata.getSeriesTotal() != null) { - lockedFields.add("Series Total"); - } else if (!metadata.getSeriesTotalLocked() && updatedMetadata.getSeriesTotal() != null) { - metadata.setSeriesTotal(updatedMetadata.getSeriesTotal()); - } - - if (metadata.getPublishedDateLocked() && updatedMetadata.getPublishedDate() != null) { - lockedFields.add("Published Date"); - } else if (!metadata.getPublishedDateLocked() && updatedMetadata.getPublishedDate() != null) { - metadata.setPublishedDate(updatedMetadata.getPublishedDate()); - } - - if (metadata.getDescriptionLocked() && updatedMetadata.getDescription() != null) { - lockedFields.add("Description"); - } else if (!metadata.getDescriptionLocked() && updatedMetadata.getDescription() != null) { - metadata.setDescription(updatedMetadata.getDescription()); - } - - if (metadata.getIsbn13Locked() && updatedMetadata.getIsbn13() != null) { - lockedFields.add("ISBN 13"); - } else if (!metadata.getIsbn13Locked() && updatedMetadata.getIsbn13() != null) { - metadata.setIsbn13(updatedMetadata.getIsbn13()); - } - - if (metadata.getIsbn10Locked() && updatedMetadata.getIsbn10() != null) { - lockedFields.add("ISBN 10"); - } else if (!metadata.getIsbn10Locked() && updatedMetadata.getIsbn10() != null) { - metadata.setIsbn10(updatedMetadata.getIsbn10()); - } - - if (metadata.getPageCountLocked() && updatedMetadata.getPageCount() != null) { - lockedFields.add("Page Count"); - } else if (!metadata.getPageCountLocked() && updatedMetadata.getPageCount() != null) { - metadata.setPageCount(updatedMetadata.getPageCount()); - } - - if (metadata.getLanguageLocked() && updatedMetadata.getLanguage() != null) { - lockedFields.add("Language"); - } else if (!metadata.getLanguageLocked() && updatedMetadata.getLanguage() != null) { - metadata.setLanguage(updatedMetadata.getLanguage()); - } - - if (metadata.getRatingLocked() && updatedMetadata.getRating() != null) { - lockedFields.add("Rating"); - } else if (!metadata.getRatingLocked() && updatedMetadata.getRating() != null) { - metadata.setRating(updatedMetadata.getRating()); - } - - if (metadata.getReviewCountLocked() && updatedMetadata.getReviewCount() != null) { - lockedFields.add("Review Count"); - } else if (!metadata.getReviewCountLocked() && updatedMetadata.getReviewCount() != null) { - metadata.setReviewCount(updatedMetadata.getReviewCount()); - } - - if (metadata.getAuthorsLocked() && updatedMetadata.getAuthors() != null) { - lockedFields.add("Authors"); - } else if (!metadata.getAuthorsLocked() && updatedMetadata.getAuthors() != null) { - metadata.setAuthors(authorMapper.toAuthorEntityList(updatedMetadata.getAuthors())); - } - - if (metadata.getCategoriesLocked() && updatedMetadata.getCategories() != null) { - lockedFields.add("Categories"); - } else if (!metadata.getCategoriesLocked() && updatedMetadata.getCategories() != null) { - metadata.setCategories(categoryMapper.toCategoryEntities(updatedMetadata.getCategories())); - } - - if (!lockedFields.isEmpty()) { - String lockedFieldsMessage = String.join(", ", lockedFields); - log.error("Attempted to update the following locked fields for book with ID {}: {}", bookId, lockedFieldsMessage); - throw ApiError.METADATA_LOCKED.createException(bookId); - } - - bookRepository.save(bookEntity); - return bookMetadataMapper.toBookMetadata(metadata, false); - } } \ No newline at end of file diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html index 7a00045a1..01c1072a4 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -1,4 +1,4 @@ -
+
@@ -172,9 +172,9 @@
+ - - +
diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts index 83096d200..50a3bcf6a 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts +++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts @@ -36,11 +36,11 @@ export class MetadataEditorComponent implements OnInit { protected urlHelper = inject(UrlHelperService); bookMetadata$: Observable = this.metadataCenterService.currentMetadata$; - bookMetadataForm: FormGroup; + metadataForm: FormGroup; currentBookId!: number; constructor() { - this.bookMetadataForm = new FormGroup({ + this.metadataForm = new FormGroup({ title: new FormControl(''), subtitle: new FormControl(''), authors: new FormControl(''), @@ -82,7 +82,7 @@ export class MetadataEditorComponent implements OnInit { if (metadata) { this.currentBookId = metadata.bookId; - this.bookMetadataForm.setValue({ + this.metadataForm.setValue({ title: metadata.title, subtitle: metadata.subtitle, authors: metadata.authors.map((author) => author.name).sort().join(', '), @@ -118,22 +118,22 @@ export class MetadataEditorComponent implements OnInit { seriesTotalLocked: metadata.seriesTotalLocked || false, }); - if (metadata.titleLocked) this.bookMetadataForm.get('title')?.disable(); - if (metadata.subtitleLocked) this.bookMetadataForm.get('subtitle')?.disable(); - if (metadata.authorsLocked) this.bookMetadataForm.get('authors')?.disable(); - if (metadata.categoriesLocked) this.bookMetadataForm.get('categories')?.disable(); - if (metadata.publisherLocked) this.bookMetadataForm.get('publisher')?.disable(); - if (metadata.publishedDateLocked) this.bookMetadataForm.get('publishedDate')?.disable(); - if (metadata.languageLocked) this.bookMetadataForm.get('language')?.disable(); - if (metadata.isbn10Locked) this.bookMetadataForm.get('isbn10')?.disable(); - if (metadata.isbn13Locked) this.bookMetadataForm.get('isbn13')?.disable(); - if (metadata.reviewCountLocked) this.bookMetadataForm.get('reviewCount')?.disable(); - if (metadata.ratingLocked) this.bookMetadataForm.get('rating')?.disable(); - if (metadata.pageCountLocked) this.bookMetadataForm.get('pageCount')?.disable(); - if (metadata.descriptionLocked) this.bookMetadataForm.get('description')?.disable(); - if (metadata.seriesNameLocked) this.bookMetadataForm.get('seriesName')?.disable(); - if (metadata.seriesNumberLocked) this.bookMetadataForm.get('seriesNumber')?.disable(); - if (metadata.seriesTotalLocked) this.bookMetadataForm.get('seriesTotal')?.disable(); + 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.reviewCountLocked) this.metadataForm.get('reviewCount')?.disable(); + if (metadata.ratingLocked) this.metadataForm.get('rating')?.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(); } }); } @@ -151,34 +151,34 @@ export class MetadataEditorComponent implements OnInit { } toggleLock(field: string): void { - const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value; + const isLocked = this.metadataForm.get(field + 'Locked')?.value; const updatedLockedState = !isLocked; - this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState); + this.metadataForm.get(field + 'Locked')?.setValue(updatedLockedState); if (updatedLockedState) { - this.bookMetadataForm.get(field)?.disable(); + this.metadataForm.get(field)?.disable(); } else { - this.bookMetadataForm.get(field)?.enable(); + this.metadataForm.get(field)?.enable(); } this.updateMetadata(); } lockAll(): void { - Object.keys(this.bookMetadataForm.controls).forEach((key) => { + Object.keys(this.metadataForm.controls).forEach((key) => { if (key.endsWith('Locked')) { - this.bookMetadataForm.get(key)?.setValue(true); + this.metadataForm.get(key)?.setValue(true); const fieldName = key.replace('Locked', ''); - this.bookMetadataForm.get(fieldName)?.disable(); + this.metadataForm.get(fieldName)?.disable(); } }); this.updateMetadata(); } unlockAll(): void { - Object.keys(this.bookMetadataForm.controls).forEach((key) => { + Object.keys(this.metadataForm.controls).forEach((key) => { if (key.endsWith('Locked')) { - this.bookMetadataForm.get(key)?.setValue(false); + this.metadataForm.get(key)?.setValue(false); const fieldName = key.replace('Locked', ''); - this.bookMetadataForm.get(fieldName)?.enable(); + this.metadataForm.get(fieldName)?.enable(); } }); this.updateMetadata(); @@ -187,39 +187,39 @@ export class MetadataEditorComponent implements OnInit { private buildMetadata() { const updatedBookMetadata: BookMetadata = { bookId: this.currentBookId, - title: this.bookMetadataForm.get('title')?.value, - subtitle: this.bookMetadataForm.get('subtitle')?.value, - authors: this.bookMetadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()), - categories: this.bookMetadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()), - publisher: this.bookMetadataForm.get('publisher')?.value, - publishedDate: this.bookMetadataForm.get('publishedDate')?.value, - isbn10: this.bookMetadataForm.get('isbn10')?.value, - isbn13: this.bookMetadataForm.get('isbn13')?.value, - description: this.bookMetadataForm.get('description')?.value, - pageCount: this.bookMetadataForm.get('pageCount')?.value, - rating: this.bookMetadataForm.get('rating')?.value, - reviewCount: this.bookMetadataForm.get('reviewCount')?.value, - language: this.bookMetadataForm.get('language')?.value, - seriesName: this.bookMetadataForm.get('seriesName')?.value, - seriesNumber: this.bookMetadataForm.get('seriesNumber')?.value, - seriesTotal: this.bookMetadataForm.get('seriesTotal')?.value, + 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, + 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.bookMetadataForm.get('titleLocked')?.value, - subtitleLocked: this.bookMetadataForm.get('subtitleLocked')?.value, - authorsLocked: this.bookMetadataForm.get('authorsLocked')?.value, - categoriesLocked: this.bookMetadataForm.get('categoriesLocked')?.value, - publisherLocked: this.bookMetadataForm.get('publisherLocked')?.value, - publishedDateLocked: this.bookMetadataForm.get('publishedDateLocked')?.value, - isbn10Locked: this.bookMetadataForm.get('isbn10Locked')?.value, - isbn13Locked: this.bookMetadataForm.get('isbn13Locked')?.value, - descriptionLocked: this.bookMetadataForm.get('descriptionLocked')?.value, - pageCountLocked: this.bookMetadataForm.get('pageCountLocked')?.value, - languageLocked: this.bookMetadataForm.get('languageLocked')?.value, - ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value, - reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value, - seriesNameLocked: this.bookMetadataForm.get('seriesNameLocked')?.value, - seriesNumberLocked: this.bookMetadataForm.get('seriesNumberLocked')?.value, - seriesTotalLocked: this.bookMetadataForm.get('seriesTotalLocked')?.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, + seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value, + seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value, + seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value, }; return updatedBookMetadata; diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-picker/metadata-picker.component.html b/booklore-ui/src/app/metadata/book-metadata-center/metadata-picker/metadata-picker.component.html index 8fed3fc8a..20c4d05f3 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-picker/metadata-picker.component.html +++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-picker/metadata-picker.component.html @@ -1,4 +1,4 @@ - +
@@ -16,6 +16,8 @@
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + + + +
+
+ +
+ +
+ + + + + +
+
+ +
+ +
+ + + + + +
+
+
+ +
+ +
- +
+ +
+ + = {}; savedFields: Record = {}; - private bookService = inject(BookService); private metadataCenterService = inject(BookMetadataCenterService); private messageService = inject(MessageService); private metadataService = inject(MetadataService); protected urlHelper = inject(UrlHelperService); - currentMetadata$: Observable = this.metadataCenterService.currentMetadata$; - protected metadata!: BookMetadata; + bookMetadata$: Observable = this.metadataCenterService.currentMetadata$; constructor() { this.metadataForm = new FormGroup({ @@ -66,19 +64,38 @@ export class MetadataPickerComponent implements OnInit { language: new FormControl(''), rating: new FormControl(''), reviewCount: 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), + seriesNameLocked: new FormControl(false), + seriesNumberLocked: new FormControl(false), + seriesTotalLocked: new FormControl(false), }); } ngOnInit(): void { - this.currentMetadata$.subscribe((metadata) => { + this.bookMetadata$.subscribe((metadata) => { if (metadata) { this.currentBookId = metadata.bookId; - this.metadata = metadata; this.metadataForm.setValue({ title: metadata.title, subtitle: metadata.subtitle, - authors: metadata.authors.map((author) => author.name).join(', '), - categories: metadata.categories.map((category) => category.name).join(', '), + authors: metadata.authors.map((author) => author.name).sort().join(', '), + categories: metadata.categories.map((category) => category.name).sort().join(', '), publisher: metadata.publisher, publishedDate: metadata.publishedDate, isbn10: metadata.isbn10, @@ -87,8 +104,45 @@ export class MetadataPickerComponent implements OnInit { pageCount: metadata.pageCount == 0 ? null : metadata.pageCount, language: metadata.language, rating: metadata.rating, - reviewCount: metadata.reviewCount + reviewCount: metadata.reviewCount, + seriesName: metadata.seriesName, + seriesNumber: metadata.seriesNumber, + seriesTotal: metadata.seriesTotal, + + 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, + seriesNameLocked: metadata.seriesNameLocked || false, + seriesNumberLocked: metadata.seriesNumberLocked || false, + seriesTotalLocked: metadata.seriesTotalLocked || 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.reviewCountLocked) this.metadataForm.get('reviewCount')?.disable(); + if (metadata.ratingLocked) this.metadataForm.get('rating')?.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(); } }); } @@ -102,24 +156,7 @@ export class MetadataPickerComponent implements OnInit { } onSave(): void { - 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') : '', - rating: this.metadataForm.get('rating')?.value || this.copiedFields['rating'] ? this.getNumberOrCopied('rating') : null, - reviewCount: this.metadataForm.get('reviewCount')?.value || this.copiedFields['reviewCount'] ? this.getNumberOrCopied('reviewCount') : null, - thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '', - }; - + const updatedBookMetadata = this.buildMetadata(); this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({ next: (bookMetadata) => { Object.keys(this.copiedFields).forEach((field) => { @@ -139,9 +176,74 @@ export class MetadataPickerComponent implements OnInit { }); } - copyMissing() { + private buildMetadata() { + 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') : '', + rating: this.metadataForm.get('rating')?.value || this.copiedFields['rating'] ? this.getNumberOrCopied('rating') : null, + reviewCount: this.metadataForm.get('reviewCount')?.value || this.copiedFields['reviewCount'] ? this.getNumberOrCopied('reviewCount') : 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.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '', + + 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, + seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value, + seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value, + seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value, + }; + return updatedBookMetadata; + } + + private updateMetadata(): void { + this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({ + next: (response) => { + this.metadataCenterService.emit(response); + }, + 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(); + } + + copyMissing(): void { Object.keys(this.fetchedMetadata).forEach((field) => { - if (!this.metadataForm.get(field)?.value && this.fetchedMetadata[field]) { + const isLocked = this.metadataForm.get(`${field}Locked`)?.value; + if (!isLocked && !this.metadataForm.get(field)?.value && this.fetchedMetadata[field]) { this.copyFetchedToCurrent(field); } }); @@ -190,6 +292,15 @@ export class MetadataPickerComponent implements OnInit { } 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); @@ -217,5 +328,4 @@ export class MetadataPickerComponent implements OnInit { closeDialog() { this.metadataCenterService.closeDialog(true); } - } diff --git a/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component.ts b/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component.ts index 71ee978f1..090612c72 100644 --- a/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component.ts +++ b/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component.ts @@ -22,9 +22,9 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges { refreshCovers: boolean = false; mergeCategories: boolean = false; - allP3 = {placeholder: 'Set All', value: ''}; - allP2 = {placeholder: 'Set All', value: ''}; - allP1 = {placeholder: 'Set All', value: ''}; + 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}, @@ -43,9 +43,9 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges { 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 || ''; - this.allP2.value = this.currentMetadataOptions.allP2 || ''; - this.allP1.value = this.currentMetadataOptions.allP1 || ''; + this.allP3.value = this.currentMetadataOptions.allP3 || null; + this.allP2.value = this.currentMetadataOptions.allP2 || null; + this.allP1.value = this.currentMetadataOptions.allP1 || null; } } @@ -82,9 +82,9 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges { } reset() { - this.allP3.value = ''; - this.allP2.value = ''; - this.allP1.value = ''; + 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, diff --git a/booklore-ui/src/app/metadata/model/request/metadata-refresh-options.model.ts b/booklore-ui/src/app/metadata/model/request/metadata-refresh-options.model.ts index 105e60cc5..71a716d3a 100644 --- a/booklore-ui/src/app/metadata/model/request/metadata-refresh-options.model.ts +++ b/booklore-ui/src/app/metadata/model/request/metadata-refresh-options.model.ts @@ -1,7 +1,7 @@ export interface MetadataRefreshOptions { - allP3: string; - allP2: string; - allP1: string; + allP3: string | null; + allP2: string | null; + allP1: string | null; refreshCovers: boolean; mergeCategories: boolean; fieldOptions?: FieldOptions; diff --git a/booklore-ui/src/app/metadata/service/metadata-dialog.service.ts b/booklore-ui/src/app/metadata/service/metadata-dialog.service.ts index a7efd21a7..912ce40af 100644 --- a/booklore-ui/src/app/metadata/service/metadata-dialog.service.ts +++ b/booklore-ui/src/app/metadata/service/metadata-dialog.service.ts @@ -19,8 +19,8 @@ export class MetadataDialogService { header: 'Open book details', modal: true, closable: true, - width: '1200px', - height: '835px', + width: '1400px', + height: '875px', showHeader: false, closeOnEscape: true, dismissableMask: true,