Implement interactive metadata review for batch updates, with progress tracking and a unified notification system
This commit is contained in:
committed by
Aditya Chandel
parent
6576f3351a
commit
116f0c950e
+102
@@ -0,0 +1,102 @@
|
||||
<div class="flex flex-col space-y-6 p-4">
|
||||
<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">4th Priority</th>
|
||||
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">3rd Priority</th>
|
||||
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">2nd Priority</th>
|
||||
<th class="px-4 py-1.5 text-left font-semibold text-gray-300">1st Priority</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td class="text-sm px-4 py-1.5 text-gray-300">All Other Fields</td>
|
||||
<td class="px-4 py-1.5">
|
||||
<p-select [options]="providers" [(ngModel)]="allP4.value"
|
||||
(onChange)="syncProvider($event, 'p4')"
|
||||
placeholder="Select All" 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"
|
||||
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"
|
||||
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"
|
||||
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>
|
||||
<td class="px-4 py-1.5">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p4"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
placeholder="Unset" appendTo="body"
|
||||
class="w-full" size="small">
|
||||
</p-select>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<div class="flex flex-row items-center justify-between gap-4 w-full">
|
||||
|
||||
<div class="flex flex-row gap-10">
|
||||
<div class="flex flex-row items-center gap-4">
|
||||
<p pTooltip="Fetch and update new book cover images" tooltipPosition="top">Update covers:</p>
|
||||
<p-checkbox [(ngModel)]="refreshCovers" [binary]="true"></p-checkbox>
|
||||
</div>
|
||||
<div class="flex flex-row items-center gap-4">
|
||||
<p pTooltip="Combine new genres with existing ones" tooltipPosition="top">Merge genres:</p>
|
||||
<p-checkbox [(ngModel)]="mergeCategories" [binary]="true"></p-checkbox>
|
||||
</div>
|
||||
<div class="flex flex-row items-center gap-4">
|
||||
<p pTooltip="Review and approve metadata changes before saving" tooltipPosition="top">Manual review:</p>
|
||||
<p-checkbox [(ngModel)]="reviewBeforeApply" [binary]="true"></p-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row gap-6">
|
||||
<p-button severity="warn" outlined="true" label="Reset Form" (onClick)="reset()"></p-button>
|
||||
<p-button [label]="submitButtonLabel" outlined="true" (onClick)="submit()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.custom-table {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--card-border);
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import {
|
||||
Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges
|
||||
} from '@angular/core';
|
||||
import {Select, SelectChangeEvent} 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 {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-advanced-fetch-options',
|
||||
templateUrl: './metadata-advanced-fetch-options.component.html',
|
||||
imports: [Select, FormsModule, Checkbox, Button, Tooltip],
|
||||
styleUrl: './metadata-advanced-fetch-options.component.scss',
|
||||
standalone: true
|
||||
})
|
||||
export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
|
||||
|
||||
@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;
|
||||
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();
|
||||
|
||||
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) {
|
||||
this.refreshCovers = this.currentMetadataOptions.refreshCovers || false;
|
||||
this.mergeCategories = this.currentMetadataOptions.mergeCategories || false;
|
||||
this.reviewBeforeApply = this.currentMetadataOptions.reviewBeforeApply || false;
|
||||
|
||||
const backendFieldOptions = this.currentMetadataOptions.fieldOptions as FieldOptions || {};
|
||||
for (const field of this.fields) {
|
||||
if (!backendFieldOptions[field]) {
|
||||
backendFieldOptions[field] = {p1: null, p2: null, p3: null, p4: null};
|
||||
} else {
|
||||
backendFieldOptions[field].p4 ??= null;
|
||||
}
|
||||
}
|
||||
this.fieldOptions = backendFieldOptions;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 =>
|
||||
opt.p1 !== null || opt.p2 !== null || opt.p3 !== null || opt.p4 !== null
|
||||
);
|
||||
|
||||
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,
|
||||
reviewBeforeApply: this.reviewBeforeApply,
|
||||
fieldOptions: this.fieldOptions
|
||||
};
|
||||
this.metadataOptionsSubmitted.emit(metadataRefreshOptions);
|
||||
} else {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'At least one provider (P1–P4) must be selected for each book field.',
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
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,
|
||||
p2: null,
|
||||
p3: null,
|
||||
p4: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
formatLabel(field: string): string {
|
||||
return field.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()).trim();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user