diff --git a/booklore-ui/src/app/book-metadata/book-metadata.component.html b/booklore-ui/src/app/book-metadata/book-metadata.component.html new file mode 100644 index 000000000..cd6b7ae99 --- /dev/null +++ b/booklore-ui/src/app/book-metadata/book-metadata.component.html @@ -0,0 +1,34 @@ +
+
+
+
+ Cover of {{ book?.metadata?.title }} +
+ +
+
+

+
+
+
diff --git a/booklore-ui/src/app/book-metadata/book-metadata.component.scss b/booklore-ui/src/app/book-metadata/book-metadata.component.scss new file mode 100644 index 000000000..e778ba24a --- /dev/null +++ b/booklore-ui/src/app/book-metadata/book-metadata.component.scss @@ -0,0 +1,88 @@ +.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.65rem; + 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; +} diff --git a/booklore-ui/src/app/book-metadata/book-metadata.component.ts b/booklore-ui/src/app/book-metadata/book-metadata.component.ts new file mode 100644 index 000000000..05426508e --- /dev/null +++ b/booklore-ui/src/app/book-metadata/book-metadata.component.ts @@ -0,0 +1,91 @@ +import {Component, OnInit, OnDestroy} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {BookService} from '../book/service/book.service'; +import {Book} from '../book/model/book.model'; +import {Button} from 'primeng/button'; +import {NgForOf} 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 + ] +}) +export class BookMetadataComponent implements OnInit, OnDestroy { + book: Book | null = null; + private routeSubscription!: Subscription; + ref: DynamicDialogRef | undefined; + + constructor( + private bookService: BookService, + private activatedRoute: ActivatedRoute, + private dialogService: DialogService) { + } + + ngOnInit(): void { + this.routeSubscription = this.activatedRoute.paramMap.subscribe((paramMap) => { + const bookId = +paramMap.get('bookId')!; + if (bookId) { + this.loadBook(bookId); + } + }); + } + + private loadBook(bookId: number): void { + this.bookService.getBook(bookId).subscribe((book) => { + this.book = book; + }); + } + + 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(id: number | undefined) { + this.ref = this.dialogService.open(BooksMetadataDialogComponent, { + header: 'Fetch Metadata (from Google Books)', + modal: false, + width: '65%', + height: '85%', + data: { + bookId: id, + bookTitle: this.book?.metadata.title, + }, + }); + + this.ref.onClose.subscribe(() => { + // @ts-ignore + this.loadBook(this.book?.id); + }); + } + + + coverImageSrc(bookId: any): string { + if (bookId === null) { + return 'assets/placeholder.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'); + } +} diff --git a/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.html b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.html new file mode 100644 index 000000000..ff0cd6734 --- /dev/null +++ b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.html @@ -0,0 +1,40 @@ +
+
+ + Search +
+
+ +
+ Loading metadata... +
+ +
+ {{ errorMessage }} +
+ +
+
+ +
+
+ + +
+ No metadata found for this book. +
+ diff --git a/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.scss b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.scss new file mode 100644 index 000000000..3ff487b7b --- /dev/null +++ b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.scss @@ -0,0 +1,105 @@ +.search-container { + margin-bottom: 20px; +} + +.input-group { + display: flex; + justify-content: space-between; + gap: 10px; /* Add space between the text box and button */ +} + +input[type="text"] { + padding: 10px; + font-size: 1rem; + width: 90%; /* Adjust width as necessary */ + border: 1px solid #ddd; + border-radius: 5px; +} + +button { + background-color: #007bff; + color: white; + border: none; + padding: 10px 15px; + font-size: 1rem; + cursor: pointer; + border-radius: 5px; + transition: background-color 0.3s ease; +} + +button:hover { + background-color: #0056b3; +} + +button:focus { + outline: none; +} + +.metadata-list { + display: flex; + flex-direction: column; + gap: 15px; +} + +.metadata-header { + display: flex; + gap: 20px; /* Space between image and text */ +} + +.book-image { + width: 100px; /* Adjust the width as needed */ + height: 150px; /* Adjust the height as needed */ + object-fit: cover; /* Ensure the image covers the area without distorting */ + border-radius: 5px; + margin-bottom: 10px; /* Add spacing between the image and the button */ +} + +.select-button { + width: auto; /* Button width adjusts to content */ + padding: 8px 15px; /* Adjust the button padding */ + margin-top: 10px; /* Space between the image and button */ + text-align: center; /* Ensure text is centered in the button */ +} + +.book-metadata { + background-color: var(--surface-50); + padding: 15px; + margin-bottom: 15px; + border: 1px solid #ddd; + border-radius: 8px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +h3 { + font-size: 1.5rem; + color: var(--text-color); +} + +p { + margin: 5px 0; + color: var(--text-color-secondary); + font-size: 1.0rem; +} + +strong { + font-weight: bold; +} + +button { + background-color: #007bff; + color: white; + border: none; + padding: 10px 15px; + font-size: 0.9rem; + cursor: pointer; + border-radius: 5px; + transition: background-color 0.3s ease; + + &:hover { + background-color: #0056b3; + } + + &:focus { + outline: none; + } +} diff --git a/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.ts b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.ts new file mode 100644 index 000000000..e9385860d --- /dev/null +++ b/booklore-ui/src/app/books-metadata-dialog/books-metadata-dialog.component.ts @@ -0,0 +1,77 @@ +import {Component, OnInit} from '@angular/core'; +import {BookMetadata} from '../book/model/book.model'; +import {BookService} from '../book/service/book.service'; +import {NgForOf, NgIf} from '@angular/common'; +import {FormBuilder, FormsModule} from '@angular/forms'; +import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; +import {Router} from '@angular/router'; +import {Button} from 'primeng/button'; + +@Component({ + selector: 'app-books-metadata-dialog', + templateUrl: './books-metadata-dialog.component.html', + imports: [ + NgIf, + NgForOf, + FormsModule, + Button + ], + styleUrls: ['./books-metadata-dialog.component.scss'] +}) +export class BooksMetadataDialogComponent implements OnInit { + bookMetadataList: BookMetadata[] = []; + isLoading = true; + errorMessage: string | null = null; + searchText: string = ''; + bookId: number = 0; + + constructor(private bookService: BookService, public dynamicDialogConfig: DynamicDialogConfig, + private dynamicDialogRef: DynamicDialogRef, private router: Router) { + this.searchText = dynamicDialogConfig.data.bookTitle; + this.bookId = this.dynamicDialogConfig.data.bookId; + } + + ngOnInit(): void { + this.bookService.fetchBookMetadataByBookId(this.bookId).subscribe({ + next: (metadataList) => { + this.bookMetadataList = metadataList; + this.isLoading = false; + }, + error: (error) => { + this.errorMessage = 'Failed to load metadata'; + this.isLoading = false; + } + }); + } + + selectMetadata(metadata: BookMetadata): void { + this.bookService.setBookMetadata(metadata.googleBookId, this.bookId).subscribe({ + next: () => { + this.dynamicDialogRef.close(); + this.router.navigate(['/book', this.bookId, 'info']); + }, + error: (error) => { + this.errorMessage = 'Failed to save book metadata'; + } + }); + + } + + truncateDescription(description: string): string { + const maxLength = 1500; + return description && description.length > maxLength ? description.substring(0, maxLength) + '...' : description; + } + + populateTitle() { + this.bookService.fetchBookMetadataByTerm(this.searchText).subscribe({ + next: (metadataList) => { + this.bookMetadataList = metadataList; + this.isLoading = false; + }, + error: (error) => { + this.errorMessage = 'Failed to load metadata'; + this.isLoading = false; + } + }) + } +} diff --git a/booklore-ui/src/app/notification/notification.component.html b/booklore-ui/src/app/notification/notification.component.html new file mode 100644 index 000000000..e4968b3c0 --- /dev/null +++ b/booklore-ui/src/app/notification/notification.component.html @@ -0,0 +1,6 @@ + diff --git a/booklore-ui/src/app/notification/notification.component.scss b/booklore-ui/src/app/notification/notification.component.scss new file mode 100644 index 000000000..019770115 --- /dev/null +++ b/booklore-ui/src/app/notification/notification.component.scss @@ -0,0 +1,3 @@ +.glowing-icon { + color: yellow; +} diff --git a/booklore-ui/src/app/notification/notification.component.ts b/booklore-ui/src/app/notification/notification.component.ts new file mode 100644 index 000000000..229e4595c --- /dev/null +++ b/booklore-ui/src/app/notification/notification.component.ts @@ -0,0 +1,45 @@ +import {Component, OnInit, OnDestroy} from '@angular/core'; +import {BookProgressService} from '../book/service/book-progress-service'; +import {BookUpdateEvent} from '../book/model/book-update-event.model'; +import {Subscription} from 'rxjs'; +import {NgClass} from '@angular/common'; + +@Component({ + selector: 'app-notification', + templateUrl: './notification.component.html', + imports: [ + NgClass + ], + styleUrls: ['./notification.component.scss'] +}) +export class NotificationComponent implements OnInit, OnDestroy { + glowing: boolean = false; + private eventSubscription!: Subscription; + + constructor(private bookProgressService: BookProgressService) {} + + ngOnInit(): void { + /*this.eventSubscription = this.bookProgressService.connect(1).subscribe({ + next: (event: BookUpdateEvent) => { + this.handleNewNotification(event); + }, + error: (error) => { + console.error('Error receiving progress updates:', error); + } + });*/ + } + + handleNewNotification(event: BookUpdateEvent): void { + this.glowing = true; + setTimeout(() => { + this.glowing = false; + console.log("reset") + }, 200); + } + + ngOnDestroy(): void { + if (this.eventSubscription) { + this.eventSubscription.unsubscribe(); + } + } +}