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,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);
}
}