WIP: Book parsing
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
{{ 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)="openEditDialog(book?.id!)" icon="pi pi-pencil"></p-button>
|
||||
<p-button [rounded]="true" [raised]="true" [outlined]="true" (onClick)="readBook(book!)" icon="pi pi-eye"></p-button>
|
||||
<p-button [rounded]="true" [raised]="true" [outlined]="true" icon="pi pi-download"></p-button>
|
||||
</div>
|
||||
|
||||
@@ -3,14 +3,12 @@ import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {BookMetadataDialogComponent} from '../book-metadata-dialog/book-metadata-dialog.component';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {forkJoin, Subscription} from 'rxjs';
|
||||
import {TagModule} from 'primeng/tag';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {MetadataSearcherComponent} from '../../../metadata-searcher/metadata-searcher.component';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {LoadingService} from '../../../loading.service';
|
||||
|
||||
@Component({
|
||||
@@ -78,10 +76,13 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
|
||||
return 'No authors available';
|
||||
}
|
||||
|
||||
openEditDialog(bookId: number, libraryId: number) {
|
||||
openEditDialog(bookId: number) {
|
||||
this.loadingService.show();
|
||||
this.bookService.getFetchBookMetadata(bookId).subscribe({
|
||||
next: (fetchedMetadata) => {
|
||||
forkJoin({
|
||||
book: this.bookService.getBookByIdFromAPI(bookId, true),
|
||||
fetchedMetadata: this.bookService.fetchMetadataFromSource(bookId)
|
||||
}).subscribe({
|
||||
next: ({ book, fetchedMetadata }) => {
|
||||
this.loadingService.hide();
|
||||
this.dialogRef = this.dialogService.open(MetadataSearcherComponent, {
|
||||
header: 'Update Book Metadata',
|
||||
@@ -95,7 +96,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
|
||||
'padding': '1.25rem 1.25rem 0',
|
||||
},
|
||||
data: {
|
||||
currentMetadata: this.book?.metadata,
|
||||
currentMetadata: book.metadata,
|
||||
fetchedMetadata: fetchedMetadata,
|
||||
book: this.book
|
||||
}
|
||||
@@ -118,27 +119,6 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/*openEditDialog1(bookId: number | undefined, libraryId: number | undefined) {
|
||||
this.dialogRef = this.dialogService.open(BookMetadataDialogComponent, {
|
||||
header: 'Metadata: Google Books',
|
||||
modal: true,
|
||||
closable: true,
|
||||
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';
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface BookMetadata {
|
||||
publisher: string;
|
||||
publishedDate: string;
|
||||
isbn10: string;
|
||||
description: string;
|
||||
description?: string;
|
||||
pageCount: number;
|
||||
language: string;
|
||||
googleBookId: string;
|
||||
@@ -25,34 +25,23 @@ export interface BookMetadata {
|
||||
}
|
||||
|
||||
export interface FetchedMetadata {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
authors: Author[];
|
||||
categories: Category[];
|
||||
publisher: string;
|
||||
publishedDate: string;
|
||||
isbn10: string;
|
||||
description: string;
|
||||
pageCount: number;
|
||||
language: string;
|
||||
googleBookId: string;
|
||||
thumbnail: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface UpdateMedata {
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
authors?: Author[];
|
||||
categories?: Category[];
|
||||
publisher?: string;
|
||||
publishedDate?: string;
|
||||
isbn10?: string;
|
||||
description?: string;
|
||||
pageCount?: number;
|
||||
language?: string;
|
||||
googleBookId?: string;
|
||||
thumbnail?: string;
|
||||
bookId: number | null;
|
||||
googleBookId: string | null;
|
||||
amazonBookId: string | null;
|
||||
title: string | null;
|
||||
subtitle?: string | null;
|
||||
publisher: string | null;
|
||||
publishedDate: string | null;
|
||||
description: string | null;
|
||||
isbn13: string | null;
|
||||
isbn10: string | null;
|
||||
pageCount: number | null;
|
||||
thumbnailUrl: string | null;
|
||||
language: string | null;
|
||||
rating: number | null;
|
||||
reviewCount: number | null;
|
||||
authors: string[];
|
||||
categories: string[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@@ -66,30 +55,15 @@ export interface Category {
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
export interface BookWithNeighborsDTO {
|
||||
currentBook: Book;
|
||||
previousBookId: number | null;
|
||||
nextBookId: number | null;
|
||||
}
|
||||
|
||||
export interface BookUpdateEvent {
|
||||
libraryId: number;
|
||||
filename: string;
|
||||
book: {
|
||||
id: number;
|
||||
libraryId: number;
|
||||
fileName: string;
|
||||
addedOn: string;
|
||||
metadata: BookMetadata;
|
||||
};
|
||||
parsingStatus: string;
|
||||
}
|
||||
|
||||
export interface BookSetting {
|
||||
pageNumber: number;
|
||||
zoom: number | string;
|
||||
sidebar_visible: boolean;
|
||||
spread: 'off' | 'even' | 'odd';
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, of} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError, map, switchMap, tap} from 'rxjs/operators';
|
||||
import {Book, BookMetadata, BookSetting, FetchedMetadata, UpdateMedata} from '../model/book.model';
|
||||
import {Book, BookMetadata, BookSetting, FetchedMetadata} from '../model/book.model';
|
||||
import {BookState} from '../model/state/book-state.model';
|
||||
|
||||
@Injectable({
|
||||
@@ -187,28 +187,15 @@ export class BookService {
|
||||
this.bookStateSubject.next({...currentState, books: filteredBooks});
|
||||
}
|
||||
|
||||
getFetchBookMetadata(bookId: number): Observable<FetchedMetadata> {
|
||||
return this.http.post<FetchedMetadata>(`${this.url}/${bookId}/query-for-books`, null);
|
||||
getBookByIdFromAPI(bookId: number, withDescription: boolean) {
|
||||
return this.http.get<Book>(`${this.url}/${bookId}`);
|
||||
}
|
||||
|
||||
updateMetadata(bookId: number, updateMedata: UpdateMedata): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, updateMedata).pipe(
|
||||
map((updatedMetadata) => {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
const updatedBooks = currentState.books?.map((book) => {
|
||||
if (book.id === bookId) {
|
||||
return { ...book, metadata: updatedMetadata };
|
||||
}
|
||||
return book;
|
||||
}) || [];
|
||||
this.bookStateSubject.next({ ...currentState, books: updatedBooks });
|
||||
return updatedMetadata;
|
||||
}),
|
||||
catchError((error) => {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
this.bookStateSubject.next({ ...currentState, error: error.message });
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
fetchMetadataFromSource(bookId: number): Observable<FetchedMetadata> {
|
||||
return this.http.post<FetchedMetadata>(`${this.url}/${bookId}/source/AMAZON/metadata`, null);
|
||||
}
|
||||
|
||||
updateMetadata(bookId: number, updateMedata: FetchedMetadata): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}/source/AMAZON/metadata`, updateMedata);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user