Add lock/unlock metadata all buttons
This commit is contained in:
+5
-1
@@ -170,8 +170,12 @@
|
||||
|
||||
<div class="flex flex-col gap-x-4 mt-auto">
|
||||
<p-divider></p-divider>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+32
-6
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user