Delete LibraryBrowser component
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<div class="library-header">
|
||||
<div class="library-header-dial">
|
||||
<h3 class="library-name">{{ currentEntityName() }}</h3>
|
||||
<p-speedDial
|
||||
[model]="items!"
|
||||
direction="right"
|
||||
transitionDelay="80"
|
||||
showIcon="pi pi-ellipsis-v"
|
||||
buttonClassName="p-button-text p-button-contrast"
|
||||
hideIcon="pi pi-times">
|
||||
</p-speedDial>
|
||||
</div>
|
||||
<div class="library-header-right">
|
||||
<p-dropdown
|
||||
optionLabel="name"
|
||||
placeholder="Select Sorting"/>
|
||||
<div class="zoom-controls">
|
||||
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-container">
|
||||
<div class="card-container">
|
||||
<virtual-scroller class="virtual-scroller" #scroll [items]="currentEntityBooks()">
|
||||
<div class="grid" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card [book]="book"></app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,51 @@
|
||||
.library-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 15px 15px 10px 17px;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 12px 12px 0 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.library-header-dial {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.library-header-right {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
align-items: center;
|
||||
}
|
||||
.library-name {
|
||||
margin: 0;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.zoom-controls {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.virtual-scroller {
|
||||
width: 100%;
|
||||
height: calc(100vh - 210px);
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
height: 243px;
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 1.3rem;
|
||||
padding: 1rem;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
align-items: start;
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user