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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@
|
||||
<label class="label"></label>
|
||||
<div class="input-container">
|
||||
<img *ngIf="!updateThumbnail" [src]="coverImageSrc(book)" alt="Book Thumbnail" class="thumbnail"/>
|
||||
<img *ngIf="updateThumbnail" [src]="fetchedMetadata.thumbnail" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||
<img *ngIf="updateThumbnail" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="shouldUpdateThumbnail()"/>
|
||||
<img [src]="fetchedMetadata.thumbnail" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Book, FetchedMetadata, UpdateMedata} from '../book/model/book.model';
|
||||
import {Book, BookMetadata, FetchedMetadata} from '../book/model/book.model';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {BookService} from '../book/service/book.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -13,7 +13,7 @@ import {MessageService} from 'primeng/api';
|
||||
export class MetadataSearcherComponent {
|
||||
|
||||
fetchedMetadata: FetchedMetadata;
|
||||
toUpdateMetadata: UpdateMedata;
|
||||
toUpdateMetadata: FetchedMetadata;
|
||||
book: Book;
|
||||
loading: boolean = false;
|
||||
updateThumbnail: boolean = false;
|
||||
@@ -21,60 +21,47 @@ export class MetadataSearcherComponent {
|
||||
constructor(public dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef,
|
||||
private bookService: BookService, private messageService: MessageService) {
|
||||
|
||||
|
||||
this.fetchedMetadata = this.dynamicDialogConfig.data.fetchedMetadata;
|
||||
this.toUpdateMetadata = JSON.parse(JSON.stringify(this.dynamicDialogConfig.data.currentMetadata));
|
||||
this.toUpdateMetadata = this.convertBookMetadataToFetchedMetadata(this.dynamicDialogConfig.data.currentMetadata);
|
||||
this.book = this.dynamicDialogConfig.data.book;
|
||||
}
|
||||
|
||||
copyFetchedToCurrent(field: keyof UpdateMedata) {
|
||||
copyFetchedToCurrent(field: keyof FetchedMetadata) {
|
||||
if (this.fetchedMetadata && this.toUpdateMetadata) {
|
||||
this.toUpdateMetadata[field] = this.fetchedMetadata[field];
|
||||
}
|
||||
}
|
||||
|
||||
get currentAuthorsString(): string {
|
||||
return this.toUpdateMetadata.authors ? this.toUpdateMetadata.authors.map(author => author.name).join(', ') : '';
|
||||
return this.toUpdateMetadata.authors ? this.toUpdateMetadata.authors.map(author => author).join(', ') : '';
|
||||
}
|
||||
|
||||
set currentAuthorsString(value: string) {
|
||||
this.toUpdateMetadata.authors = value.split(',').map(name => ({
|
||||
id: this.toUpdateMetadata.authors?.find(author => author.name.trim() === name.trim())?.id || 0,
|
||||
name: name.trim()
|
||||
}));
|
||||
this.toUpdateMetadata.authors = value.split(',');
|
||||
}
|
||||
|
||||
get fetchedAuthorsString(): string {
|
||||
return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author.name).join(', ') : '';
|
||||
return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author).join(', ') : '';
|
||||
}
|
||||
|
||||
set fetchedAuthorsString(value: string) {
|
||||
this.fetchedMetadata.authors = value.split(',').map(name => ({
|
||||
id: this.fetchedMetadata.authors?.find(author => author.name.trim() === name.trim())?.id || 0,
|
||||
name: name.trim()
|
||||
}));
|
||||
this.fetchedMetadata.authors = value.split(',');
|
||||
}
|
||||
|
||||
get currentCategoriesString(): string {
|
||||
return this.toUpdateMetadata.categories ? this.toUpdateMetadata.categories.map(category => category.name).join(', ') : '';
|
||||
return this.toUpdateMetadata.categories ? this.toUpdateMetadata.categories.map(category => category).join(', ') : '';
|
||||
}
|
||||
|
||||
set currentCategoriesString(value: string) {
|
||||
this.toUpdateMetadata.categories = value.split(',').map(name => ({
|
||||
id: this.toUpdateMetadata.categories?.find(category => category.name.trim() === name.trim())?.id || 0,
|
||||
name: name.trim()
|
||||
}));
|
||||
this.toUpdateMetadata.categories = value.split(',');
|
||||
}
|
||||
|
||||
get fetchedCategoriesString(): string {
|
||||
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category.name).join(', ') : '';
|
||||
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : '';
|
||||
}
|
||||
|
||||
set fetchedCategoriesString(value: string) {
|
||||
this.fetchedMetadata.categories = value.split(',').map(name => ({
|
||||
id: this.fetchedMetadata.categories?.find(category => category.name.trim() === name.trim())?.id || 0,
|
||||
name: name.trim()
|
||||
}));
|
||||
this.fetchedMetadata.categories = value.split(',');
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
@@ -142,12 +129,34 @@ export class MetadataSearcherComponent {
|
||||
this.toUpdateMetadata.categories = this.fetchedMetadata.categories;
|
||||
}
|
||||
|
||||
if(this.updateThumbnail) {
|
||||
this.toUpdateMetadata.thumbnail = this.fetchedMetadata.thumbnail;
|
||||
if (this.updateThumbnail) {
|
||||
this.toUpdateMetadata.thumbnailUrl = this.fetchedMetadata.thumbnailUrl;
|
||||
}
|
||||
}
|
||||
|
||||
shouldUpdateThumbnail() {
|
||||
this.updateThumbnail = true;
|
||||
}
|
||||
|
||||
convertBookMetadataToFetchedMetadata(bookMetadata: BookMetadata): FetchedMetadata {
|
||||
return {
|
||||
bookId: null,
|
||||
googleBookId: bookMetadata.googleBookId || null,
|
||||
amazonBookId: '',
|
||||
title: bookMetadata.title || null,
|
||||
subtitle: bookMetadata.subtitle || null,
|
||||
publisher: bookMetadata.publisher || null,
|
||||
publishedDate: bookMetadata.publishedDate || null,
|
||||
description: bookMetadata.description || null,
|
||||
isbn13: '',
|
||||
isbn10: bookMetadata.isbn10 || null,
|
||||
pageCount: bookMetadata.pageCount || null,
|
||||
thumbnailUrl: '',
|
||||
language: bookMetadata.language || null,
|
||||
rating: null,
|
||||
reviewCount: null,
|
||||
authors: bookMetadata.authors.map(author => author.name),
|
||||
categories: bookMetadata.categories.map(category => category.name),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user