feat(magic-shelf): add genre filter support and improve category labeling in rule fields (#2075)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {IconPickerService, IconSelection} from '../../../shared/service/icon-pic
|
||||
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';
|
||||
|
||||
export type RuleOperator =
|
||||
| 'equals'
|
||||
@@ -172,10 +173,14 @@ export class MagicShelfComponent implements OnInit {
|
||||
{label: 'OR', value: 'or'},
|
||||
];
|
||||
|
||||
fieldOptions = Object.entries(FIELD_CONFIGS).map(([key, config]) => ({
|
||||
label: config.label,
|
||||
value: key as RuleField
|
||||
}));
|
||||
fieldOptions = Object.entries(FIELD_CONFIGS).map(([key, config]) => {
|
||||
// Use "Genre" instead of "Categories" for user-facing label
|
||||
const label = key === 'categories' ? 'Genre' : config.label;
|
||||
return {
|
||||
label: label,
|
||||
value: key as RuleField
|
||||
};
|
||||
});
|
||||
|
||||
fileType: { label: string; value: string }[] = [
|
||||
{label: 'PDF', value: 'pdf'},
|
||||
@@ -192,6 +197,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
|
||||
libraries: Library[] = [];
|
||||
libraryOptions: { label: string; value: number }[] = [];
|
||||
categoryOptions: { label: string; value: string }[] = [];
|
||||
|
||||
form = new FormGroup({
|
||||
name: new FormControl<string | null>(null),
|
||||
@@ -205,6 +211,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
editMode!: boolean;
|
||||
|
||||
libraryService = inject(LibraryService);
|
||||
bookService = inject(BookService);
|
||||
magicShelfService = inject(MagicShelfService);
|
||||
ref = inject(DynamicDialogRef);
|
||||
messageService = inject(MessageService);
|
||||
@@ -223,6 +230,24 @@ export class MagicShelfComponent implements OnInit {
|
||||
const id = this.config?.data?.id;
|
||||
this.editMode = !!this.config?.data?.editMode;
|
||||
|
||||
// Load available categories from book metadata
|
||||
this.bookService.bookState$.subscribe(state => {
|
||||
if (state.loaded && state.books) {
|
||||
// Extract unique categories from all books
|
||||
const categoriesSet = new Set<string>();
|
||||
state.books.forEach(book => {
|
||||
if (book.metadata?.categories) {
|
||||
book.metadata.categories.forEach(cat => categoriesSet.add(cat));
|
||||
}
|
||||
});
|
||||
|
||||
this.categoryOptions = Array.from(categoriesSet).map(cat => ({
|
||||
label: cat,
|
||||
value: cat
|
||||
})).sort((a, b) => a.label.localeCompare(b.label));
|
||||
}
|
||||
});
|
||||
|
||||
if (id) {
|
||||
this.shelfId = id;
|
||||
this.magicShelfService.getShelf(id).subscribe((data) => {
|
||||
|
||||
Reference in New Issue
Block a user