Remove default provider and use p1, p2 and p3

This commit is contained in:
aditya.chandel
2025-01-24 20:33:00 -07:00
parent 0a8a44522f
commit da7497f2c1
6 changed files with 89 additions and 63 deletions
@@ -13,8 +13,8 @@
<tr>
<td class="px-4 py-2 text-gray-300"></td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="allDefault.value"
(onChange)="syncProvider($event, 'default')"
<p-select [options]="providers" [(ngModel)]="allP3.value"
(onChange)="syncProvider($event, 'p3')"
placeholder="Select All"
class="w-full">
</p-select>
@@ -38,7 +38,7 @@
<tr *ngFor="let field of fields" [hidden]="field === 'cover' && !refreshCovers">
<td class="px-4 py-2 text-gray-300">{{ field | titlecase }}</td>
<td class="px-4 py-2">
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].default"
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p3"
placeholder="Unset"
class="w-full">
</p-select>
@@ -22,16 +22,16 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
refreshCovers: boolean = false;
mergeCategories: boolean = false;
allDefault = {placeholder: 'Set All', value: ''};
allP3 = {placeholder: 'Set All', value: ''};
allP2 = {placeholder: 'Set All', value: ''};
allP1 = {placeholder: 'Set All', value: ''};
fieldOptions: FieldOptions = {
title: {default: null, p2: null, p1: null},
description: {default: null, p2: null, p1: null},
authors: {default: null, p2: null, p1: null},
categories: {default: null, p2: null, p1: null},
cover: {default: null, p2: null, p1: null}
title: {p3: null, p2: null, p1: null},
description: {p3: null, p2: null, p1: null},
authors: {p3: null, p2: null, p1: null},
categories: {p3: null, p2: null, p1: null},
cover: {p3: null, p2: null, p1: null}
};
private messageService = inject(MessageService);
@@ -43,7 +43,9 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
this.refreshCovers = this.currentMetadataOptions.refreshCovers || false;
this.mergeCategories = this.currentMetadataOptions.mergeCategories || false;
this.fieldOptions = this.currentMetadataOptions.fieldOptions || this.fieldOptions;
this.allDefault.value = this.currentMetadataOptions.defaultProvider || '';
this.allP3.value = this.currentMetadataOptions.allP3 || '';
this.allP2.value = this.currentMetadataOptions.allP2 || '';
this.allP1.value = this.currentMetadataOptions.allP1 || '';
}
}
@@ -54,12 +56,15 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
}
submit() {
const allProvidersSelected = Object.keys(this.fieldOptions).every(field => {
return this.fieldOptions[field as keyof FieldOptions].default !== null;
const allP3Selected = Object.keys(this.fieldOptions).every(field => {
return this.fieldOptions[field as keyof FieldOptions].p3 !== null;
});
if (allProvidersSelected) {
if (allP3Selected) {
const metadataRefreshOptions: MetadataRefreshOptions = {
defaultProvider: this.allDefault.value,
allP1: this.allP1.value,
allP2: this.allP2.value,
allP3: this.allP3.value,
refreshCovers: this.refreshCovers,
mergeCategories: this.mergeCategories,
fieldOptions: this.fieldOptions
@@ -71,18 +76,18 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
severity: 'error',
summary: 'Error',
life: 5000,
detail: 'Base provider must be selected for all the book fields.'
detail: 'At least one provider must be selected for all the book fields.'
});
}
}
reset() {
this.allDefault.value = '';
this.allP3.value = '';
this.allP2.value = '';
this.allP1.value = '';
for (const field of Object.keys(this.fieldOptions)) {
this.fieldOptions[field as keyof FieldOptions] = {
default: null,
p3: null,
p2: null,
p1: null
};
@@ -1,12 +1,14 @@
export interface MetadataRefreshOptions {
defaultProvider: string;
allP3: string;
allP2: string;
allP1: string;
refreshCovers: boolean;
mergeCategories: boolean;
fieldOptions?: FieldOptions;
}
export interface FieldProvider {
default: string | null;
p3: string | null;
p2: string | null;
p1: string | null;
}