From f141fa49baa2904e4926458c9520c1cffbdb4657 Mon Sep 17 00:00:00 2001 From: Muppetteer Date: Fri, 21 Nov 2025 17:56:53 +1100 Subject: [PATCH] Feature: Autocomplete for publisher and series on book metadata edit screen (#1587) * Autocomplete for publisher and series on book metadata edit screen * Add autocomplete to bulk edit metadata form * seriesName was missing the [disabled]="clearFields.seriesName" attribute --------- Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> --- .../metadata-editor.component.html | 29 ++- .../metadata-editor.component.ts | 28 +++ .../bulk-metadata-update-component.html | 185 +++++++++++++----- .../bulk-metadata-update-component.ts | 122 ++++++++++-- 4 files changed, 296 insertions(+), 68 deletions(-) diff --git a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html index 423273dc0..02a1c06d6 100644 --- a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -125,7 +125,18 @@
- + + @if (!book.metadata!['publisherLocked']) { } @@ -137,7 +148,7 @@
- + @if (!book.metadata!['languageLocked']) { } @@ -235,7 +246,19 @@
- + + @if (!book.metadata!['seriesNameLocked']) { } diff --git a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts index a5777e7dd..2e1623554 100644 --- a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts +++ b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts @@ -81,10 +81,14 @@ export class MetadataEditorComponent implements OnInit { allCategories!: string[]; allMoods!: string[]; allTags!: string[]; + allPublishers!: string[]; + allSeries!: string[]; filteredCategories: string[] = []; filteredAuthors: string[] = []; filteredMoods: string[] = []; filteredTags: string[] = []; + filteredPublishers: string[] = []; + filteredSeries: string[] = []; filterCategories(event: { query: string }) { const query = event.query.toLowerCase(); @@ -114,6 +118,20 @@ export class MetadataEditorComponent implements OnInit { ); } + filterPublishers(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredPublishers = this.allPublishers.filter((publisher) => + publisher.toLowerCase().includes(query) + ); + } + + filterSeries(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredSeries = this.allSeries.filter((seriesName) => + seriesName.toLowerCase().includes(query) + ); + } + constructor() { this.metadataForm = new FormGroup({ title: new FormControl(""), @@ -201,6 +219,8 @@ export class MetadataEditorComponent implements OnInit { const categories = new Set(); const moods = new Set(); const tags = new Set(); + const publishers = new Set(); + const series = new Set(); (bookState.books ?? []).forEach((book) => { book.metadata?.authors?.forEach((author) => authors.add(author)); @@ -209,12 +229,20 @@ export class MetadataEditorComponent implements OnInit { ); book.metadata?.moods?.forEach((mood) => moods.add(mood)); book.metadata?.tags?.forEach((tag) => tags.add(tag)); + if (book.metadata?.publisher) { + publishers.add(book.metadata.publisher); + } + if (book.metadata?.seriesName) { + series.add(book.metadata.seriesName); + } }); this.allAuthors = Array.from(authors); this.allCategories = Array.from(categories); this.allMoods = Array.from(moods); this.allTags = Array.from(tags); + this.allPublishers = Array.from(publishers); + this.allSeries = Array.from(series); }); } diff --git a/booklore-ui/src/app/features/metadata/component/bulk-metadata-update/bulk-metadata-update-component.html b/booklore-ui/src/app/features/metadata/component/bulk-metadata-update/bulk-metadata-update-component.html index a49145962..43e92f885 100644 --- a/booklore-ui/src/app/features/metadata/component/bulk-metadata-update/bulk-metadata-update-component.html +++ b/booklore-ui/src/app/features/metadata/component/bulk-metadata-update/bulk-metadata-update-component.html @@ -36,40 +36,39 @@
-
- - -
- - -
- - -
- -
+ +
+ + + +
+ -
+
+ +
+ +
+ + + +
-
+
+ +
+ +
+ + + +
-
+
- - -
- -
@@ -151,7 +196,19 @@
- + +
Clear
- + +
Clear
- + +
+ cat.toLowerCase().includes(query) + ); + } + + filterAuthors(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredAuthors = this.allAuthors.filter((author) => + author.toLowerCase().includes(query) + ); + } + + filterMoods(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredMoods = this.allMoods.filter((mood) => + mood.toLowerCase().includes(query) + ); + } + + filterTags(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredTags = this.allTags.filter((tag) => + tag.toLowerCase().includes(query) + ); + } + + filterPublishers(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredPublishers = this.allPublishers.filter((publisher) => + publisher.toLowerCase().includes(query) + ); + } + + filterSeries(event: { query: string }) { + const query = event.query.toLowerCase(); + this.filteredSeries = this.allSeries.filter((seriesName) => + seriesName.toLowerCase().includes(query) + ); + } + ngOnInit(): void { this.bookIds = this.config.data?.bookIds ?? []; this.books = this.bookService.getBooksByIdsFromState(this.bookIds); @@ -75,6 +131,42 @@ export class BulkMetadataUpdateComponent implements OnInit { moods: [], tags: [] }); + + this.bookService.bookState$ + .pipe( + filter((bookState) => bookState.loaded), + take(1) + ) + .subscribe((bookState) => { + const authors = new Set(); + const categories = new Set(); + const moods = new Set(); + const tags = new Set(); + const publishers = new Set(); + const series = new Set(); + + (bookState.books ?? []).forEach((book) => { + book.metadata?.authors?.forEach((author) => authors.add(author)); + book.metadata?.categories?.forEach((category) => + categories.add(category) + ); + book.metadata?.moods?.forEach((mood) => moods.add(mood)); + book.metadata?.tags?.forEach((tag) => tags.add(tag)); + if (book.metadata?.publisher) { + publishers.add(book.metadata.publisher); + } + if (book.metadata?.seriesName) { + series.add(book.metadata.seriesName); + } + }); + + this.allAuthors = Array.from(authors); + this.allGenres = Array.from(categories); + this.allMoods = Array.from(moods); + this.allTags = Array.from(tags); + this.allPublishers = Array.from(publishers); + this.allSeries = Array.from(series); + }); } onFieldClearToggle(field: keyof typeof this.clearFields): void { @@ -89,21 +181,25 @@ export class BulkMetadataUpdateComponent implements OnInit { } } - // Handle blur event for AutoComplete to add custom values - onAutoCompleteBlur(fieldName: string, event: any) { - const inputValue = event.target.value?.trim(); - if (inputValue) { - const currentValue = this.metadataForm.get(fieldName)?.value || []; - const values = Array.isArray(currentValue) ? currentValue : - typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : []; + onAutoCompleteSelect(fieldName: string, event: any) { + const values = this.metadataForm.get(fieldName)?.value || []; + if (!values.includes(event.value)) { + this.metadataForm.get(fieldName)?.setValue([...values, event.value]); + } + (event.originalEvent.target as HTMLInputElement).value = ""; + } - // Add the new value if it's not already in the array - if (!values.includes(inputValue)) { - values.push(inputValue); - this.metadataForm.get(fieldName)?.setValue(values); + onAutoCompleteKeyUp(fieldName: string, event: KeyboardEvent) { + if (event.key === "Enter") { + const input = event.target as HTMLInputElement; + const value = input.value?.trim(); + if (value) { + const values = this.metadataForm.get(fieldName)?.value || []; + if (!values.includes(value)) { + this.metadataForm.get(fieldName)?.setValue([...values, value]); + } + input.value = ""; } - // Clear the input - event.target.value = ''; } }