Add rating and review count. Remove asin.

This commit is contained in:
aditya.chandel
2025-01-04 14:29:42 -07:00
parent 525a1e8753
commit 82b7cca0a5
7 changed files with 139 additions and 48 deletions
@@ -54,11 +54,15 @@
</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" formControlName="asin"/>
<div class="flex flex-col w-1/3">
<label for="rating">Rating</label>
<input pInputText id="rating" class="w-full" formControlName="rating"/>
</div>
<div class="flex flex-col w-1/2">
<div class="flex flex-col w-1/3">
<label for="reviewCount">Review Count</label>
<input pInputText id="reviewCount" class="w-full" formControlName="reviewCount"/>
</div>
<div class="flex flex-col w-1/3">
<label for="page-count">Page Count</label>
<input pInputText id="page-count" class="w-full" formControlName="pageCount"/>
</div>
@@ -46,10 +46,11 @@ export class BookDetailsComponent implements OnInit {
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
});
}
@@ -66,10 +67,11 @@ export class BookDetailsComponent implements OnInit {
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin ? bookMetadata.asin : '',
description: bookMetadata.description,
pageCount: bookMetadata.pageCount,
language: bookMetadata.language
pageCount: bookMetadata.pageCount == 0 ? null : bookMetadata.pageCount,
language: bookMetadata.language,
rating: bookMetadata.rating,
reviewCount: bookMetadata.reviewCount
});
}
});
@@ -86,9 +88,10 @@ export class BookDetailsComponent implements OnInit {
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,
rating: this.bookMetadataForm.get('rating')?.value,
reviewCount: this.bookMetadataForm.get('reviewCount')?.value,
language: this.bookMetadataForm.get('language')?.value
};
this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
@@ -54,9 +54,10 @@ export class BookInfoTabsComponent implements OnInit {
publishedDate: metadata?.publishedDate || '',
isbn10: metadata?.isbn10 || '',
isbn13: metadata?.isbn13 || '',
asin: metadata?.asin || '',
description: metadata?.description,
pageCount: metadata?.pageCount || 0,
pageCount: metadata?.pageCount || null,
reviewCount: metadata?.reviewCount || null,
rating: metadata?.rating || null,
language: metadata?.language || '',
googleBookId: metadata?.googleBookId || '',
};
@@ -1,5 +1,18 @@
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="h-full flex pt-4 flex-col">
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="h-full flex pt-1 flex-col">
<div class="overflow-y-scroll flex-1">
<div class="flex justify-center items-center" [ngStyle]="{'padding-bottom': '0.75rem', 'padding-left': '4.95rem'}">
<p class="ml-3">Current Metadata</p>
<p-button
severity="info"
icon='pi pi-angle-double-left'
[ngStyle]="{'padding-left': '2rem', 'padding-right': '2rem'}"
[outlined]="true"
[pTooltip]="'Copy all missing metadata'"
(onClick)="copyMissing()"></p-button>
<p>Fetched Metadata</p>
</div>
<div class="form-row">
<label for="title" class="label">Title</label>
<div class="input-container">
@@ -98,20 +111,6 @@
</div>
</div>
<div class="form-row">
<label for="pageCount" class="label">Pages</label>
<div class="input-container">
<input pInputText id="pageCount" formControlName="pageCount" class="input"/>
<p-button
[icon]="isValueSaved('pageCount') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('pageCount'), 'yellow-outlined-button': isValueCopied('pageCount')}"
class="arrow-button"
(click)="copyFetchedToCurrent('pageCount')"/>
<input pInputText [value]="fetchedMetadata.pageCount" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="description" class="label">Description</label>
<div class="input-container">
@@ -140,6 +139,63 @@
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
</div>
</div>
<div class="form-row">
<label for="isbn13" class="label">ISBN-13</label>
<div class="input-container">
<input pInputText id="isbn13" formControlName="isbn13" class="input"/>
<p-button
[icon]="isValueSaved('isbn13') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('isbn13'), 'yellow-outlined-button': isValueCopied('isbn13')}"
class="arrow-button"
(click)="copyFetchedToCurrent('isbn13')"/>
<input pInputText [value]="fetchedMetadata.isbn13" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="rating" class="label">Rating</label>
<div class="input-container">
<input pInputText id="rating" formControlName="rating" class="input"/>
<p-button
[icon]="isValueSaved('pageCount') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('rating'), 'yellow-outlined-button': isValueCopied('rating')}"
class="arrow-button"
(click)="copyFetchedToCurrent('rating')"/>
<input pInputText [value]="fetchedMetadata.rating" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="reviewCount" class="label">Rating</label>
<div class="input-container">
<input pInputText id="reviewCount" formControlName="reviewCount" class="input"/>
<p-button
[icon]="isValueSaved('reviewCount') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('reviewCount'), 'yellow-outlined-button': isValueCopied('reviewCount')}"
class="arrow-button"
(click)="copyFetchedToCurrent('reviewCount')"/>
<input pInputText [value]="fetchedMetadata.reviewCount" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="pageCount" class="label">Pages</label>
<div class="input-container">
<input pInputText id="pageCount" formControlName="pageCount" class="input"/>
<p-button
[icon]="isValueSaved('pageCount') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('pageCount'), 'yellow-outlined-button': isValueCopied('pageCount')}"
class="arrow-button"
(click)="copyFetchedToCurrent('pageCount')"/>
<input pInputText [value]="fetchedMetadata.pageCount" class="input" readonly/>
</div>
</div>
</div>
<div class="flex flex-col gap-x-4 mt-auto">
@@ -5,11 +5,12 @@ import {MessageService} from 'primeng/api';
import {Button} from 'primeng/button';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext';
import {NgClass, NgIf} from '@angular/common';
import {NgClass, NgIf, NgStyle} 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';
import {Tooltip} from 'primeng/tooltip';
@Component({
selector: 'app-metadata-searcher',
@@ -23,7 +24,9 @@ import {BookMetadataBI} from '../../book/model/book-metadata-for-book-info.model
NgIf,
Divider,
ReactiveFormsModule,
NgClass
NgClass,
NgStyle,
Tooltip
]
})
export class MetadataSearcherComponent implements OnInit {
@@ -50,10 +53,11 @@ export class MetadataSearcherComponent implements OnInit {
publishedDate: new FormControl(''),
isbn10: new FormControl(''),
isbn13: new FormControl(''),
asin: new FormControl(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
});
}
@@ -70,10 +74,11 @@ export class MetadataSearcherComponent implements OnInit {
publishedDate: bookMetadata.publishedDate,
isbn10: bookMetadata.isbn10,
isbn13: bookMetadata.isbn13,
asin: bookMetadata.asin ? bookMetadata.asin : null,
description: bookMetadata.description,
pageCount: bookMetadata.pageCount == 0 ? null : bookMetadata.pageCount,
language: bookMetadata.language
language: bookMetadata.language,
rating: bookMetadata.rating,
reviewCount: bookMetadata.reviewCount
});
}
});
@@ -94,22 +99,23 @@ export class MetadataSearcherComponent implements OnInit {
onSave(): void {
const updatedBookMetadata: BookMetadataBI = {
bookId: this.currentBookId,
title: this.getValueOrCopied('title'),
subtitle: this.getValueOrCopied('subtitle'),
authors: this.getArrayFromFormField('authors', this.fetchedMetadata.authors),
categories: this.getArrayFromFormField('categories', this.fetchedMetadata.categories),
publisher: this.getValueOrCopied('publisher'),
publishedDate: this.getValueOrCopied('publishedDate'),
isbn10: this.getValueOrCopied('isbn10'),
isbn13: this.getValueOrCopied('isbn13'),
asin: this.getValueOrCopied('asin'),
description: this.getValueOrCopied('description'),
pageCount: this.getPageCountOrCopied(),
language: this.getValueOrCopied('language'),
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : undefined
title: this.bookMetadataForm.get('title')?.value || this.copiedFields['title'] ? this.getValueOrCopied('title') : '',
subtitle: this.bookMetadataForm.get('subtitle')?.value || this.copiedFields['subtitle'] ? this.getValueOrCopied('subtitle') : '',
authors: this.bookMetadataForm.get('authors')?.value || this.copiedFields['authors'] ? this.getArrayFromFormField('authors', this.fetchedMetadata.authors) : [],
categories: this.bookMetadataForm.get('categories')?.value || this.copiedFields['categories'] ? this.getArrayFromFormField('categories', this.fetchedMetadata.categories) : [],
publisher: this.bookMetadataForm.get('publisher')?.value || this.copiedFields['publisher'] ? this.getValueOrCopied('publisher') : '',
publishedDate: this.bookMetadataForm.get('publishedDate')?.value || this.copiedFields['publishedDate'] ? this.getValueOrCopied('publishedDate') : '',
isbn10: this.bookMetadataForm.get('isbn10')?.value || this.copiedFields['isbn10'] ? this.getValueOrCopied('isbn10') : '',
isbn13: this.bookMetadataForm.get('isbn13')?.value || this.copiedFields['isbn13'] ? this.getValueOrCopied('isbn13') : '',
description: this.bookMetadataForm.get('description')?.value || this.copiedFields['description'] ? this.getValueOrCopied('description') : '',
pageCount: this.bookMetadataForm.get('pageCount')?.value || this.copiedFields['pageCount'] ? this.getPageCountOrCopied() : null,
language: this.bookMetadataForm.get('language')?.value || this.copiedFields['language'] ? this.getValueOrCopied('language') : '',
rating: this.bookMetadataForm.get('rating')?.value || this.copiedFields['rating'] ? this.getNumberOrCopied('rating') : null,
reviewCount: this.bookMetadataForm.get('reviewCount')?.value || this.copiedFields['reviewCount'] ? this.getNumberOrCopied('reviewCount') : null,
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '',
};
this.bookService.updateMetadata(updatedBookMetadata.bookId, updatedBookMetadata).subscribe({
this.bookService.updateMetadata(this.currentBookId, updatedBookMetadata).subscribe({
next: () => {
Object.keys(this.copiedFields).forEach((field) => {
if (this.copiedFields[field]) {
@@ -128,6 +134,24 @@ export class MetadataSearcherComponent implements OnInit {
});
}
copyMissing() {
Object.keys(this.fetchedMetadata).forEach((field) => {
if (!this.bookMetadataForm.get(field)?.value && this.fetchedMetadata[field]) {
this.copyFetchedToCurrent(field);
}
});
}
private getNumberOrCopied(field: string): number | null {
const formValue = this.bookMetadataForm.get(field)?.value;
if (formValue === '' || formValue === null || isNaN(formValue)) {
this.copiedFields[field] = true;
return this.fetchedMetadata[field] || null;
}
return Number(formValue);
}
private getPageCountOrCopied(): number | null {
const formValue = this.bookMetadataForm.get('pageCount')?.value;
if (formValue === '' || formValue === null || isNaN(formValue)) {
@@ -165,6 +189,7 @@ export class MetadataSearcherComponent implements OnInit {
const value = this.fetchedMetadata[field];
if (value) {
this.bookMetadataForm.get(field)?.setValue(value);
this.copiedFields[field] = true;
this.highlightCopiedInput(field);
}
}
@@ -188,4 +213,5 @@ export class MetadataSearcherComponent implements OnInit {
closeDialog() {
this.bookInfoService.closeDialog(true);
}
}
@@ -8,7 +8,8 @@ export interface BookMetadataBI {
publishedDate: string;
isbn10: string;
isbn13: string;
asin?: string;
rating?: number | null;
reviewCount?: number | null;
description?: string;
pageCount?: number | null;
language: string;
+2 -2
View File
@@ -19,9 +19,10 @@ export interface BookMetadata {
publishedDate: string;
isbn10: string;
isbn13: string;
asin: string;
description?: string;
pageCount: number;
rating: number;
reviewCount: number;
language: string;
googleBookId: string;
[key: string]: any;
@@ -45,7 +46,6 @@ export interface FetchedMetadata {
reviewCount: number | null;
authors: string[];
categories: string[];
asin: string | null;
[key: string]: any;
}