feat(shelf): add shelf filtering options and integrate into book processing (#2268)
* feat(shelf): add shelf filtering options and integrate into book processing Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(book-rule-evaluator): normalize array values to lowercase for rule comparisons Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * feat(filter): enhance library and shelf filtering logic for 'or' and 'and' modes Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * feat(shelf): implement support for multiple shelf IDs in book retrieval and filtering Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> --------- Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -20,6 +20,8 @@ import {CheckboxChangeEvent, CheckboxModule} from "primeng/checkbox";
|
||||
import {UserService} from "../../settings/user-management/user.service";
|
||||
import {IconDisplayComponent} from '../../../shared/components/icon-display/icon-display.component';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {ShelfService} from '../../book/service/shelf.service';
|
||||
import {Shelf} from '../../book/model/shelf.model';
|
||||
|
||||
export type RuleOperator =
|
||||
| 'equals'
|
||||
@@ -41,6 +43,7 @@ export type RuleOperator =
|
||||
|
||||
export type RuleField =
|
||||
| 'library'
|
||||
| 'shelf'
|
||||
| 'title'
|
||||
| 'subtitle'
|
||||
| 'authors'
|
||||
@@ -116,6 +119,7 @@ export type GroupFormGroup = FormGroup<{
|
||||
|
||||
const FIELD_CONFIGS: Record<RuleField, FullFieldConfig> = {
|
||||
library: {label: 'Library'},
|
||||
shelf: {label: 'Shelf'},
|
||||
readStatus: {label: 'Read Status'},
|
||||
dateFinished: {label: 'Date Finished', type: 'date'},
|
||||
lastReadTime: {label: 'Last Read Time', type: 'date'},
|
||||
@@ -203,6 +207,8 @@ export class MagicShelfComponent implements OnInit {
|
||||
|
||||
libraries: Library[] = [];
|
||||
libraryOptions: { label: string; value: number }[] = [];
|
||||
shelves: Shelf[] = [];
|
||||
shelfOptions: { label: string; value: number }[] = [];
|
||||
categoryOptions: { label: string; value: string }[] = [];
|
||||
|
||||
form = new FormGroup({
|
||||
@@ -217,6 +223,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
editMode!: boolean;
|
||||
|
||||
libraryService = inject(LibraryService);
|
||||
shelfService = inject(ShelfService);
|
||||
bookService = inject(BookService);
|
||||
magicShelfService = inject(MagicShelfService);
|
||||
ref = inject(DynamicDialogRef);
|
||||
@@ -286,6 +293,12 @@ export class MagicShelfComponent implements OnInit {
|
||||
label: lib.name,
|
||||
value: lib.id!
|
||||
}));
|
||||
|
||||
this.shelves = this.shelfService.getShelvesFromState();
|
||||
this.shelfOptions = this.shelves.map(shelf => ({
|
||||
label: shelf.name,
|
||||
value: shelf.id!
|
||||
}));
|
||||
}
|
||||
|
||||
buildGroupFromData(data: GroupRule): GroupFormGroup {
|
||||
@@ -355,14 +368,14 @@ export class MagicShelfComponent implements OnInit {
|
||||
if (!field) return [...baseOperators, ...multiValueOperators];
|
||||
|
||||
const config = FIELD_CONFIGS[field];
|
||||
const isMultiValueField = ['library', 'authors', 'categories', 'moods', 'tags', 'readStatus', 'fileType', 'language', 'title', 'subtitle', 'publisher', 'seriesName', 'isbn13', 'isbn10'].includes(field);
|
||||
const isMultiValueField = ['library', 'shelf', 'authors', 'categories', 'moods', 'tags', 'readStatus', 'fileType', 'language', 'title', 'subtitle', 'publisher', 'seriesName', 'isbn13', 'isbn10'].includes(field);
|
||||
const operators = [...baseOperators];
|
||||
|
||||
if (isMultiValueField) {
|
||||
operators.push(...multiValueOperators);
|
||||
}
|
||||
|
||||
const isTextEligible = !['library', 'readStatus', 'fileType'].includes(field);
|
||||
const isTextEligible = !['library', 'shelf', 'readStatus', 'fileType'].includes(field);
|
||||
|
||||
if (config.type === 'number' || config.type === 'decimal' || config.type === 'date') {
|
||||
operators.push(...comparisonOperators);
|
||||
|
||||
Reference in New Issue
Block a user