Add 4th Priority (P4) Support to Metadata Fetch Options
This commit is contained in:
committed by
Aditya Chandel
parent
2d77644b8e
commit
32cc5f0d92
+15
-2
@@ -3,6 +3,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">Book Field</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">4th Priority</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">3rd Priority</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">2nd Priority</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">1st Priority</th>
|
||||
@@ -12,6 +13,13 @@
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2 text-gray-300">All Other Fields</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="allP4.value"
|
||||
(onChange)="syncProvider($event, 'p4')"
|
||||
placeholder="Select All" appendTo="body"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="allP3.value"
|
||||
(onChange)="syncProvider($event, 'p3')"
|
||||
@@ -36,7 +44,13 @@
|
||||
</tr>
|
||||
|
||||
<tr *ngFor="let field of fields" [hidden]="field === 'cover' && !refreshCovers">
|
||||
<td class="px-4 py-2 text-gray-300">{{formatLabel(field) }}</td>
|
||||
<td class="px-4 py-2 text-gray-300">{{ formatLabel(field) }}</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p4"
|
||||
placeholder="Unset" appendTo="body"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p3"
|
||||
placeholder="Unset" appendTo="body"
|
||||
@@ -75,5 +89,4 @@
|
||||
<p-button [label]="submitButtonLabel" outlined="true" (onClick)="submit()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
+54
-66
@@ -1,11 +1,17 @@
|
||||
import {Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
|
||||
import {
|
||||
Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges
|
||||
} from '@angular/core';
|
||||
import {Select, SelectChangeEvent} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgForOf} from '@angular/common';
|
||||
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,
|
||||
FieldProvider,
|
||||
MetadataRefreshOptions
|
||||
} from '../../model/request/metadata-refresh-options.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-advanced-fetch-options',
|
||||
@@ -16,52 +22,35 @@ import {FieldOptions, FieldProvider, MetadataRefreshOptions} from '../../model/r
|
||||
})
|
||||
export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
|
||||
|
||||
@Output() metadataOptionsSubmitted: EventEmitter<MetadataRefreshOptions> = new EventEmitter<MetadataRefreshOptions>();
|
||||
fields: (keyof FieldOptions)[] = [
|
||||
'title',
|
||||
'subtitle',
|
||||
'description',
|
||||
'authors',
|
||||
'publisher',
|
||||
'publishedDate',
|
||||
'seriesName',
|
||||
'seriesNumber',
|
||||
'seriesTotal',
|
||||
'isbn13',
|
||||
'isbn10',
|
||||
'language',
|
||||
'categories',
|
||||
'cover'
|
||||
];
|
||||
providers: string[] = ['Amazon', 'Google', 'GoodReads', 'Hardcover'];
|
||||
refreshCovers: boolean = false;
|
||||
mergeCategories: boolean = false;
|
||||
|
||||
allP3 = {placeholder: 'Set All', value: null as string | null};
|
||||
allP2 = {placeholder: 'Set All', value: null as string | null};
|
||||
allP1 = {placeholder: 'Set All', value: null as string | null};
|
||||
|
||||
fieldOptions: FieldOptions = {
|
||||
title: {p3: null, p2: null, p1: null},
|
||||
subtitle: {p3: null, p2: null, p1: null},
|
||||
description: {p3: null, p2: null, p1: null},
|
||||
authors: {p3: null, p2: null, p1: null},
|
||||
publisher: {p3: null, p2: null, p1: null},
|
||||
publishedDate: {p3: null, p2: null, p1: null},
|
||||
seriesName: {p3: null, p2: null, p1: null},
|
||||
seriesNumber: {p3: null, p2: null, p1: null},
|
||||
seriesTotal: {p3: null, p2: null, p1: null},
|
||||
isbn13: {p3: null, p2: null, p1: null},
|
||||
isbn10: {p3: null, p2: null, p1: null},
|
||||
language: {p3: null, p2: null, p1: null},
|
||||
categories: {p3: null, p2: null, p1: null},
|
||||
cover: {p3: null, p2: null, p1: null}
|
||||
};
|
||||
|
||||
private messageService = inject(MessageService);
|
||||
@Output() metadataOptionsSubmitted = new EventEmitter<MetadataRefreshOptions>();
|
||||
@Input() currentMetadataOptions!: MetadataRefreshOptions;
|
||||
@Input() submitButtonLabel!: string;
|
||||
|
||||
fields: (keyof FieldOptions)[] = [
|
||||
'title', 'subtitle', 'description', 'authors', 'publisher', 'publishedDate',
|
||||
'seriesName', 'seriesNumber', 'seriesTotal', 'isbn13', 'isbn10',
|
||||
'language', 'categories', 'cover'
|
||||
];
|
||||
providers: string[] = ['Amazon', 'Google', 'GoodReads', 'Hardcover'];
|
||||
|
||||
refreshCovers: boolean = false;
|
||||
mergeCategories: 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();
|
||||
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
private initializeFieldOptions(): FieldOptions {
|
||||
return this.fields.reduce((acc, field) => {
|
||||
acc[field] = { p1: null, p2: null, p3: null, p4: null };
|
||||
return acc;
|
||||
}, {} as FieldOptions);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['currentMetadataOptions'] && this.currentMetadataOptions) {
|
||||
@@ -69,18 +58,19 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
|
||||
this.mergeCategories = this.currentMetadataOptions.mergeCategories || false;
|
||||
|
||||
const backendFieldOptions = this.currentMetadataOptions.fieldOptions as FieldOptions || {};
|
||||
|
||||
for (const field of this.fields) {
|
||||
if (!backendFieldOptions[field]) {
|
||||
backendFieldOptions[field] = {p3: null, p2: null, p1: null};
|
||||
backendFieldOptions[field] = { p1: null, p2: null, p3: null, p4: null };
|
||||
} else {
|
||||
backendFieldOptions[field].p4 ??= null;
|
||||
}
|
||||
}
|
||||
|
||||
this.fieldOptions = backendFieldOptions;
|
||||
|
||||
this.allP3.value = this.currentMetadataOptions.allP3 || null;
|
||||
this.allP2.value = this.currentMetadataOptions.allP2 || null;
|
||||
this.allP1.value = this.currentMetadataOptions.allP1 || null;
|
||||
this.allP2.value = this.currentMetadataOptions.allP2 || null;
|
||||
this.allP3.value = this.currentMetadataOptions.allP3 || null;
|
||||
this.allP4.value = this.currentMetadataOptions.allP4 || null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,49 +81,47 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
|
||||
}
|
||||
|
||||
submit() {
|
||||
const allP3Selected = Object.keys(this.fieldOptions).every(field => {
|
||||
return this.fieldOptions[field as keyof FieldOptions].p3 !== null;
|
||||
});
|
||||
const allFieldsHaveProvider = Object.values(this.fieldOptions).every(opt =>
|
||||
opt.p1 !== null || opt.p2 !== null || opt.p3 !== null || opt.p4 !== null
|
||||
);
|
||||
|
||||
if (allP3Selected) {
|
||||
if (allFieldsHaveProvider) {
|
||||
const metadataRefreshOptions: MetadataRefreshOptions = {
|
||||
allP1: this.allP1.value,
|
||||
allP2: this.allP2.value,
|
||||
allP3: this.allP3.value,
|
||||
allP4: this.allP4.value,
|
||||
refreshCovers: this.refreshCovers,
|
||||
mergeCategories: this.mergeCategories,
|
||||
fieldOptions: this.fieldOptions
|
||||
};
|
||||
|
||||
this.metadataOptionsSubmitted.emit(metadataRefreshOptions);
|
||||
} else {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
life: 5000,
|
||||
detail: 'At least one provider must be selected for all the book fields.'
|
||||
detail: 'At least one provider (P1–P4) must be selected for each book field.',
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.allP3.value = null;
|
||||
this.allP2.value = null;
|
||||
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] = {
|
||||
p3: null,
|
||||
p1: null,
|
||||
p2: null,
|
||||
p1: null
|
||||
p3: null,
|
||||
p4: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
formatLabel(field: string): string {
|
||||
return field
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.replace(/^./, str => str.toUpperCase())
|
||||
.trim();
|
||||
return field.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()).trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface MetadataRefreshOptions {
|
||||
allP4: string | null;
|
||||
allP3: string | null;
|
||||
allP2: string | null;
|
||||
allP1: string | null;
|
||||
@@ -8,6 +9,7 @@ export interface MetadataRefreshOptions {
|
||||
}
|
||||
|
||||
export interface FieldProvider {
|
||||
p4: string | null;
|
||||
p3: string | null;
|
||||
p2: string | null;
|
||||
p1: string | null;
|
||||
|
||||
Reference in New Issue
Block a user