WIP: Match book

This commit is contained in:
aditya.chandel
2025-01-03 00:16:09 -07:00
parent 9e34a15b3d
commit 2c6c15e43c
6 changed files with 203 additions and 7 deletions
@@ -1,4 +1,4 @@
<div class="container pt-6 px-2 flex flex-col h-full">
<div class="container pt-4 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">
@@ -1,11 +1,18 @@
<p-tabs value="0">
<p-tabs value="0" style="height: 100%; overflow: hidden;">
<p-tablist>
<p-tab value="0">Book Details</p-tab>
<p-tab value="1">Match Book</p-tab>
<p-tab value="2">Manage File</p-tab>
</p-tablist>
<p-tabpanels>
<p-tabpanel value="0">
<app-book-details [bookForm]="bookForm" (save)="saveBook($event)"></app-book-details>
<p-tabpanels style="height: 100%; overflow: hidden;">
<p-tabpanel value="0" style="height: 100%; overflow: hidden;">
<app-book-details [bookForm]="metadataForm" (save)="saveBook($event)"></app-book-details>
</p-tabpanel>
<p-tabpanel value="1" style="height: 100%; overflow: hidden;">
<app-book-match [metadata]="metadataForm"></app-book-match>
</p-tabpanel>
<p-tabpanel value="2" style="height: 100%; overflow: hidden;">
<p>I too work!!</p>
</p-tabpanel>
</p-tabpanels>
</p-tabs>
@@ -6,6 +6,7 @@ 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';
@Component({
selector: 'book-info-tabs',
@@ -18,12 +19,13 @@ import {MessageService} from 'primeng/api';
Tab,
TabPanels,
BookDetailsComponent,
BookMatchComponent,
TabPanel
]
})
export class BookInfoTabsComponent implements OnInit {
book: Book | undefined;
bookForm: BookMetadataForm = {} as BookMetadataForm;
metadataForm: BookMetadataForm = {} as BookMetadataForm;
constructor(private bookService: BookService, private dynamicDialogConfig: DynamicDialogConfig,
private messageService: MessageService) {}
@@ -41,7 +43,7 @@ export class BookInfoTabsComponent implements OnInit {
private initializeBookForm(): void {
if (this.book?.metadata) {
this.bookForm = {
this.metadataForm = {
...this.book.metadata,
authors: this.book.metadata.authors?.map(a => a.name) || [],
categories: this.book.metadata.categories?.map(c => c.name) || []
@@ -0,0 +1,58 @@
<form class="flex flex-col w-full h-full pt-4" [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="flex w-full gap-x-4 items-end px-2">
<div class="flex flex-col gap-1 w-1/6">
<label for="provider">Provider</label>
<p-select
id="provider"
class="w-full"
[options]="providers"
formControlName="provider"
placeholder="Select Provider.."
></p-select>
</div>
<div class="flex flex-col gap-1 w-1/6">
<label for="isbn">ISBN</label>
<input pInputText formControlName="isbn" id="isbn" class="w-full" />
</div>
<div class="flex flex-col gap-1 w-2/6">
<label for="title">Title</label>
<input pInputText formControlName="title" id="title" class="w-full" />
</div>
<div class="flex flex-col gap-1 w-2/6">
<label for="author">Author</label>
<input pInputText formControlName="author" id="author" class="w-full" />
</div>
<div>
<p-button label="Search" type="submit" [disabled]="!isSearchEnabled"></p-button>
</div>
</div>
<!-- Scrollable books list -->
<div class="mt-8 flex-1 overflow-y-auto">
<div *ngFor="let book of books" class="flex flex-col w-full">
<div class="flex w-full flex-row">
<p-image [src]="book.imageUrl" alt="Image" width="110" height="100" class="mr-4"/>
<div class="flex flex-col w-full m-2">
<div class="flex flex-row gap-4 justify-between">
<p class="font-bold">{{ book.title }}</p>
<div class="flex gap-4">
<p>ISBN: {{ book.isbn }}</p>
<p> | </p>
<p>Year: {{ book.year }}</p>
</div>
</div>
<p>by {{ book.author }}</p>
<p class="mt-4 truncate-text">
{{ book.description }}
</p>
</div>
</div>
<p-divider></p-divider>
</div>
</div>
</form>
@@ -0,0 +1,7 @@
.truncate-text {
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
@@ -0,0 +1,122 @@
import {Component, Input, OnChanges, SimpleChanges} from '@angular/core';
import {FormBuilder, FormGroup, ReactiveFormsModule} from '@angular/forms';
import {Button} from 'primeng/button';
import {Select} from 'primeng/select';
import {InputText} from 'primeng/inputtext';
import {BookMetadataForm} from '../../book/model/book-metadata-form';
import {Image} from 'primeng/image';
import {Divider} from 'primeng/divider';
import {NgForOf} from '@angular/common';
@Component({
selector: 'app-book-match',
templateUrl: './book-match.component.html',
styleUrls: ['./book-match.component.scss'],
imports: [
Select,
ReactiveFormsModule,
Button,
InputText,
Image,
Divider,
NgForOf
],
standalone: true
})
export class BookMatchComponent implements OnChanges {
form: FormGroup;
providers: string[] = ['Amazon', 'Google Books', 'Google Books (API)'];
@Input() metadata!: BookMetadataForm;
books = [
{
title: 'Code That Fits in Your Head',
isbn: '1234567890',
year: 2000,
author: 'Mark Seemann',
description: `How to Reduce Code Complexity and Develop Software More Sustainably.
"Mark Seemann is well known for explaining complex concepts clearly and thoroughly. In this book he condenses his wide-ranging software development experience into a set of practical, pragmatic techniques for writing sustainable and human-friendly code. This book will be a must-read for every programmer who wants to write better, more maintainable software. It covers a variety of topics from managing complexity to understanding software architecture, and helps developers see how their decisions can influence the success or failure of their projects.`,
imageUrl: 'https://m.media-amazon.com/images/I/61GzazUmKyL._SL1462_.jpg'
},
{
title: 'The Pragmatic Programmer',
isbn: '9876543210',
year: 1999,
author: 'Andrew Hunt',
description: `A book that helps developers keep track of software practices and strategies that ensure long-term success. It emphasizes adaptability, flexibility, and sustainable development practices. Written by Andrew Hunt and David Thomas, this timeless classic has been guiding developers on their journey to mastering their craft for over 20 years.`,
imageUrl: 'https://m.media-amazon.com/images/I/81OthjkJBuL._AC_UL320_.jpg'
},
{
title: 'Clean Code',
isbn: '1122334455',
year: 2008,
author: 'Robert C. Martin',
description: `This book provides guidelines for writing clean, maintainable code. It is divided into several sections that cover topics like meaningful naming conventions, functions, comments, and the importance of writing code that others can easily understand and work with.`,
imageUrl: 'https://m.media-amazon.com/images/I/81-xuU4chcL._AC_UL320_.jpg'
},
{
title: 'Domain-Driven Design',
isbn: '2233445566',
year: 2003,
author: 'Eric Evans',
description: `In this book, Eric Evans presents a methodology for designing complex software systems called Domain-Driven Design (DDD). This approach is based on collaboration between technical experts and domain experts, working together to create a shared understanding of the problem domain and translating that into software models.`,
imageUrl: 'https://m.media-amazon.com/images/I/71dx2jr5cML._AC_UL320_.jpg'
},
{
title: 'Refactoring: Improving the Design of Existing Code',
isbn: '3344556677',
year: 1999,
author: 'Martin Fowler',
description: `Refactoring provides techniques for improving the design of existing code without changing its functionality. In this book, Martin Fowler offers a practical approach to restructuring software to improve its internal structure, making it easier to understand and maintain.`,
imageUrl: 'https://m.media-amazon.com/images/I/81yLrM7b4uL._AC_UL320_.jpg'
},
{
title: 'The Clean Coder',
isbn: '4455667788',
year: 2011,
author: 'Robert C. Martin',
description: `The Clean Coder focuses on what it means to be a professional software developer. Robert C. Martin (Uncle Bob) presents a series of principles and techniques that every developer should adopt to approach their work with professionalism and integrity.`,
imageUrl: 'https://m.media-amazon.com/images/I/81-s6sxtdGL._AC_UL320_.jpg'
},
{
title: 'Working Effectively with Legacy Code',
isbn: '5566778899',
year: 2004,
author: 'Michael Feathers',
description: `Working with legacy code can be one of the most challenging aspects of software development. Michael Feathers provides practical strategies for dealing with and improving legacy codebases that were not designed with the same care or architecture as modern software.`,
imageUrl: 'https://m.media-amazon.com/images/I/91D4vYbkvwL._AC_UL320_.jpg'
}
];
constructor(private fb: FormBuilder) {
this.form = this.fb.group({
provider: [null],
isbn: [''],
title: [''],
author: [''],
});
}
ngOnChanges(changes: SimpleChanges): void {
if (changes['metadata'] && this.metadata) {
const firstAuthor = this.metadata.authors && this.metadata.authors.length > 0 ? this.metadata.authors[0] : '';
this.form.patchValue({
isbn: this.metadata.isbn10 || '',
title: this.metadata.title || '',
author: firstAuthor,
});
}
}
get isSearchEnabled(): boolean {
const providerSelected = !!this.form.get('provider')?.value;
const isbnOrTitle = this.form.get('isbn')?.value || this.form.get('title')?.value;
return providerSelected && isbnOrTitle;
}
onSubmit(): void {
if (this.form.valid) {
console.log('Form submitted', this.form.value);
}
}
}