WIP: New metadata engine

This commit is contained in:
aditya.chandel
2025-01-01 01:12:27 -07:00
parent 1d06f83de8
commit ea2ac58f03
30 changed files with 1145 additions and 83 deletions
@@ -74,7 +74,9 @@ export class BookCardComponent implements OnInit {
{
label: 'View metadata',
icon: 'pi pi-info-circle',
command: () => this.openBookInfo(this.book),
command: () => {
this.openBookInfo(this.book)
},
},
],
},
@@ -20,7 +20,7 @@
<div *ngFor="let metadata of bookMetadataList" class="book-metadata">
<div class="metadata-header">
<div class="book-image-container">
<img class="book-image" [src]="metadata.thumbnail || 'assets/book-cover-metadata.png'" alt="Book Cover"/>
<!--<img class="book-image" [src]="metadata.thumbnail || 'assets/book-cover-metadata.png'" alt="Book Cover"/>-->
<p-button class="select-button" (click)="selectMetadata(metadata)">Select</p-button>
</div>
<div>
@@ -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!, book?.libraryId!)" 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>
@@ -9,6 +9,9 @@ import {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({
selector: 'app-book-metadata',
@@ -27,18 +30,18 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
previousBookId: number | null = null;
private routeSubscription!: Subscription;
private dialogRef: DynamicDialogRef | undefined;
private dialogRef!: DynamicDialogRef;
private dialogSubscription?: Subscription;
constructor(
private bookService: BookService, private activatedRoute: ActivatedRoute,
private dialogService: DialogService, private router: Router,
private libraryService: LibraryService) {
private libraryService: LibraryService, private loadingService: LoadingService,) {
}
ngOnInit(): void {
this.routeSubscription = this.activatedRoute.paramMap.subscribe((paramMap) => {
const bookId = +paramMap.get('bookId')!;
const bookId = +paramMap.get('bookId')!;
const libraryId = +paramMap.get('libraryId')!;
if (bookId && libraryId) {
this.loadBookWithNeighbors(bookId, libraryId);
@@ -75,7 +78,47 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
return 'No authors available';
}
openEditDialog(bookId: number | undefined, libraryId: number | undefined) {
openEditDialog(bookId: number, libraryId: number) {
this.loadingService.show();
this.bookService.getFetchBookMetadata(bookId).subscribe({
next: (fetchedMetadata) => {
this.loadingService.hide();
this.dialogRef = this.dialogService.open(MetadataSearcherComponent, {
header: 'Update Book Metadata',
modal: true,
closable: true,
width: '1350px',
height: '1000px',
contentStyle: {
'overflow-y': 'auto',
'max-height': 'calc(100vh - 150px)',
'padding': '1.25rem 1.25rem 0',
},
data: {
currentMetadata: this.book?.metadata,
fetchedMetadata: fetchedMetadata,
book: this.book
}
});
if (this.dialogRef) {
this.dialogSubscription = this.dialogRef.onClose.subscribe(() => {
if (this.book?.id && this.book?.libraryId) {
this.loadBookWithNeighbors(this.book.id, this.book.libraryId);
}
});
} else {
console.error('DialogRef is undefined or null');
}
},
error: (error) => {
this.loadingService.hide();
console.error('Error fetching metadata:', error);
}
});
}
/*openEditDialog1(bookId: number | undefined, libraryId: number | undefined) {
this.dialogRef = this.dialogService.open(BookMetadataDialogComponent, {
header: 'Metadata: Google Books',
modal: true,
@@ -94,7 +137,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
this.loadBookWithNeighbors(this.book.id, this.book.libraryId);
}
});
}
}*/
coverImageSrc(bookId: number | undefined): string {
if (bookId === null) {
+33 -1
View File
@@ -10,7 +10,6 @@ export interface Book {
}
export interface BookMetadata {
thumbnail: string;
title: string;
subtitle?: string;
authors: Author[];
@@ -22,6 +21,39 @@ export interface BookMetadata {
pageCount: number;
language: string;
googleBookId: string;
[key: string]: any;
}
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;
[key: string]: any;
}
export interface Author {
@@ -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} from '../model/book.model';
import {Book, BookMetadata, BookSetting, FetchedMetadata, UpdateMedata} from '../model/book.model';
import {BookState} from '../model/state/book-state.model';
@Injectable({
@@ -186,4 +186,29 @@ export class BookService {
const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.has(book.id));
this.bookStateSubject.next({...currentState, books: filteredBooks});
}
getFetchBookMetadata(bookId: number): Observable<FetchedMetadata> {
return this.http.post<FetchedMetadata>(`${this.url}/${bookId}/query-for-books`, null);
}
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;
})
);
}
}
@@ -4,7 +4,7 @@ import { HttpClient } from '@angular/common/http';
import { catchError, map } from 'rxjs/operators';
import { Library } from '../model/library.model';
import { BookService } from './book.service';
import { BookWithNeighborsDTO } from '../model/book.model';
import {BookMetadata, BookWithNeighborsDTO} from '../model/book.model';
import { SortOption } from '../model/sort.model';
import { LibraryState } from '../model/state/library-state.model';
@@ -113,4 +113,5 @@ export class LibraryService {
map(state => (state.books || []).filter(book => book.libraryId === libraryId).length)
);
}
}