Implement new book details dialog/tab
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<div class="container pt-6 px-2 flex flex-col h-full">
|
||||
<div class="space-y-4 flex-grow">
|
||||
<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"/>
|
||||
</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"/>
|
||||
</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"/>
|
||||
</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"/>
|
||||
</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>
|
||||
</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="https://m.media-amazon.com/images/I/61GzazUmKyL._SL1462_.jpg" alt="Image" width="250"/>
|
||||
</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()"
|
||||
/>
|
||||
</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"/>
|
||||
</div>
|
||||
<div class="flex flex-col w-1/2">
|
||||
<label for="language">Language</label>
|
||||
<input pInputText id="language" class="w-full" [(ngModel)]="bookForm.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"/>
|
||||
</div>
|
||||
<div class="flex flex-col w-1/2">
|
||||
<label for="isbn13">ISBN13</label>
|
||||
<input pInputText id="isbn13" class="w-full" [(ngModel)]="bookForm.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"/>
|
||||
</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"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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" severity="secondary"/>
|
||||
<p-button label="Save" (onClick)="onSave()"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } 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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-details',
|
||||
standalone: true,
|
||||
templateUrl: './book-details.component.html',
|
||||
imports: [
|
||||
InputText,
|
||||
Textarea,
|
||||
Image,
|
||||
Button,
|
||||
Divider,
|
||||
FormsModule
|
||||
],
|
||||
styleUrl: './book-details.component.scss'
|
||||
})
|
||||
export class BookDetailsComponent implements OnChanges {
|
||||
|
||||
@Input() bookForm!: BookMetadataForm;
|
||||
@Output() save = new EventEmitter<BookMetadataForm>();
|
||||
|
||||
authorsInput: string = '';
|
||||
categoriesInput: string = '';
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (this.bookForm.authors) {
|
||||
this.authorsInput = this.bookForm.authors.join(', ');
|
||||
}
|
||||
if (this.bookForm.categories) {
|
||||
this.categoriesInput = this.bookForm.categories.join(', ');
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<p-tabs value="0">
|
||||
<p-tablist>
|
||||
<p-tab value="0">Book Details</p-tab>
|
||||
<p-tab value="1">Match Book</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel value="0">
|
||||
<app-book-details [bookForm]="bookForm" (save)="saveBook($event)"></app-book-details>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {BookDetailsComponent} from './book-details/book-details.component';
|
||||
import {DynamicDialogConfig} 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';
|
||||
|
||||
@Component({
|
||||
selector: 'book-info-tabs',
|
||||
standalone: true,
|
||||
templateUrl: './book-info-tabs.component.html',
|
||||
styleUrl: './book-info-tabs.component.scss',
|
||||
imports: [
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
BookDetailsComponent,
|
||||
TabPanel
|
||||
]
|
||||
})
|
||||
export class BookInfoTabsComponent implements OnInit {
|
||||
book: Book | undefined;
|
||||
bookForm: BookMetadataForm = {} as BookMetadataForm;
|
||||
|
||||
constructor(private bookService: BookService, private dynamicDialogConfig: DynamicDialogConfig,
|
||||
private messageService: MessageService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.getBookByIdFromAPI(this.dynamicDialogConfig.data.bookId, true).subscribe({
|
||||
next: (book) => {
|
||||
this.book = book;
|
||||
this.initializeBookForm();
|
||||
},
|
||||
error: (error) => {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private initializeBookForm(): void {
|
||||
if (this.book?.metadata) {
|
||||
this.bookForm = {
|
||||
...this.book.metadata,
|
||||
authors: this.book.metadata.authors?.map(a => a.name) || [],
|
||||
categories: this.book.metadata.categories?.map(c => c.name) || []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
saveBook(bookMetadataForm: BookMetadataForm) {
|
||||
console.log(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'});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,14 @@
|
||||
</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()"
|
||||
|
||||
@@ -16,6 +16,7 @@ import {Button} from 'primeng/button';
|
||||
import {AppConfiguratorComponent} from '../configurator/configurator.component';
|
||||
import {StyleClass} from 'primeng/styleclass';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {BookInfoTabsComponent} from '../../../book-info-tabs/book-info-tabs.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
@@ -39,7 +40,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
items!: MenuItem[];
|
||||
ref: DynamicDialogRef | undefined;
|
||||
|
||||
latestEvent: LogNotification = { message: 'No recent notifications...' };
|
||||
latestEvent: LogNotification = {message: 'No recent notifications...'};
|
||||
eventHighlight: boolean = false;
|
||||
showEvents: boolean = false;
|
||||
eventTimeout: any;
|
||||
@@ -76,6 +77,22 @@ 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: '1000px',
|
||||
height: '835px',
|
||||
showHeader: false,
|
||||
closeOnEscape: true,
|
||||
data: {
|
||||
bookId: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openLibraryCreatorDialog(): void {
|
||||
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||
header: 'Create New Library',
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface BookMetadataForm {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
authors: Array<string>;
|
||||
categories: Array<string>;
|
||||
publisher: string;
|
||||
publishedDate: string;
|
||||
isbn10: string;
|
||||
isbn13: string;
|
||||
asin: string;
|
||||
description?: string;
|
||||
pageCount: number;
|
||||
language: string;
|
||||
googleBookId: string;
|
||||
}
|
||||
@@ -17,6 +17,8 @@ export interface BookMetadata {
|
||||
publisher: string;
|
||||
publishedDate: string;
|
||||
isbn10: string;
|
||||
isbn13: string;
|
||||
asin: string;
|
||||
description?: string;
|
||||
pageCount: number;
|
||||
language: string;
|
||||
|
||||
@@ -4,6 +4,7 @@ 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';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -202,4 +203,9 @@ export class BookService {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user