Support Editing Metadata for Multiple Books at Once via Bulk Edit Interface
This commit is contained in:
committed by
Aditya Chandel
parent
2d041f79f3
commit
82c843bbe5
+7
@@ -16,6 +16,7 @@ import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -53,6 +54,12 @@ public class MetadataController {
|
|||||||
return ResponseEntity.ok(bookMetadata);
|
return ResponseEntity.ok(bookMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/bulk-edit-metadata")
|
||||||
|
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||||
|
public ResponseEntity<List<BookMetadata>> bulkEditMetadata(@RequestBody BulkMetadataUpdateRequest bulkMetadataUpdateRequest, @RequestParam boolean mergeCategories) {
|
||||||
|
return ResponseEntity.ok(bookMetadataService.bulkUpdateMetadata(bulkMetadataUpdateRequest, mergeCategories));
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping(path = "/metadata/refresh")
|
@PutMapping(path = "/metadata/refresh")
|
||||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||||
public ResponseEntity<String> scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) {
|
public ResponseEntity<String> scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) {
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package com.adityachandel.booklore.model.dto.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BulkMetadataUpdateRequest {
|
||||||
|
|
||||||
|
private Set<Long> bookIds;
|
||||||
|
|
||||||
|
private Set<String> authors;
|
||||||
|
private String publisher;
|
||||||
|
private String language;
|
||||||
|
private String seriesName;
|
||||||
|
private Integer seriesTotal;
|
||||||
|
private LocalDate publishedDate;
|
||||||
|
private Set<String> genres;
|
||||||
|
}
|
||||||
+28
-6
@@ -6,10 +6,7 @@ import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
|||||||
import com.adityachandel.booklore.model.dto.Book;
|
import com.adityachandel.booklore.model.dto.Book;
|
||||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||||
import com.adityachandel.booklore.model.dto.EpubMetadata;
|
import com.adityachandel.booklore.model.dto.EpubMetadata;
|
||||||
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
|
import com.adityachandel.booklore.model.dto.request.*;
|
||||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshOptions;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.ToggleAllLockRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||||
@@ -393,6 +390,9 @@ public class BookMetadataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFieldLocks(List<Long> bookIds, Map<String, String> fieldActions) {
|
public void toggleFieldLocks(List<Long> bookIds, Map<String, String> fieldActions) {
|
||||||
|
Map<String, String> fieldMapping = Map.of(
|
||||||
|
"thumbnailLocked", "coverLocked"
|
||||||
|
);
|
||||||
List<BookMetadataEntity> metadataEntities = bookMetadataRepository
|
List<BookMetadataEntity> metadataEntities = bookMetadataRepository
|
||||||
.getMetadataForBookIds(bookIds)
|
.getMetadataForBookIds(bookIds)
|
||||||
.stream()
|
.stream()
|
||||||
@@ -401,12 +401,13 @@ public class BookMetadataService {
|
|||||||
|
|
||||||
for (BookMetadataEntity metadataEntity : metadataEntities) {
|
for (BookMetadataEntity metadataEntity : metadataEntities) {
|
||||||
fieldActions.forEach((field, action) -> {
|
fieldActions.forEach((field, action) -> {
|
||||||
|
String entityField = fieldMapping.getOrDefault(field, field);
|
||||||
try {
|
try {
|
||||||
String setterName = "set" + Character.toUpperCase(field.charAt(0)) + field.substring(1);
|
String setterName = "set" + Character.toUpperCase(entityField.charAt(0)) + entityField.substring(1);
|
||||||
Method setter = BookMetadataEntity.class.getMethod(setterName, Boolean.class);
|
Method setter = BookMetadataEntity.class.getMethod(setterName, Boolean.class);
|
||||||
setter.invoke(metadataEntity, "LOCK".equalsIgnoreCase(action));
|
setter.invoke(metadataEntity, "LOCK".equalsIgnoreCase(action));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to invoke setter for field: " + field + " on bookId: " + metadataEntity.getBookId(), e);
|
throw new RuntimeException("Failed to invoke setter for field: " + entityField + " on bookId: " + metadataEntity.getBookId(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -487,4 +488,25 @@ public class BookMetadataService {
|
|||||||
public EpubMetadata getBackedUpMetadata(Long bookId) {
|
public EpubMetadata getBackedUpMetadata(Long bookId) {
|
||||||
return metadataBackupRestoreService.getBackedUpMetadata(bookId);
|
return metadataBackupRestoreService.getBackedUpMetadata(bookId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<BookMetadata> bulkUpdateMetadata(BulkMetadataUpdateRequest request, boolean mergeCategories) {
|
||||||
|
List<BookEntity> books = bookRepository.findAllWithMetadataByIds(request.getBookIds());
|
||||||
|
for (BookEntity book : books) {
|
||||||
|
BookMetadata bookMetadata = BookMetadata.builder()
|
||||||
|
.authors(request.getAuthors())
|
||||||
|
.publisher(request.getPublisher())
|
||||||
|
.language(request.getLanguage())
|
||||||
|
.seriesName(request.getSeriesName())
|
||||||
|
.seriesTotal(request.getSeriesTotal())
|
||||||
|
.publishedDate(request.getPublishedDate())
|
||||||
|
.categories(request.getGenres())
|
||||||
|
.build();
|
||||||
|
bookMetadataUpdater.setBookMetadata(book, bookMetadata, false, mergeCategories);
|
||||||
|
}
|
||||||
|
return books.stream()
|
||||||
|
.map(BookEntity::getMetadata)
|
||||||
|
.map(m -> bookMetadataMapper.toBookMetadata(m, false))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+18
-13
@@ -131,21 +131,26 @@ public class BookMetadataUpdater {
|
|||||||
private void updateCategoriesIfNeeded(BookMetadata newMetadata, BookMetadataEntity metadata, boolean mergeCategories) {
|
private void updateCategoriesIfNeeded(BookMetadata newMetadata, BookMetadataEntity metadata, boolean mergeCategories) {
|
||||||
if (shouldUpdateField(metadata.getCategoriesLocked(), newMetadata.getCategories()) && newMetadata.getCategories() != null) {
|
if (shouldUpdateField(metadata.getCategoriesLocked(), newMetadata.getCategories()) && newMetadata.getCategories() != null) {
|
||||||
if (mergeCategories) {
|
if (mergeCategories) {
|
||||||
HashSet<CategoryEntity> existingCategories = new HashSet<>(metadata.getCategories());
|
Set<CategoryEntity> existingCategories = new HashSet<>(metadata.getCategories());
|
||||||
newMetadata.getCategories().stream()
|
for (String categoryName : newMetadata.getCategories()) {
|
||||||
.filter(c -> c != null && !c.isBlank())
|
if (categoryName == null || categoryName.isBlank()) continue;
|
||||||
.forEach(categoryName -> {
|
|
||||||
CategoryEntity categoryEntity = categoryRepository.findByName(categoryName)
|
CategoryEntity categoryEntity = categoryRepository.findByName(categoryName)
|
||||||
.orElseGet(() -> 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 = newMetadata.getCategories().stream()
|
Set<CategoryEntity> newCategoryEntities = new HashSet<>();
|
||||||
.filter(c -> c != null && !c.isBlank())
|
for (String categoryName : newMetadata.getCategories()) {
|
||||||
.map(categoryName -> categoryRepository.findByName(categoryName)
|
if (categoryName == null || categoryName.isBlank()) continue;
|
||||||
.orElseGet(() -> CategoryEntity.builder().name(categoryName).build()))
|
|
||||||
.collect(Collectors.toSet());
|
CategoryEntity categoryEntity = categoryRepository.findByName(categoryName)
|
||||||
|
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build()));
|
||||||
|
|
||||||
|
newCategoryEntities.add(categoryEntity);
|
||||||
|
}
|
||||||
metadata.setCategories(newCategoryEntities);
|
metadata.setCategories(newCategoryEntities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -46,7 +46,6 @@ public class MetadataBackupRestoreService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (Files.exists(metadataFile)) {
|
if (Files.exists(metadataFile)) {
|
||||||
log.info("Backup already exists for book ID {}", bookEntity.getId());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component
|
|||||||
import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component';
|
import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component';
|
||||||
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';
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class BookDialogHelperService {
|
export class BookDialogHelperService {
|
||||||
@@ -51,4 +52,20 @@ export class BookDialogHelperService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openBulkMetadataEditDialog(bookIds: Set<number>): DynamicDialogRef {
|
||||||
|
return this.dialogService.open(BulkMetadataUpdateComponent, {
|
||||||
|
header: 'Bulk Edit Metadata',
|
||||||
|
modal: true,
|
||||||
|
closable: true,
|
||||||
|
style: {
|
||||||
|
width: '90vw',
|
||||||
|
maxWidth: '1200px',
|
||||||
|
position: 'absolute'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
bookIds: Array.from(bookIds)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,40 +215,40 @@
|
|||||||
<div class="book-browser-footer bg-[var(--card-background)] bg-opacity-10" [@slideInOut]>
|
<div class="book-browser-footer bg-[var(--card-background)] bg-opacity-10" [@slideInOut]>
|
||||||
<div class="flex justify-between gap-8">
|
<div class="flex justify-between gap-8">
|
||||||
@if (entityType$ | async; as entityType) {
|
@if (entityType$ | async; as entityType) {
|
||||||
@if (entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS || entityType === EntityType.UNSHELVED) {
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-bookmark-fill"
|
|
||||||
outlined="true"
|
|
||||||
severity="info"
|
|
||||||
(onClick)="openShelfAssigner()"
|
|
||||||
pTooltip="Assign to shelf"
|
|
||||||
tooltipPosition="top">
|
|
||||||
</p-button>
|
|
||||||
}
|
|
||||||
@if (entityType === EntityType.SHELF) {
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-bookmark"
|
|
||||||
outlined="true"
|
|
||||||
severity="info"
|
|
||||||
(click)="unshelfBooks()"
|
|
||||||
pTooltip="Remove from shelf"
|
|
||||||
tooltipPosition="top">
|
|
||||||
</p-button>
|
|
||||||
}
|
|
||||||
@if (userService.userState$ | async; as userData) {
|
@if (userService.userState$ | async; as userData) {
|
||||||
<div>
|
@if (userData.permissions.canEditMetadata) {
|
||||||
@if (userData.permissions.canEditMetadata) {
|
<p-tieredmenu #menu [model]="metadataMenuItems" [popup]="true" appendTo="body"/>
|
||||||
<p-button
|
<p-button
|
||||||
icon="pi pi-database"
|
(click)="menu.toggle($event)"
|
||||||
outlined="true"
|
tooltip="Metadata actions"
|
||||||
severity="info"
|
tooltipPosition="top"
|
||||||
(click)="updateMetadata()"
|
outlined="true"
|
||||||
pTooltip="Update metadata"
|
severity="info"
|
||||||
tooltipPosition="top">
|
icon="pi pi-database">
|
||||||
</p-button>
|
</p-button>
|
||||||
}
|
}
|
||||||
</div>
|
@if (entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS || entityType === EntityType.UNSHELVED) {
|
||||||
|
<p-button
|
||||||
|
icon="pi pi-bookmark-fill"
|
||||||
|
outlined="true"
|
||||||
|
severity="info"
|
||||||
|
(onClick)="openShelfAssigner()"
|
||||||
|
pTooltip="Assign to shelf"
|
||||||
|
tooltipPosition="top">
|
||||||
|
</p-button>
|
||||||
|
}
|
||||||
|
@if (entityType === EntityType.SHELF) {
|
||||||
|
<p-button
|
||||||
|
icon="pi pi-bookmark"
|
||||||
|
outlined="true"
|
||||||
|
severity="info"
|
||||||
|
(click)="unshelfBooks()"
|
||||||
|
pTooltip="Remove from shelf"
|
||||||
|
tooltipPosition="top">
|
||||||
|
</p-button>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<p-button
|
<p-button
|
||||||
outlined="true"
|
outlined="true"
|
||||||
icon="pi pi-lock"
|
icon="pi pi-lock"
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import {Popover} from 'primeng/popover';
|
|||||||
import {Slider} from 'primeng/slider';
|
import {Slider} from 'primeng/slider';
|
||||||
import {Select} from 'primeng/select';
|
import {Select} from 'primeng/select';
|
||||||
import {FilterSortPreferenceService} from './filters/filter-sorting-preferences.service';
|
import {FilterSortPreferenceService} from './filters/filter-sorting-preferences.service';
|
||||||
|
import {TieredMenu} from 'primeng/tieredmenu';
|
||||||
|
|
||||||
export enum EntityType {
|
export enum EntityType {
|
||||||
LIBRARY = 'Library',
|
LIBRARY = 'Library',
|
||||||
@@ -73,7 +74,7 @@ const SORT_DIRECTION = {
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './book-browser.component.html',
|
templateUrl: './book-browser.component.html',
|
||||||
styleUrls: ['./book-browser.component.scss'],
|
styleUrls: ['./book-browser.component.scss'],
|
||||||
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select],
|
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select, TieredMenu],
|
||||||
providers: [SeriesCollapseFilter],
|
providers: [SeriesCollapseFilter],
|
||||||
animations: [
|
animations: [
|
||||||
trigger('slideInOut', [
|
trigger('slideInOut', [
|
||||||
@@ -143,6 +144,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
lastAppliedSort: SortOption | null = null;
|
lastAppliedSort: SortOption | null = null;
|
||||||
filterVisibility = true;
|
filterVisibility = true;
|
||||||
private settingFiltersFromUrl = false;
|
private settingFiltersFromUrl = false;
|
||||||
|
protected metadataMenuItems: MenuItem[] | undefined;
|
||||||
|
|
||||||
get currentCardSize() {
|
get currentCardSize() {
|
||||||
return this.coverScalePreferenceService.currentCardSize;
|
return this.coverScalePreferenceService.currentCardSize;
|
||||||
@@ -192,6 +194,19 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.deselectAllBooks();
|
this.deselectAllBooks();
|
||||||
this.clearFilter();
|
this.clearFilter();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.metadataMenuItems = [
|
||||||
|
{
|
||||||
|
label: 'Refresh Metadata',
|
||||||
|
icon: 'pi pi-refresh',
|
||||||
|
command: () => this.updateMetadata()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Bulk Edit Metadata',
|
||||||
|
icon: 'pi pi-pencil',
|
||||||
|
command: () => this.bulkEditMetadata()
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
@@ -577,4 +592,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
updateMetadata(): void {
|
updateMetadata(): void {
|
||||||
this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks);
|
this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bulkEditMetadata(): void {
|
||||||
|
this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cover-container.shimmer {
|
.cover-container.shimmer {
|
||||||
background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
|
/*background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
|
||||||
background-size: 200% 100%;
|
background-size: 200% 100%;
|
||||||
animation: shimmer 2.5s infinite linear;
|
animation: shimmer 2.5s infinite linear;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes shimmer {
|
@keyframes shimmer {
|
||||||
|
|||||||
+131
@@ -0,0 +1,131 @@
|
|||||||
|
<div class="relative">
|
||||||
|
@if (loading) {
|
||||||
|
<div class="absolute inset-0 z-50 flex items-center justify-center bg-black/60">
|
||||||
|
<p-progressSpinner></p-progressSpinner>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div class="p-4 border border-gray-700 rounded-md mb-4 bg-gray-900 text-gray-200">
|
||||||
|
<div class="flex justify-between items-center mb-2">
|
||||||
|
<p class="text-base font-semibold">
|
||||||
|
Editing {{ books.length }} Book{{ books.length !== 1 ? 's' : '' }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
(click)="showBookList = !showBookList"
|
||||||
|
class="text-sm text-sky-400 hover:underline"
|
||||||
|
>
|
||||||
|
{{ showBookList ? 'Hide' : 'Show' }} Titles
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (showBookList) {
|
||||||
|
<div
|
||||||
|
class="max-h-48 overflow-y-auto border-t border-gray-700 pt-2 pl-1 text-sm text-gray-300"
|
||||||
|
>
|
||||||
|
<ul class="list-disc pl-5 space-y-1">
|
||||||
|
@for (book of books; track book) {
|
||||||
|
<li>{{ book.metadata?.title || 'Untitled Book' }}</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form [formGroup]="metadataForm" (ngSubmit)="onSubmit()" class="flex flex-col gap-4 w-full p-4">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<label for="authors" class="flex items-center gap-2">
|
||||||
|
Author(s)
|
||||||
|
<i
|
||||||
|
class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Enter multiple authors. Press Enter after typing each name."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer"
|
||||||
|
></i>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="w-full">
|
||||||
|
<p-chips
|
||||||
|
formControlName="authors"
|
||||||
|
addOnBlur="true"
|
||||||
|
></p-chips>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<label for="publisher">Publisher</label>
|
||||||
|
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-row flex-wrap gap-4">
|
||||||
|
<div class="flex flex-col gap-2 w-1/3">
|
||||||
|
<label for="language">Language</label>
|
||||||
|
<input pInputText id="language" formControlName="language" fluid/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 w-1/3">
|
||||||
|
<label for="seriesTotal">Total Books in Series</label>
|
||||||
|
<input
|
||||||
|
pInputText
|
||||||
|
id="seriesTotal"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
formControlName="seriesTotal"
|
||||||
|
fluid
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 w-1/4">
|
||||||
|
<label for="publishedDate">Published Date</label>
|
||||||
|
<p-datepicker
|
||||||
|
id="publishedDate"
|
||||||
|
formControlName="publishedDate"
|
||||||
|
dateFormat="yy-mm-dd"
|
||||||
|
showIcon
|
||||||
|
appendTo="body"
|
||||||
|
fluid></p-datepicker>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<label for="seriesName">Series Name</label>
|
||||||
|
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<label for="genres" class="flex items-center gap-2">
|
||||||
|
Genre(s)
|
||||||
|
<i
|
||||||
|
class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Enter multiple genres. Press Enter after typing each genre."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer"
|
||||||
|
></i>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="w-full">
|
||||||
|
<p-chips
|
||||||
|
formControlName="genres"
|
||||||
|
addOnBlur="true"
|
||||||
|
></p-chips>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2 mt-2">
|
||||||
|
<p-checkbox
|
||||||
|
inputId="mergeCategories"
|
||||||
|
name="mergeCategories"
|
||||||
|
[(ngModel)]="mergeCategories"
|
||||||
|
[ngModelOptions]="{ standalone: true }"
|
||||||
|
binary="true"
|
||||||
|
class="text-sm"
|
||||||
|
/>
|
||||||
|
<label for="mergeCategories" class="text-sm text-gray-300 cursor-pointer">
|
||||||
|
Keep existing categories and add new ones (uncheck to remove all existing categories)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end mt-4">
|
||||||
|
<p-button type="submit" label="Apply to Selected" [disabled]="loading"/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
::ng-deep .p-inputchips {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
|
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||||
|
import {CommonModule} from '@angular/common';
|
||||||
|
import {InputText} from 'primeng/inputtext';
|
||||||
|
import {Button} from 'primeng/button';
|
||||||
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
|
import {Chips} from 'primeng/chips';
|
||||||
|
import {DatePicker} from 'primeng/datepicker';
|
||||||
|
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
|
||||||
|
import {BookService} from '../../service/book.service';
|
||||||
|
import {Book, BulkMetadataUpdateRequest} from '../../model/book.model';
|
||||||
|
import {Checkbox} from 'primeng/checkbox';
|
||||||
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-bulk-metadata-update-component',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
InputText,
|
||||||
|
Button,
|
||||||
|
Tooltip,
|
||||||
|
Chips,
|
||||||
|
DatePicker,
|
||||||
|
FormsModule,
|
||||||
|
Checkbox,
|
||||||
|
ProgressSpinner
|
||||||
|
],
|
||||||
|
providers: [MessageService],
|
||||||
|
templateUrl: './bulk-metadata-update-component.html',
|
||||||
|
styleUrl: './bulk-metadata-update-component.scss'
|
||||||
|
})
|
||||||
|
export class BulkMetadataUpdateComponent implements OnInit {
|
||||||
|
metadataForm!: FormGroup;
|
||||||
|
bookIds: number[] = [];
|
||||||
|
books: Book[] = [];
|
||||||
|
showBookList = true;
|
||||||
|
mergeCategories = true;
|
||||||
|
loading = false;
|
||||||
|
|
||||||
|
private readonly config = inject(DynamicDialogConfig);
|
||||||
|
private readonly ref = inject(DynamicDialogRef);
|
||||||
|
private readonly fb = inject(FormBuilder);
|
||||||
|
private readonly bookService = inject(BookService);
|
||||||
|
private readonly messageService = inject(MessageService);
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.bookIds = this.config.data?.bookIds ?? [];
|
||||||
|
this.books = this.bookService.getBooksByIdsFromState(this.bookIds);
|
||||||
|
|
||||||
|
this.metadataForm = this.fb.group({
|
||||||
|
authors: [],
|
||||||
|
publisher: [''],
|
||||||
|
language: [''],
|
||||||
|
seriesName: [''],
|
||||||
|
seriesTotal: [''],
|
||||||
|
publishedDate: [null],
|
||||||
|
genres: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit(): void {
|
||||||
|
if (this.metadataForm.valid) {
|
||||||
|
const formValue = this.metadataForm.value;
|
||||||
|
|
||||||
|
const payload: BulkMetadataUpdateRequest = {
|
||||||
|
bookIds: this.bookIds,
|
||||||
|
authors: formValue.authors?.length ? formValue.authors : undefined,
|
||||||
|
publisher: formValue.publisher?.trim() || undefined,
|
||||||
|
language: formValue.language?.trim() || undefined,
|
||||||
|
seriesName: formValue.seriesName?.trim() || undefined,
|
||||||
|
seriesTotal: formValue.seriesTotal || undefined,
|
||||||
|
publishedDate: formValue.publishedDate
|
||||||
|
? new Date(formValue.publishedDate).toISOString().split('T')[0]
|
||||||
|
: undefined,
|
||||||
|
genres: formValue.genres?.length ? formValue.genres : undefined
|
||||||
|
};
|
||||||
|
this.loading = true;
|
||||||
|
this.bookService.updateBooksMetadata(payload, this.mergeCategories).subscribe({
|
||||||
|
next: (updatedBooks) => {
|
||||||
|
this.loading = false;
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Metadata Updated',
|
||||||
|
detail: `${updatedBooks.length} book${updatedBooks.length > 1 ? 's' : ''} updated successfully`,
|
||||||
|
});
|
||||||
|
this.ref.close(true);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error('Bulk metadata update failed:', error);
|
||||||
|
this.loading = false;
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Update Failed',
|
||||||
|
detail: 'An error occurred while updating book metadata',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -148,3 +148,14 @@ export const enum PdfPageSpread {
|
|||||||
EVEN = 'EVEN',
|
EVEN = 'EVEN',
|
||||||
ODD = 'ODD',
|
ODD = 'ODD',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BulkMetadataUpdateRequest {
|
||||||
|
bookIds: number[];
|
||||||
|
authors?: string[];
|
||||||
|
publisher?: string;
|
||||||
|
language?: string;
|
||||||
|
seriesName?: string;
|
||||||
|
seriesTotal?: number;
|
||||||
|
publishedDate?: string;
|
||||||
|
genres?: string[];
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {inject, Injectable} from '@angular/core';
|
|||||||
import {BehaviorSubject, first, Observable, of} from 'rxjs';
|
import {BehaviorSubject, first, Observable, of} from 'rxjs';
|
||||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
import {catchError, filter, map, tap} from 'rxjs/operators';
|
import {catchError, filter, map, tap} from 'rxjs/operators';
|
||||||
import {Book, BookMetadata, BookRecommendation, BookSetting} from '../model/book.model';
|
import {Book, BookMetadata, BookRecommendation, BookSetting, BulkMetadataUpdateRequest} from '../model/book.model';
|
||||||
import {BookState} from '../model/state/book-state.model';
|
import {BookState} from '../model/state/book-state.model';
|
||||||
import {API_CONFIG} from '../../config/api-config';
|
import {API_CONFIG} from '../../config/api-config';
|
||||||
import {FetchMetadataRequest} from '../metadata/model/request/fetch-metadata-request.model';
|
import {FetchMetadataRequest} from '../metadata/model/request/fetch-metadata-request.model';
|
||||||
@@ -55,6 +55,14 @@ export class BookService {
|
|||||||
return currentState.books?.find(book => +book.id === +bookId);
|
return currentState.books?.find(book => +book.id === +bookId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBooksByIdsFromState(bookIds: number[]): Book[] {
|
||||||
|
const currentState = this.bookStateSubject.value;
|
||||||
|
if (!currentState.books || bookIds.length === 0) return [];
|
||||||
|
|
||||||
|
const idSet = new Set(bookIds.map(id => +id));
|
||||||
|
return currentState.books.filter(book => idSet.has(+book.id));
|
||||||
|
}
|
||||||
|
|
||||||
updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | undefined>, shelvesToUnassign: Set<number | undefined>): Observable<Book[]> {
|
updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | undefined>, shelvesToUnassign: Set<number | undefined>): Observable<Book[]> {
|
||||||
const requestPayload = {
|
const requestPayload = {
|
||||||
bookIds: Array.from(bookIds),
|
bookIds: Array.from(bookIds),
|
||||||
@@ -252,6 +260,18 @@ export class BookService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBooksMetadata(request: BulkMetadataUpdateRequest, mergeCategories: boolean): Observable<BookMetadata[]> {
|
||||||
|
const params = new HttpParams().set('mergeCategories', mergeCategories.toString());
|
||||||
|
return this.http.put<BookMetadata[]>(`${this.url}/bulk-edit-metadata`, request, {params}).pipe(
|
||||||
|
map(updatedMetadataList => {
|
||||||
|
request.bookIds.forEach((id, index) => {
|
||||||
|
this.handleBookMetadataUpdate(id, updatedMetadataList[index]);
|
||||||
|
});
|
||||||
|
return updatedMetadataList;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toggleAllLock(bookIds: Set<number>, lock: string): Observable<void> {
|
toggleAllLock(bookIds: Set<number>, lock: string): Observable<void> {
|
||||||
const requestBody = {
|
const requestBody = {
|
||||||
bookIds: Array.from(bookIds),
|
bookIds: Array.from(bookIds),
|
||||||
|
|||||||
Reference in New Issue
Block a user