Add bulk lock/unlock metadata functionality for books
This commit is contained in:
committed by
Aditya Chandel
parent
5c50a157cd
commit
941206bdf3
+7
@@ -0,0 +1,7 @@
|
||||
<div class="flex flex-col items-center text-center space-y-6">
|
||||
<p class="pt-6 px-4">Lock or unlock all metadata for all the selected books</p>
|
||||
<div class="flex gap-4 justify-center">
|
||||
<p-button icon="pi pi-lock" label="Lock" outlined="true" severity="danger" (onClick)="toggleLock('LOCK')"></p-button>
|
||||
<p-button icon="pi pi-lock-open" label="Unlock" outlined="true" severity="success" (onClick)="toggleLock('UNLOCK')"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-lock-unlock-metadata-dialog',
|
||||
imports: [
|
||||
Button
|
||||
],
|
||||
templateUrl: './lock-unlock-metadata-dialog.component.html',
|
||||
styleUrl: './lock-unlock-metadata-dialog.component.scss'
|
||||
})
|
||||
export class LockUnlockMetadataDialogComponent {
|
||||
private bookService = inject(BookService);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
private dialogRef = inject(DynamicDialogRef);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
bookIds: Set<number> = this.dynamicDialogConfig.data.bookIds;
|
||||
|
||||
toggleLock(action: 'LOCK' | 'UNLOCK'): void {
|
||||
this.bookService.toggleAllLock(this.bookIds, action).subscribe({
|
||||
next: () => {
|
||||
const isLock = action === 'LOCK';
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: `Metadata ${isLock ? 'Locked' : 'Unlocked'}`,
|
||||
detail: `All selected books have been ${isLock ? 'locked' : 'unlocked'} successfully.`,
|
||||
});
|
||||
this.dialogRef.close(action.toLowerCase());
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: `Failed to ${action === 'LOCK' ? 'Lock' : 'Unlock'}`,
|
||||
detail: `An error occurred while ${action === 'LOCK' ? 'locking' : 'unlocking'} metadata.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user