Checkpoint
This commit is contained in:
+4
-3
@@ -9,11 +9,12 @@
|
||||
(scroll)="onScroll($event)">
|
||||
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover" alt="Cover of {{ book.title }}" loading="lazy"/>
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<h4>{{ book.title }}</h4>
|
||||
<h4>{{ book.metadata.title }}</h4>
|
||||
<p>{{ getAuthorNames(book) }}</p>
|
||||
<p-button label="View" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book.id)"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+9
-4
@@ -61,7 +61,7 @@ h4 {
|
||||
|
||||
p {
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.7rem;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.2;
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
@@ -69,15 +69,20 @@ p {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.view-btn {
|
||||
.view-btn, .read-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
transform: translate(-50%, -20%);
|
||||
display: none;
|
||||
z-index: 1;
|
||||
margin: -60px 0;
|
||||
}
|
||||
|
||||
.book-item:hover .view-btn {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.book-item:hover .read-btn {
|
||||
display: block;
|
||||
top: 75%;
|
||||
}
|
||||
|
||||
+7
-2
@@ -4,6 +4,7 @@ import {BookService} from '../../service/book.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard-scroller',
|
||||
@@ -26,7 +27,7 @@ export class DashboardScrollerComponent implements OnInit {
|
||||
|
||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||
|
||||
constructor(private bookService: BookService) {
|
||||
constructor(private bookService: BookService, private router: Router) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -67,7 +68,7 @@ export class DashboardScrollerComponent implements OnInit {
|
||||
}
|
||||
|
||||
getAuthorNames(book: Book): string {
|
||||
return book.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||
return book.metadata.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||
}
|
||||
|
||||
openBook(bookId: number): void {
|
||||
@@ -83,4 +84,8 @@ export class DashboardScrollerComponent implements OnInit {
|
||||
this.loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
openBookInfo(bookId: number) {
|
||||
this.router.navigate(['/book', bookId, 'info']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]=true
|
||||
(scrolled)="loadMore()">
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.title }}" loading="lazy"/>
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<h4>{{ book.title }}</h4>
|
||||
<h4>{{ book.metadata.title }}</h4>
|
||||
<p>{{ getAuthorNames(book) }}</p>
|
||||
<p-button label="View" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-eye" class="view-btn" (click)="readBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book.id)"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
height: auto;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 8px;
|
||||
position: relative; /* Positioning container for the button and overlay */
|
||||
position: relative; /* Positioning container for the buttons and overlay */
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
@@ -24,7 +24,7 @@
|
||||
object-fit: cover;
|
||||
background-color: #444;
|
||||
transition: background-color 0.3s ease, filter 0.3s ease; /* Add transition for blur effect */
|
||||
position: relative; /* Make this the reference point for the overlay */
|
||||
position: relative; /* Make this the reference point for the overlay and buttons */
|
||||
}
|
||||
|
||||
/* Blur and overlay effect */
|
||||
@@ -40,7 +40,7 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
|
||||
z-index: 0; /* Put overlay behind the button */
|
||||
z-index: 0; /* Put overlay behind the buttons */
|
||||
}
|
||||
|
||||
.book-info {
|
||||
@@ -62,7 +62,6 @@ h4 {
|
||||
max-width: 100%;
|
||||
text-align: center;
|
||||
margin-bottom: 5px;
|
||||
|
||||
}
|
||||
|
||||
p {
|
||||
@@ -87,17 +86,22 @@ p {
|
||||
}
|
||||
|
||||
/* PrimeNG button styling */
|
||||
.view-btn {
|
||||
.view-btn, .read-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%); /* Center button on the image */
|
||||
transform: translate(-50%, -20%); /* Center buttons within the book-cover */
|
||||
display: none; /* Hide by default */
|
||||
z-index: 1; /* Ensure it appears over the image */
|
||||
margin: -60px 0; /* Add spacing between the buttons */
|
||||
}
|
||||
|
||||
.book-item:hover .view-btn {
|
||||
display: block; /* Show the button when the card is hovered */
|
||||
display: block; /* Show the View button when the card is hovered */
|
||||
}
|
||||
|
||||
.book-item:hover .read-btn {
|
||||
display: block; /* Show the Read button when the card is hovered */
|
||||
top: 75%; /* Slightly adjust the position to be below the View button */
|
||||
}
|
||||
|
||||
.infinite-scroll {
|
||||
|
||||
@@ -1,33 +1,79 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, NgZone } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BookProgressService } from '../../service/book-progress-service';
|
||||
import { BookUpdateEvent } from '../../model/book-update-event.model';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { Book } from '../../model/book.model';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-browser-v2',
|
||||
standalone: false,
|
||||
templateUrl: './library-browser.component.html',
|
||||
styleUrls: ['./library-browser.component.scss'],
|
||||
imports: [
|
||||
InfiniteScrollDirective,
|
||||
Button,
|
||||
NgForOf
|
||||
]
|
||||
})
|
||||
export class LibraryBrowserComponent implements OnInit {
|
||||
books: Book[] = [];
|
||||
private libraryId: number = 1;
|
||||
private currentPage: number = 0;
|
||||
|
||||
constructor(private bookService: BookService, private route: ActivatedRoute) {}
|
||||
constructor(
|
||||
private bookService: BookService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router,
|
||||
private bookProgressService: BookProgressService,
|
||||
private ngZone: NgZone
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
const libraryId = params.get('libraryId');
|
||||
if (libraryId) {
|
||||
this.libraryId = +libraryId;
|
||||
this.resetState();
|
||||
this.loadBooks();
|
||||
}
|
||||
combineLatest([this.activatedRoute.paramMap, this.activatedRoute.queryParamMap])
|
||||
.subscribe(([params, queryParams]) => {
|
||||
const libraryId = params.get('libraryId');
|
||||
if (libraryId) {
|
||||
this.libraryId = +libraryId;
|
||||
this.resetState();
|
||||
this.loadBooks();
|
||||
}
|
||||
const watch = queryParams.get('watch');
|
||||
if (watch) {
|
||||
this.startListeningForProgress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startListeningForProgress(): void {
|
||||
this.bookProgressService.connect(this.libraryId).subscribe({
|
||||
next: (event: BookUpdateEvent) => this.addBookToCollection(event),
|
||||
error: (error) => console.error('Error receiving progress updates:', error),
|
||||
});
|
||||
}
|
||||
|
||||
addBookToCollection(event: BookUpdateEvent): void {
|
||||
if(event.parsingStatus === 'PARSED_NEW_BOOK') {
|
||||
const newBook: Book = {
|
||||
id: event.book.id,
|
||||
libraryId: event.book.libraryId,
|
||||
metadata: event.book.metadata,
|
||||
};
|
||||
this.ngZone.run(() => {
|
||||
if (!this.books.find((book) => book.id === newBook.id)) {
|
||||
this.books = [newBook, ...this.books];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Status other than: PARSED_NEW_BOOK');
|
||||
}
|
||||
}
|
||||
|
||||
resetState(): void {
|
||||
console.log("resetState")
|
||||
this.books = [];
|
||||
this.currentPage = 0;
|
||||
}
|
||||
@@ -38,9 +84,7 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
this.books = [...this.books, ...response.content];
|
||||
this.currentPage++;
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error loading books:', err);
|
||||
},
|
||||
error: (err) => console.error('Error loading books:', err),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,11 +97,15 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
}
|
||||
|
||||
getAuthorNames(book: Book): string {
|
||||
return book.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||
return book.metadata.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||
}
|
||||
|
||||
openBook(bookId: number): void {
|
||||
readBook(bookId: number): void {
|
||||
const url = `/pdf-viewer/book/${bookId}`;
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
openBookInfo(bookId: number) {
|
||||
this.router.navigate(['/book', bookId, 'info']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DirectoryPickerComponent} from '../directory-picker/directory-picker.component';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-creator',
|
||||
@@ -20,8 +21,10 @@ export class LibraryCreatorComponent {
|
||||
public dialogService: DialogService,
|
||||
private dynamicDialogRef: DynamicDialogRef,
|
||||
private messageService: MessageService,
|
||||
private libraryServiceV2: LibraryService
|
||||
) {}
|
||||
private libraryServiceV2: LibraryService,
|
||||
private router: Router,
|
||||
) {
|
||||
}
|
||||
|
||||
show() {
|
||||
this.ref = this.dialogService.open(DirectoryPickerComponent, {
|
||||
@@ -29,7 +32,7 @@ export class LibraryCreatorComponent {
|
||||
modal: false,
|
||||
width: '50%',
|
||||
height: '75%',
|
||||
contentStyle: { overflow: 'auto' },
|
||||
contentStyle: {overflow: 'auto'},
|
||||
baseZIndex: 10
|
||||
});
|
||||
|
||||
@@ -56,6 +59,10 @@ export class LibraryCreatorComponent {
|
||||
this.libraryServiceV2.createLibrary(newLibrary).subscribe({
|
||||
next: (createdLibrary) => {
|
||||
console.log('Library successfully created:', createdLibrary);
|
||||
this.router.navigate(
|
||||
['/library', createdLibrary.id, 'books'],
|
||||
{queryParams: {watch: true}}
|
||||
);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to create library:', err);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<ng-container *ngIf="books.length > 0; else noResults">
|
||||
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
|
||||
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
|
||||
<span class="search-book-name">{{ book.title }}</span>
|
||||
<span class="search-book-name">{{ book.metadata.title }}</span>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import {BookMetadata} from './book.model';
|
||||
|
||||
export interface BookUpdateEvent {
|
||||
libraryId: number;
|
||||
filename: string;
|
||||
book: {
|
||||
id: number;
|
||||
libraryId: number;
|
||||
fileName: string;
|
||||
addedOn: string;
|
||||
metadata: BookMetadata;
|
||||
};
|
||||
parsingStatus: string;
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
import {Author} from './author.model';
|
||||
|
||||
export interface Book {
|
||||
id: number;
|
||||
libraryId: number;
|
||||
title: string;
|
||||
authors: Author[];
|
||||
metadata: BookMetadata
|
||||
}
|
||||
|
||||
export interface PaginatedBooksResponse {
|
||||
@@ -16,3 +13,29 @@ export interface PaginatedBooksResponse {
|
||||
first: boolean;
|
||||
last: boolean;
|
||||
}
|
||||
|
||||
export interface BookMetadata {
|
||||
thumbnail: string;
|
||||
title: string;
|
||||
authors: Author[];
|
||||
categories: Category[];
|
||||
publisher: string;
|
||||
publishedDate: string;
|
||||
isbn10: string;
|
||||
description: string;
|
||||
pageCount: number;
|
||||
language: string;
|
||||
googleBookId: string;
|
||||
}
|
||||
|
||||
export interface Author {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookUpdateEvent} from '../model/book-update-event.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookProgressService {
|
||||
private eventSource: EventSource | null = null;
|
||||
|
||||
connect(libraryId: number): Observable<BookUpdateEvent> {
|
||||
const url = `http://localhost:8080/v1/library/${libraryId}/parse`;
|
||||
|
||||
return new Observable((observer) => {
|
||||
this.eventSource = new EventSource(url);
|
||||
|
||||
this.eventSource.onmessage = (event) => {
|
||||
const data: BookUpdateEvent = JSON.parse(event.data);
|
||||
observer.next(data);
|
||||
};
|
||||
|
||||
this.eventSource.onerror = (error) => {
|
||||
console.error('SSE connection error:', error);
|
||||
observer.error(error);
|
||||
};
|
||||
|
||||
return () => {
|
||||
this.closeConnection();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
closeConnection(): void {
|
||||
if (this.eventSource) {
|
||||
this.eventSource.close();
|
||||
this.eventSource = null;
|
||||
console.log('SSE connection closed');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { Book, PaginatedBooksResponse } from '../model/book.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Book, BookMetadata, PaginatedBooksResponse} from '../model/book.model';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BookSetting} from '../model/book-settings.model';
|
||||
|
||||
@Injectable({
|
||||
@@ -12,7 +12,8 @@ export class BookService {
|
||||
private readonly libraryUrl = 'http://localhost:8080/v1/library';
|
||||
private readonly bookUrl = 'http://localhost:8080/v1/book';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getBook(bookId: number): Observable<Book> {
|
||||
return this.http.get<Book>(`${this.bookUrl}/${bookId}`);
|
||||
@@ -36,7 +37,6 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
searchBooks(query: string): Observable<Book[]> {
|
||||
if (query.length < 2) {
|
||||
return new Observable<Book[]>();
|
||||
@@ -64,4 +64,17 @@ export class BookService {
|
||||
updateLastReadTime(bookId: number): Observable<void> {
|
||||
return this.http.put<void>(`${this.bookUrl}/${bookId}/update-last-read`, {});
|
||||
}
|
||||
|
||||
fetchBookMetadataByBookId(bookId: number): Observable<BookMetadata[]> {
|
||||
return this.http.get<BookMetadata[]>(`${this.bookUrl}/${bookId}/fetch-metadata`);
|
||||
}
|
||||
|
||||
fetchBookMetadataByTerm(term: string): Observable<BookMetadata[]> {
|
||||
return this.http.get<BookMetadata[]>(`${this.bookUrl}/fetch-metadata?term=${term}`);
|
||||
}
|
||||
|
||||
setBookMetadata(googleBookId: string, bookId: number): Observable<void> {
|
||||
const requestBody = {googleBookId: googleBookId};
|
||||
return this.http.put<void>(`${this.bookUrl}/${bookId}/set-metadata`, requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user