feat: add metadata presence filter to magic shelf (#2757)

This commit is contained in:
ACX
2026-02-14 21:41:03 -07:00
committed by GitHub
parent af0f5a4080
commit 0899b99188
10 changed files with 1913 additions and 15 deletions
@@ -159,6 +159,8 @@
<p-select [options]="seriesGapsOptions" formControlName="value" [placeholder]="t('placeholders.selectSeriesGap')" appendTo="body" class="value-input"></p-select>
} @else if (ruleCtrl.get('field')?.value === 'seriesPosition') {
<p-select [options]="seriesPositionOptions" formControlName="value" [placeholder]="t('placeholders.selectSeriesPosition')" appendTo="body" class="value-input"></p-select>
} @else if (ruleCtrl.get('field')?.value === 'metadataPresence') {
<p-select [options]="metadataPresenceOptions" [group]="true" optionGroupLabel="label" optionGroupChildren="items" [filter]="true" filterBy="label" formControlName="value" [placeholder]="t('placeholders.selectMetadataField')" appendTo="body" class="value-input"></p-select>
} @else if (['includes_any', 'includes_all', 'excludes_all'].includes(ruleCtrl.get('operator')?.value)) {
@if (ruleCtrl.get('field')?.value === 'readStatus') {
<p-multiSelect [options]="readStatusOptions" formControlName="value" display="chip" class="value-input" appendTo="body" [placeholder]="t('placeholders.selectStatuses')"></p-multiSelect>
@@ -63,6 +63,14 @@ describe('MagicShelfComponent (Part 3)', () => {
expect(operators[0].label).toContain('has');
});
it('should return has/hasNot operators for metadataPresence', () => {
const operators = component.getOperatorOptionsForField('metadataPresence');
expect(operators).toHaveLength(2);
expect(operators.map(o => o.value)).toEqual(['equals', 'not_equals']);
expect(operators[0].label).toContain('has');
expect(operators[1].label).toContain('hasNot');
});
it('should include relative date operators for date fields', () => {
const operators = component.getOperatorOptionsForField('dateFinished');
const values = operators.map(o => o.value);
@@ -496,8 +504,8 @@ describe('MagicShelfComponent (Part 3)', () => {
});
describe('fieldOptions completeness', () => {
it('should have 8 groups total', () => {
expect(component.fieldOptions.length).toBe(8);
it('should have 9 groups total', () => {
expect(component.fieldOptions.length).toBe(9);
});
it('should map categories field to genre translation key', () => {
@@ -526,6 +534,70 @@ describe('MagicShelfComponent (Part 3)', () => {
expect(fieldValues).toContain('lastReadTime');
expect(fieldValues).toContain('addedOn');
});
it('should include metadataScore and metadataPresence in qualityMetadata group', () => {
const groups = component.fieldOptions;
const qualityGroup = groups.find(g => g.label.includes('qualityMetadata'));
const fieldValues = qualityGroup?.items.map(i => i.value) ?? [];
expect(fieldValues).toContain('metadataScore');
expect(fieldValues).toContain('metadataPresence');
});
it('should NOT include metadataScore in ratingsReviews group', () => {
const groups = component.fieldOptions;
const ratingsGroup = groups.find(g => g.label.includes('ratingsReviews'));
const fieldValues = ratingsGroup?.items.map(i => i.value) ?? [];
expect(fieldValues).not.toContain('metadataScore');
});
});
describe('metadataPresenceOptions', () => {
it('should return 10 groups', () => {
const options = component.metadataPresenceOptions;
expect(options).toHaveLength(10);
});
it('should have grouped structure with label and items', () => {
const options = component.metadataPresenceOptions;
options.forEach(group => {
expect(group.label).toBeDefined();
expect(group.items).toBeDefined();
expect(group.items.length).toBeGreaterThan(0);
group.items.forEach(item => {
expect(item.label).toBeDefined();
expect(item.value).toBeDefined();
});
});
});
it('should include key metadata fields', () => {
const options = component.metadataPresenceOptions;
const allValues = options.flatMap(g => g.items.map(i => i.value));
expect(allValues).toContain('title');
expect(allValues).toContain('thumbnailUrl');
expect(allValues).toContain('authors');
expect(allValues).toContain('isbn13');
expect(allValues).toContain('goodreadsId');
expect(allValues).toContain('audiobookDuration');
expect(allValues).toContain('comicCharacters');
});
});
describe('buildRuleFromData for metadataPresence', () => {
it('should parse metadataPresence rule with string value', () => {
const rule: Rule = {field: 'metadataPresence', operator: 'equals', value: 'thumbnailUrl'};
const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('field')?.value).toBe('metadataPresence');
expect(formGroup.get('operator')?.value).toBe('equals');
expect(formGroup.get('value')?.value).toBe('thumbnailUrl');
});
it('should parse metadataPresence rule with not_equals', () => {
const rule: Rule = {field: 'metadataPresence', operator: 'not_equals', value: 'description'};
const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('operator')?.value).toBe('not_equals');
expect(formGroup.get('value')?.value).toBe('description');
});
});
describe('numericFieldConfigMap', () => {
@@ -92,7 +92,8 @@ export type RuleField =
| 'seriesStatus'
| 'seriesGaps'
| 'seriesPosition'
| 'readingProgress';
| 'readingProgress'
| 'metadataPresence';
interface FullFieldConfig {
@@ -183,7 +184,8 @@ const FIELD_CONFIGS: Record<RuleField, FullFieldConfig> = {
seriesStatus: {label: 'seriesStatus'},
seriesGaps: {label: 'seriesGaps'},
seriesPosition: {label: 'seriesPosition'},
readingProgress: {label: 'readingProgress', type: 'decimal', max: 100}
readingProgress: {label: 'readingProgress', type: 'decimal', max: 100},
metadataPresence: {label: 'metadataPresence'}
};
interface FieldGroup {
@@ -196,7 +198,8 @@ const FIELD_GROUPS: FieldGroup[] = [
{ translationKey: 'bookInfo', fields: ['title', 'subtitle', 'description', 'authors', 'categories', 'publisher', 'language', 'pageCount', 'ageRating', 'contentRating'] },
{ translationKey: 'series', fields: ['seriesName', 'seriesNumber', 'seriesTotal', 'seriesStatus', 'seriesGaps', 'seriesPosition'] },
{ translationKey: 'dates', fields: ['publishedDate', 'dateFinished', 'lastReadTime', 'addedOn'] },
{ translationKey: 'ratingsReviews', fields: ['personalRating', 'metadataScore', 'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount', 'hardcoverRating', 'hardcoverReviewCount', 'ranobedbRating', 'lubimyczytacRating', 'audibleRating', 'audibleReviewCount'] },
{ translationKey: 'ratingsReviews', fields: ['personalRating', 'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount', 'hardcoverRating', 'hardcoverReviewCount', 'ranobedbRating', 'lubimyczytacRating', 'audibleRating', 'audibleReviewCount'] },
{ translationKey: 'qualityMetadata', fields: ['metadataScore', 'metadataPresence'] },
{ translationKey: 'tagsMoods', fields: ['moods', 'tags'] },
{ translationKey: 'audiobook', fields: ['narrator', 'abridged', 'audiobookDuration'] },
{ translationKey: 'fileIdentifiers', fields: ['fileType', 'fileSize', 'isbn13', 'isbn10', 'isPhysical'] }
@@ -330,6 +333,81 @@ export class MagicShelfComponent implements OnInit {
];
}
get metadataPresenceOptions() {
return [
{ label: this.t.translate('magicShelf.metadataFieldGroups.bookInfo'), items: [
{label: this.t.translate('magicShelf.metadataFields.title'), value: 'title'},
{label: this.t.translate('magicShelf.metadataFields.subtitle'), value: 'subtitle'},
{label: this.t.translate('magicShelf.metadataFields.description'), value: 'description'},
{label: this.t.translate('magicShelf.metadataFields.thumbnailUrl'), value: 'thumbnailUrl'},
{label: this.t.translate('magicShelf.metadataFields.publisher'), value: 'publisher'},
{label: this.t.translate('magicShelf.metadataFields.publishedDate'), value: 'publishedDate'},
{label: this.t.translate('magicShelf.metadataFields.language'), value: 'language'},
{label: this.t.translate('magicShelf.metadataFields.pageCount'), value: 'pageCount'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.authorsCategories'), items: [
{label: this.t.translate('magicShelf.metadataFields.authors'), value: 'authors'},
{label: this.t.translate('magicShelf.metadataFields.categories'), value: 'categories'},
{label: this.t.translate('magicShelf.metadataFields.moods'), value: 'moods'},
{label: this.t.translate('magicShelf.metadataFields.tags'), value: 'tags'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.series'), items: [
{label: this.t.translate('magicShelf.metadataFields.seriesName'), value: 'seriesName'},
{label: this.t.translate('magicShelf.metadataFields.seriesNumber'), value: 'seriesNumber'},
{label: this.t.translate('magicShelf.metadataFields.seriesTotal'), value: 'seriesTotal'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.identifiers'), items: [
{label: this.t.translate('magicShelf.metadataFields.isbn13'), value: 'isbn13'},
{label: this.t.translate('magicShelf.metadataFields.isbn10'), value: 'isbn10'},
{label: this.t.translate('magicShelf.metadataFields.asin'), value: 'asin'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.contentClassification'), items: [
{label: this.t.translate('magicShelf.metadataFields.ageRating'), value: 'ageRating'},
{label: this.t.translate('magicShelf.metadataFields.contentRating'), value: 'contentRating'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.ratings'), items: [
{label: this.t.translate('magicShelf.metadataFields.personalRating'), value: 'personalRating'},
{label: this.t.translate('magicShelf.metadataFields.amazonRating'), value: 'amazonRating'},
{label: this.t.translate('magicShelf.metadataFields.goodreadsRating'), value: 'goodreadsRating'},
{label: this.t.translate('magicShelf.metadataFields.hardcoverRating'), value: 'hardcoverRating'},
{label: this.t.translate('magicShelf.metadataFields.ranobedbRating'), value: 'ranobedbRating'},
{label: this.t.translate('magicShelf.metadataFields.lubimyczytacRating'), value: 'lubimyczytacRating'},
{label: this.t.translate('magicShelf.metadataFields.audibleRating'), value: 'audibleRating'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.reviewCounts'), items: [
{label: this.t.translate('magicShelf.metadataFields.amazonReviewCount'), value: 'amazonReviewCount'},
{label: this.t.translate('magicShelf.metadataFields.goodreadsReviewCount'), value: 'goodreadsReviewCount'},
{label: this.t.translate('magicShelf.metadataFields.hardcoverReviewCount'), value: 'hardcoverReviewCount'},
{label: this.t.translate('magicShelf.metadataFields.audibleReviewCount'), value: 'audibleReviewCount'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.externalIds'), items: [
{label: this.t.translate('magicShelf.metadataFields.goodreadsId'), value: 'goodreadsId'},
{label: this.t.translate('magicShelf.metadataFields.hardcoverId'), value: 'hardcoverId'},
{label: this.t.translate('magicShelf.metadataFields.googleId'), value: 'googleId'},
{label: this.t.translate('magicShelf.metadataFields.audibleId'), value: 'audibleId'},
{label: this.t.translate('magicShelf.metadataFields.lubimyczytacId'), value: 'lubimyczytacId'},
{label: this.t.translate('magicShelf.metadataFields.ranobedbId'), value: 'ranobedbId'},
{label: this.t.translate('magicShelf.metadataFields.comicvineId'), value: 'comicvineId'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.audiobook'), items: [
{label: this.t.translate('magicShelf.metadataFields.narrator'), value: 'narrator'},
{label: this.t.translate('magicShelf.metadataFields.abridged'), value: 'abridged'},
{label: this.t.translate('magicShelf.metadataFields.audiobookDuration'), value: 'audiobookDuration'},
]},
{ label: this.t.translate('magicShelf.metadataFieldGroups.comic'), items: [
{label: this.t.translate('magicShelf.metadataFields.comicCharacters'), value: 'comicCharacters'},
{label: this.t.translate('magicShelf.metadataFields.comicTeams'), value: 'comicTeams'},
{label: this.t.translate('magicShelf.metadataFields.comicLocations'), value: 'comicLocations'},
{label: this.t.translate('magicShelf.metadataFields.comicPencillers'), value: 'comicPencillers'},
{label: this.t.translate('magicShelf.metadataFields.comicInkers'), value: 'comicInkers'},
{label: this.t.translate('magicShelf.metadataFields.comicColorists'), value: 'comicColorists'},
{label: this.t.translate('magicShelf.metadataFields.comicLetterers'), value: 'comicLetterers'},
{label: this.t.translate('magicShelf.metadataFields.comicCoverArtists'), value: 'comicCoverArtists'},
{label: this.t.translate('magicShelf.metadataFields.comicEditors'), value: 'comicEditors'},
]},
];
}
get dateUnitOptions() {
return [
{label: this.t.translate('magicShelf.dateUnits.days'), value: 'days'},
@@ -540,7 +618,7 @@ export class MagicShelfComponent implements OnInit {
{label: this.t.translate('magicShelf.operators.isNot'), value: 'not_equals'},
];
}
if (field === 'seriesGaps') {
if (field === 'seriesGaps' || field === 'metadataPresence') {
return [
{label: this.t.translate('magicShelf.operators.has'), value: 'equals'},
{label: this.t.translate('magicShelf.operators.hasNot'), value: 'not_equals'},
@@ -0,0 +1,533 @@
import {beforeEach, describe, expect, it} from 'vitest';
import {TestBed} from '@angular/core/testing';
import {BookRuleEvaluatorService} from './book-rule-evaluator.service';
import {Book, ReadStatus} from '../../book/model/book.model';
import {GroupRule} from '../component/magic-shelf-component';
describe('BookRuleEvaluatorService - metadataPresence', () => {
let service: BookRuleEvaluatorService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(BookRuleEvaluatorService);
});
const createBook = (overrides: Partial<Book> = {}): Book => ({
id: 1,
bookType: 'EPUB',
libraryId: 1,
libraryName: 'Test Library',
fileName: 'test.epub',
filePath: '/path/to/test.epub',
readStatus: ReadStatus.UNREAD,
shelves: [],
metadata: {
bookId: 1,
title: 'Test Book',
authors: ['Test Author'],
categories: ['Fiction'],
language: 'en'
},
...overrides
});
const rule = (operator: string, value: string): GroupRule => ({
name: 'test', type: 'group', join: 'and',
rules: [{field: 'metadataPresence', operator, value} as never]
});
describe('string fields', () => {
it('should detect present title', () => {
const book = createBook({metadata: {bookId: 1, title: 'A Book'}});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(true);
expect(service.evaluateGroup(book, rule('not_equals', 'title'))).toBe(false);
});
it('should detect missing title', () => {
const book = createBook({metadata: {bookId: 1, title: undefined}});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(false);
expect(service.evaluateGroup(book, rule('not_equals', 'title'))).toBe(true);
});
it('should treat empty string as absent', () => {
const book = createBook({metadata: {bookId: 1, title: ''}});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(false);
});
it('should treat whitespace-only string as absent', () => {
const book = createBook({metadata: {bookId: 1, title: ' '}});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(false);
});
it('should detect present subtitle', () => {
const book = createBook({metadata: {bookId: 1, subtitle: 'A Novel'}});
expect(service.evaluateGroup(book, rule('equals', 'subtitle'))).toBe(true);
});
it('should detect missing subtitle', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('equals', 'subtitle'))).toBe(false);
});
it('should detect present description', () => {
const book = createBook({metadata: {bookId: 1, description: 'A tale of adventure'}});
expect(service.evaluateGroup(book, rule('equals', 'description'))).toBe(true);
});
it('should detect missing description', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'description'))).toBe(true);
});
it('should detect present publisher', () => {
const book = createBook({metadata: {bookId: 1, publisher: 'Tor Books'}});
expect(service.evaluateGroup(book, rule('equals', 'publisher'))).toBe(true);
});
it('should detect present publishedDate', () => {
const book = createBook({metadata: {bookId: 1, publishedDate: '2024-01-01'}});
expect(service.evaluateGroup(book, rule('equals', 'publishedDate'))).toBe(true);
});
it('should detect missing publishedDate', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('equals', 'publishedDate'))).toBe(false);
});
it('should detect present language', () => {
const book = createBook({metadata: {bookId: 1, language: 'en'}});
expect(service.evaluateGroup(book, rule('equals', 'language'))).toBe(true);
});
it('should detect present thumbnailUrl', () => {
const book = createBook({metadata: {bookId: 1, thumbnailUrl: 'https://example.com/cover.jpg'}});
expect(service.evaluateGroup(book, rule('equals', 'thumbnailUrl'))).toBe(true);
});
it('should detect missing thumbnailUrl', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'thumbnailUrl'))).toBe(true);
});
it('should detect present narrator', () => {
const book = createBook({metadata: {bookId: 1, narrator: 'Stephen Fry'}});
expect(service.evaluateGroup(book, rule('equals', 'narrator'))).toBe(true);
});
it('should detect present contentRating', () => {
const book = createBook({metadata: {bookId: 1, contentRating: 'MATURE'}});
expect(service.evaluateGroup(book, rule('equals', 'contentRating'))).toBe(true);
});
it('should detect present seriesName', () => {
const book = createBook({metadata: {bookId: 1, seriesName: 'Dune'}});
expect(service.evaluateGroup(book, rule('equals', 'seriesName'))).toBe(true);
});
it('should detect missing seriesName', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('equals', 'seriesName'))).toBe(false);
});
});
describe('identifier fields', () => {
it('should detect present isbn13', () => {
const book = createBook({metadata: {bookId: 1, isbn13: '9780123456789'}});
expect(service.evaluateGroup(book, rule('equals', 'isbn13'))).toBe(true);
});
it('should detect missing isbn13', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'isbn13'))).toBe(true);
});
it('should detect present isbn10', () => {
const book = createBook({metadata: {bookId: 1, isbn10: '0123456789'}});
expect(service.evaluateGroup(book, rule('equals', 'isbn10'))).toBe(true);
});
it('should detect present asin', () => {
const book = createBook({metadata: {bookId: 1, asin: 'B08N5WRWNW'}});
expect(service.evaluateGroup(book, rule('equals', 'asin'))).toBe(true);
});
it('should detect missing asin', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'asin'))).toBe(true);
});
});
describe('numeric fields', () => {
it('should detect present pageCount', () => {
const book = createBook({metadata: {bookId: 1, pageCount: 350}});
expect(service.evaluateGroup(book, rule('equals', 'pageCount'))).toBe(true);
});
it('should detect missing pageCount', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('equals', 'pageCount'))).toBe(false);
});
it('should treat zero pageCount as present', () => {
const book = createBook({metadata: {bookId: 1, pageCount: 0}});
expect(service.evaluateGroup(book, rule('equals', 'pageCount'))).toBe(true);
});
it('should detect present seriesNumber', () => {
const book = createBook({metadata: {bookId: 1, seriesNumber: 3}});
expect(service.evaluateGroup(book, rule('equals', 'seriesNumber'))).toBe(true);
});
it('should detect present seriesTotal', () => {
const book = createBook({metadata: {bookId: 1, seriesTotal: 10}});
expect(service.evaluateGroup(book, rule('equals', 'seriesTotal'))).toBe(true);
});
it('should detect present ageRating', () => {
const book = createBook({metadata: {bookId: 1, ageRating: 16}});
expect(service.evaluateGroup(book, rule('equals', 'ageRating'))).toBe(true);
});
});
describe('array fields', () => {
it('should detect present authors', () => {
const book = createBook({metadata: {bookId: 1, authors: ['Author One']}});
expect(service.evaluateGroup(book, rule('equals', 'authors'))).toBe(true);
});
it('should detect empty authors as absent', () => {
const book = createBook({metadata: {bookId: 1, authors: []}});
expect(service.evaluateGroup(book, rule('equals', 'authors'))).toBe(false);
expect(service.evaluateGroup(book, rule('not_equals', 'authors'))).toBe(true);
});
it('should detect missing authors (undefined) as absent', () => {
const book = createBook({metadata: {bookId: 1, authors: undefined}});
expect(service.evaluateGroup(book, rule('equals', 'authors'))).toBe(false);
});
it('should detect present categories', () => {
const book = createBook({metadata: {bookId: 1, categories: ['Fantasy']}});
expect(service.evaluateGroup(book, rule('equals', 'categories'))).toBe(true);
});
it('should detect empty categories as absent', () => {
const book = createBook({metadata: {bookId: 1, categories: []}});
expect(service.evaluateGroup(book, rule('equals', 'categories'))).toBe(false);
});
it('should detect present moods', () => {
const book = createBook({metadata: {bookId: 1, moods: ['Dark', 'Atmospheric']}});
expect(service.evaluateGroup(book, rule('equals', 'moods'))).toBe(true);
});
it('should detect missing moods as absent', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'moods'))).toBe(true);
});
it('should detect present tags', () => {
const book = createBook({metadata: {bookId: 1, tags: ['favorite']}});
expect(service.evaluateGroup(book, rule('equals', 'tags'))).toBe(true);
});
it('should detect missing tags as absent', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'tags'))).toBe(true);
});
});
describe('rating fields', () => {
it('should detect present personalRating', () => {
const book = createBook({personalRating: 8});
expect(service.evaluateGroup(book, rule('equals', 'personalRating'))).toBe(true);
});
it('should detect missing personalRating', () => {
const book = createBook({personalRating: undefined});
expect(service.evaluateGroup(book, rule('equals', 'personalRating'))).toBe(false);
expect(service.evaluateGroup(book, rule('not_equals', 'personalRating'))).toBe(true);
});
it('should detect present amazonRating', () => {
const book = createBook({metadata: {bookId: 1, amazonRating: 4.5}});
expect(service.evaluateGroup(book, rule('equals', 'amazonRating'))).toBe(true);
});
it('should detect missing amazonRating', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'amazonRating'))).toBe(true);
});
it('should detect present goodreadsRating', () => {
const book = createBook({metadata: {bookId: 1, goodreadsRating: 4.1}});
expect(service.evaluateGroup(book, rule('equals', 'goodreadsRating'))).toBe(true);
});
it('should detect present hardcoverRating', () => {
const book = createBook({metadata: {bookId: 1, hardcoverRating: 3.9}});
expect(service.evaluateGroup(book, rule('equals', 'hardcoverRating'))).toBe(true);
});
it('should detect present ranobedbRating', () => {
const book = createBook({metadata: {bookId: 1, ranobedbRating: 4.0}});
expect(service.evaluateGroup(book, rule('equals', 'ranobedbRating'))).toBe(true);
});
it('should detect present lubimyczytacRating', () => {
const book = createBook({metadata: {bookId: 1, lubimyczytacRating: 4.2}});
expect(service.evaluateGroup(book, rule('equals', 'lubimyczytacRating'))).toBe(true);
});
it('should detect present audibleRating', () => {
const book = createBook({metadata: {bookId: 1, audibleRating: 4.7}});
expect(service.evaluateGroup(book, rule('equals', 'audibleRating'))).toBe(true);
});
});
describe('review count fields', () => {
it('should detect present amazonReviewCount', () => {
const book = createBook({metadata: {bookId: 1, amazonReviewCount: 1200}});
expect(service.evaluateGroup(book, rule('equals', 'amazonReviewCount'))).toBe(true);
});
it('should detect missing amazonReviewCount', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'amazonReviewCount'))).toBe(true);
});
it('should detect present goodreadsReviewCount', () => {
const book = createBook({metadata: {bookId: 1, goodreadsReviewCount: 5000}});
expect(service.evaluateGroup(book, rule('equals', 'goodreadsReviewCount'))).toBe(true);
});
it('should detect present hardcoverReviewCount', () => {
const book = createBook({metadata: {bookId: 1, hardcoverReviewCount: 300}});
expect(service.evaluateGroup(book, rule('equals', 'hardcoverReviewCount'))).toBe(true);
});
it('should detect present audibleReviewCount', () => {
const book = createBook({metadata: {bookId: 1, audibleReviewCount: 500}});
expect(service.evaluateGroup(book, rule('equals', 'audibleReviewCount'))).toBe(true);
});
});
describe('external ID fields', () => {
it('should detect present goodreadsId', () => {
const book = createBook({metadata: {bookId: 1, goodreadsId: '12345'}});
expect(service.evaluateGroup(book, rule('equals', 'goodreadsId'))).toBe(true);
});
it('should detect missing goodreadsId', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'goodreadsId'))).toBe(true);
});
it('should detect present hardcoverId', () => {
const book = createBook({metadata: {bookId: 1, hardcoverId: 'hc-123'}});
expect(service.evaluateGroup(book, rule('equals', 'hardcoverId'))).toBe(true);
});
it('should detect present googleId', () => {
const book = createBook({metadata: {bookId: 1, googleId: 'gid-456'}});
expect(service.evaluateGroup(book, rule('equals', 'googleId'))).toBe(true);
});
it('should detect present audibleId', () => {
const book = createBook({metadata: {bookId: 1, audibleId: 'aud-789'}});
expect(service.evaluateGroup(book, rule('equals', 'audibleId'))).toBe(true);
});
it('should detect present lubimyczytacId', () => {
const book = createBook({metadata: {bookId: 1, lubimyczytacId: 'lub-321'}});
expect(service.evaluateGroup(book, rule('equals', 'lubimyczytacId'))).toBe(true);
});
it('should detect present ranobedbId', () => {
const book = createBook({metadata: {bookId: 1, ranobedbId: 'ran-654'}});
expect(service.evaluateGroup(book, rule('equals', 'ranobedbId'))).toBe(true);
});
it('should detect present comicvineId', () => {
const book = createBook({metadata: {bookId: 1, comicvineId: 'cv-987'}});
expect(service.evaluateGroup(book, rule('equals', 'comicvineId'))).toBe(true);
});
it('should detect missing comicvineId', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'comicvineId'))).toBe(true);
});
});
describe('boolean fields', () => {
it('should detect present abridged (true)', () => {
const book = createBook({metadata: {bookId: 1, abridged: true}});
expect(service.evaluateGroup(book, rule('equals', 'abridged'))).toBe(true);
});
it('should detect present abridged (false)', () => {
const book = createBook({metadata: {bookId: 1, abridged: false}});
expect(service.evaluateGroup(book, rule('equals', 'abridged'))).toBe(true);
});
it('should detect missing abridged', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('equals', 'abridged'))).toBe(false);
expect(service.evaluateGroup(book, rule('not_equals', 'abridged'))).toBe(true);
});
});
describe('audiobook fields', () => {
it('should detect present audiobookDuration', () => {
const book = createBook({metadata: {bookId: 1, audiobookMetadata: {durationSeconds: 36000}}});
expect(service.evaluateGroup(book, rule('equals', 'audiobookDuration'))).toBe(true);
});
it('should detect missing audiobookDuration (no audiobookMetadata)', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'audiobookDuration'))).toBe(true);
});
it('should detect zero audiobookDuration as present', () => {
const book = createBook({metadata: {bookId: 1, audiobookMetadata: {durationSeconds: 0}}});
expect(service.evaluateGroup(book, rule('equals', 'audiobookDuration'))).toBe(true);
});
});
describe('comic metadata fields', () => {
it('should detect present comicCharacters', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {characters: ['Batman', 'Joker']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicCharacters'))).toBe(true);
});
it('should detect empty comicCharacters as absent', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {characters: []}}});
expect(service.evaluateGroup(book, rule('equals', 'comicCharacters'))).toBe(false);
});
it('should detect missing comicCharacters (no comicMetadata)', () => {
const book = createBook({metadata: {bookId: 1}});
expect(service.evaluateGroup(book, rule('not_equals', 'comicCharacters'))).toBe(true);
});
it('should detect present comicTeams', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {teams: ['Justice League']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicTeams'))).toBe(true);
});
it('should detect present comicLocations', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {locations: ['Gotham City']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicLocations'))).toBe(true);
});
it('should detect present comicPencillers', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {pencillers: ['Jim Lee']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicPencillers'))).toBe(true);
});
it('should detect present comicInkers', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {inkers: ['Scott Williams']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicInkers'))).toBe(true);
});
it('should detect present comicColorists', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {colorists: ['Alex Sinclair']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicColorists'))).toBe(true);
});
it('should detect present comicLetterers', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {letterers: ['Todd Klein']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicLetterers'))).toBe(true);
});
it('should detect present comicCoverArtists', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {coverArtists: ['Alex Ross']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicCoverArtists'))).toBe(true);
});
it('should detect present comicEditors', () => {
const book = createBook({metadata: {bookId: 1, comicMetadata: {editors: ['Mark Doyle']}}});
expect(service.evaluateGroup(book, rule('equals', 'comicEditors'))).toBe(true);
});
});
describe('edge cases', () => {
it('should return false for unknown metadata field', () => {
const book = createBook();
expect(service.evaluateGroup(book, rule('equals', 'nonExistentField'))).toBe(false);
});
it('should handle book with no metadata', () => {
const book = createBook({metadata: undefined});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(false);
expect(service.evaluateGroup(book, rule('not_equals', 'title'))).toBe(true);
});
it('should handle non-string rule value gracefully', () => {
const book = createBook({metadata: {bookId: 1, title: 'Test'}});
const g: GroupRule = {
name: 'test', type: 'group', join: 'and',
rules: [{field: 'metadataPresence', operator: 'equals', value: null} as never]
};
expect(service.evaluateGroup(book, g)).toBe(false);
});
it('should not require allBooks parameter', () => {
const book = createBook({metadata: {bookId: 1, title: 'Test'}});
expect(service.evaluateGroup(book, rule('equals', 'title'))).toBe(true);
});
});
describe('combined rules', () => {
it('should match books missing cover OR description', () => {
const bookNoCover = createBook({metadata: {bookId: 1, title: 'Test', description: 'Has desc'}});
const bookNoDesc = createBook({metadata: {bookId: 2, title: 'Test', thumbnailUrl: 'http://cover.jpg'}});
const bookHasBoth = createBook({metadata: {bookId: 3, title: 'Test', description: 'Has desc', thumbnailUrl: 'http://cover.jpg'}});
const group: GroupRule = {
name: 'test', type: 'group', join: 'or',
rules: [
{field: 'metadataPresence', operator: 'not_equals', value: 'thumbnailUrl'},
{field: 'metadataPresence', operator: 'not_equals', value: 'description'}
]
};
expect(service.evaluateGroup(bookNoCover, group)).toBe(true);
expect(service.evaluateGroup(bookNoDesc, group)).toBe(true);
expect(service.evaluateGroup(bookHasBoth, group)).toBe(false);
});
it('should match books with complete identifiers', () => {
const bookComplete = createBook({metadata: {bookId: 1, isbn13: '9780123456789', goodreadsId: '12345'}});
const bookPartial = createBook({metadata: {bookId: 2, isbn13: '9780123456789'}});
const group: GroupRule = {
name: 'test', type: 'group', join: 'and',
rules: [
{field: 'metadataPresence', operator: 'equals', value: 'isbn13'},
{field: 'metadataPresence', operator: 'equals', value: 'goodreadsId'}
]
};
expect(service.evaluateGroup(bookComplete, group)).toBe(true);
expect(service.evaluateGroup(bookPartial, group)).toBe(false);
});
it('should work with non-metadataPresence rules in same group', () => {
const book = createBook({
readStatus: ReadStatus.UNREAD,
metadata: {bookId: 1, title: 'Test'}
});
const group: GroupRule = {
name: 'test', type: 'group', join: 'and',
rules: [
{field: 'readStatus', operator: 'equals', value: 'UNREAD'},
{field: 'metadataPresence', operator: 'not_equals', value: 'thumbnailUrl'}
]
};
expect(service.evaluateGroup(book, group)).toBe(true);
});
});
});
@@ -17,6 +17,10 @@ export class BookRuleEvaluatorService {
}
private evaluateRule(book: Book, rule: Rule, allBooks: Book[]): boolean {
if (rule.field === 'metadataPresence') {
return this.evaluateMetadataPresence(book, rule);
}
if (rule.field === 'seriesStatus' || rule.field === 'seriesGaps' || rule.field === 'seriesPosition') {
return this.evaluateCompositeField(book, rule, allBooks);
}
@@ -472,6 +476,76 @@ export class BookRuleEvaluatorService {
}
}
private evaluateMetadataPresence(book: Book, rule: Rule): boolean {
const metadataField = typeof rule.value === 'string' ? rule.value : '';
const isPresent = this.isMetadataFieldPresent(book, metadataField);
return rule.operator === 'equals' ? isPresent : !isPresent;
}
private isMetadataFieldPresent(book: Book, field: string): boolean {
const val = this.getMetadataFieldValue(book, field);
if (val == null) return false;
if (typeof val === 'string') return val.trim() !== '';
if (Array.isArray(val)) return val.length > 0;
return true;
}
private getMetadataFieldValue(book: Book, field: string): unknown {
switch (field) {
case 'title': return book.metadata?.title;
case 'subtitle': return book.metadata?.subtitle;
case 'description': return book.metadata?.description;
case 'publisher': return book.metadata?.publisher;
case 'publishedDate': return book.metadata?.publishedDate;
case 'language': return book.metadata?.language;
case 'thumbnailUrl': return book.metadata?.thumbnailUrl;
case 'narrator': return book.metadata?.narrator;
case 'contentRating': return book.metadata?.contentRating;
case 'pageCount': return book.metadata?.pageCount;
case 'seriesNumber': return book.metadata?.seriesNumber;
case 'seriesTotal': return book.metadata?.seriesTotal;
case 'ageRating': return book.metadata?.ageRating;
case 'seriesName': return book.metadata?.seriesName;
case 'isbn13': return book.metadata?.isbn13;
case 'isbn10': return book.metadata?.isbn10;
case 'asin': return book.metadata?.asin;
case 'authors': return book.metadata?.authors;
case 'categories': return book.metadata?.categories;
case 'moods': return book.metadata?.moods;
case 'tags': return book.metadata?.tags;
case 'personalRating': return book.personalRating;
case 'amazonRating': return book.metadata?.amazonRating;
case 'goodreadsRating': return book.metadata?.goodreadsRating;
case 'hardcoverRating': return book.metadata?.hardcoverRating;
case 'ranobedbRating': return book.metadata?.ranobedbRating;
case 'lubimyczytacRating': return book.metadata?.lubimyczytacRating;
case 'audibleRating': return book.metadata?.audibleRating;
case 'amazonReviewCount': return book.metadata?.amazonReviewCount;
case 'goodreadsReviewCount': return book.metadata?.goodreadsReviewCount;
case 'hardcoverReviewCount': return book.metadata?.hardcoverReviewCount;
case 'audibleReviewCount': return book.metadata?.audibleReviewCount;
case 'goodreadsId': return book.metadata?.goodreadsId;
case 'hardcoverId': return book.metadata?.hardcoverId;
case 'googleId': return book.metadata?.googleId;
case 'audibleId': return book.metadata?.audibleId;
case 'lubimyczytacId': return book.metadata?.lubimyczytacId;
case 'ranobedbId': return book.metadata?.ranobedbId;
case 'comicvineId': return book.metadata?.comicvineId;
case 'abridged': return book.metadata?.abridged;
case 'audiobookDuration': return book.metadata?.audiobookMetadata?.durationSeconds;
case 'comicCharacters': return book.metadata?.comicMetadata?.characters;
case 'comicTeams': return book.metadata?.comicMetadata?.teams;
case 'comicLocations': return book.metadata?.comicMetadata?.locations;
case 'comicPencillers': return book.metadata?.comicMetadata?.pencillers;
case 'comicInkers': return book.metadata?.comicMetadata?.inkers;
case 'comicColorists': return book.metadata?.comicMetadata?.colorists;
case 'comicLetterers': return book.metadata?.comicMetadata?.letterers;
case 'comicCoverArtists': return book.metadata?.comicMetadata?.coverArtists;
case 'comicEditors': return book.metadata?.comicMetadata?.editors;
default: return null;
}
}
private computeDateThreshold(amount: number, unit: string): Date {
const now = new Date();
switch (unit.toLowerCase()) {
+70 -3
View File
@@ -51,7 +51,8 @@
"selectPeriod": "Select Period",
"selectSeriesStatus": "Select Status",
"selectSeriesGap": "Select Gap Type",
"selectSeriesPosition": "Select Position"
"selectSeriesPosition": "Select Position",
"selectMetadataField": "Select Metadata Field"
},
"conditions": {
"and": "AND",
@@ -104,7 +105,8 @@
"seriesStatus": "Series Status",
"seriesGaps": "Series Gaps",
"seriesPosition": "Series Position",
"readingProgress": "Reading Progress (%)"
"readingProgress": "Reading Progress (%)",
"metadataPresence": "Metadata Presence"
},
"fieldGroups": {
"organization": "Organization",
@@ -114,7 +116,8 @@
"ratingsReviews": "Ratings & Reviews",
"tagsMoods": "Tags & Moods",
"audiobook": "Audiobook",
"fileIdentifiers": "File & Identifiers"
"fileIdentifiers": "File & Identifiers",
"qualityMetadata": "Quality & Metadata"
},
"operators": {
"equals": "Equals",
@@ -192,6 +195,70 @@
"month": "This Month",
"year": "This Year"
},
"metadataFieldGroups": {
"bookInfo": "Book Info",
"authorsCategories": "Authors & Categories",
"series": "Series",
"identifiers": "Identifiers",
"contentClassification": "Content Classification",
"ratings": "Ratings",
"reviewCounts": "Review Counts",
"externalIds": "External IDs",
"audiobook": "Audiobook",
"comic": "Comic"
},
"metadataFields": {
"title": "Title",
"subtitle": "Subtitle",
"description": "Description",
"thumbnailUrl": "Cover Image",
"publisher": "Publisher",
"publishedDate": "Published Date",
"language": "Language",
"pageCount": "Page Count",
"authors": "Authors",
"categories": "Genre",
"moods": "Moods",
"tags": "Tags",
"seriesName": "Series Name",
"seriesNumber": "Series Number",
"seriesTotal": "Series Total",
"isbn13": "ISBN-13",
"isbn10": "ISBN-10",
"asin": "ASIN",
"ageRating": "Age Rating",
"contentRating": "Content Rating",
"personalRating": "Personal Rating",
"amazonRating": "Amazon Rating",
"goodreadsRating": "Goodreads Rating",
"hardcoverRating": "Hardcover Rating",
"ranobedbRating": "Ranobedb Rating",
"lubimyczytacRating": "Lubimyczytac Rating",
"audibleRating": "Audible Rating",
"amazonReviewCount": "Amazon Reviews",
"goodreadsReviewCount": "Goodreads Reviews",
"hardcoverReviewCount": "Hardcover Reviews",
"audibleReviewCount": "Audible Reviews",
"goodreadsId": "Goodreads ID",
"hardcoverId": "Hardcover ID",
"googleId": "Google ID",
"audibleId": "Audible ID",
"lubimyczytacId": "Lubimyczytac ID",
"ranobedbId": "Ranobedb ID",
"comicvineId": "ComicVine ID",
"narrator": "Narrator",
"abridged": "Abridged",
"audiobookDuration": "Duration",
"comicCharacters": "Characters",
"comicTeams": "Teams",
"comicLocations": "Locations",
"comicPencillers": "Pencillers",
"comicInkers": "Inkers",
"comicColorists": "Colorists",
"comicLetterers": "Letterers",
"comicCoverArtists": "Cover Artists",
"comicEditors": "Editors"
},
"toast": {
"validationErrorSummary": "Validation Error",
"validationErrorDetail": "You must add at least one valid rule before saving.",
+70 -3
View File
@@ -51,7 +51,8 @@
"selectPeriod": "Seleccionar Per\u00edodo",
"selectSeriesStatus": "Seleccionar Estado",
"selectSeriesGap": "Seleccionar Tipo de Hueco",
"selectSeriesPosition": "Seleccionar Posici\u00f3n"
"selectSeriesPosition": "Seleccionar Posici\u00f3n",
"selectMetadataField": "Seleccionar Campo de Metadatos"
},
"conditions": {
"and": "Y",
@@ -104,7 +105,8 @@
"seriesStatus": "Estado de la Serie",
"seriesGaps": "Huecos en la Serie",
"seriesPosition": "Posici\u00f3n en la Serie",
"readingProgress": "Progreso de Lectura (%)"
"readingProgress": "Progreso de Lectura (%)",
"metadataPresence": "Presencia de Metadatos"
},
"fieldGroups": {
"organization": "Organizaci\u00f3n",
@@ -114,7 +116,8 @@
"ratingsReviews": "Calificaciones y Rese\u00f1as",
"tagsMoods": "Etiquetas y Estados de \u00c1nimo",
"audiobook": "Audiolibro",
"fileIdentifiers": "Archivo e Identificadores"
"fileIdentifiers": "Archivo e Identificadores",
"qualityMetadata": "Calidad y Metadatos"
},
"operators": {
"equals": "Igual",
@@ -192,6 +195,70 @@
"month": "Este Mes",
"year": "Este A\u00f1o"
},
"metadataFieldGroups": {
"bookInfo": "Info del Libro",
"authorsCategories": "Autores y Categor\u00edas",
"series": "Serie",
"identifiers": "Identificadores",
"contentClassification": "Clasificaci\u00f3n de Contenido",
"ratings": "Calificaciones",
"reviewCounts": "Cantidad de Rese\u00f1as",
"externalIds": "IDs Externos",
"audiobook": "Audiolibro",
"comic": "C\u00f3mic"
},
"metadataFields": {
"title": "T\u00edtulo",
"subtitle": "Subt\u00edtulo",
"description": "Descripci\u00f3n",
"thumbnailUrl": "Imagen de Portada",
"publisher": "Editorial",
"publishedDate": "Fecha de Publicaci\u00f3n",
"language": "Idioma",
"pageCount": "N\u00famero de P\u00e1ginas",
"authors": "Autores",
"categories": "G\u00e9nero",
"moods": "Estados de \u00c1nimo",
"tags": "Etiquetas",
"seriesName": "Nombre de la Serie",
"seriesNumber": "N\u00famero de Serie",
"seriesTotal": "Total de la Serie",
"isbn13": "ISBN-13",
"isbn10": "ISBN-10",
"asin": "ASIN",
"ageRating": "Clasificaci\u00f3n por Edad",
"contentRating": "Clasificaci\u00f3n de Contenido",
"personalRating": "Calificaci\u00f3n Personal",
"amazonRating": "Calificaci\u00f3n de Amazon",
"goodreadsRating": "Calificaci\u00f3n de Goodreads",
"hardcoverRating": "Calificaci\u00f3n de Hardcover",
"ranobedbRating": "Calificaci\u00f3n de Ranobedb",
"lubimyczytacRating": "Calificaci\u00f3n de Lubimyczytac",
"audibleRating": "Calificaci\u00f3n de Audible",
"amazonReviewCount": "Rese\u00f1as de Amazon",
"goodreadsReviewCount": "Rese\u00f1as de Goodreads",
"hardcoverReviewCount": "Rese\u00f1as de Hardcover",
"audibleReviewCount": "Rese\u00f1as de Audible",
"goodreadsId": "ID de Goodreads",
"hardcoverId": "ID de Hardcover",
"googleId": "ID de Google",
"audibleId": "ID de Audible",
"lubimyczytacId": "ID de Lubimyczytac",
"ranobedbId": "ID de Ranobedb",
"comicvineId": "ID de ComicVine",
"narrator": "Narrador",
"abridged": "Abreviado",
"audiobookDuration": "Duraci\u00f3n",
"comicCharacters": "Personajes",
"comicTeams": "Equipos",
"comicLocations": "Ubicaciones",
"comicPencillers": "Dibujantes",
"comicInkers": "Entintadores",
"comicColorists": "Coloristas",
"comicLetterers": "Letristas",
"comicCoverArtists": "Artistas de Portada",
"comicEditors": "Editores"
},
"toast": {
"validationErrorSummary": "Error de Validaci\u00f3n",
"validationErrorDetail": "Debe agregar al menos una regla v\u00e1lida antes de guardar.",