Add an “Overwrite All Metadata” button to the book metadata picker

This commit is contained in:
adityachandelgit
2025-04-16 17:48:39 -06:00
committed by Aditya Chandel
parent 12e7673805
commit 92fc0c9ec8
2 changed files with 37 additions and 21 deletions
@@ -4,11 +4,18 @@
<p class="ml-3 text-lg">Current Metadata</p>
<p-button
severity="info"
icon='pi pi-angle-double-left'
[ngStyle]="{'padding-left': '2rem', 'padding-right': '2rem'}"
icon='pi pi-angle-left'
[ngStyle]="{'padding-left': '2rem', 'padding-right': '0.5rem'}"
[outlined]="true"
pTooltip="Select all missing field" tooltipPosition="bottom"
pTooltip="Move all missing field" tooltipPosition="bottom"
(onClick)="copyMissing()"></p-button>
<p-button
severity="info"
icon='pi pi-angle-double-left'
[ngStyle]="{'padding-left': '0.5rem', 'padding-right': '2rem'}"
[outlined]="true"
pTooltip="Move all field" tooltipPosition="bottom"
(onClick)="copyAll()"></p-button>
<p class="text-lg">Fetched Metadata</p>
</div>
@@ -279,6 +279,33 @@ export class MetadataPickerComponent implements OnInit {
});
}
copyAll() {
Object.keys(this.fetchedMetadata).forEach((field) => {
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
if (!isLocked && this.fetchedMetadata[field] && field !== 'thumbnailUrl') {
this.copyFetchedToCurrent(field);
}
});
}
copyFetchedToCurrent(field: string): void {
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
if (isLocked) {
this.messageService.add({
severity: 'warn',
summary: 'Action Blocked',
detail: `${field} is locked and cannot be updated.`
});
return;
}
const value = this.fetchedMetadata[field];
if (value) {
this.metadataForm.get(field)?.setValue(value);
this.copiedFields[field] = true;
this.highlightCopiedInput(field);
}
}
private getNumberOrCopied(field: string): number | null {
const formValue = this.metadataForm.get(field)?.value;
if (formValue === '' || formValue === null || isNaN(formValue)) {
@@ -317,24 +344,6 @@ export class MetadataPickerComponent implements OnInit {
return Array.isArray(fieldValue) ? fieldValue : [];
}
copyFetchedToCurrent(field: string): void {
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
if (isLocked) {
this.messageService.add({
severity: 'warn',
summary: 'Action Blocked',
detail: `${field} is locked and cannot be updated.`
});
return;
}
const value = this.fetchedMetadata[field];
if (value) {
this.metadataForm.get(field)?.setValue(value);
this.copiedFields[field] = true;
this.highlightCopiedInput(field);
}
}
lockAll(): void {
Object.keys(this.metadataForm.controls).forEach((key) => {
if (key.endsWith('Locked')) {