Support Individual Metadata Editing for Multiple Books
This commit is contained in:
committed by
Aditya Chandel
parent
82c843bbe5
commit
551234f02a
+1
-1
@@ -9,7 +9,7 @@
|
||||
<p-tab value="match">Search Metadata</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="h-[calc(100vh-10rem)]">
|
||||
<p-tabpanels class="overflow-auto" style="height: calc(100vh - 10rem);">
|
||||
<p-tabpanel value="view">
|
||||
<app-metadata-viewer [book]="book" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
|
||||
</p-tabpanel>
|
||||
|
||||
@@ -20,5 +20,4 @@ export class BookMetadataCenterService {
|
||||
emitBookChanged(book: Book | null) {
|
||||
this.bookChangedSubject.next(book);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+26
-13
@@ -1,12 +1,13 @@
|
||||
@if (bookMetadata$ | async; as metadata) {
|
||||
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" class="pt-2 flex flex-col h-full">
|
||||
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" class="flex flex-col h-full">
|
||||
@if (isLoading) {
|
||||
<div class="absolute inset-0 bg-black opacity-25 z-10"></div>
|
||||
<div class="absolute inset-0 bg-black opacity-25 z-10 "></div>
|
||||
}
|
||||
@if (isLoading) {
|
||||
<p-progressSpinner [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
|
||||
}
|
||||
<div class="overflow-y-scroll flex-1">
|
||||
|
||||
<div class="flex-grow overflow-auto p-4">
|
||||
<div class="flex flex-row w-full gap-4">
|
||||
<div class="flex flex-col items-center gap-2 relative">
|
||||
<img
|
||||
@@ -349,7 +350,7 @@
|
||||
<p-tabpanels>
|
||||
<p-tabpanel value="editor">
|
||||
<form [formGroup]="metadataForm">
|
||||
<p-editor #quillEditor formControlName="description" [readonly]="quillDisabled()" [style]="{ height: '215px' }">
|
||||
<p-editor #quillEditor formControlName="description" [readonly]="quillDisabled()" [style]="{ height: '200px' }">
|
||||
<ng-template #header>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-bold" aria-label="Bold"></button>
|
||||
@@ -383,7 +384,7 @@
|
||||
<p-tabpanel value="html" class="w-full">
|
||||
<textarea
|
||||
class="w-full p-4"
|
||||
rows="10"
|
||||
rows="9"
|
||||
[disabled]="quillDisabled()"
|
||||
[ngModel]="htmlTextarea"
|
||||
(ngModelChange)="onHtmlTextareaChange($event)"
|
||||
@@ -403,15 +404,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-x-4 mt-auto">
|
||||
|
||||
|
||||
<div class="mt-auto">
|
||||
<p-divider></p-divider>
|
||||
<div class="flex gap-x-4 justify-end">
|
||||
<p-button label="Restore Metadata" icon="pi pi-refresh" [outlined]="true" severity="danger" (onClick)="restoreMetadata()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
|
||||
<div class="flex justify-between px-2 pt-1 pb-4 bg-gray-900 z-10">
|
||||
@if (showNavigationButtons) {
|
||||
<div class="flex gap-x-4">
|
||||
<p-button label="Close" icon="pi pi-times" [outlined]="true" severity="danger" (onClick)="closeDialog()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Previous Book" [disabled]="disablePrevious" icon="pi pi-arrow-left" [outlined]="true" severity="info" (onClick)="onPrevious()"></p-button>
|
||||
<p-button label="Next Book" [disabled]="disableNext" icon="pi pi-arrow-right" iconPos="right" [outlined]="true" severity="info" (onClick)="onNext()"></p-button>
|
||||
</div>
|
||||
}
|
||||
<div class="flex gap-x-4 items-center ml-auto">
|
||||
<p-button label="Restore Metadata" icon="pi pi-refresh" [outlined]="true" severity="danger" (onClick)="restoreMetadata()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Save" icon="pi pi-check" [loading]="isSaving" [disabled]="isSaving" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
+24
-2
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, OnInit, ViewChild} from '@angular/core';
|
||||
import {Component, EventEmitter, inject, Input, OnInit, Output, ViewChild} from '@angular/core';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
@@ -48,6 +48,14 @@ export class MetadataEditorComponent implements OnInit {
|
||||
|
||||
@ViewChild(Editor) quillEditor!: Editor;
|
||||
|
||||
@Output() nextBookClicked = new EventEmitter<void>();
|
||||
@Output() previousBookClicked = new EventEmitter<void>();
|
||||
@Output() closeDialogButtonClicked = new EventEmitter<void>();
|
||||
|
||||
@Input() disableNext = false;
|
||||
@Input() disablePrevious = false;
|
||||
@Input() showNavigationButtons = false;
|
||||
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
@@ -60,6 +68,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
isUploading = false;
|
||||
isLoading = false;
|
||||
htmlTextarea = '';
|
||||
isSaving = false;
|
||||
|
||||
constructor() {
|
||||
this.metadataForm = new FormGroup({
|
||||
@@ -233,12 +242,15 @@ export class MetadataEditorComponent implements OnInit {
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
this.isSaving = true;
|
||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
|
||||
next: (response) => {
|
||||
this.isSaving = false;
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
this.metadataCenterService.emitMetadata(response);
|
||||
},
|
||||
error: (err) => {
|
||||
this.isSaving = false;
|
||||
console.error('Update metadata failed:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
@@ -363,7 +375,6 @@ export class MetadataEditorComponent implements OnInit {
|
||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
||||
next: (response) => {
|
||||
this.metadataCenterService.emitMetadata(response);
|
||||
|
||||
if (shouldLockAllFields !== undefined) {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -444,4 +455,15 @@ export class MetadataEditorComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onNext() {
|
||||
this.nextBookClicked.emit();
|
||||
}
|
||||
|
||||
onPrevious() {
|
||||
this.previousBookClicked.emit();
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.closeDialogButtonClicked.emit();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
<div class="pt-2 flex flex-col h-full overflow-hidden">
|
||||
<div class="pt-2 flex flex-col h-full">
|
||||
@if (metadata$ | async; as metadata) {
|
||||
<div>
|
||||
<div class="flex flex-row">
|
||||
@@ -287,7 +287,7 @@
|
||||
<p-divider></p-divider>
|
||||
|
||||
@if (metadata$ | async; as metadata) {
|
||||
<div class="flex-1 overflow-auto space-y-2 px-2">
|
||||
<div class="flex-1 space-y-2 px-2">
|
||||
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }" class="transition-all duration-300 overflow-hidden description-container">
|
||||
<div class="readonly-editor px-2">
|
||||
<p-editor #quillEditor [readonly]="true" [style]="{height: '250px'}" [(ngModel)]="metadata.description">
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<div class="rounded-xl">
|
||||
<p-tabs [value]="'edit'" lazy="true">
|
||||
<p-tablist>
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tab value="edit">Edit Metadata</p-tab>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tab value="match">Search Metadata</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="h-[calc(100vh-10rem)]">
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tabpanel value="edit">
|
||||
<app-metadata-editor
|
||||
[disableNext]="currentIndex >= books.length - 1"
|
||||
[disablePrevious]="currentIndex <= 0"
|
||||
(nextBookClicked)="handleNextBook()"
|
||||
(previousBookClicked)="handlePreviousBook()"
|
||||
(closeDialogButtonClicked)="handleCloseDialogButton()"
|
||||
[showNavigationButtons]="true"
|
||||
></app-metadata-editor>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tabpanel value="match">
|
||||
<app-metadata-searcher></app-metadata-searcher>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {MetadataEditorComponent} from '../book-metadata-center/metadata-editor/metadata-editor.component';
|
||||
import {MetadataSearcherComponent} from '../book-metadata-center/metadata-searcher/metadata-searcher.component';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {BookMetadataCenterService} from '../book-metadata-center/book-metadata-center.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-multi-book-metadata-editor-component',
|
||||
imports: [
|
||||
MetadataEditorComponent,
|
||||
MetadataSearcherComponent,
|
||||
Tab,
|
||||
TabList,
|
||||
TabPanel,
|
||||
TabPanels,
|
||||
Tabs
|
||||
],
|
||||
templateUrl: './multi-book-metadata-editor-component.html',
|
||||
standalone: true,
|
||||
styleUrl: './multi-book-metadata-editor-component.scss'
|
||||
})
|
||||
export class MultiBookMetadataEditorComponent implements OnInit, OnDestroy {
|
||||
|
||||
bookIds: number[] = [];
|
||||
books: Book[] = [];
|
||||
loading = false;
|
||||
|
||||
private userSubscription: Subscription = Subscription.EMPTY;
|
||||
private metadataSubscription: Subscription = Subscription.EMPTY;
|
||||
canEditMetadata: boolean = false;
|
||||
admin: boolean = false;
|
||||
currentIndex = 0;
|
||||
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly ref = inject(DynamicDialogRef);
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookIds = this.config.data?.bookIds ?? [];
|
||||
|
||||
this.userSubscription = this.userService.userState$.subscribe(userData => {
|
||||
const userPermissions = userData?.permissions;
|
||||
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
|
||||
this.admin = userPermissions?.admin ?? false;
|
||||
});
|
||||
|
||||
this.metadataSubscription = this.metadataCenterService.currentMetadata$.subscribe(updatedMetadata => {
|
||||
if (updatedMetadata) {
|
||||
const index = this.books.findIndex(book => book.metadata?.bookId === updatedMetadata.bookId);
|
||||
if (index !== -1) {
|
||||
this.books[index] = {
|
||||
...this.books[index],
|
||||
metadata: updatedMetadata
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.loading = true;
|
||||
this.bookService.getBooksByIdsFromAPI(this.bookIds, true).subscribe({
|
||||
next: (fetchedBooks) => {
|
||||
this.books = fetchedBooks;
|
||||
this.loading = false;
|
||||
|
||||
if (this.books.length > 0) {
|
||||
this.metadataCenterService.emitBookChanged(this.books[this.currentIndex]);
|
||||
this.metadataCenterService.emitMetadata(this.books[this.currentIndex].metadata!);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed to load books',
|
||||
detail: err.message || 'An error occurred while fetching books.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription.unsubscribe();
|
||||
this.metadataSubscription.unsubscribe();
|
||||
this.metadataCenterService.emitBookChanged(null);
|
||||
}
|
||||
|
||||
handleNextBook() {
|
||||
if (this.currentIndex < this.books.length - 1) {
|
||||
this.currentIndex++;
|
||||
const book = this.books[this.currentIndex];
|
||||
this.metadataCenterService.emitBookChanged(book);
|
||||
this.metadataCenterService.emitMetadata(book.metadata!);
|
||||
}
|
||||
}
|
||||
|
||||
handlePreviousBook() {
|
||||
if (this.currentIndex > 0) {
|
||||
this.currentIndex--;
|
||||
const book = this.books[this.currentIndex];
|
||||
this.metadataCenterService.emitBookChanged(book);
|
||||
this.metadataCenterService.emitMetadata(book.metadata!);
|
||||
}
|
||||
}
|
||||
|
||||
handleCloseDialogButton() {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user