Add lock/unlock metadata all buttons

This commit is contained in:
aditya.chandel
2025-01-25 23:39:34 -07:00
parent 41aef60b11
commit 58d8fa0778
2 changed files with 37 additions and 7 deletions
@@ -170,8 +170,12 @@
<div class="flex flex-col gap-x-4 mt-auto"> <div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider> <p-divider></p-divider>
<div class="flex gap-x-4 justify-end"> <div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button> <p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
<p-button class="pr-10" label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
<p-button label="Save" icon="pi pi-check" type="submit"></p-button> <p-button label="Save" icon="pi pi-check" type="submit"></p-button>
</div> </div>
</div> </div>
@@ -159,14 +159,29 @@ export class MetadataEditorComponent implements OnInit {
} else { } else {
this.bookMetadataForm.get(field)?.enable(); this.bookMetadataForm.get(field)?.enable();
} }
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({ this.updateMetadata();
next: (response) => { }
this.metadataCenterService.emit(response);
}, lockAll(): void {
error: () => { Object.keys(this.bookMetadataForm.controls).forEach((key) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update lock'}); if (key.endsWith('Locked')) {
this.bookMetadataForm.get(key)?.setValue(true);
const fieldName = key.replace('Locked', '');
this.bookMetadataForm.get(fieldName)?.disable();
} }
}); });
this.updateMetadata();
}
unlockAll(): void {
Object.keys(this.bookMetadataForm.controls).forEach((key) => {
if (key.endsWith('Locked')) {
this.bookMetadataForm.get(key)?.setValue(false);
const fieldName = key.replace('Locked', '');
this.bookMetadataForm.get(fieldName)?.enable();
}
});
this.updateMetadata();
} }
private buildMetadata() { private buildMetadata() {
@@ -210,6 +225,17 @@ export class MetadataEditorComponent implements OnInit {
return updatedBookMetadata; return updatedBookMetadata;
} }
private updateMetadata(): void {
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
next: (response) => {
this.metadataCenterService.emit(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update lock state'});
}
});
}
closeDialog() { closeDialog() {
this.metadataCenterService.closeDialog(true); this.metadataCenterService.closeDialog(true);
} }