Move components

This commit is contained in:
aditya.chandel
2024-12-21 21:45:06 -07:00
parent d56daaafc1
commit a30eb17255
7 changed files with 6 additions and 6 deletions
@@ -0,0 +1,14 @@
<div class="book-card">
<div class="cover-container">
<img [src]="coverImageSrc(book)" class="book-cover placeholder" alt="Cover of {{ book.metadata.title }}" loading="lazy" />
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book)"></p-button>
<p-button [rounded]="true" icon="pi pi-book" class="info-btn" (click)="readBook(book)"></p-button>
</div>
<div class="book-info">
<div class="book-title-container">
<h4 class="book-title">{{ book.metadata.title }}</h4>
<p-menu #menu [model]="items" [popup]="true" appendTo="body" />
<p-button [text]="true" (click)="menu.toggle($event)" icon="pi pi-ellipsis-v" />
</div>
</div>
</div>
@@ -0,0 +1,67 @@
.book-card {
background-color: var(--surface-card);
border-radius: 8px 8px 0 0;
position: relative;
overflow: hidden;
}
.cover-container {
position: relative;
}
.book-title-container {
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: row;
}
.book-title {
font-size: 0.85rem;
color: var(--text-color);
margin-bottom: 6px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
padding: 6px 6px 3px;
}
.book-cover {
width: 100%;
height: auto;
max-height: 100%;
object-fit: cover;
border-radius: 8px 8px 0 0;
transition: filter 0.2s ease-in-out;
}
.info-btn, .read-btn {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: none;
transition: opacity 0.2s ease-in-out;
}
.info-btn {
top: 25%; /* 30% below the top of the image */
}
.read-btn {
bottom: 25%; /* 30% above the bottom of the image */
}
.cover-container {
position: relative; /* Ensures buttons are positioned relative to the image */
}
.cover-container:hover .book-cover {
filter: blur(2px);
}
.cover-container:hover .info-btn,
.cover-container:hover .read-btn {
display: block;
}
@@ -0,0 +1,79 @@
import {Component, Input, OnInit} from '@angular/core';
import {Book} from '../../model/book.model';
import {Button} from 'primeng/button';
import {LibraryAndBookService} from '../../service/library-and-book.service';
import {Router} from '@angular/router';
import {MenuModule} from 'primeng/menu';
import {MenuItem} from 'primeng/api';
import {DialogService} from "primeng/dynamicdialog";
import {ShelfAssignerComponent} from "../shelf-assigner/shelf-assigner.component";
@Component({
selector: 'app-book-card',
templateUrl: './book-card.component.html',
styleUrls: ['./book-card.component.scss'],
imports: [
Button,
MenuModule
]
})
export class BookCardComponent implements OnInit {
@Input() book!: Book;
items: MenuItem[] | undefined;
constructor(
private libraryBookService: LibraryAndBookService, private router: Router,
private dialogService: DialogService) {
}
coverImageSrc(book: Book): string {
return this.libraryBookService.getBookCoverUrl(book.id);
}
readBook(book: Book) {
this.libraryBookService.readBook(book);
}
openBookInfo(book: Book) {
this.router.navigate(['/library', book.libraryId, 'book', book.id, 'info']);
}
ngOnInit(): void {
this.items = [
{
label: 'Options',
items: [
{
label: 'Add to shelf',
icon: 'pi pi-folder',
command: () => {
this.openShelfDialog(this.book);
}
},
{
label: 'View metadata',
icon: 'pi pi-info-circle',
command: () => {
this.openBookInfo(this.book);
}
}
]
}
];
}
private openShelfDialog(book: Book) {
this.dialogService.open(ShelfAssignerComponent, {
header: 'Update Shelves: ' + book.metadata.title,
modal: true,
width: '30%',
height: '70%',
contentStyle: {overflow: 'auto'},
baseZIndex: 10,
data: {
book: this.book
},
});
}
}
@@ -0,0 +1,33 @@
<div class="dialog-container">
<div class="checkbox-list">
<div *ngFor="let shelf of shelves()" class="flex items-center">
<p-checkbox [inputId]="shelf.name" name="group" [value]="shelf" [(ngModel)]="selectedShelves" />
<label [for]="shelf.id" class="ml-2">{{ shelf.name }}</label>
</div>
</div>
<!-- Divider and Bottom Section -->
<div class="bottom-section">
<p-divider></p-divider>
<div class="bottom-container">
<p-button outlined="true" label="Create Shelf" (onClick)="createShelfDialog()"></p-button>
<div>
<p-button class="spacing-right" severity="secondary" label="Cancel" (onClick)="closeDialog()"></p-button>
<p-button label="Save" (onClick)="updateBooksShelves()"></p-button>
</div>
</div>
</div>
<p-dialog [(visible)]="displayShelfDialog" header="Create Shelf" [modal]="true" [closable]="true" (onHide)="closeShelfDialog()" [style]="{ width: '400px', height: 'auto' }">
<div class="p-fluid">
<div class="field">
<label for="shelfName">Shelf Name</label>
<input id="shelfName" type="text" pInputText [(ngModel)]="shelfName"/>
</div>
</div>
<ng-template pTemplate="footer">
<p-button label="Cancel" severity="secondary" (onClick)="closeShelfDialog()" class="p-button-text"></p-button>
<p-button label="Save" (onClick)="saveNewShelf()"></p-button>
</ng-template>
</p-dialog>
</div>
@@ -0,0 +1,49 @@
.dialog-container {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
}
.bottom-section {
margin-top: auto;
}
.bottom-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
}
p-divider {
margin: 1rem 0;
border-color: var(--text-color-secondary);
}
.spacing-right {
margin-right: 1rem;
}
p-dialog .p-dialog-content {
display: flex;
flex-direction: column;
justify-content: space-between;
gap: 1rem; /* Adds space between elements inside the dialog */
}
p-dialog .p-dialog-footer {
display: flex;
justify-content: flex-end;
}
.dialog-container .checkbox-list {
display: flex;
flex-direction: column;
gap: 1rem; /* Adds gap between each checkbox row */
padding: 1rem;
}
.checkbox-list .flex {
margin-bottom: 0.5rem; /* Optional: adds a smaller gap between each checkbox item */
}
@@ -0,0 +1,76 @@
import {Component, computed, OnInit} from '@angular/core';
import {LibraryAndBookService} from '../../service/library-and-book.service';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {Book} from '../../model/book.model';
import {MessageService} from 'primeng/api';
@Component({
selector: 'app-shelf-assigner',
standalone: false,
templateUrl: './shelf-assigner.component.html',
styleUrl: './shelf-assigner.component.scss'
})
export class ShelfAssignerComponent implements OnInit {
shelves = computed(() => {
return this.libraryBookService.shelves();
});
book: Book;
selectedShelves: any[] = [];
displayShelfDialog: boolean = false;
shelfName: string = '';
constructor(
private libraryBookService: LibraryAndBookService, private dynamicDialogConfig: DynamicDialogConfig,
private dynamicDialogRef: DynamicDialogRef, private messageService: MessageService) {
this.book = this.dynamicDialogConfig.data.book;
}
ngOnInit(): void {
if (this.book.shelves) {
const bookShelfIds = this.book.shelves.map(shelf => shelf.id);
this.selectedShelves = this.shelves().filter(shelf => bookShelfIds.includes(shelf.id));
}
}
saveNewShelf() {
this.libraryBookService.createShelf(this.shelfName).subscribe(
() => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Shelf created: ' + this.shelfName});
this.displayShelfDialog = false;
},
(error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
console.error('Error creating shelf:', error);
}
);
}
updateBooksShelves() {
const shelfIds = this.selectedShelves.map((shelf) => shelf.id);
this.libraryBookService.assignShelvesToBook(this.book, shelfIds).subscribe(
() => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book\'s shelves updated'});
this.dynamicDialogRef.close();
},
(error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book\'s shelves'});
this.dynamicDialogRef.close();
}
);
}
createShelfDialog(): void {
this.displayShelfDialog = true;
}
closeShelfDialog(): void {
this.displayShelfDialog = false;
}
closeDialog() {
this.dynamicDialogRef.close();
}
}