WIP: Arrange UI files for better structuring

This commit is contained in:
aditya.chandel
2025-01-12 13:22:14 -07:00
parent 7728cebcf9
commit 7df0052036
92 changed files with 115 additions and 114 deletions
@@ -0,0 +1,224 @@
<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="Select all missing field" tooltipPosition="bottom"
(onClick)="copyMissing()"></p-button>
<p>Fetched Metadata</p>
</div>
<div class="form-row">
<label for="title" class="label">Title</label>
<div class="input-container">
<input pInputText id="title" formControlName="title" class="input"/>
<p-button
[icon]="isValueSaved('title') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('title'), 'yellow-outlined-button': isValueCopied('title')}"
class="arrow-button"
(click)="copyFetchedToCurrent('title')"/>
<input pInputText [value]="fetchedMetadata.title" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="authors" class="label">Authors</label>
<div class="input-container">
<input pInputText id="authors" formControlName="authors" class="input"/>
<p-button
[icon]="isValueSaved('authors') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('authors'), 'yellow-outlined-button': isValueCopied('authors')}"
class="arrow-button"
(click)="copyFetchedToCurrent('authors')"/>
<input pInputText [value]="fetchedAuthorsString()" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="categories" class="label">Categories</label>
<div class="input-container">
<input pInputText id="categories" formControlName="categories" class="input"/>
<p-button
[icon]="isValueSaved('categories') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('categories'), 'yellow-outlined-button': isValueCopied('categories')}"
class="arrow-button"
(click)="copyFetchedToCurrent('categories')"/>
<input pInputText [value]="fetchedCategoriesString()" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="publisher" class="label">Publisher</label>
<div class="input-container">
<input pInputText id="publisher" formControlName="publisher" class="input"/>
<p-button
[icon]="isValueSaved('publisher') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('publisher'), 'yellow-outlined-button': isValueCopied('publisher')}"
class="arrow-button"
(click)="copyFetchedToCurrent('publisher')"/>
<input pInputText [value]="fetchedMetadata.publisher" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="publishedDate" class="label">Published</label>
<div class="input-container">
<input pInputText id="publishedDate" formControlName="publishedDate" class="input"/>
<p-button
[icon]="isValueSaved('publishedDate') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('publishedDate'), 'yellow-outlined-button': isValueCopied('publishedDate')}"
class="arrow-button"
(click)="copyFetchedToCurrent('publishedDate')"/>
<input pInputText [value]="fetchedMetadata.publishedDate" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="isbn10" class="label">ISBN-10</label>
<div class="input-container">
<input pInputText id="isbn10" formControlName="isbn10" class="input"/>
<p-button
[icon]="isValueSaved('isbn10') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('isbn10'), 'yellow-outlined-button': isValueCopied('isbn10')}"
class="arrow-button"
(click)="copyFetchedToCurrent('isbn10')"/>
<input pInputText [value]="fetchedMetadata.isbn10" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="language" class="label">Language</label>
<div class="input-container">
<input pInputText id="language" formControlName="language" class="input"/>
<p-button
[icon]="isValueSaved('language') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('language'), 'yellow-outlined-button': isValueCopied('language')}"
class="arrow-button"
(click)="copyFetchedToCurrent('language')"/>
<input pInputText [value]="fetchedMetadata.language" class="input" readonly/>
</div>
</div>
<div class="form-row">
<label for="description" class="label">Description</label>
<div class="input-container">
<textarea id="description" formControlName="description" class="input"></textarea>
<p-button
[icon]="isValueSaved('description') ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': isValueSaved('description'), 'yellow-outlined-button': isValueCopied('description')}"
class="arrow-button"
(click)="copyFetchedToCurrent('description')"/>
<textarea [value]="fetchedMetadata.description" class="input" readonly></textarea>
</div>
</div>
<div class="form-row">
<label class="label"></label>
<div class="input-container">
<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]="thumbnailSaved ? 'pi pi-check' : 'pi pi-arrow-left'"
[outlined]="true"
[ngClass]="{'green-outlined-button': thumbnailSaved, 'yellow-outlined-button': updateThumbnailUrl}"
class="arrow-button"
(click)="shouldUpdateThumbnail()"/>
<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 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="Select all missing field" tooltipPosition="top"
(onClick)="copyMissing()"></p-button>
<p>Fetched Metadata</p>
</div>
</div>
<div class="flex flex-col gap-x-4 mt-auto">
<p-divider></p-divider>
<div class="flex justify-between">
<p-button label="Back" icon="pi pi-arrow-left" severity="info" (onClick)="goBackClick()"></p-button>
<div class="flex gap-x-4 justify-end">
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
<p-button label="Save" icon="pi pi-check" severity="primary" type="submit"></p-button>
</div>
</div>
</div>
</form>
@@ -0,0 +1,50 @@
.form-row {
display: flex;
align-items: center;
margin-bottom: 0.75rem;
width: 100%;
justify-content: flex-start;
}
.label {
width: 6rem;
text-align: left;
}
.input-container {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}
.input {
width: 50%;
padding: 0.5rem;
border-radius: 0.25rem;
margin: 0 0.5rem;
}
.thumbnail {
width: 15.625rem;
height: 21.875rem;
border-radius: 0.5rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
margin-left: 2.5rem;
margin-right: 2.5rem;
}
.arrow-button {
padding-left: 1rem;
padding-right: 1rem;
}
.yellow-outlined-button {
--p-button-outlined-primary-border-color: yellow;
--p-button-outlined-primary-color: yellow;
}
.green-outlined-button {
--p-button-outlined-primary-border-color: limegreen;
--p-button-outlined-primary-color: limegreen;
}
@@ -0,0 +1,221 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {BookMetadata, FetchedMetadata} from '../../../book/model/book.model';
import {BookService} from '../../../book/service/book.service';
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, NgStyle} from '@angular/common';
import {Divider} from 'primeng/divider';
import {BookMetadataCenterService} from '../book-metadata-center.service';
import {Observable} from 'rxjs';
import {BookMetadataBI} from '../../../book/model/book-metadata-for-book-info.model';
import {Tooltip} from 'primeng/tooltip';
import {MetadataService} from '../../../book/service/metadata.service';
@Component({
selector: 'app-metadata-picker',
standalone: true,
templateUrl: './metadata-picker.component.html',
styleUrls: ['./metadata-picker.component.scss'],
imports: [
Button,
FormsModule,
InputText,
NgIf,
Divider,
ReactiveFormsModule,
NgClass,
NgStyle,
Tooltip
]
})
export class MetadataPickerComponent implements OnInit {
@Input() fetchedMetadata!: FetchedMetadata;
@Output() goBack = new EventEmitter<boolean>();
bookMetadataForm: FormGroup;
bookMetadata$: Observable<BookMetadataBI | null>;
currentBookId!: number;
updateThumbnailUrl: boolean = false;
thumbnailSaved: boolean = false;
copiedFields: { [key: string]: boolean } = {};
savedFields: { [key: string]: boolean } = {};
constructor(private bookService: BookService,
private bookInfoService: BookMetadataCenterService,
private messageService: MessageService,
private metadataService: MetadataService) {
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(''),
description: new FormControl(''),
pageCount: new FormControl(''),
language: new FormControl(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
});
}
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,
description: bookMetadata.description,
pageCount: bookMetadata.pageCount == 0 ? null : bookMetadata.pageCount,
language: bookMetadata.language,
rating: bookMetadata.rating,
reviewCount: bookMetadata.reviewCount
});
}
});
}
fetchedAuthorsString(): string {
return this.fetchedMetadata.authors ? this.fetchedMetadata.authors.map(author => author).join(', ') : '';
}
fetchedCategoriesString(): string {
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : '';
}
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
onSave(): void {
const updatedBookMetadata: BookMetadataBI = {
bookId: this.currentBookId,
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.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
next: (bookMetadata) => {
Object.keys(this.copiedFields).forEach((field) => {
if (this.copiedFields[field]) {
this.savedFields[field] = true;
}
});
if (this.updateThumbnailUrl) {
this.thumbnailSaved = true;
}
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'});
}
});
}
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)) {
this.copiedFields['pageCount'] = true;
return this.fetchedMetadata.pageCount || null;
}
return Number(formValue);
}
private getValueOrCopied(field: string): string {
const formValue = this.bookMetadataForm.get(field)?.value;
if (!formValue || formValue === '') {
this.copiedFields[field] = true;
return this.fetchedMetadata[field] || '';
}
return formValue;
}
getArrayFromFormField(field: string, fallbackValue: any): any[] {
const fieldValue = this.bookMetadataForm.get(field)?.value;
if (!fieldValue) {
return fallbackValue ? (Array.isArray(fallbackValue) ? fallbackValue : [fallbackValue]) : [];
}
if (typeof fieldValue === 'string') {
return fieldValue.split(',').map(item => item.trim());
}
return Array.isArray(fieldValue) ? fieldValue : [];
}
shouldUpdateThumbnail() {
this.updateThumbnailUrl = true;
}
copyFetchedToCurrent(field: string): void {
const value = this.fetchedMetadata[field];
if (value) {
this.bookMetadataForm.get(field)?.setValue(value);
this.copiedFields[field] = true;
this.highlightCopiedInput(field);
}
}
highlightCopiedInput(field: string): void {
this.copiedFields = {...this.copiedFields, [field]: true};
}
isValueCopied(field: string): boolean {
return this.copiedFields[field];
}
isValueSaved(field: string): boolean {
return this.savedFields[field];
}
goBackClick() {
this.goBack.emit(true);
}
closeDialog() {
this.bookInfoService.closeDialog(true);
}
}