WIP: Metadata

This commit is contained in:
aditya.chandel
2025-01-03 23:43:16 -07:00
parent f976c70bed
commit c7724e6837
17 changed files with 295 additions and 324 deletions
+1 -3
View File
@@ -1,6 +1,5 @@
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {AppLayoutModule} from './book/component/layout/app.layout.module';
@@ -41,9 +40,8 @@ import {ProgressSpinnerModule} from 'primeng/progressspinner';
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
import {providePrimeNG} from 'primeng/config';
import Aura from '@primeng/themes/aura';
import { MetadataSearcherComponent } from './book-info-tabs/metadata-searcher/metadata-searcher.component';
import {IftaLabel} from 'primeng/iftalabel';
import { LoadingOverlayComponent } from './loading-overlay/loading-overlay.component';
import {LoadingOverlayComponent} from './loading-overlay/loading-overlay.component';
@NgModule({
declarations: [
@@ -1,88 +1,76 @@
<div class="container pt-4 flex flex-col h-full">
<div class="space-y-4 overflow-y-auto flex-1">
<div *ngIf="bookMetadata$ | async as bookMetadata" class="container pt-4 flex flex-col h-full">
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="space-y-4 overflow-y-auto flex-1">
<div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-2/3">
<label for="title">Title</label>
<input pInputText id="title" class="w-full" [(ngModel)]="bookForm.title"/>
<input pInputText id="title" class="w-full" formControlName="title"/>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="subtitle">Subtitle</label>
<input pInputText id="subtitle" class="w-full" [(ngModel)]="bookForm.subtitle"/>
<input pInputText id="subtitle" class="w-full" formControlName="subtitle"/>
</div>
</div>
<div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-3/4">
<label for="authors">Authors</label>
<input pInputText
id="authors"
class="w-full"
[(ngModel)]="authorsInput"
(ngModelChange)="onAuthorsInputChange()"
placeholder="Enter authors separated by commas"/>
<input pInputText id="authors" class="w-full" formControlName="authors" placeholder="Enter authors separated by commas"/>
</div>
<div class="flex flex-col gap-1 w-1/4">
<label for="publish">Publish Date</label>
<input pInputText id="publish" class="w-full" [(ngModel)]="bookForm.publishedDate"/>
<input pInputText id="publish" class="w-full" formControlName="publishedDate"/>
</div>
</div>
<div class="flex flex-col gap-1 w-full">
<label for="description">Description</label>
<textarea id="description" rows="5" cols="30" pTextarea [(ngModel)]="bookForm.description"></textarea>
<textarea id="description" rows="5" cols="30" pTextarea formControlName="description"></textarea>
</div>
<div class="flex flex-grow w-full justify-between gap-4">
<div class="w-1/3 flex justify-center items-center pt-4 pr-4 pb-4">
<p-image [src]="coverImageSrc(bookId)" alt="Image" width="250"/>
<p-image [src]="coverImageSrc(bookMetadata.bookId)" alt="Image" width="250"></p-image>
</div>
<div class="w-2/3 space-y-2">
<div class="flex flex-col gap-1 w-full">
<label for="categories">Categories</label>
<input
pInputText
id="categories"
class="w-full"
[(ngModel)]="categoriesInput"
(input)="onCategoriesInputChange()"
/>
<input pInputText id="categories" class="w-full" formControlName="categories"/>
</div>
<div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-1/2">
<label for="publisher">Publisher</label>
<input pInputText id="publisher" class="w-full" [(ngModel)]="bookForm.publisher"/>
<input pInputText id="publisher" class="w-full" formControlName="publisher"/>
</div>
<div class="flex flex-col w-1/2">
<label for="language">Language</label>
<input pInputText id="language" class="w-full" [(ngModel)]="bookForm.language"/>
<input pInputText id="language" class="w-full" formControlName="language"/>
</div>
</div>
<div class="flex w-full gap-x-4">
<div class="flex flex-col gap-1 w-1/2">
<label for="isbn10">ISBN10</label>
<input pInputText id="isbn10" class="w-full" [(ngModel)]="bookForm.isbn10"/>
<input pInputText id="isbn10" class="w-full" formControlName="isbn10"/>
</div>
<div class="flex flex-col w-1/2">
<label for="isbn13">ISBN13</label>
<input pInputText id="isbn13" class="w-full" [(ngModel)]="bookForm.isbn13"/>
<input pInputText id="isbn13" class="w-full" formControlName="isbn13"/>
</div>
</div>
<div class="flex w-full gap-x-4">
<div class="flex flex-col w-1/2">
<label for="aisn">AISN</label>
<input pInputText id="aisn" class="w-full" [(ngModel)]="bookForm.asin"/>
<input pInputText id="aisn" class="w-full" formControlName="asin"/>
</div>
<div class="flex flex-col w-1/2">
<label for="page-count">Page Count</label>
<input pInputText id="page-count" class="w-full" [(ngModel)]="bookForm.pageCount"/>
<input pInputText id="page-count" class="w-full" formControlName="pageCount"/>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider>
<div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="closeDialog.emit()"/>
<p-button label="Save" icon="pi pi-check" (onClick)="onSave()"/>
<p-button label="Cancel" icon="pi pi-times" severity="secondary"></p-button>
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
</div>
</div>
</div>
@@ -1,12 +1,16 @@
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {InputText} from 'primeng/inputtext';
import {Textarea} from 'primeng/textarea';
import {Image} from 'primeng/image';
import {Button} from 'primeng/button';
import {Divider} from 'primeng/divider';
import {FormsModule} from '@angular/forms';
import {BookMetadataForm} from '../../book/model/book-metadata-form';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {Observable} from 'rxjs';
import {BookInfoService} from '../book-info.service';
import {AsyncPipe, NgIf} from '@angular/common';
import {BookService} from '../../book/service/book.service';
import {BookMetadataBI} from '../../book/model/book-metadata-for-book-info.model';
import {MessageService} from 'primeng/api';
@Component({
selector: 'app-book-details',
@@ -19,55 +23,86 @@ import {BookService} from '../../book/service/book.service';
Image,
Button,
Divider,
FormsModule
FormsModule,
AsyncPipe,
NgIf,
ReactiveFormsModule
]
})
export class BookDetailsComponent implements OnChanges {
export class BookDetailsComponent implements OnInit {
@Input() bookForm!: BookMetadataForm;
@Input() bookId!: number;
@Output() save = new EventEmitter<BookMetadataForm>();
@Output() closeDialog = new EventEmitter<unknown>();
bookMetadata$: Observable<BookMetadataBI | null>;
bookMetadataForm: FormGroup;
currentBookId!: number;
authorsInput: string = '';
categoriesInput: string = '';
constructor(private bookService: BookService) {
constructor(private bookInfoService: BookInfoService, private bookService: BookService, private messageService: MessageService) {
this.bookMetadata$ = this.bookInfoService.bookMetadata$;
this.bookMetadataForm = new FormGroup({
title: new FormControl(''),
subtitle: new FormControl(''),
authors: new FormControl(''),
categories: new FormControl(''),
publisher: new FormControl(''),
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
});
}
ngOnChanges(changes: SimpleChanges): void {
if (this.bookForm.authors) {
this.authorsInput = this.bookForm.authors.join(', ');
}
if (this.bookForm.categories) {
this.categoriesInput = this.bookForm.categories.join(', ');
}
ngOnInit(): void {
this.bookMetadata$.subscribe((bookMetadata) => {
if (bookMetadata) {
this.currentBookId = bookMetadata.bookId;
this.bookMetadataForm.setValue({
title: bookMetadata.title,
subtitle: bookMetadata.subtitle,
authors: bookMetadata.authors.join(', '),
categories: bookMetadata.categories.join(', '),
publisher: bookMetadata.publisher,
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin ? bookMetadata.asin : '',
description: bookMetadata.description,
pageCount: bookMetadata.pageCount,
language: bookMetadata.language
});
}
});
}
onSave(): void {
if (this.authorsInput) {
this.bookForm.authors = this.authorsInput.split(',').map(author => author.trim());
}
if (this.categoriesInput) {
this.bookForm.categories = this.categoriesInput.split(',').map(category => category.trim());
}
this.save.emit(this.bookForm);
const updatedBookMetadata: BookMetadataBI = {
bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value,
subtitle: this.bookMetadataForm.get('subtitle')?.value,
authors: this.bookMetadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()),
categories: this.bookMetadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()),
publisher: this.bookMetadataForm.get('publisher')?.value,
publishedDate: this.bookMetadataForm.get('publishedDate')?.value,
isbn10: this.bookMetadataForm.get('isbn10')?.value,
isbn13: this.bookMetadataForm.get('isbn13')?.value,
asin: this.bookMetadataForm.get('asin')?.value,
description: this.bookMetadataForm.get('description')?.value,
pageCount: this.bookMetadataForm.get('pageCount')?.value,
language: this.bookMetadataForm.get('language')?.value
};
this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.bookInfoService.emit(updatedBookMetadata);
},
error: (error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
})
}
onAuthorsInputChange(): void {
if (this.authorsInput) {
this.bookForm.authors = this.authorsInput.split(',').map(author => author.trim());
}
}
onCategoriesInputChange(): void {
if (this.categoriesInput) {
this.bookForm.categories = this.categoriesInput.split(',').map(category => category.trim());
}
}
coverImageSrc(bookId: number) {
return this.bookService.getBookCoverUrl(bookId);
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
}
@@ -6,10 +6,10 @@
</p-tablist>
<p-tabpanels style="height: 100%; overflow: hidden; padding-bottom: 0">
<p-tabpanel value="0" style="height: 100%; overflow: hidden;">
<app-book-details [bookId]="book.id" [bookForm]="metadataForm" (save)="saveBook($event)" (closeDialog)="closeDialog($event)"></app-book-details>
<app-book-details></app-book-details>
</p-tabpanel>
<p-tabpanel value="1" style="height: 100%; overflow: hidden;">
<app-book-match [book]="book" (closeDialog)="closeDialog($event)"></app-book-match>
<app-book-match></app-book-match>
</p-tabpanel>
<p-tabpanel value="2" style="height: 100%; overflow: hidden;">
<p>I too work!!</p>
@@ -3,10 +3,11 @@ import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
import {BookDetailsComponent} from './book-details/book-details.component';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {BookService} from '../book/service/book.service';
import {Book} from '../book/model/book.model';
import {BookMetadataForm} from '../book/model/book-metadata-form';
import {MessageService} from 'primeng/api';
import {BookMatchComponent} from './book-match/book-match.component';
import {BookInfoService} from './book-info.service';
import {Book} from '../book/model/book.model';
import {BookMetadataBI} from '../book/model/book-metadata-for-book-info.model';
@Component({
selector: 'book-info-tabs',
@@ -19,42 +20,39 @@ import {BookMatchComponent} from './book-match/book-match.component';
Tab,
TabPanels,
BookDetailsComponent,
TabPanel,
BookMatchComponent,
TabPanel
]
],
})
export class BookInfoTabsComponent {
book: Book;
metadataForm: BookMetadataForm = {} as BookMetadataForm;
export class BookInfoTabsComponent implements OnInit {
constructor(private bookService: BookService, private dynamicDialogConfig: DynamicDialogConfig,
private messageService: MessageService, private dynamicDialogRef: DynamicDialogRef) {
this.book = this.dynamicDialogConfig.data.book;
this.initializeBookForm();
constructor(private dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef, private bookInfoService: BookInfoService) {
}
private initializeBookForm(): void {
if (this.book?.metadata) {
this.metadataForm = {
...this.book.metadata,
authors: this.book.metadata.authors?.map(a => a.name) || [],
categories: this.book.metadata.categories?.map(c => c.name) || []
};
ngOnInit(): void {
const initialBook = this.dynamicDialogConfig.data.book;
if (initialBook?.metadata) {
this.bookInfoService.emit(this.convertToBookMetadataBI(initialBook));
}
}
saveBook(bookMetadataForm: BookMetadataForm) {
this.bookService.updateMetadataV2(this.book?.id!, bookMetadataForm).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
},
error: (error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
});
}
closeDialog($event: any) {
this.dynamicDialogRef.close();
private convertToBookMetadataBI(book: Book): BookMetadataBI {
const metadata = book.metadata;
return {
bookId: book.id,
title: metadata?.title || '',
subtitle: metadata?.subtitle,
authors: metadata?.authors?.map((author) => author.name) || [],
categories: metadata?.categories?.map((category) => category.name) || [],
publisher: metadata?.publisher || '',
publishedDate: metadata?.publishedDate || '',
isbn10: metadata?.isbn10 || '',
isbn13: metadata?.isbn13 || '',
asin: metadata?.asin || '',
description: metadata?.description,
pageCount: metadata?.pageCount || 0,
language: metadata?.language || '',
googleBookId: metadata?.googleBookId || '',
};
}
}
@@ -0,0 +1,16 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {BookMetadataBI} from '../book/model/book-metadata-for-book-info.model';
@Injectable({
providedIn: 'root'
})
export class BookInfoService {
private subject = new BehaviorSubject<BookMetadataBI | null>(null);
bookMetadata$ = this.subject.asObservable();
emit(bookMetadata: BookMetadataBI) {
this.subject.next(bookMetadata);
}
}
@@ -1,14 +1,8 @@
<form *ngIf="!selectedMetadata" class="flex flex-col w-full h-full pt-4" [formGroup]="form" (ngSubmit)="onSubmit()">
<form *ngIf="!selectedFetchedMetadata" class="flex flex-col w-full h-full pt-4" [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="flex w-full gap-x-4 items-end">
<div class="flex flex-col gap-1 w-1/6">
<label for="provider">Provider</label>
<p-select
id="provider"
class="w-full"
[options]="providers"
formControlName="provider"
placeholder="Select Provider.."
></p-select>
<p-select id="provider" class="w-full" [options]="providers" formControlName="provider" placeholder="Select Provider.."></p-select>
</div>
<div class="flex flex-col gap-1 w-1/6">
@@ -36,7 +30,7 @@
</div>
<div *ngIf="!loading" class="mt-8 flex-1 overflow-y-auto">
<div *ngFor="let book of fetchedMetadata" class="book-item flex flex-col w-full">
<div *ngFor="let book of allFetchedMetadata" class="book-item flex flex-col w-full">
<div class="flex w-full flex-row book-item-content" (click)="onBookClick(book)">
<img [src]="book.thumbnailUrl" alt="Image" class="img-fixed-dimensions pr-2"/>
<div class=" flex flex-col w-full m-2">
@@ -59,6 +53,6 @@
</div>
</form>
<div *ngIf="selectedMetadata" class="h-full flex-auto">
<app-metadata-searcher [book]="book!" [fetchedMetadata]="selectedMetadata" (closeDialog)="closeTheDialog($event)"></app-metadata-searcher>
<div *ngIf="selectedFetchedMetadata" class="h-full flex-auto">
<app-metadata-searcher [fetchedMetadata]="selectedFetchedMetadata" (goBack)="onGoBack($event)"></app-metadata-searcher>
</div>
@@ -8,9 +8,10 @@ import {NgForOf, NgIf} from '@angular/common';
import {Provider} from '../../book/model/provider.model';
import {BookService} from '../../book/service/book.service';
import {FetchMetadataRequest} from '../../book/model/fetch-metadata-request.model';
import {Book, FetchedMetadata} from '../../book/model/book.model';
import {FetchedMetadata} from '../../book/model/book.model';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MetadataSearcherComponent} from '../metadata-searcher/metadata-searcher.component';
import {BookInfoService} from '../book-info.service';
@Component({
selector: 'app-book-match',
@@ -31,18 +32,16 @@ import {MetadataSearcherComponent} from '../metadata-searcher/metadata-searcher.
})
export class BookMatchComponent implements OnInit {
@Input() book!: Book;
@Output() closeDialog = new EventEmitter<unknown>();
form: FormGroup;
providers = Object.values(Provider);
fetchedMetadata: FetchedMetadata[] = [];
selectedMetadata!: FetchedMetadata;
allFetchedMetadata: FetchedMetadata[] = [];
selectedFetchedMetadata!: FetchedMetadata | null;
bookId!: number;
loading: boolean = false;
constructor(private fb: FormBuilder, private bookService: BookService) {
constructor(private fb: FormBuilder, private bookService: BookService, private bookInfoService: BookInfoService) {
this.form = this.fb.group({
provider: [null],
provider: null,
isbn: [''],
title: [''],
author: [''],
@@ -50,12 +49,17 @@ export class BookMatchComponent implements OnInit {
}
ngOnInit() {
const firstAuthor = this.book!.metadata?.authors && this.book!.metadata?.authors.length > 0 ? this.book!.metadata?.authors[0].name : '';
this.form.patchValue({
isbn: this.book!.metadata?.isbn10 || '',
title: this.book!.metadata?.title || '',
author: firstAuthor,
});
this.bookInfoService.bookMetadata$.subscribe((bookMetadata => {
if (bookMetadata) {
this.bookId = bookMetadata.bookId;
this.form.setValue(({
provider: null,
isbn: bookMetadata.isbn10,
title: bookMetadata.title,
author: bookMetadata.authors.length > 0 ? bookMetadata.authors[0] : ''
}))
}
}))
}
get isSearchEnabled(): boolean {
@@ -74,27 +78,24 @@ export class BookMatchComponent implements OnInit {
return;
}
const fetchRequest: FetchMetadataRequest = {
bookId: 1,
bookId: this.bookId,
provider: providerKey,
title: this.form.get('title')?.value,
isbn: this.form.get('isbn')?.value,
author: this.form.get('author')?.value
};
this.loading = true;
this.bookService.fetchMetadataFromSource(fetchRequest.bookId, fetchRequest)
this.bookService.fetchMetadata(fetchRequest.bookId, fetchRequest)
.subscribe({
next: (fetchedMetadata) => {
console.log('Metadata fetched successfully', fetchedMetadata);
this.loading = false;
this.fetchedMetadata = fetchedMetadata.map((book) => ({
this.allFetchedMetadata = fetchedMetadata.map((book) => ({
...book,
thumbnailUrl: book.thumbnailUrl
}));
},
error: (err) => {
this.loading = false;
console.error('Error fetching metadata', err);
}
});
} else {
@@ -107,11 +108,11 @@ export class BookMatchComponent implements OnInit {
return safeText.length > length ? safeText.substring(0, length) + '...' : safeText;
}
onBookClick(book: FetchedMetadata) {
this.selectedMetadata = book;
onBookClick(fetchedMetadata: FetchedMetadata) {
this.selectedFetchedMetadata = fetchedMetadata;
}
closeTheDialog($event: unknown) {
this.closeDialog.emit()
onGoBack($event: boolean) {
this.selectedFetchedMetadata = null;
}
}
@@ -1,91 +1,90 @@
<div class="h-full flex pt-4 flex-col">
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="h-full flex pt-4 flex-col">
<div class="overflow-y-scroll flex-1">
<div class="form-row">
<label for="title" class="label">Title</label>
<div class="input-container">
<input pInputText id="title" [(ngModel)]="toUpdateMetadata.title" class="input"/>
<input pInputText id="title" formControlName="title" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('title')"/>
<input pInputText id="titleFetched" [(ngModel)]="fetchedMetadata.title" class="input"/>
<input pInputText [value]="fetchedMetadata.title" class="input"/>
</div>
</div>
<div class="form-row">
<label for="authors" class="label">Authors</label>
<div class="input-container">
<input pInputText id="authors" [(ngModel)]="currentAuthorsString" class="input"/>
<input pInputText id="authors" formControlName="authors" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('authors')"/>
<input pInputText id="authorsFetched" [(ngModel)]="fetchedAuthorsString" class="input"/>
<input pInputText [value]="fetchedAuthorsString()" class="input"/>
</div>
</div>
<div class="form-row">
<label for="categories" class="label">Categories</label>
<div class="input-container">
<input pInputText id="categories" [(ngModel)]="currentCategoriesString" class="input"/>
<input pInputText id="categories" formControlName="categories" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('categories')"/>
<input pInputText id="categoriesFetched" [(ngModel)]="fetchedCategoriesString" class="input"/>
<input pInputText [value]="fetchedCategoriesString()" class="input"/>
</div>
</div>
<div class="form-row">
<label for="publisher" class="label">Publisher</label>
<div class="input-container">
<input pInputText id="publisher" [(ngModel)]="toUpdateMetadata.publisher" class="input"/>
<input pInputText id="publisher" formControlName="publisher" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publisher')"/>
<input pInputText id="publisherFetched" [(ngModel)]="fetchedMetadata.publisher" class="input"/>
<input pInputText [value]="fetchedMetadata.publisher" class="input"/>
</div>
</div>
<div class="form-row">
<label for="publishedDate" class="label">Published</label>
<div class="input-container">
<input pInputText id="publishedDate" [(ngModel)]="toUpdateMetadata.publishedDate" class="input"/>
<input pInputText id="publishedDate" formControlName="publishedDate" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('publishedDate')"/>
<input pInputText id="publishedDateFetched" [(ngModel)]="fetchedMetadata.publishedDate" class="input"/>
<input pInputText [value]="fetchedMetadata.publishedDate" class="input"/>
</div>
</div>
<div class="form-row">
<label for="isbn10" class="label">ISBN-10</label>
<div class="input-container">
<input pInputText id="isbn10" [(ngModel)]="toUpdateMetadata.isbn10" class="input"/>
<input pInputText id="isbn10" formControlName="isbn10" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('isbn10')"/>
<input pInputText id="isbn10Fetched" [(ngModel)]="fetchedMetadata.isbn10" class="input"/>
<input pInputText [value]="fetchedMetadata.isbn10" class="input"/>
</div>
</div>
<div class="form-row">
<label for="language" class="label">Language</label>
<div class="input-container">
<input pInputText id="language" [(ngModel)]="toUpdateMetadata.language" class="input"/>
<input pInputText id="language" formControlName="language" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('language')"/>
<input pInputText id="languageFetched" [(ngModel)]="fetchedMetadata.language" class="input"/>
<input pInputText [value]="fetchedMetadata.language" class="input"/>
</div>
</div>
<div class="form-row">
<label for="language" class="label">Pages</label>
<label for="pageCount" class="label">Pages</label>
<div class="input-container">
<input pInputText id="pageCount" [(ngModel)]="toUpdateMetadata.pageCount" class="input"/>
<input pInputText id="pageCount" formControlName="pageCount" class="input"/>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('pageCount')"/>
<input pInputText id="pageCountFetched" [(ngModel)]="fetchedMetadata.pageCount" class="input"/>
<input pInputText [value]="fetchedMetadata.pageCount" class="input"/>
</div>
</div>
<div class="form-row">
<label for="description" class="label">Description</label>
<div class="input-container">
<textarea id="description" [(ngModel)]="toUpdateMetadata.description" class="input"></textarea>
<textarea id="description" formControlName="description" class="input"></textarea>
<p-button icon="pi pi-arrow-left" [outlined]="true" class="arrow-button" (click)="copyFetchedToCurrent('description')"/>
<textarea id="descriptionFetched" [(ngModel)]="fetchedMetadata.description" class="input"></textarea>
<textarea [value]="fetchedMetadata.description" class="input"></textarea>
</div>
</div>
<div class="form-row">
<label class="label"></label>
<div class="input-container">
<img *ngIf="!updateThumbnail" [src]="coverImageSrc(book)" alt="Book Thumbnail" class="thumbnail"/>
<img *ngIf="updateThumbnail" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
<img *ngIf="!updateThumbnailUrl" [src]="coverImageSrc(currentBookId)" alt="Book Thumbnail" class="thumbnail"/>
<img *ngIf="updateThumbnailUrl" [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.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
</div>
@@ -94,10 +93,14 @@
<div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider>
<div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="closeDialog.emit()"></p-button>
<p-button label="Save" icon="pi pi-check" severity="primary" [disabled]="loading" (onClick)="saveMetadata()"></p-button>
<div class="flex justify-between">
<p-button label="Back" icon="pi pi-arrow-left" severity="warn" (onClick)="goBackClick()"></p-button>
<div class="flex gap-x-4 justify-end">
<p-button label="Cancel" icon="pi pi-times" severity="secondary"></p-button>
<p-button label="Save" icon="pi pi-check" severity="primary" type="submit" [disabled]="loading"></p-button>
</div>
</div>
</div>
</div>
</form>
@@ -1,12 +1,15 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Book, BookMetadata, FetchedMetadata} from '../../book/model/book.model';
import {FetchedMetadata} from '../../book/model/book.model';
import {BookService} from '../../book/service/book.service';
import {MessageService} from 'primeng/api';
import {Button} from 'primeng/button';
import {FormsModule} from '@angular/forms';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext';
import {NgIf} from '@angular/common';
import {Divider} from 'primeng/divider';
import {BookInfoService} from '../book-info.service';
import {Observable} from 'rxjs';
import {BookMetadataBI} from '../../book/model/book-metadata-for-book-info.model';
@Component({
selector: 'app-metadata-searcher',
@@ -18,76 +21,95 @@ import {Divider} from 'primeng/divider';
FormsModule,
InputText,
NgIf,
Divider
Divider,
ReactiveFormsModule
]
})
export class MetadataSearcherComponent implements OnInit {
@Input() fetchedMetadata!: FetchedMetadata;
@Input() book!: Book;
@Output() closeDialog = new EventEmitter<unknown>();
@Output() goBack = new EventEmitter<boolean>();
toUpdateMetadata!: FetchedMetadata;
bookMetadataForm: FormGroup;
bookMetadata$: Observable<BookMetadataBI | null>;
currentBookId!: number;
loading: boolean = false;
updateThumbnail: boolean = false;
constructor(private bookService: BookService, private messageService: MessageService) {
updateThumbnailUrl: boolean = false;
constructor(private bookService: BookService, private bookInfoService: BookInfoService, private messageService: MessageService) {
this.bookMetadata$ = this.bookInfoService.bookMetadata$;
this.bookMetadataForm = new FormGroup({
title: new FormControl(''),
subtitle: new FormControl(''),
authors: new FormControl(''),
categories: new FormControl(''),
publisher: new FormControl(''),
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
});
}
ngOnInit() {
console.log(this.book)
this.toUpdateMetadata = this.convertBookMetadataToFetchedMetadata(this.book!.metadata!);
ngOnInit(): void {
this.bookMetadata$.subscribe((bookMetadata) => {
if (bookMetadata) {
this.currentBookId = bookMetadata.bookId;
this.bookMetadataForm.setValue({
title: bookMetadata.title,
subtitle: bookMetadata.subtitle,
authors: bookMetadata.authors.join(', '),
categories: bookMetadata.categories.join(', '),
publisher: bookMetadata.publisher,
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin,
description: bookMetadata.description,
pageCount: bookMetadata.pageCount == 0 ? null : bookMetadata.pageCount,
language: bookMetadata.language
});
}
});
}
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).join(', ') : '';
}
set currentAuthorsString(value: string) {
this.toUpdateMetadata.authors = value.split(',');
}
get fetchedAuthorsString(): string {
fetchedAuthorsString(): string {
return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author).join(', ') : '';
}
set fetchedAuthorsString(value: string) {
this.fetchedMetadata.authors = value.split(',');
}
get currentCategoriesString(): string {
return this.toUpdateMetadata.categories ? this.toUpdateMetadata.categories.map(category => category).join(', ') : '';
}
set currentCategoriesString(value: string) {
this.toUpdateMetadata.categories = value.split(',');
}
get fetchedCategoriesString(): string {
fetchedCategoriesString(): string {
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : '';
}
set fetchedCategoriesString(value: string) {
this.fetchedMetadata.categories = value.split(',');
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
coverImageSrc(book: Book): string {
return this.bookService.getBookCoverUrl(book.id);
}
onSave(): void {
const updatedBookMetadata: BookMetadataBI = {
bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value || this.fetchedMetadata.title,
subtitle: this.bookMetadataForm.get('subtitle')?.value || this.fetchedMetadata.subtitle,
authors: this.bookMetadataForm.get('authors')?.value ? this.bookMetadataForm.get('authors')?.value.split(',').map((author: string) => author.trim()) : this.fetchedMetadata.authors,
categories: this.bookMetadataForm.get('categories')?.value ? this.bookMetadataForm.get('categories')?.value.split(',').map((category: string) => category.trim()) : this.fetchedMetadata.categories,
publisher: this.bookMetadataForm.get('publisher')?.value || this.fetchedMetadata.publisher,
publishedDate: this.bookMetadataForm.get('publishedDate')?.value || this.fetchedMetadata.publishedDate,
isbn10: this.bookMetadataForm.get('isbn10')?.value || this.fetchedMetadata.isbn10,
isbn13: this.bookMetadataForm.get('isbn13')?.value || this.fetchedMetadata.isbn13,
asin: this.bookMetadataForm.get('asin')?.value || this.fetchedMetadata.asin,
description: this.bookMetadataForm.get('description')?.value || this.fetchedMetadata.description,
pageCount: this.bookMetadataForm.get('pageCount')?.value || this.fetchedMetadata.pageCount,
language: this.bookMetadataForm.get('language')?.value || this.fetchedMetadata.language,
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : undefined
};
saveMetadata() {
this.loading = true;
this.updateFields();
this.bookService.updateMetadata(this.book.id, this.toUpdateMetadata).subscribe({
this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.bookInfoService.emit(updatedBookMetadata);
this.loading = false;
},
error: (error) => {
@@ -97,75 +119,18 @@ export class MetadataSearcherComponent implements OnInit {
});
}
updateFields() {
if (!this.toUpdateMetadata.title && this.fetchedMetadata.title) {
this.toUpdateMetadata.title = this.fetchedMetadata.title;
}
if (!this.toUpdateMetadata.subtitle && this.fetchedMetadata.subtitle) {
this.toUpdateMetadata.subtitle = this.fetchedMetadata.subtitle;
}
if (!this.toUpdateMetadata.publisher && this.fetchedMetadata.publisher) {
this.toUpdateMetadata.publisher = this.fetchedMetadata.publisher;
}
if (!this.toUpdateMetadata.publishedDate && this.fetchedMetadata.publishedDate) {
this.toUpdateMetadata.publishedDate = this.fetchedMetadata.publishedDate;
}
if (!this.toUpdateMetadata.description && this.fetchedMetadata.description) {
this.toUpdateMetadata.description = this.fetchedMetadata.description;
}
if (!this.toUpdateMetadata.isbn10 && this.fetchedMetadata.isbn10) {
this.toUpdateMetadata.isbn10 = this.fetchedMetadata.isbn10;
}
if (!this.toUpdateMetadata.language && this.fetchedMetadata.language) {
this.toUpdateMetadata.language = this.fetchedMetadata.language;
}
if (!this.toUpdateMetadata.pageCount && this.fetchedMetadata.pageCount) {
this.toUpdateMetadata.pageCount = this.fetchedMetadata.pageCount;
}
if (!this.toUpdateMetadata.authors || this.toUpdateMetadata.authors.length === 0) {
this.toUpdateMetadata.authors = this.fetchedMetadata.authors;
}
if (!this.toUpdateMetadata.categories || this.toUpdateMetadata.categories.length === 0) {
this.toUpdateMetadata.categories = this.fetchedMetadata.categories;
}
if (this.updateThumbnail) {
this.toUpdateMetadata.thumbnailUrl = this.fetchedMetadata.thumbnailUrl;
}
}
shouldUpdateThumbnail() {
this.updateThumbnail = true;
this.updateThumbnailUrl = 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),
};
copyFetchedToCurrent(field: string): void {
const value = this.fetchedMetadata[field];
if (value) {
this.bookMetadataForm.get(field)?.setValue(value);
}
}
goBackClick() {
this.goBack.emit(true);
}
}
@@ -85,7 +85,6 @@ export class BookCardComponent implements OnInit {
openBookDetailsDialog(bookId: number): void {
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
next: (book) => {
console.log(book)
this.dialogService.open(BookInfoTabsComponent, {
header: 'Open book details',
modal: true,
@@ -36,14 +36,6 @@
</div>
</li>
<p-divider layout="vertical" />
<li>
<a class="topbar-item">
<i class="pi pi-book text-surface-700 dark:text-surface-100" (click)="openBookDetailsDialog()"
pTooltip="Book Details" tooltipPosition="top"></i>
</a>
</li>
<li>
<a class="topbar-item">
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
@@ -77,22 +77,6 @@ export class AppTopBarComponent implements OnDestroy {
this.showEvents = !this.showEvents;
}
openBookDetailsDialog(): void {
this.ref = this.dialogService.open(BookInfoTabsComponent, {
header: 'Open book details',
modal: true,
closable: true,
width: '1200px',
height: '835px',
showHeader: false,
closeOnEscape: true,
data: {
bookId: 1
}
});
}
openLibraryCreatorDialog(): void {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library',
@@ -1,4 +1,5 @@
export interface BookMetadataForm {
export interface BookMetadataBI {
bookId: number;
title: string;
subtitle?: string;
authors: Array<string>;
@@ -7,9 +8,10 @@ export interface BookMetadataForm {
publishedDate: string;
isbn10: string;
isbn13: string;
asin: string;
asin?: string;
description?: string;
pageCount: number;
pageCount?: number | null;
language: string;
googleBookId: string;
googleBookId?: string;
thumbnailUrl?: string;
}
@@ -45,6 +45,7 @@ export interface FetchedMetadata {
reviewCount: number | null;
authors: string[];
categories: string[];
asin: string | null;
[key: string]: any;
}
@@ -4,8 +4,8 @@ import {HttpClient} from '@angular/common/http';
import {catchError, map, switchMap, tap} from 'rxjs/operators';
import {Book, BookMetadata, BookSetting, FetchedMetadata} from '../model/book.model';
import {BookState} from '../model/state/book-state.model';
import {BookMetadataForm} from '../model/book-metadata-form';
import {FetchMetadataRequest} from '../model/fetch-metadata-request.model';
import {BookMetadataBI} from '../model/book-metadata-for-book-info.model';
@Injectable({
providedIn: 'root',
@@ -197,16 +197,12 @@ export class BookService {
});
}
fetchMetadataFromSource(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> {
fetchMetadata(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> {
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}/metadata`, request);
}
updateMetadata(bookId: number, updateMedata: FetchedMetadata): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/source/AMAZON/metadata`, updateMedata);
}
updateMetadataV2(bookId: number, bookMetadataForm: BookMetadataForm): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadataForm);
updateMetadata(bookId: number, bookMetadata: BookMetadataBI): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/metadata`, bookMetadata);
}
}
-1
View File
@@ -1,4 +1,3 @@
// loading.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';