Add support for Moods and Tags in Magic Shelves (#1324)

This commit is contained in:
Aditya Chandel
2025-10-11 21:43:57 -06:00
committed by GitHub
parent c98c3cbc4a
commit 27635bd007
2 changed files with 19 additions and 10 deletions
@@ -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':
@@ -15,7 +15,7 @@ import {DynamicDialogConfig} from 'primeng/dynamicdialog';
import {MultiSelect} from 'primeng/multiselect'; import {MultiSelect} from 'primeng/multiselect';
import {AutoComplete} from 'primeng/autocomplete'; import {AutoComplete} from 'primeng/autocomplete';
import {EMPTY_CHECK_OPERATORS, MULTI_VALUE_OPERATORS, parseValue, removeNulls, serializeDateRules} from '../magic-shelf-utils'; import {EMPTY_CHECK_OPERATORS, MULTI_VALUE_OPERATORS, parseValue, removeNulls, serializeDateRules} from '../magic-shelf-utils';
import { IconPickerService } from '../utilities/services/icon-picker.service'; import {IconPickerService} from '../utilities/services/icon-picker.service';
export type RuleOperator = export type RuleOperator =
| 'equals' | 'equals'
@@ -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},
@@ -189,10 +193,10 @@ export class MagicShelfComponent implements OnInit {
shelfId: number | null = null; shelfId: number | null = null;
libraryService = inject(LibraryService); libraryService = inject(LibraryService);
magicShelfService = inject(MagicShelfService); magicShelfService = inject(MagicShelfService);
messageService = inject(MessageService); messageService = inject(MessageService);
config = inject(DynamicDialogConfig); config = inject(DynamicDialogConfig);
private iconPicker = inject(IconPickerService); private iconPicker = inject(IconPickerService);
trackByFn(ruleCtrl: AbstractControl, index: number): any { trackByFn(ruleCtrl: AbstractControl, index: number): any {
@@ -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,20 +415,17 @@ 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) {
const currentValue = formControl.value || []; const currentValue = formControl.value || [];
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 = '';
} }
} }