Support moods and tags in Bookdrop metadata picker (#1306)
This commit is contained in:
-1
@@ -15,7 +15,6 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
+15
-7
@@ -49,7 +49,9 @@ export class BookdropFileMetadataPickerComponent {
|
||||
|
||||
metadataChips = [
|
||||
{label: 'Authors', controlName: 'authors', lockedKey: 'authorsLocked', fetchedKey: 'authors'},
|
||||
{label: 'Genres', controlName: 'categories', lockedKey: 'categoriesLocked', fetchedKey: 'categories'}
|
||||
{label: 'Genres', controlName: 'categories', lockedKey: 'categoriesLocked', fetchedKey: 'categories'},
|
||||
{label: 'Moods', controlName: 'moods', lockedKey: 'moodsLocked', fetchedKey: 'moods'},
|
||||
{label: 'Tags', controlName: 'tags', lockedKey: 'tagsLocked', fetchedKey: 'tags'},
|
||||
];
|
||||
|
||||
metadataDescription = [
|
||||
@@ -81,7 +83,15 @@ export class BookdropFileMetadataPickerComponent {
|
||||
|
||||
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;
|
||||
const currentValue = this.metadataForm.get(field)?.value;
|
||||
const fetchedValue = this.fetchedMetadata[field];
|
||||
|
||||
const isEmpty = Array.isArray(currentValue)
|
||||
? currentValue.length === 0
|
||||
: !currentValue;
|
||||
|
||||
if (!isLocked && isEmpty && fetchedValue) {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
@@ -140,20 +150,16 @@ export class BookdropFileMetadataPickerComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// 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()) : [];
|
||||
|
||||
// Add the new value if it's not already in the array
|
||||
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : []
|
||||
if (!values.includes(inputValue)) {
|
||||
values.push(inputValue);
|
||||
this.metadataForm.get(fieldName)?.setValue(values);
|
||||
}
|
||||
// Clear the input
|
||||
event.target.value = '';
|
||||
}
|
||||
}
|
||||
@@ -165,6 +171,8 @@ export class BookdropFileMetadataPickerComponent {
|
||||
subtitle: this.originalMetadata.subtitle || null,
|
||||
authors: [...(this.originalMetadata.authors ?? [])].sort(),
|
||||
categories: [...(this.originalMetadata.categories ?? [])].sort(),
|
||||
moods: [...(this.originalMetadata.moods ?? [])].sort(),
|
||||
tags: [...(this.originalMetadata.tags ?? [])].sort(),
|
||||
publisher: this.originalMetadata.publisher || null,
|
||||
publishedDate: this.originalMetadata.publishedDate || null,
|
||||
isbn10: this.originalMetadata.isbn10 || null,
|
||||
|
||||
+4
@@ -253,6 +253,8 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
subtitle: original?.subtitle || null,
|
||||
authors: [...(original?.authors ?? [])].sort(),
|
||||
categories: [...(original?.categories ?? [])].sort(),
|
||||
moods: [...(original?.moods ?? [])].sort(),
|
||||
tags: [...(original?.tags ?? [])].sort(),
|
||||
publisher: original?.publisher || null,
|
||||
publishedDate: original?.publishedDate || null,
|
||||
isbn10: original?.isbn10 ?? null,
|
||||
@@ -496,6 +498,8 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
subtitle: new FormControl(original?.subtitle ?? ''),
|
||||
authors: new FormControl([...(original?.authors ?? [])].sort()),
|
||||
categories: new FormControl([...(original?.categories ?? [])].sort()),
|
||||
moods: new FormControl([...(original?.moods ?? [])].sort()),
|
||||
tags: new FormControl([...(original?.tags ?? [])].sort()),
|
||||
publisher: new FormControl(original?.publisher ?? ''),
|
||||
publishedDate: new FormControl(original?.publishedDate ?? ''),
|
||||
isbn10: new FormControl(original?.isbn10 ?? ''),
|
||||
|
||||
Reference in New Issue
Block a user