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:
@@ -138,6 +138,8 @@
|
||||
<p-multiSelect [options]="fileType" formControlName="value" display="chip" class="value-input" appendTo="body" placeholder="Select File Types"></p-multiSelect>
|
||||
} @else if (ruleCtrl.get('field')?.value === 'library') {
|
||||
<p-multiSelect [options]="libraryOptions" formControlName="value" display="chip" class="value-input" appendTo="body" placeholder="Select Libraries"></p-multiSelect>
|
||||
} @else if (ruleCtrl.get('field')?.value === 'categories') {
|
||||
<p-multiSelect [options]="categoryOptions" formControlName="value" display="chip" class="value-input" appendTo="body" placeholder="Select Genres"></p-multiSelect>
|
||||
} @else {
|
||||
<div class="autocomplete-wrapper">
|
||||
<p-autoComplete [formControl]="ruleCtrl.get('value')" [multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" placeholder="Enter values (press Enter)" (onBlur)="onAutoCompleteBlur(ruleCtrl.get('value'), $event)"></p-autoComplete>
|
||||
@@ -149,6 +151,8 @@
|
||||
<p-select [options]="fileType" formControlName="value" placeholder="Select File Type" appendTo="body" class="value-input"></p-select>
|
||||
} @else if (ruleCtrl.get('field')?.value === 'library') {
|
||||
<p-select [options]="libraryOptions" formControlName="value" placeholder="Select Library" appendTo="body" class="value-input"></p-select>
|
||||
} @else if (ruleCtrl.get('field')?.value === 'categories') {
|
||||
<p-select [options]="categoryOptions" formControlName="value" placeholder="Select Genre" appendTo="body" class="value-input"></p-select>
|
||||
} @else {
|
||||
<input pInputText formControlName="value" class="value-input" placeholder="Value"/>
|
||||
}
|
||||
|
||||
@@ -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