Checkpoint

This commit is contained in:
aditya.chandel
2024-12-15 22:41:13 -07:00
parent 0aa1c1b923
commit 767c6604e8
51 changed files with 297 additions and 212 deletions
@@ -0,0 +1,55 @@
<div class="book-metadata-container">
<div class="book-metadata">
<div class="book-header">
<div class="cover-container">
<img [src]="coverImageSrc(book?.id)" class="book-cover placeholder" alt="Cover of {{ book?.metadata?.title }}" loading="lazy"/>
<div>
<div class="book-navigation">
<p-button
icon="pi pi-arrow-left"
class="navigation-button"
severity="help"
(click)="navigateToBook(previousBookId, book?.libraryId!)"
[rounded]="true"
[outlined]="true"
[disabled]="!canGoPrevious()">
</p-button>
<p-button
icon="pi pi-arrow-right"
class="navigation-button"
severity="help"
(click)="navigateToBook(nextBookId, book?.libraryId!)"
[rounded]="true"
[outlined]="true"
[disabled]="!canGoNext()">
</p-button>
</div>
</div>
</div>
<div class="metadata">
<div class="title-row">
<h1 class="book-title">
{{ book?.metadata?.title }}<span *ngIf="book?.metadata?.subtitle">: {{ book?.metadata?.subtitle }}</span>
</h1>
<div class="button-group">
<p-button [rounded]="true" [raised]="true" [outlined]="true" (onClick)="openEditDialog(book?.id, book?.libraryId)" icon="pi pi-pencil"></p-button>
<p-button [rounded]="true" [raised]="true" [outlined]="true" (onClick)="readBook(book?.id)" icon="pi pi-eye"></p-button>
<p-button [rounded]="true" [raised]="true" [outlined]="true" icon="pi pi-download"></p-button>
</div>
</div>
<p class="author">Author — {{ getAuthorNames(book) }}</p>
<div class="categories">
<p-button *ngFor="let category of book?.metadata?.categories" label="{{category.name}}" severity="info" [rounded]="true" [outlined]="true" size="small"></p-button>
</div>
<div class="details">
<p><strong>Publisher:</strong> {{ book?.metadata?.publisher || 'N/A' }}</p>
<p><strong>Published:</strong> {{ book?.metadata?.publishedDate || 'Unknown' }}</p>
<p><strong>Language:</strong> {{ book?.metadata?.language || 'Unknown' }}</p>
</div>
</div>
</div>
<div class="book-description">
<p [innerHTML]="book?.metadata?.description || 'No description available.'"></p>
</div>
</div>
</div>
@@ -0,0 +1,101 @@
.book-metadata-container {
height: calc(100vh - 10rem); /* Full height minus header and footer */
overflow-y: auto; /* Enable vertical scrolling */
transition: transform 0.2s, left 0.2s; /* Smooth transition for movements */
background-color: var(--surface-card);
border-radius: 12px;
padding: 1.5rem 2rem; /* Adjust padding */
}
.book-metadata {
color: var(--text-color);
}
.book-header {
display: flex;
gap: 16px;
}
.cover-container {
max-width: 200px;
flex-shrink: 0;
}
.book-cover {
width: 100%;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.metadata {
flex-grow: 1;
}
.title-row {
display: flex;
justify-content: space-between; /* Ensures title and buttons are spaced out */
align-items: center;
margin-bottom: 0.6rem;
}
.book-title {
font-size: 1.25rem;
font-weight: bold;
margin: 0;
}
.button-group {
display: flex;
gap: 1.5rem; /* Spacing between buttons */
}
.p-button-sm {
font-size: 0.8rem;
padding: 0.5rem;
}
.p-button-text {
color: var(--primary-color);
}
.author {
font-size: 1.1rem;
color: var(--text-color-secondary);
margin: 9px 0;
}
.categories {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 12px;
}
.category {
background-color: var(--text-color);
color: #555;
font-size: 0.8rem;
padding: 4px 8px;
border-radius: 16px;
}
.details p {
margin: 4px 0;
}
.book-description {
margin-top: 16px;
}
.book-navigation {
display: flex;
justify-content: space-between;
margin: 0.8rem 1rem 0;
}
.book-subtitle {
font-size: 1rem;
color: var(--text-color-secondary);
margin-top: 0.25rem;
font-weight: normal;
}
@@ -0,0 +1,116 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {BookService} from '../../service/book.service';
import {Book} from '../../model/book.model';
import {Button} from 'primeng/button';
import {NgForOf, NgIf} from '@angular/common';
import {BooksMetadataDialogComponent} from '../books-metadata-dialog/books-metadata-dialog.component';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {Subscription} from 'rxjs';
import {TagModule} from 'primeng/tag';
@Component({
selector: 'app-book-metadata',
templateUrl: './book-metadata.component.html',
styleUrls: ['./book-metadata.component.scss'],
imports: [
Button,
NgForOf,
TagModule,
NgIf
]
})
export class BookMetadataComponent implements OnInit, OnDestroy {
book: Book | null = null;
nextBookId: number | null = null;
previousBookId: number | null = null;
private routeSubscription!: Subscription;
private dialogRef: DynamicDialogRef | undefined;
private dialogSubscription?: Subscription;
constructor(
private bookService: BookService, private activatedRoute: ActivatedRoute,
private dialogService: DialogService, private router: Router) {
}
ngOnInit(): void {
this.routeSubscription = this.activatedRoute.paramMap.subscribe((paramMap) => {
const bookId = +paramMap.get('bookId')!;
const libraryId = +paramMap.get('libraryId')!;
if (bookId && libraryId) {
this.loadBookWithNeighbors(bookId, libraryId);
}
});
}
private loadBookWithNeighbors(libraryId: number, bookId: number): void {
this.bookService.getBookWithNeighbours(bookId, libraryId).subscribe((response) => {
this.book = response.currentBook;
this.nextBookId = response.nextBookId;
this.previousBookId = response.previousBookId;
});
}
navigateToBook(bookId: number | null, libraryId: number | null): void {
if (bookId && libraryId) {
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
}
}
canGoNext(): boolean {
return this.nextBookId !== null;
}
canGoPrevious(): boolean {
return this.previousBookId !== null;
}
getAuthorNames(book: Book | null): string {
if (book && book.metadata && book.metadata.authors) {
return book.metadata.authors.map((author) => author.name).join(', ');
}
return 'No authors available';
}
openEditDialog(bookId: number | undefined, libraryId: number | undefined) {
this.dialogRef = this.dialogService.open(BooksMetadataDialogComponent, {
header: 'Metadata: Google Books',
modal: false,
width: '65%',
height: '85%',
data: {
bookId: bookId,
libraryId: libraryId,
bookTitle: this.book?.metadata.title,
},
});
this.dialogSubscription = this.dialogRef.onClose.subscribe(() => {
if (this.book?.id && this.book.libraryId) {
this.loadBookWithNeighbors(this.book.id, this.book.libraryId);
}
});
}
coverImageSrc(bookId: number | undefined): string {
if (bookId === null) {
return 'assets/book-cover-metadata.png';
}
return this.bookService.getBookCoverUrl(bookId!);
}
ngOnDestroy(): void {
if (this.routeSubscription) {
this.routeSubscription.unsubscribe();
}
}
readBook(id: number | undefined) {
const url = `/pdf-viewer/book/${id}`;
window.open(url, '_blank');
this.routeSubscription?.unsubscribe();
this.dialogSubscription?.unsubscribe();
this.dialogRef?.close();
}
}