WIP: Arrange UI files for better structuring
This commit is contained in:
+104
@@ -0,0 +1,104 @@
|
||||
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as bookMetadata" class="pt-2 flex flex-col h-full">
|
||||
|
||||
<div class="overflow-y-scroll flex-1">
|
||||
|
||||
<div class="flex flex-row w-full gap-4">
|
||||
|
||||
<p-image [src]="coverImageSrc(bookMetadata.bookId)" alt="Image" width="225"></p-image>
|
||||
|
||||
<div class="flex flex-col flex-grow pl-2">
|
||||
|
||||
<div class="flex flex-row w-full gap-4 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="title">Title</label>
|
||||
<input pInputText id="title" formControlName="title" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="subtitle">Subtitle</label>
|
||||
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="authors">Authors</label>
|
||||
<input pInputText id="authors" formControlName="authors" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="publisher">Publisher</label>
|
||||
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="categories">Categories</label>
|
||||
<input pInputText id="categories" formControlName="categories" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="publishedDate">Publish Date</label>
|
||||
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Language, ISBN 10, and ISBN 13 -->
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="language">Language</label>
|
||||
<input pInputText id="language" formControlName="language" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="isbn10">ISBN 10</label>
|
||||
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="isbn13">ISBN 13</label>
|
||||
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="reviewCount">Review Count</label>
|
||||
<input pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="rating">Rating</label>
|
||||
<input pInputText id="rating" formControlName="rating" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="pageCount">Page Count</label>
|
||||
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<label for="description">Description</label>
|
||||
<!--<p-editor class="w-full" formControlName="description" id="description" [style]="{ height: '18rem' }">
|
||||
<ng-template #header>
|
||||
<span class="ql-formats">
|
||||
<button type="button" class="ql-bold" aria-label="Bold"></button>
|
||||
<button type="button" class="ql-italic" aria-label="Italic"></button>
|
||||
<button type="button" class="ql-underline" aria-label="Underline"></button>
|
||||
</span>
|
||||
</ng-template>
|
||||
</p-editor>-->
|
||||
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
|
||||
</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" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
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 {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookMetadataCenterService} from '../book-metadata-center.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';
|
||||
import {MetadataService} from '../../../book/service/metadata.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-editor',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-editor.component.html',
|
||||
styleUrl: './metadata-editor.component.scss',
|
||||
imports: [
|
||||
InputText,
|
||||
Textarea,
|
||||
Image,
|
||||
Button,
|
||||
Divider,
|
||||
FormsModule,
|
||||
AsyncPipe,
|
||||
NgIf,
|
||||
ReactiveFormsModule
|
||||
]
|
||||
})
|
||||
export class MetadataEditorComponent implements OnInit {
|
||||
|
||||
bookMetadata$: Observable<BookMetadataBI | null>;
|
||||
bookMetadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
|
||||
constructor(private bookInfoService: BookMetadataCenterService,
|
||||
private bookService: BookService,
|
||||
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
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
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,
|
||||
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.metadataService.updateBookMetadata(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'});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
coverImageSrc(bookId: number): string {
|
||||
return this.bookService.getBookCoverUrl(bookId);
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.bookInfoService.closeDialog(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user