From 58d8fa0778263cd11b62f8603c3b2c56bb83bbb7 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Sat, 25 Jan 2025 23:39:34 -0700
Subject: [PATCH] Add lock/unlock metadata all buttons
---
.../metadata-editor.component.html | 6 ++-
.../metadata-editor.component.ts | 38 ++++++++++++++++---
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
index d6d04d0ed..7a00045a1 100644
--- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
+++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
@@ -170,8 +170,12 @@
diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts
index b1109429e..83096d200 100644
--- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts
+++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.ts
@@ -159,14 +159,29 @@ export class MetadataEditorComponent implements OnInit {
} else {
this.bookMetadataForm.get(field)?.enable();
}
- 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'});
+ this.updateMetadata();
+ }
+
+ lockAll(): void {
+ Object.keys(this.bookMetadataForm.controls).forEach((key) => {
+ 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() {
@@ -210,6 +225,17 @@ export class MetadataEditorComponent implements OnInit {
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() {
this.metadataCenterService.closeDialog(true);
}