diff --git a/booklore-ui/src/app/app.module.ts b/booklore-ui/src/app/app.module.ts index ae65a8992..557bb6878 100644 --- a/booklore-ui/src/app/app.module.ts +++ b/booklore-ui/src/app/app.module.ts @@ -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: [ diff --git a/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.html b/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.html index 792ede23f..8880815d9 100644 --- a/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.html +++ b/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.html @@ -1,88 +1,76 @@ -
-
+
+
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
-
- +
- - + +
diff --git a/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.ts b/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.ts index 0db7448a3..cb4b0a884 100644 --- a/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.ts +++ b/booklore-ui/src/app/book-info-tabs/book-details/book-details.component.ts @@ -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(); - @Output() closeDialog = new EventEmitter(); + bookMetadata$: Observable; + 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); } } diff --git a/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.html b/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.html index 70a8a00cf..12a40c6dd 100644 --- a/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.html +++ b/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.html @@ -6,10 +6,10 @@ - + - +

I too work!!

diff --git a/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.ts b/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.ts index 3f1f4ea11..2fe131b4f 100644 --- a/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.ts +++ b/booklore-ui/src/app/book-info-tabs/book-info-tabs.component.ts @@ -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 || '', + }; } } diff --git a/booklore-ui/src/app/book-info-tabs/book-info.service.ts b/booklore-ui/src/app/book-info-tabs/book-info.service.ts new file mode 100644 index 000000000..e44b4fc50 --- /dev/null +++ b/booklore-ui/src/app/book-info-tabs/book-info.service.ts @@ -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(null); + bookMetadata$ = this.subject.asObservable(); + + emit(bookMetadata: BookMetadataBI) { + this.subject.next(bookMetadata); + } +} diff --git a/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.html b/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.html index 9f48fd745..0734f03f8 100644 --- a/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.html +++ b/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.html @@ -1,14 +1,8 @@ -
+
- +
@@ -36,7 +30,7 @@
-
+
Image
@@ -59,6 +53,6 @@
-
- +
+
diff --git a/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.ts b/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.ts index d2de2e491..78563cb12 100644 --- a/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.ts +++ b/booklore-ui/src/app/book-info-tabs/book-match/book-match.component.ts @@ -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(); - 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; } } diff --git a/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.html b/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.html index 96d8dd0d1..c03b029b5 100644 --- a/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.html +++ b/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.html @@ -1,91 +1,90 @@ -
+
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
-
- +
- + - +
- + - +
- Book Thumbnail - Fetched Thumbnail + Book Thumbnail + Fetched Thumbnail Fetched Thumbnail
@@ -94,10 +93,14 @@
-
- - +
+ +
+ + +
-
+ + diff --git a/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.ts b/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.ts index 009b33be5..1323474aa 100644 --- a/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.ts +++ b/booklore-ui/src/app/book-info-tabs/metadata-searcher/metadata-searcher.component.ts @@ -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(); + @Output() goBack = new EventEmitter(); - toUpdateMetadata!: FetchedMetadata; + bookMetadataForm: FormGroup; + bookMetadata$: Observable; + 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); } } diff --git a/booklore-ui/src/app/book/component/book-card/book-card.component.ts b/booklore-ui/src/app/book/component/book-card/book-card.component.ts index eb9a74108..2140f28d7 100644 --- a/booklore-ui/src/app/book/component/book-card/book-card.component.ts +++ b/booklore-ui/src/app/book/component/book-card/book-card.component.ts @@ -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, diff --git a/booklore-ui/src/app/book/component/layout/app.topbar.component.html b/booklore-ui/src/app/book/component/layout/app.topbar.component.html index 79a3aad65..151a6e684 100644 --- a/booklore-ui/src/app/book/component/layout/app.topbar.component.html +++ b/booklore-ui/src/app/book/component/layout/app.topbar.component.html @@ -36,14 +36,6 @@
- -
  • - - - -
  • -
  • ; @@ -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; } diff --git a/booklore-ui/src/app/book/model/book.model.ts b/booklore-ui/src/app/book/model/book.model.ts index d5741dc4a..ccfa926df 100644 --- a/booklore-ui/src/app/book/model/book.model.ts +++ b/booklore-ui/src/app/book/model/book.model.ts @@ -45,6 +45,7 @@ export interface FetchedMetadata { reviewCount: number | null; authors: string[]; categories: string[]; + asin: string | null; [key: string]: any; } diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts index e8cb35117..8e5e60f7d 100644 --- a/booklore-ui/src/app/book/service/book.service.ts +++ b/booklore-ui/src/app/book/service/book.service.ts @@ -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 { + fetchMetadata(bookId: number, request: FetchMetadataRequest): Observable { return this.http.post(`${this.url}/${bookId}/metadata`, request); } - updateMetadata(bookId: number, updateMedata: FetchedMetadata): Observable { - return this.http.put(`${this.url}/${bookId}/source/AMAZON/metadata`, updateMedata); - } - - updateMetadataV2(bookId: number, bookMetadataForm: BookMetadataForm): Observable { - return this.http.put(`${this.url}/${bookId}/metadata`, bookMetadataForm); + updateMetadata(bookId: number, bookMetadata: BookMetadataBI): Observable { + return this.http.put(`${this.url}/${bookId}/metadata`, bookMetadata); } } diff --git a/booklore-ui/src/app/loading.service.ts b/booklore-ui/src/app/loading.service.ts index 62bad77f6..ec0d5e21b 100644 --- a/booklore-ui/src/app/loading.service.ts +++ b/booklore-ui/src/app/loading.service.ts @@ -1,4 +1,3 @@ -// loading.service.ts import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs';