Delete LibraryBrowser component
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {RouterModule, Routes} from '@angular/router';
|
import {RouterModule, Routes} from '@angular/router';
|
||||||
import {AppLayoutComponent} from './book/component/layout/app.layout.component';
|
import {AppLayoutComponent} from './book/component/layout/app.layout.component';
|
||||||
import {LibraryBrowserComponent} from './book/component/library-browser/library-browser.component';
|
|
||||||
import {PdfViewerComponent} from './book/component/pdf-viewer/pdf-viewer.component';
|
import {PdfViewerComponent} from './book/component/pdf-viewer/pdf-viewer.component';
|
||||||
import {DashboardComponent} from './book/component/dashboard/dashboard.component';
|
import {DashboardComponent} from './book/component/dashboard/dashboard.component';
|
||||||
import {BookMetadataComponent} from './book/component/book-metadata/book-metadata.component';
|
import {BookMetadataComponent} from './book/component/book-metadata/book-metadata.component';
|
||||||
|
import {BooksBrowserComponent} from './book/component/books-browser/books-browser.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,10 @@ const routes: Routes = [
|
|||||||
path: '', component: DashboardComponent,
|
path: '', component: DashboardComponent,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'library/:libraryId/books', component: LibraryBrowserComponent,
|
path: 'library/:libraryId/books', component: BooksBrowserComponent,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'shelf/:shelfId/books', component: BooksBrowserComponent,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'library/:libraryId/book/:bookId/info', component: BookMetadataComponent,
|
path: 'library/:libraryId/book/:bookId/info', component: BookMetadataComponent,
|
||||||
|
|||||||
@@ -30,13 +30,17 @@ import { ShelfAssignerComponent } from './shelf-assigner/shelf-assigner.componen
|
|||||||
import {CheckboxModule} from 'primeng/checkbox';
|
import {CheckboxModule} from 'primeng/checkbox';
|
||||||
import {DividerModule} from 'primeng/divider';
|
import {DividerModule} from 'primeng/divider';
|
||||||
import {DialogModule} from 'primeng/dialog';
|
import {DialogModule} from 'primeng/dialog';
|
||||||
|
import { BooksBrowserComponent } from './book/component/books-browser/books-browser.component';
|
||||||
|
import {BookCardComponent} from './book-card/book-card.component';
|
||||||
|
import {SpeedDialModule} from 'primeng/speeddial';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
DirectoryPickerComponent,
|
DirectoryPickerComponent,
|
||||||
LibraryCreatorComponent,
|
LibraryCreatorComponent,
|
||||||
ShelfAssignerComponent
|
ShelfAssignerComponent,
|
||||||
|
BooksBrowserComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
@@ -61,6 +65,8 @@ import {DialogModule} from 'primeng/dialog';
|
|||||||
CheckboxModule,
|
CheckboxModule,
|
||||||
DividerModule,
|
DividerModule,
|
||||||
DialogModule,
|
DialogModule,
|
||||||
|
BookCardComponent,
|
||||||
|
SpeedDialModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
DialogService,
|
DialogService,
|
||||||
|
|||||||
@@ -5,18 +5,17 @@ import {LibraryAndBookService} from '../book/service/library-and-book.service';
|
|||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {MenuModule} from 'primeng/menu';
|
import {MenuModule} from 'primeng/menu';
|
||||||
import {MenuItem} from 'primeng/api';
|
import {MenuItem} from 'primeng/api';
|
||||||
import {DirectoryPickerComponent} from "../book/component/directory-picker/directory-picker.component";
|
|
||||||
import {DialogService} from "primeng/dynamicdialog";
|
import {DialogService} from "primeng/dynamicdialog";
|
||||||
import {ShelfAssignerComponent} from "../shelf-assigner/shelf-assigner.component";
|
import {ShelfAssignerComponent} from "../shelf-assigner/shelf-assigner.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-book-card',
|
selector: 'app-book-card',
|
||||||
templateUrl: './book-card.component.html',
|
templateUrl: './book-card.component.html',
|
||||||
|
styleUrls: ['./book-card.component.scss'],
|
||||||
imports: [
|
imports: [
|
||||||
Button,
|
Button,
|
||||||
MenuModule
|
MenuModule
|
||||||
],
|
]
|
||||||
styleUrls: ['./book-card.component.scss']
|
|
||||||
})
|
})
|
||||||
export class BookCardComponent implements OnInit {
|
export class BookCardComponent implements OnInit {
|
||||||
@Input() book!: Book;
|
@Input() book!: Book;
|
||||||
@@ -51,6 +50,13 @@ export class BookCardComponent implements OnInit {
|
|||||||
command: () => {
|
command: () => {
|
||||||
this.openShelfDialog(this.book);
|
this.openShelfDialog(this.book);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'View metadata',
|
||||||
|
icon: 'pi pi-info-circle',
|
||||||
|
command: () => {
|
||||||
|
this.openBookInfo(this.book);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,12 +1,12 @@
|
|||||||
<div class="library-header">
|
<div class="library-header">
|
||||||
<div class="library-header-dial">
|
<div class="library-header-dial">
|
||||||
<h3 class="library-name">{{ currentLibraryName() }}</h3>
|
<h3 class="library-name">{{ currentEntityName() }}</h3>
|
||||||
<p-speedDial
|
<p-speedDial
|
||||||
[model]="items!"
|
[model]="items!"
|
||||||
direction="right"
|
direction="right"
|
||||||
transitionDelay="80"
|
transitionDelay="80"
|
||||||
showIcon="pi pi-bars"
|
showIcon="pi pi-ellipsis-v"
|
||||||
buttonClassName="p-button-text"
|
buttonClassName="p-button-text p-button-contrast"
|
||||||
hideIcon="pi pi-times">
|
hideIcon="pi pi-times">
|
||||||
</p-speedDial>
|
</p-speedDial>
|
||||||
</div>
|
</div>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
<div class="card-container">
|
<div class="card-container">
|
||||||
<virtual-scroller class="virtual-scroller" #scroll [items]="currentLibraryBooks()">
|
<virtual-scroller class="virtual-scroller" #scroll [items]="currentEntityBooks()">
|
||||||
<div class="grid" #container>
|
<div class="grid" #container>
|
||||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||||
<app-book-card [book]="book"></app-book-card>
|
<app-book-card [book]="book"></app-book-card>
|
||||||
-1
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
.library-header-dial {
|
.library-header-dial {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-right: 5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.library-header-right {
|
.library-header-right {
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
import { Component, OnInit, computed, signal } from '@angular/core';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { LibraryAndBookService } from '../../service/library-and-book.service';
|
||||||
|
import { ConfirmationService, MenuItem, MessageService } from 'primeng/api';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-books-browser',
|
||||||
|
standalone: false,
|
||||||
|
templateUrl: './books-browser.component.html',
|
||||||
|
styleUrls: ['./books-browser.component.scss']
|
||||||
|
})
|
||||||
|
export class BooksBrowserComponent implements OnInit {
|
||||||
|
|
||||||
|
private currentEntityId = signal<number | null>(null);
|
||||||
|
private entityType = signal<'library' | 'shelf'>('library'); // Default to library
|
||||||
|
|
||||||
|
items: MenuItem[] | undefined;
|
||||||
|
|
||||||
|
protected currentEntityBooks = computed(() => {
|
||||||
|
if (this.currentEntityId() != null) {
|
||||||
|
return this.entityType() === 'library'
|
||||||
|
? this.libraryBookService.getLibraryBooks(this.currentEntityId()!)()
|
||||||
|
: this.libraryBookService.getShelfBooks(this.currentEntityId()!)();
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
protected currentEntityName = computed(() => {
|
||||||
|
if (this.entityType() === 'library') {
|
||||||
|
return 'Library: ' + (this.libraryBookService.libraries().find(library => library.id === this.currentEntityId())?.name || 'Library not found');
|
||||||
|
}
|
||||||
|
return 'Shelf: ' + (this.libraryBookService.shelves().find(shelf => shelf.id === this.currentEntityId())?.name || 'Shelf not found');
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private activatedRoute: ActivatedRoute,
|
||||||
|
private router: Router,
|
||||||
|
private libraryBookService: LibraryAndBookService,
|
||||||
|
private confirmationService: ConfirmationService,
|
||||||
|
private messageService: MessageService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.activatedRoute.paramMap.subscribe((params) => {
|
||||||
|
const libraryId = Number(params.get('libraryId'));
|
||||||
|
const shelfId = Number(params.get('shelfId'));
|
||||||
|
|
||||||
|
if (libraryId) {
|
||||||
|
this.entityType.set('library');
|
||||||
|
this.currentEntityId.set(libraryId);
|
||||||
|
this.libraryBookService.loadBooksSignal(libraryId);
|
||||||
|
} else if (shelfId) {
|
||||||
|
this.entityType.set('shelf');
|
||||||
|
this.currentEntityId.set(shelfId);
|
||||||
|
this.libraryBookService.loadBooksSignal(shelfId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.entityType() === 'library') {
|
||||||
|
this.initializeLibraryMenuItems();
|
||||||
|
} else if (this.entityType() === 'shelf') {
|
||||||
|
//this.initializeShelfMenuItems();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private initializeLibraryMenuItems(): void {
|
||||||
|
this.items = [
|
||||||
|
{
|
||||||
|
icon: 'pi pi-pencil',
|
||||||
|
tooltipOptions: {
|
||||||
|
tooltipLabel: 'Rename',
|
||||||
|
tooltipPosition: 'top'
|
||||||
|
},
|
||||||
|
command: () => {
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Sure you want to delete: ' + this.currentEntityName() + "?",
|
||||||
|
header: 'Confirmation',
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
acceptIcon: 'none',
|
||||||
|
rejectIcon: 'none',
|
||||||
|
rejectButtonStyleClass: 'p-button-text',
|
||||||
|
accept: () => {
|
||||||
|
this.libraryBookService.deleteLibrary(this.currentEntityId()).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',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'pi pi-trash',
|
||||||
|
tooltipOptions: {
|
||||||
|
tooltipLabel: 'Delete',
|
||||||
|
tooltipPosition: 'top'
|
||||||
|
},
|
||||||
|
command: () => {
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Sure you want to delete: ' + this.currentEntityName() + "?",
|
||||||
|
header: 'Confirmation',
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
acceptIcon: 'none',
|
||||||
|
rejectIcon: 'none',
|
||||||
|
rejectButtonStyleClass: 'p-button-text',
|
||||||
|
accept: () => {
|
||||||
|
this.libraryBookService.deleteLibrary(this.currentEntityId()).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',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*private initializeShelfMenuItems(): void {
|
||||||
|
this.items = [
|
||||||
|
{
|
||||||
|
icon: 'pi pi-pencil',
|
||||||
|
tooltipOptions: {
|
||||||
|
tooltipLabel: 'Rename',
|
||||||
|
tooltipPosition: 'top'
|
||||||
|
},
|
||||||
|
command: () => {
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Sure you want to delete: ' + this.currentEntityName() + "?",
|
||||||
|
header: 'Confirmation',
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
acceptIcon: 'none',
|
||||||
|
rejectIcon: 'none',
|
||||||
|
rejectButtonStyleClass: 'p-button-text',
|
||||||
|
accept: () => {
|
||||||
|
this.libraryBookService.deleteShelf(this.currentEntityId()).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',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'pi pi-trash',
|
||||||
|
tooltipOptions: {
|
||||||
|
tooltipLabel: 'Delete',
|
||||||
|
tooltipPosition: 'top'
|
||||||
|
},
|
||||||
|
command: () => {
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Sure you want to delete: ' + this.currentEntityName() + "?",
|
||||||
|
header: 'Confirmation',
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
acceptIcon: 'none',
|
||||||
|
rejectIcon: 'none',
|
||||||
|
rejectButtonStyleClass: 'p-button-text',
|
||||||
|
accept: () => {
|
||||||
|
this.libraryBookService.deleteShelf(this.currentEntityId()).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',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ export class AppMenuComponent implements OnInit {
|
|||||||
separator: false,
|
separator: false,
|
||||||
items: libraries.map((lib) => ({
|
items: libraries.map((lib) => ({
|
||||||
label: lib.name,
|
label: lib.name,
|
||||||
icon: 'pi pi-fw pi-home',
|
icon: 'pi pi-fw pi-book',
|
||||||
routerLink: [`/library/${lib.id}/books`],
|
routerLink: [`/library/${lib.id}/books`],
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
@@ -49,15 +49,4 @@ export class AppMenuComponent implements OnInit {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.populateHome();
|
this.populateHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
private populateHome() {
|
|
||||||
this.home = [
|
|
||||||
{
|
|
||||||
label: 'Home',
|
|
||||||
items: [
|
|
||||||
{label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/']},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
import {Component, computed, OnInit, signal} from '@angular/core';
|
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
|
||||||
import {LibraryAndBookService} from '../../service/library-and-book.service';
|
|
||||||
import {Button} from 'primeng/button';
|
|
||||||
import {NgForOf} from '@angular/common';
|
|
||||||
import {FormsModule} from '@angular/forms';
|
|
||||||
import {DropdownModule} from 'primeng/dropdown';
|
|
||||||
import {LazyLoadImageModule} from 'ng-lazyload-image';
|
|
||||||
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
|
|
||||||
import {SpeedDialModule} from 'primeng/speeddial';
|
|
||||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
|
||||||
import {ConfirmDialogModule} from 'primeng/confirmdialog';
|
|
||||||
import {BookCardComponent} from '../../../book-card/book-card.component';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-library-browser-v2',
|
|
||||||
templateUrl: './library-browser.component.html',
|
|
||||||
styleUrls: ['./library-browser.component.scss'],
|
|
||||||
imports: [
|
|
||||||
Button,
|
|
||||||
NgForOf,
|
|
||||||
FormsModule,
|
|
||||||
DropdownModule,
|
|
||||||
LazyLoadImageModule,
|
|
||||||
VirtualScrollerModule,
|
|
||||||
SpeedDialModule,
|
|
||||||
ConfirmDialogModule,
|
|
||||||
BookCardComponent
|
|
||||||
]
|
|
||||||
})
|
|
||||||
export class LibraryBrowserComponent implements OnInit {
|
|
||||||
private currentLibraryId = signal<number | null>(null);
|
|
||||||
|
|
||||||
protected currentLibraryBooks = computed(() =>
|
|
||||||
this.currentLibraryId() != null ? this.libraryBookService.getLibraryBooks(this.currentLibraryId()!)() : []);
|
|
||||||
|
|
||||||
protected currentLibraryName = computed(() =>
|
|
||||||
this.libraryBookService.libraries().find(library => library.id === this.currentLibraryId())?.name || 'Library not found');
|
|
||||||
|
|
||||||
items: MenuItem[] | undefined;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private activatedRoute: ActivatedRoute,
|
|
||||||
private router: Router, private libraryBookService: LibraryAndBookService,
|
|
||||||
private confirmationService: ConfirmationService, private messageService: MessageService) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.items = [
|
|
||||||
{
|
|
||||||
icon: 'pi pi-pencil',
|
|
||||||
tooltipOptions: {
|
|
||||||
tooltipLabel: 'Rename',
|
|
||||||
tooltipPosition: "top"
|
|
||||||
},
|
|
||||||
command: () => {
|
|
||||||
this.confirmationService.confirm({
|
|
||||||
message: 'Sure you want to delete: ' + this.currentLibraryName() + "?",
|
|
||||||
header: 'Confirmation',
|
|
||||||
icon: 'pi pi-exclamation-triangle',
|
|
||||||
acceptIcon:"none",
|
|
||||||
rejectIcon:"none",
|
|
||||||
rejectButtonStyleClass:"p-button-text",
|
|
||||||
accept: () => {
|
|
||||||
this.libraryBookService.deleteLibrary(this.currentLibraryId()).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', life: 3000 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: 'pi pi-trash',
|
|
||||||
tooltipOptions: {
|
|
||||||
tooltipLabel: 'Delete',
|
|
||||||
tooltipPosition: "top"
|
|
||||||
},
|
|
||||||
command: () => {
|
|
||||||
this.confirmationService.confirm({
|
|
||||||
message: 'Sure you want to delete: ' + this.currentLibraryName() + "?",
|
|
||||||
header: 'Confirmation',
|
|
||||||
icon: 'pi pi-exclamation-triangle',
|
|
||||||
acceptIcon:"none",
|
|
||||||
rejectIcon:"none",
|
|
||||||
rejectButtonStyleClass:"p-button-text",
|
|
||||||
accept: () => {
|
|
||||||
this.libraryBookService.deleteLibrary(this.currentLibraryId()).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', life: 3000 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
this.activatedRoute.paramMap.subscribe((params) => {
|
|
||||||
const libraryId = Number(params.get('libraryId'));
|
|
||||||
if (libraryId) {
|
|
||||||
this.currentLibraryId.set(libraryId);
|
|
||||||
this.libraryBookService.loadBooksSignal(libraryId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -175,6 +175,13 @@ export class LibraryAndBookService {
|
|||||||
return computed(() => this.libraryBooksMap().get(libraryId) || []);
|
return computed(() => this.libraryBooksMap().get(libraryId) || []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getShelfBooks(shelfId: number) {
|
||||||
|
return computed(() => {
|
||||||
|
const allBooks = Array.from(this.libraryBooksMap().values()).flat();
|
||||||
|
return allBooks.filter(book => book.shelves?.some(shelf => shelf.id === shelfId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loadBooksSignal(libraryId: number) {
|
loadBooksSignal(libraryId: number) {
|
||||||
if (!this.loadedLibraries.has(libraryId)) {
|
if (!this.loadedLibraries.has(libraryId)) {
|
||||||
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
|
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user