Add support for Moods and Tags in Magic Shelves (#1324)
This commit is contained in:
@@ -41,6 +41,10 @@ export class BookRuleEvaluatorService {
|
|||||||
return (book.metadata?.authors ?? []).map(a => a.toLowerCase());
|
return (book.metadata?.authors ?? []).map(a => a.toLowerCase());
|
||||||
case 'categories':
|
case 'categories':
|
||||||
return (book.metadata?.categories ?? []).map(c => c.toLowerCase());
|
return (book.metadata?.categories ?? []).map(c => c.toLowerCase());
|
||||||
|
case 'moods':
|
||||||
|
return (book.metadata?.moods ?? []).map(m => m.toLowerCase());
|
||||||
|
case 'tags':
|
||||||
|
return (book.metadata?.tags ?? []).map(t => t.toLowerCase());
|
||||||
case 'readStatus':
|
case 'readStatus':
|
||||||
return [String(book.readStatus).toLowerCase()];
|
return [String(book.readStatus).toLowerCase()];
|
||||||
case 'fileType':
|
case 'fileType':
|
||||||
@@ -190,6 +194,10 @@ export class BookRuleEvaluatorService {
|
|||||||
return (book.metadata?.authors ?? []).map(a => a.toLowerCase());
|
return (book.metadata?.authors ?? []).map(a => a.toLowerCase());
|
||||||
case 'categories':
|
case 'categories':
|
||||||
return (book.metadata?.categories ?? []).map(c => c.toLowerCase());
|
return (book.metadata?.categories ?? []).map(c => c.toLowerCase());
|
||||||
|
case 'moods':
|
||||||
|
return (book.metadata?.moods ?? []).map(m => m.toLowerCase());
|
||||||
|
case 'tags':
|
||||||
|
return (book.metadata?.tags ?? []).map(t => t.toLowerCase());
|
||||||
case 'publisher':
|
case 'publisher':
|
||||||
return book.metadata?.publisher?.toLowerCase() ?? null;
|
return book.metadata?.publisher?.toLowerCase() ?? null;
|
||||||
case 'publishedDate':
|
case 'publishedDate':
|
||||||
|
|||||||
@@ -59,7 +59,9 @@ export type RuleField =
|
|||||||
| 'fileSize'
|
| 'fileSize'
|
||||||
| 'readStatus'
|
| 'readStatus'
|
||||||
| 'dateFinished'
|
| 'dateFinished'
|
||||||
| 'metadataScore';
|
| 'metadataScore'
|
||||||
|
| 'moods'
|
||||||
|
| 'tags';
|
||||||
|
|
||||||
|
|
||||||
interface FullFieldConfig {
|
interface FullFieldConfig {
|
||||||
@@ -112,6 +114,8 @@ const FIELD_CONFIGS: Record<RuleField, FullFieldConfig> = {
|
|||||||
title: {label: 'Title'},
|
title: {label: 'Title'},
|
||||||
authors: {label: 'Authors'},
|
authors: {label: 'Authors'},
|
||||||
categories: {label: 'Categories'},
|
categories: {label: 'Categories'},
|
||||||
|
moods: {label: 'Moods'},
|
||||||
|
tags: {label: 'Tags'},
|
||||||
publisher: {label: 'Publisher'},
|
publisher: {label: 'Publisher'},
|
||||||
publishedDate: {label: 'Published Date', type: 'date'},
|
publishedDate: {label: 'Published Date', type: 'date'},
|
||||||
personalRating: {label: 'Personal Rating', type: 'decimal', max: 10},
|
personalRating: {label: 'Personal Rating', type: 'decimal', max: 10},
|
||||||
@@ -293,7 +297,7 @@ export class MagicShelfComponent implements OnInit {
|
|||||||
if (!field) return [...baseOperators, ...multiValueOperators];
|
if (!field) return [...baseOperators, ...multiValueOperators];
|
||||||
|
|
||||||
const config = FIELD_CONFIGS[field];
|
const config = FIELD_CONFIGS[field];
|
||||||
const isMultiValueField = ['library', 'authors', 'categories', 'readStatus', 'fileType', 'language', 'title', 'subtitle', 'publisher', 'seriesName'].includes(field);
|
const isMultiValueField = ['library', 'authors', 'categories', 'moods', 'tags', 'readStatus', 'fileType', 'language', 'title', 'subtitle', 'publisher', 'seriesName'].includes(field);
|
||||||
const operators = [...baseOperators];
|
const operators = [...baseOperators];
|
||||||
|
|
||||||
if (isMultiValueField) {
|
if (isMultiValueField) {
|
||||||
@@ -411,7 +415,6 @@ export class MagicShelfComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle blur event for AutoComplete to add custom values
|
|
||||||
onAutoCompleteBlur(formControl: any, event: any) {
|
onAutoCompleteBlur(formControl: any, event: any) {
|
||||||
const inputValue = event.target.value?.trim();
|
const inputValue = event.target.value?.trim();
|
||||||
if (inputValue) {
|
if (inputValue) {
|
||||||
@@ -419,12 +422,10 @@ export class MagicShelfComponent implements OnInit {
|
|||||||
const values = Array.isArray(currentValue) ? currentValue :
|
const values = Array.isArray(currentValue) ? currentValue :
|
||||||
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : [];
|
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : [];
|
||||||
|
|
||||||
// Add the new value if it's not already in the array
|
|
||||||
if (!values.includes(inputValue)) {
|
if (!values.includes(inputValue)) {
|
||||||
values.push(inputValue);
|
values.push(inputValue);
|
||||||
formControl.setValue(values);
|
formControl.setValue(values);
|
||||||
}
|
}
|
||||||
// Clear the input
|
|
||||||
event.target.value = '';
|
event.target.value = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user