Fix authors and categories not getting set properly in the viewer.
This commit is contained in:
@@ -8,7 +8,7 @@ import {Book, BookMetadata} from '../../book/model/book.model';
|
||||
export class BookMetadataCenterService {
|
||||
|
||||
private bookMetadataSubject = new BehaviorSubject<BookMetadata | null>(null);
|
||||
bookMetadata$ = this.bookMetadataSubject.asObservable();
|
||||
currentMetadata$ = this.bookMetadataSubject.asObservable();
|
||||
|
||||
private dialogCloseSubject = new BehaviorSubject<boolean | null>(null);
|
||||
dialogClose$ = this.dialogCloseSubject.asObservable();
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private metadataService = inject(MetadataService);
|
||||
|
||||
bookMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.bookMetadata$;
|
||||
bookMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
|
||||
bookMetadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" class="h-full flex pt-1 flex-col">
|
||||
<form [formGroup]="metadataForm" (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'}">
|
||||
|
||||
+26
-26
@@ -34,7 +34,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
@Input() fetchedMetadata!: FetchedMetadata;
|
||||
@Output() goBack = new EventEmitter<boolean>();
|
||||
|
||||
bookMetadataForm: FormGroup;
|
||||
metadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
updateThumbnailUrl: boolean = false;
|
||||
thumbnailSaved: boolean = false;
|
||||
@@ -46,10 +46,10 @@ export class MetadataPickerComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private metadataService = inject(MetadataService);
|
||||
|
||||
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.bookMetadata$;
|
||||
currentMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
|
||||
|
||||
constructor() {
|
||||
this.bookMetadataForm = new FormGroup({
|
||||
this.metadataForm = new FormGroup({
|
||||
title: new FormControl(''),
|
||||
subtitle: new FormControl(''),
|
||||
authors: new FormControl(''),
|
||||
@@ -67,10 +67,10 @@ export class MetadataPickerComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.metadata$.subscribe((metadata) => {
|
||||
this.currentMetadata$.subscribe((metadata) => {
|
||||
if (metadata) {
|
||||
this.currentBookId = metadata.bookId;
|
||||
this.bookMetadataForm.setValue({
|
||||
this.metadataForm.setValue({
|
||||
title: metadata.title,
|
||||
subtitle: metadata.subtitle,
|
||||
authors: metadata.authors.map((author) => author.name).join(', '),
|
||||
@@ -104,24 +104,24 @@ export class MetadataPickerComponent implements OnInit {
|
||||
onSave(): void {
|
||||
const updatedBookMetadata: BookMetadata = {
|
||||
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,
|
||||
title: this.metadataForm.get('title')?.value || this.copiedFields['title'] ? this.getValueOrCopied('title') : '',
|
||||
subtitle: this.metadataForm.get('subtitle')?.value || this.copiedFields['subtitle'] ? this.getValueOrCopied('subtitle') : '',
|
||||
authors: this.metadataForm.get('authors')?.value || this.copiedFields['authors'] ? this.getArrayFromFormField('authors', this.fetchedMetadata.authors) : [],
|
||||
categories: this.metadataForm.get('categories')?.value || this.copiedFields['categories'] ? this.getArrayFromFormField('categories', this.fetchedMetadata.categories) : [],
|
||||
publisher: this.metadataForm.get('publisher')?.value || this.copiedFields['publisher'] ? this.getValueOrCopied('publisher') : '',
|
||||
publishedDate: this.metadataForm.get('publishedDate')?.value || this.copiedFields['publishedDate'] ? this.getValueOrCopied('publishedDate') : '',
|
||||
isbn10: this.metadataForm.get('isbn10')?.value || this.copiedFields['isbn10'] ? this.getValueOrCopied('isbn10') : '',
|
||||
isbn13: this.metadataForm.get('isbn13')?.value || this.copiedFields['isbn13'] ? this.getValueOrCopied('isbn13') : '',
|
||||
description: this.metadataForm.get('description')?.value || this.copiedFields['description'] ? this.getValueOrCopied('description') : '',
|
||||
pageCount: this.metadataForm.get('pageCount')?.value || this.copiedFields['pageCount'] ? this.getPageCountOrCopied() : null,
|
||||
language: this.metadataForm.get('language')?.value || this.copiedFields['language'] ? this.getValueOrCopied('language') : '',
|
||||
rating: this.metadataForm.get('rating')?.value || this.copiedFields['rating'] ? this.getNumberOrCopied('rating') : null,
|
||||
reviewCount: this.metadataForm.get('reviewCount')?.value || this.copiedFields['reviewCount'] ? this.getNumberOrCopied('reviewCount') : null,
|
||||
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '',
|
||||
};
|
||||
|
||||
this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
|
||||
next: () => {
|
||||
next: (bookMetadata) => {
|
||||
Object.keys(this.copiedFields).forEach((field) => {
|
||||
if (this.copiedFields[field]) {
|
||||
this.savedFields[field] = true;
|
||||
@@ -131,7 +131,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
this.thumbnailSaved = true;
|
||||
}
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
this.metadataCenterService.emit(updatedBookMetadata);
|
||||
this.metadataCenterService.emit(bookMetadata);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||
@@ -141,14 +141,14 @@ export class MetadataPickerComponent implements OnInit {
|
||||
|
||||
copyMissing() {
|
||||
Object.keys(this.fetchedMetadata).forEach((field) => {
|
||||
if (!this.bookMetadataForm.get(field)?.value && this.fetchedMetadata[field]) {
|
||||
if (!this.metadataForm.get(field)?.value && this.fetchedMetadata[field]) {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getNumberOrCopied(field: string): number | null {
|
||||
const formValue = this.bookMetadataForm.get(field)?.value;
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || null;
|
||||
@@ -157,7 +157,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
}
|
||||
|
||||
private getPageCountOrCopied(): number | null {
|
||||
const formValue = this.bookMetadataForm.get('pageCount')?.value;
|
||||
const formValue = this.metadataForm.get('pageCount')?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields['pageCount'] = true;
|
||||
return this.fetchedMetadata.pageCount || null;
|
||||
@@ -166,7 +166,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
}
|
||||
|
||||
private getValueOrCopied(field: string): string {
|
||||
const formValue = this.bookMetadataForm.get(field)?.value;
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (!formValue || formValue === '') {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || '';
|
||||
@@ -175,7 +175,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
}
|
||||
|
||||
getArrayFromFormField(field: string, fallbackValue: any): any[] {
|
||||
const fieldValue = this.bookMetadataForm.get(field)?.value;
|
||||
const fieldValue = this.metadataForm.get(field)?.value;
|
||||
if (!fieldValue) {
|
||||
return fallbackValue ? (Array.isArray(fallbackValue) ? fallbackValue : [fallbackValue]) : [];
|
||||
}
|
||||
@@ -192,7 +192,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
copyFetchedToCurrent(field: string): void {
|
||||
const value = this.fetchedMetadata[field];
|
||||
if (value) {
|
||||
this.bookMetadataForm.get(field)?.setValue(value);
|
||||
this.metadataForm.get(field)?.setValue(value);
|
||||
this.copiedFields[field] = true;
|
||||
this.highlightCopiedInput(field);
|
||||
}
|
||||
|
||||
+6
-6
@@ -54,7 +54,7 @@ export class MetadataSearcherComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.metadataCenterService.bookMetadata$.subscribe((metadata => {
|
||||
this.metadataCenterService.currentMetadata$.subscribe((metadata => {
|
||||
if (metadata) {
|
||||
this.bookId = metadata.bookId;
|
||||
this.form.setValue(({
|
||||
@@ -62,9 +62,9 @@ export class MetadataSearcherComponent implements OnInit {
|
||||
isbn: metadata.isbn10,
|
||||
title: metadata.title,
|
||||
author: metadata.authors?.length! > 0 ? metadata.authors[0].name : ''
|
||||
}))
|
||||
}));
|
||||
}
|
||||
}))
|
||||
}));
|
||||
}
|
||||
|
||||
get isSearchEnabled(): boolean {
|
||||
@@ -94,9 +94,9 @@ export class MetadataSearcherComponent implements OnInit {
|
||||
.subscribe({
|
||||
next: (fetchedMetadata) => {
|
||||
this.loading = false;
|
||||
this.allFetchedMetadata = fetchedMetadata.map((book) => ({
|
||||
...book,
|
||||
thumbnailUrl: book.thumbnailUrl
|
||||
this.allFetchedMetadata = fetchedMetadata.map((fetchedMetadata) => ({
|
||||
...fetchedMetadata,
|
||||
thumbnailUrl: fetchedMetadata.thumbnailUrl
|
||||
}));
|
||||
},
|
||||
error: () => {
|
||||
|
||||
+6
-6
@@ -37,27 +37,27 @@
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<p-tag *ngFor="let category of metadata.categories" value="{{category}}"></p-tag>
|
||||
<p-tag *ngFor="let category of metadata.categories" [value]="category.name"></p-tag>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<p-divider></p-divider>-->
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div *ngIf="metadata$ | async as metadata" class="book-description space-y-4 overflow-y-auto flex-1">
|
||||
<!--<p class="pt-2 px-2" [innerHTML]="bookMetadata.description || 'No description available.'"></p>-->
|
||||
<div class="pt-6">
|
||||
<p class="pt-2 px-2" [innerHTML]="metadata.description || 'No description available.'"></p>
|
||||
<!--<div class="pt-6">
|
||||
<p-editor [(ngModel)]="metadata.description" [style]="{ height: '350px' }" [readonly]="true">
|
||||
<ng-template #header>
|
||||
</ng-template>
|
||||
</p-editor>
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-x-4 mt-auto">
|
||||
<!--<p-divider></p-divider>-->
|
||||
<p-divider></p-divider>
|
||||
<div class="flex gap-x-4 justify-end">
|
||||
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||
</div>
|
||||
|
||||
+3
-3
@@ -7,16 +7,16 @@ import {BookMetadataCenterService} from '../book-metadata-center.service';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Editor} from 'primeng/editor';
|
||||
import {Author, Book} from '../../../book/model/book.model';
|
||||
import {FileService} from '../../../book/service/file.service';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, NgForOf, NgIf, AsyncPipe, Rating, FormsModule, Tag, Editor]
|
||||
imports: [Button, NgForOf, NgIf, AsyncPipe, Rating, FormsModule, Tag, Divider]
|
||||
})
|
||||
export class MetadataViewerComponent {
|
||||
|
||||
@@ -24,7 +24,7 @@ export class MetadataViewerComponent {
|
||||
private fileService = inject(FileService);
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
|
||||
metadata$: Observable<Book['metadata'] | null> = this.metadataCenterService.bookMetadata$;
|
||||
metadata$: Observable<Book['metadata'] | null> = this.metadataCenterService.currentMetadata$;
|
||||
|
||||
coverImageSrc(bookId: number | undefined): string {
|
||||
return bookId ? this.bookService.getBookCoverUrl(bookId) : 'assets/book-cover-metadata.png';
|
||||
|
||||
Reference in New Issue
Block a user