Enhance metadata options to allow skipping fields during fetch and support extended field options (#1263)

This commit is contained in:
Aditya Chandel
2025-10-05 00:15:11 -06:00
committed by GitHub
parent 41f68a6075
commit ff230f34fc
9 changed files with 689 additions and 424 deletions
@@ -177,58 +177,56 @@
</div>
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1 md:basis-[50%]">
<div class="flex flex-col gap-1 w-full">
<label class="text-sm" for="moods">Moods</label>
<div class="flex justify-between items-center gap-2">
<div class="w-full">
<p-autoComplete
class="w-full"
formControlName="moods"
[multiple]="true"
[dropdown]="false"
[suggestions]="filteredMoods"
[forceSelection]="false"
[showClear]="true"
(completeMethod)="filterMoods($event)"
(onKeyUp)="onAutoCompleteKeyUp('moods', $event)"
(onSelect)="onAutoCompleteSelect('moods', $event)">
</p-autoComplete>
</div>
@if (!book.metadata!['moodsLocked']) {
<p-button size="small" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('moods')" severity="success"></p-button>
}
@if (book.metadata!['moodsLocked']) {
<p-button size="small" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('moods')" severity="warn"></p-button>
}
<div class="flex flex-col gap-1 w-full">
<label class="text-sm" for="moods">Moods</label>
<div class="flex justify-between items-center gap-2">
<div class="w-full">
<p-autoComplete
class="w-full"
formControlName="moods"
[multiple]="true"
[dropdown]="false"
[suggestions]="filteredMoods"
[forceSelection]="false"
[showClear]="true"
(completeMethod)="filterMoods($event)"
(onKeyUp)="onAutoCompleteKeyUp('moods', $event)"
(onSelect)="onAutoCompleteSelect('moods', $event)">
</p-autoComplete>
</div>
@if (!book.metadata!['moodsLocked']) {
<p-button size="small" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('moods')" severity="success"></p-button>
}
@if (book.metadata!['moodsLocked']) {
<p-button size="small" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('moods')" severity="warn"></p-button>
}
</div>
</div>
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1 md:basis-[50%]">
<div class="flex flex-col gap-1 w-full">
<label class="text-sm" for="tags">Tags</label>
<div class="flex justify-between items-center gap-2">
<div class="w-full">
<p-autoComplete
class="w-full"
formControlName="tags"
[multiple]="true"
[dropdown]="false"
[suggestions]="filteredTags"
[forceSelection]="false"
[showClear]="true"
(completeMethod)="filterTags($event)"
(onKeyUp)="onAutoCompleteKeyUp('tags', $event)"
(onSelect)="onAutoCompleteSelect('tags', $event)">
</p-autoComplete>
</div>
@if (!book.metadata!['tagsLocked']) {
<p-button size="small" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('tags')" severity="success"></p-button>
}
@if (book.metadata!['tagsLocked']) {
<p-button size="small" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('tags')" severity="warn"></p-button>
}
</div>
<div class="flex flex-col md:flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-full">
<label class="text-sm" for="tags">Tags</label>
<div class="flex justify-between items-center gap-2">
<div class="w-full">
<p-autoComplete
class="w-full"
formControlName="tags"
[multiple]="true"
[dropdown]="false"
[suggestions]="filteredTags"
[forceSelection]="false"
[showClear]="true"
(completeMethod)="filterTags($event)"
(onKeyUp)="onAutoCompleteKeyUp('tags', $event)"
(onSelect)="onAutoCompleteSelect('tags', $event)">
</p-autoComplete>
</div>
@if (!book.metadata!['tagsLocked']) {
<p-button size="small" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('tags')" severity="success"></p-button>
}
@if (book.metadata!['tagsLocked']) {
<p-button size="small" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('tags')" severity="warn"></p-button>
}
</div>
</div>
</div>
@@ -2,95 +2,100 @@
<table class="min-w-full table-auto border-collapse custom-table">
<thead>
<tr>
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">Book Field</th>
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">Skip</th>
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">Metadata Field</th>
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">
4th Priority
<i class="pi pi-question-circle ml-1 text-xs"
pTooltip="Last fallback option - only used if 1st, 2nd, and 3rd priorities fail or are empty"
tooltipPosition="top"></i>
</th>
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">
3rd Priority
<i class="pi pi-question-circle ml-1 text-xs"
pTooltip="Third choice - used if 1st and 2nd priorities don't have data"
tooltipPosition="top"></i>
</th>
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">
2nd Priority
<i class="pi pi-question-circle ml-1 text-xs"
pTooltip="Second choice - used if 1st priority doesn't have data"
tooltipPosition="top"></i>
</th>
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">
<th class="px-4 py-1.5 text-left font-semibold text-zinc-300">
1st Priority
<i class="pi pi-question-circle ml-1 text-xs"
pTooltip="First choice - always tried first for this field"
tooltipPosition="top"></i>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-sm px-4 py-1.5 text-gray-300">
All Other Fields
<i class="pi pi-question-circle ml-1 text-xs"
pTooltip="Quick way to set the same provider priority for all fields at once"
tooltipPosition="right"></i>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="allP4.value"
(onChange)="syncProvider($event, 'p4')"
placeholder="Select All" appendTo="body"
<td class="px-4 py-2"></td>
<td class="px-4 py-2 text-sm text-zinc-400 italic">Set All:</td>
<td class="px-4 py-2">
<p-select [options]="providersWithClear" [(ngModel)]="bulkP4"
(ngModelChange)="setBulkProvider('p4', $event)"
placeholder="Set all P4" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="allP3.value"
(onChange)="syncProvider($event, 'p3')"
placeholder="Select All" appendTo="body"
<td class="px-4 py-2">
<p-select [options]="providersWithClear" [(ngModel)]="bulkP3"
(ngModelChange)="setBulkProvider('p3', $event)"
placeholder="Set all P3" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="allP2.value"
(onChange)="syncProvider($event, 'p2')"
placeholder="Select All" appendTo="body"
<td class="px-4 py-2">
<p-select [options]="providersWithClear" [(ngModel)]="bulkP2"
(ngModelChange)="setBulkProvider('p2', $event)"
placeholder="Set all P2" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="allP1.value"
(onChange)="syncProvider($event, 'p1')"
placeholder="Select All" appendTo="body"
<td class="px-4 py-2">
<p-select [options]="providersWithClear" [(ngModel)]="bulkP1"
(ngModelChange)="setBulkProvider('p1', $event)"
placeholder="Set all P1" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
</tr>
@for (field of fields; track field) {
<tr [hidden]="field === 'cover' && !refreshCovers">
<td class="text-sm px-4 py-1.5 text-gray-300">{{ formatLabel(field) }}</td>
</thead>
<tbody>
@for (field of nonProviderSpecificFields; track field) {
<tr [hidden]="field === 'cover' && !refreshCovers"
[class.opacity-50]="skipFields[field]">
<td class="px-4 py-1.5">
<p-checkbox [(ngModel)]="skipFields[field]" [binary]="true"
pTooltip="Skip this field during metadata fetch"
tooltipPosition="top"></p-checkbox>
</td>
<td class="px-4 py-1.5 text-zinc-200">{{ formatLabel(field) }}</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p4"
[disabled]="skipFields[field]"
placeholder="Unset" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p3"
[disabled]="skipFields[field]"
placeholder="Unset" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p2"
[disabled]="skipFields[field]"
placeholder="Unset" appendTo="body"
class="w-full" size="small">
</p-select>
</td>
<td class="px-4 py-1.5">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p1"
[disabled]="skipFields[field]"
placeholder="Unset" appendTo="body"
class="w-full" size="small">
</p-select>
@@ -100,6 +105,20 @@
</tbody>
</table>
<div class="space-y-4">
<h3 class="text-lg font-semibold text-zinc-300">Provider-Specific Fields</h3>
<p class="text-sm text-zinc-400">These fields are unique to specific providers and cannot have custom priority settings. Use the checkboxes to skip fetching these fields entirely.</p>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
@for (field of providerSpecificFields; track field) {
<div class="flex items-center space-x-3 p-3 border border-zinc-600 rounded-lg">
<p-checkbox [(ngModel)]="skipFields[field]" [binary]="true"
pTooltip="Skip this field during metadata fetch"
tooltipPosition="top"></p-checkbox>
<span class="text-sm text-zinc-300">{{ formatLabel(field) }}</span>
</div>
}
</div>
</div>
<div class="flex flex-row items-center justify-between gap-4 w-full">
@@ -1,17 +1,11 @@
import {
Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges
} from '@angular/core';
import {Select, SelectChangeEvent} from 'primeng/select';
import {Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
import {Select} from 'primeng/select';
import {FormsModule} from '@angular/forms';
import {Checkbox} from 'primeng/checkbox';
import {Button} from 'primeng/button';
import {MessageService} from 'primeng/api';
import {
FieldOptions,
FieldProvider,
MetadataRefreshOptions
} from '../../model/request/metadata-refresh-options.model';
import {FieldOptions, MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
import {Tooltip} from 'primeng/tooltip';
@Component({
@@ -30,25 +24,49 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
fields: (keyof FieldOptions)[] = [
'title', 'subtitle', 'description', 'authors', 'publisher', 'publishedDate',
'seriesName', 'seriesNumber', 'seriesTotal', 'isbn13', 'isbn10',
'language', 'categories', 'cover'
'language', 'categories', 'cover', 'pageCount',
'asin', 'goodreadsId', 'comicvineId', 'hardcoverId', 'googleId',
'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount',
'hardcoverRating', 'hardcoverReviewCount', 'moods', 'tags'
];
providerSpecificFields: (keyof FieldOptions)[] = [
'asin', 'goodreadsId', 'comicvineId', 'hardcoverId', 'googleId',
'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount',
'hardcoverRating', 'hardcoverReviewCount', 'moods', 'tags'
];
nonProviderSpecificFields: (keyof FieldOptions)[] = [
'title', 'subtitle', 'description', 'authors', 'publisher', 'publishedDate',
'seriesName', 'seriesNumber', 'seriesTotal', 'isbn13', 'isbn10',
'language', 'categories', 'cover', 'pageCount',
];
providers: string[] = ['Amazon', 'Google', 'GoodReads', 'Hardcover', 'Comicvine', 'Douban'];
providersWithClear: string[] = ['Clear All', 'Amazon', 'Google', 'GoodReads', 'Hardcover', 'Comicvine', 'Douban'];
refreshCovers: boolean = false;
mergeCategories: boolean = false;
reviewBeforeApply: boolean = false;
allP1 = {placeholder: 'Set All', value: null as string | null};
allP2 = {placeholder: 'Set All', value: null as string | null};
allP3 = {placeholder: 'Set All', value: null as string | null};
allP4 = {placeholder: 'Set All', value: null as string | null};
fieldOptions: FieldOptions = this.initializeFieldOptions();
skipFields: Record<keyof FieldOptions, boolean> = this.initializeSkipFields();
bulkP1: string | null = null;
bulkP2: string | null = null;
bulkP3: string | null = null;
bulkP4: string | null = null;
private messageService = inject(MessageService);
private justSubmitted = false;
private providerSpecificFieldsList = [
'asin', 'goodreadsId', 'comicvineId', 'hardcoverId', 'googleId',
'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount',
'hardcoverRating', 'hardcoverReviewCount', 'moods', 'tags'
];
private initializeFieldOptions(): FieldOptions {
return this.fields.reduce((acc, field) => {
acc[field] = {p1: null, p2: null, p3: null, p4: null};
@@ -56,6 +74,13 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
}, {} as FieldOptions);
}
private initializeSkipFields(): Record<keyof FieldOptions, boolean> {
return this.fields.reduce((acc, field) => {
acc[field] = false;
return acc;
}, {} as Record<keyof FieldOptions, boolean>);
}
ngOnChanges(changes: SimpleChanges): void {
if (changes['currentMetadataOptions'] && this.currentMetadataOptions && !this.justSubmitted) {
this.refreshCovers = this.currentMetadataOptions.refreshCovers || false;
@@ -72,10 +97,11 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
}
this.fieldOptions = backendFieldOptions;
this.allP1 = {placeholder: 'Set All', value: this.currentMetadataOptions.allP1 || null};
this.allP2 = {placeholder: 'Set All', value: this.currentMetadataOptions.allP2 || null};
this.allP3 = {placeholder: 'Set All', value: this.currentMetadataOptions.allP3 || null};
this.allP4 = {placeholder: 'Set All', value: this.currentMetadataOptions.allP4 || null};
if (this.currentMetadataOptions.skipFields) {
this.skipFields = {...this.skipFields, ...this.currentMetadataOptions.skipFields};
} else {
this.skipFields = this.initializeSkipFields();
}
}
}
@@ -92,14 +118,10 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
return cloned;
}
syncProvider(event: SelectChangeEvent, providerType: keyof FieldProvider) {
for (const field of Object.keys(this.fieldOptions)) {
this.fieldOptions[field as keyof FieldOptions][providerType] = event.value;
}
}
submit() {
const allFieldsHaveProvider = Object.values(this.fieldOptions).every(opt =>
const allFieldsHaveProvider = Object.entries(this.fieldOptions).every(([field, opt]) =>
this.skipFields[field as keyof FieldOptions] ||
this.isProviderSpecificField(field as keyof FieldOptions) ||
opt.p1 !== null || opt.p2 !== null || opt.p3 !== null || opt.p4 !== null
);
@@ -108,14 +130,11 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
const metadataRefreshOptions: MetadataRefreshOptions = {
libraryId: null,
allP1: this.allP1.value,
allP2: this.allP2.value,
allP3: this.allP3.value,
allP4: this.allP4.value,
refreshCovers: this.refreshCovers,
mergeCategories: this.mergeCategories,
reviewBeforeApply: this.reviewBeforeApply,
fieldOptions: this.fieldOptions
fieldOptions: this.fieldOptions,
skipFields: this.skipFields
};
this.metadataOptionsSubmitted.emit(metadataRefreshOptions);
@@ -127,18 +146,41 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: 'At least one provider (P1–P4) must be selected for each book field.',
detail: 'At least one provider (P1–P4) must be selected for each non-skipped book field.',
life: 5000
});
}
}
setBulkProvider(priority: 'p1' | 'p2' | 'p3' | 'p4', provider: string | null): void {
if (!provider) return;
const value = provider === 'Clear All' ? null : provider;
for (const field of this.nonProviderSpecificFields) {
if (!this.skipFields[field]) {
this.fieldOptions[field][priority] = value;
}
}
switch (priority) {
case 'p1':
this.bulkP1 = null;
break;
case 'p2':
this.bulkP2 = null;
break;
case 'p3':
this.bulkP3 = null;
break;
case 'p4':
this.bulkP4 = null;
break;
}
}
reset() {
this.justSubmitted = false;
this.allP1.value = null;
this.allP2.value = null;
this.allP3.value = null;
this.allP4.value = null;
for (const field of Object.keys(this.fieldOptions)) {
this.fieldOptions[field as keyof FieldOptions] = {
p1: null,
@@ -147,9 +189,53 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
p4: null
};
}
this.skipFields = this.initializeSkipFields();
// Reset bulk selectors
this.bulkP1 = null;
this.bulkP2 = null;
this.bulkP3 = null;
this.bulkP4 = null;
}
formatLabel(field: string): string {
return field.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()).trim();
const fieldLabels: Record<string, string> = {
'title': 'Title',
'subtitle': 'Subtitle',
'description': 'Description',
'authors': 'Authors',
'publisher': 'Publisher',
'publishedDate': 'Published Date',
'seriesName': 'Series Name',
'seriesNumber': 'Series Number',
'seriesTotal': 'Series Total',
'isbn13': 'ISBN-13',
'isbn10': 'ISBN-10',
'language': 'Language',
'categories': 'Genres',
'cover': 'Cover Image',
'pageCount': 'Page Count',
'rating': 'Rating',
'reviewCount': 'Review Count',
'asin': 'Amazon ASIN',
'goodreadsId': 'Goodreads ID',
'comicvineId': 'Comicvine ID',
'hardcoverId': 'Hardcover ID',
'googleId': 'Google Books ID',
'amazonRating': 'Amazon Rating',
'amazonReviewCount': 'Amazon Review Count',
'goodreadsRating': 'Goodreads Rating',
'goodreadsReviewCount': 'Goodreads Review Count',
'hardcoverRating': 'Hardcover Rating',
'hardcoverReviewCount': 'Hardcover Review Count',
'moods': 'Moods (Hardcover)',
'tags': 'Tags (Hardcover)'
};
return fieldLabels[field] || field.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()).trim();
}
isProviderSpecificField(field: keyof FieldOptions): boolean {
return this.providerSpecificFieldsList.includes(field as string);
}
}
@@ -1,13 +1,10 @@
export interface MetadataRefreshOptions {
libraryId: number | null;
allP4: string | null;
allP3: string | null;
allP2: string | null;
allP1: string | null;
refreshCovers: boolean;
mergeCategories: boolean;
reviewBeforeApply: boolean;
fieldOptions?: FieldOptions;
skipFields?: Record<keyof FieldOptions, boolean>;
}
export interface FieldProvider {
@@ -32,4 +29,18 @@ export interface FieldOptions {
isbn13: FieldProvider;
isbn10: FieldProvider;
language: FieldProvider;
pageCount: FieldProvider;
asin: FieldProvider;
goodreadsId: FieldProvider;
comicvineId: FieldProvider;
hardcoverId: FieldProvider;
googleId: FieldProvider;
amazonRating: FieldProvider;
amazonReviewCount: FieldProvider;
goodreadsRating: FieldProvider;
goodreadsReviewCount: FieldProvider;
hardcoverRating: FieldProvider;
hardcoverReviewCount: FieldProvider;
moods: FieldProvider;
tags: FieldProvider;
}