Support Individual Metadata Editing for Multiple Books
This commit is contained in:
committed by
Aditya Chandel
parent
82c843bbe5
commit
551234f02a
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@RequestMapping("/api/v1/books")
|
@RequestMapping("/api/v1/books")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -42,6 +43,11 @@ public class BookController {
|
|||||||
return ResponseEntity.ok(bookService.getBook(bookId, withDescription));
|
return ResponseEntity.ok(bookService.getBook(bookId, withDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/batch")
|
||||||
|
public ResponseEntity<List<Book>> getBooksByIds(@RequestParam Set<Long> ids, @RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||||
|
return ResponseEntity.ok(bookService.getBooksByIds(ids, withDescription));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/{bookId}/cover")
|
@GetMapping("/{bookId}/cover")
|
||||||
public ResponseEntity<Resource> getBookCover(@PathVariable long bookId) {
|
public ResponseEntity<Resource> getBookCover(@PathVariable long bookId) {
|
||||||
return ResponseEntity.ok(bookService.getBookCover(bookId));
|
return ResponseEntity.ok(bookService.getBookCover(bookId));
|
||||||
|
|||||||
@@ -74,6 +74,34 @@ public class BookService {
|
|||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Book> getBooksByIds(Set<Long> bookIds, boolean withDescription) {
|
||||||
|
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||||
|
|
||||||
|
List<BookEntity> bookEntities;
|
||||||
|
|
||||||
|
bookEntities = bookQueryService.findAllWithMetadataByIds(bookIds);
|
||||||
|
|
||||||
|
Map<Long, UserBookProgressEntity> progressMap = userProgressService.fetchUserProgress(
|
||||||
|
user.getId(), bookEntities.stream().map(BookEntity::getId).collect(Collectors.toSet()));
|
||||||
|
|
||||||
|
return bookEntities.stream().map(bookEntity -> {
|
||||||
|
Book book = bookMapper.toBook(bookEntity);
|
||||||
|
book.setFilePath(FileUtils.getBookFullPath(bookEntity));
|
||||||
|
|
||||||
|
if (!withDescription) {
|
||||||
|
book.getMetadata().setDescription(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
UserBookProgressEntity progress = progressMap.get(bookEntity.getId());
|
||||||
|
if (progress != null) {
|
||||||
|
setBookProgress(book, progress);
|
||||||
|
book.setLastReadTime(progress.getLastReadTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return book;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
private void setBookProgress(Book book, UserBookProgressEntity progress) {
|
private void setBookProgress(Book book, UserBookProgressEntity progress) {
|
||||||
switch (book.getBookType()) {
|
switch (book.getBookType()) {
|
||||||
case EPUB -> book.setEpubProgress(EpubProgress.builder()
|
case EPUB -> book.setEpubProgress(EpubProgress.builder()
|
||||||
|
|||||||
+1
-1
@@ -139,7 +139,7 @@ public class BookMetadataUpdater {
|
|||||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build()));
|
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build()));
|
||||||
|
|
||||||
existingCategories.add(categoryEntity);
|
existingCategories.add(categoryEntity);
|
||||||
}
|
` }
|
||||||
metadata.setCategories(existingCategories);
|
metadata.setCategories(existingCategories);
|
||||||
} else if (!newMetadata.getCategories().isEmpty()) {
|
} else if (!newMetadata.getCategories().isEmpty()) {
|
||||||
Set<CategoryEntity> newCategoryEntities = new HashSet<>();
|
Set<CategoryEntity> newCategoryEntities = new HashSet<>();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/l
|
|||||||
import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||||
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
||||||
import {BulkMetadataUpdateComponent} from '../../metadata/bulk-metadata-update-component/bulk-metadata-update-component';
|
import {BulkMetadataUpdateComponent} from '../../metadata/bulk-metadata-update-component/bulk-metadata-update-component';
|
||||||
|
import {MultiBookMetadataEditorComponent} from '../../metadata/multi-book-metadata-editor-component/multi-book-metadata-editor-component';
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class BookDialogHelperService {
|
export class BookDialogHelperService {
|
||||||
@@ -68,4 +69,22 @@ export class BookDialogHelperService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openMultibookMetadataEditerDialog(bookIds: Set<number>): DynamicDialogRef {
|
||||||
|
return this.dialogService.open(MultiBookMetadataEditorComponent, {
|
||||||
|
header: 'Bulk Edit Metadata',
|
||||||
|
showHeader: false,
|
||||||
|
modal: true,
|
||||||
|
closable: true,
|
||||||
|
closeOnEscape: true,
|
||||||
|
dismissableMask: true,
|
||||||
|
style: {
|
||||||
|
width: '95vw',
|
||||||
|
overflow: 'none',
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
bookIds: Array.from(bookIds)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,9 +202,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
command: () => this.updateMetadata()
|
command: () => this.updateMetadata()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Bulk Edit Metadata',
|
label: 'Edit Bulk Metadata',
|
||||||
icon: 'pi pi-pencil',
|
icon: 'pi pi-pencil',
|
||||||
command: () => this.bulkEditMetadata()
|
command: () => this.bulkEditMetadata()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Edit Multi Book Metadata',
|
||||||
|
icon: 'pi pi-pencil',
|
||||||
|
command: () => this.multiBookEditMetadata()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -596,4 +601,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
bulkEditMetadata(): void {
|
bulkEditMetadata(): void {
|
||||||
this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks);
|
this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multiBookEditMetadata(): void {
|
||||||
|
this.dialogHelperService.openMultibookMetadataEditerDialog(this.selectedBooks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
<p-tab value="match">Search Metadata</p-tab>
|
<p-tab value="match">Search Metadata</p-tab>
|
||||||
}
|
}
|
||||||
</p-tablist>
|
</p-tablist>
|
||||||
<p-tabpanels class="h-[calc(100vh-10rem)]">
|
<p-tabpanels class="overflow-auto" style="height: calc(100vh - 10rem);">
|
||||||
<p-tabpanel value="view">
|
<p-tabpanel value="view">
|
||||||
<app-metadata-viewer [book]="book" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
|
<app-metadata-viewer [book]="book" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
|
|||||||
@@ -20,5 +20,4 @@ export class BookMetadataCenterService {
|
|||||||
emitBookChanged(book: Book | null) {
|
emitBookChanged(book: Book | null) {
|
||||||
this.bookChangedSubject.next(book);
|
this.bookChangedSubject.next(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-13
@@ -1,12 +1,13 @@
|
|||||||
@if (bookMetadata$ | async; as metadata) {
|
@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) {
|
@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) {
|
@if (isLoading) {
|
||||||
<p-progressSpinner [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
|
<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-row w-full gap-4">
|
||||||
<div class="flex flex-col items-center gap-2 relative">
|
<div class="flex flex-col items-center gap-2 relative">
|
||||||
<img
|
<img
|
||||||
@@ -349,7 +350,7 @@
|
|||||||
<p-tabpanels>
|
<p-tabpanels>
|
||||||
<p-tabpanel value="editor">
|
<p-tabpanel value="editor">
|
||||||
<form [formGroup]="metadataForm">
|
<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>
|
<ng-template #header>
|
||||||
<span class="ql-formats">
|
<span class="ql-formats">
|
||||||
<button class="ql-bold" aria-label="Bold"></button>
|
<button class="ql-bold" aria-label="Bold"></button>
|
||||||
@@ -383,7 +384,7 @@
|
|||||||
<p-tabpanel value="html" class="w-full">
|
<p-tabpanel value="html" class="w-full">
|
||||||
<textarea
|
<textarea
|
||||||
class="w-full p-4"
|
class="w-full p-4"
|
||||||
rows="10"
|
rows="9"
|
||||||
[disabled]="quillDisabled()"
|
[disabled]="quillDisabled()"
|
||||||
[ngModel]="htmlTextarea"
|
[ngModel]="htmlTextarea"
|
||||||
(ngModelChange)="onHtmlTextareaChange($event)"
|
(ngModelChange)="onHtmlTextareaChange($event)"
|
||||||
@@ -403,15 +404,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-x-4 mt-auto">
|
|
||||||
|
|
||||||
|
<div class="mt-auto">
|
||||||
<p-divider></p-divider>
|
<p-divider></p-divider>
|
||||||
<div class="flex gap-x-4 justify-end">
|
<div class="flex justify-between px-2 pt-1 pb-4 bg-gray-900 z-10">
|
||||||
<p-button label="Restore Metadata" icon="pi pi-refresh" [outlined]="true" severity="danger" (onClick)="restoreMetadata()"></p-button>
|
@if (showNavigationButtons) {
|
||||||
<p-divider layout="vertical"/>
|
<div class="flex gap-x-4">
|
||||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
<p-button label="Close" icon="pi pi-times" [outlined]="true" severity="danger" (onClick)="closeDialog()"></p-button>
|
||||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
<p-divider layout="vertical"/>
|
||||||
<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="Save" icon="pi pi-check" type="submit"></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>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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 {InputText} from 'primeng/inputtext';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {Divider} from 'primeng/divider';
|
import {Divider} from 'primeng/divider';
|
||||||
@@ -48,6 +48,14 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
|
|
||||||
@ViewChild(Editor) quillEditor!: Editor;
|
@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 metadataCenterService = inject(BookMetadataCenterService);
|
||||||
private messageService = inject(MessageService);
|
private messageService = inject(MessageService);
|
||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
@@ -60,6 +68,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
isUploading = false;
|
isUploading = false;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
htmlTextarea = '';
|
htmlTextarea = '';
|
||||||
|
isSaving = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.metadataForm = new FormGroup({
|
this.metadataForm = new FormGroup({
|
||||||
@@ -233,12 +242,15 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSave(): void {
|
onSave(): void {
|
||||||
|
this.isSaving = true;
|
||||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
|
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
|
this.isSaving = false;
|
||||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||||
this.metadataCenterService.emitMetadata(response);
|
this.metadataCenterService.emitMetadata(response);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
|
this.isSaving = false;
|
||||||
console.error('Update metadata failed:', err);
|
console.error('Update metadata failed:', err);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
@@ -363,7 +375,6 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.metadataCenterService.emitMetadata(response);
|
this.metadataCenterService.emitMetadata(response);
|
||||||
|
|
||||||
if (shouldLockAllFields !== undefined) {
|
if (shouldLockAllFields !== undefined) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
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) {
|
@if (metadata$ | async; as metadata) {
|
||||||
<div>
|
<div>
|
||||||
<div class="flex flex-row">
|
<div class="flex flex-row">
|
||||||
@@ -287,7 +287,7 @@
|
|||||||
<p-divider></p-divider>
|
<p-divider></p-divider>
|
||||||
|
|
||||||
@if (metadata$ | async; as metadata) {
|
@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 [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }" class="transition-all duration-300 overflow-hidden description-container">
|
||||||
<div class="readonly-editor px-2">
|
<div class="readonly-editor px-2">
|
||||||
<p-editor #quillEditor [readonly]="true" [style]="{height: '250px'}" [(ngModel)]="metadata.description">
|
<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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -176,6 +176,15 @@ export class BookService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBooksByIdsFromAPI(bookIds: number[], withDescription: boolean) {
|
||||||
|
return this.http.get<Book[]>(`${this.url}/batch`, {
|
||||||
|
params: {
|
||||||
|
ids: bookIds.map(id => id.toString()),
|
||||||
|
withDescription: withDescription.toString()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
downloadFile(bookId: number): void {
|
downloadFile(bookId: number): void {
|
||||||
const downloadUrl = `${this.url}/${bookId}/download`;
|
const downloadUrl = `${this.url}/${bookId}/download`;
|
||||||
this.http.get(downloadUrl, {responseType: 'blob', observe: 'response'})
|
this.http.get(downloadUrl, {responseType: 'blob', observe: 'response'})
|
||||||
|
|||||||
Reference in New Issue
Block a user