Checkpoint: Switch to using enums in BookBrowserComponent

This commit is contained in:
aditya.chandel
2024-12-30 14:52:03 -07:00
parent 48b6906f41
commit ea272ea1de
4 changed files with 233 additions and 206 deletions
@@ -0,0 +1,112 @@
import { Injectable } from '@angular/core';
import { MenuItem, ConfirmationService, MessageService } from 'primeng/api';
import { Router } from '@angular/router';
import {LibraryService} from './library.service';
import {ShelfService} from './shelf.service';
@Injectable({
providedIn: 'root',
})
export class LibraryShelfMenuService {
constructor(
private confirmationService: ConfirmationService,
private messageService: MessageService,
private libraryService: LibraryService,
private shelfService: ShelfService,
private router: Router
) {}
initializeLibraryMenuItems(entity: any): MenuItem[] {
return [
{
label: 'Options',
items: [
{
label: 'Delete Library',
icon: 'pi pi-trash',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to delete library: ${entity?.name}?`,
header: 'Confirmation',
accept: () => {
this.libraryService.deleteLibrary(entity?.id!).subscribe({
complete: () => {
this.router.navigate(['/']);
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Library was deleted'});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to delete library',
});
}
});
}
});
}
},
{
label: 'Refresh Library',
icon: 'pi pi-refresh',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to refresh library: ${entity?.name}?`,
header: 'Confirmation',
accept: () => {
this.libraryService.refreshLibrary(entity?.id!).subscribe({
complete: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Library refresh scheduled'});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to refresh library',
});
}
});
}
});
}
}
]
}
];
}
initializeShelfMenuItems(entity: any): MenuItem[] {
return [
{
label: 'Options',
items: [
{
label: 'Delete Shelf',
icon: 'pi pi-trash',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to delete shelf: ${entity?.name}?`,
header: 'Confirmation',
accept: () => {
this.shelfService.deleteShelf(entity?.id!).subscribe({
complete: () => {
this.router.navigate(['/']);
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Shelf was deleted'});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to delete shelf',
});
}
});
}
});
}
}
]
}
];
}
}