Display toast on metadata update not on lock update
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave('saveButton')" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
|
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
|
||||||
|
|
||||||
<div class="overflow-y-scroll flex-1">
|
<div class="overflow-y-scroll flex-1">
|
||||||
|
|
||||||
|
|||||||
+33
-25
@@ -123,7 +123,38 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSave(source: string): void {
|
onSave(): void {
|
||||||
|
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
|
||||||
|
next: (response) => {
|
||||||
|
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||||
|
this.metadataCenterService.emit(response);
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleLock(field: string): void {
|
||||||
|
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
|
||||||
|
const updatedLockedState = !isLocked;
|
||||||
|
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
|
||||||
|
if (updatedLockedState) {
|
||||||
|
this.bookMetadataForm.get(field)?.disable();
|
||||||
|
} 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'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildMetadata() {
|
||||||
const updatedBookMetadata: BookMetadata = {
|
const updatedBookMetadata: BookMetadata = {
|
||||||
bookId: this.currentBookId,
|
bookId: this.currentBookId,
|
||||||
title: this.bookMetadataForm.get('title')?.value,
|
title: this.bookMetadataForm.get('title')?.value,
|
||||||
@@ -154,30 +185,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value,
|
ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value,
|
||||||
reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value,
|
reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value,
|
||||||
};
|
};
|
||||||
|
return updatedBookMetadata;
|
||||||
this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
|
|
||||||
next: (response) => {
|
|
||||||
if (source === 'saveButton') {
|
|
||||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
|
||||||
}
|
|
||||||
this.metadataCenterService.emit(response);
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleLock(field: string): void {
|
|
||||||
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
|
|
||||||
const updatedLockedState = !isLocked;
|
|
||||||
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
|
|
||||||
if (updatedLockedState) {
|
|
||||||
this.bookMetadataForm.get(field)?.disable();
|
|
||||||
} else {
|
|
||||||
this.bookMetadataForm.get(field)?.enable();
|
|
||||||
}
|
|
||||||
this.onSave('lock');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
|
|||||||
Reference in New Issue
Block a user