Enhance Quick Metadata Refresh Functionality

This commit is contained in:
aditya.chandel
2025-05-28 17:46:30 -07:00
committed by Aditya Chandel
parent da6decb349
commit 40294019f5
13 changed files with 125 additions and 60 deletions
@@ -203,9 +203,12 @@ public class BookMetadataService {
metadataCombined.setAsin(metadata.getAsin() != null ? metadata.getAsin() : metadataCombined.getAsin()); metadataCombined.setAsin(metadata.getAsin() != null ? metadata.getAsin() : metadataCombined.getAsin());
metadataCombined.setPageCount(metadata.getPageCount() != null ? metadata.getPageCount() : metadataCombined.getPageCount()); metadataCombined.setPageCount(metadata.getPageCount() != null ? metadata.getPageCount() : metadataCombined.getPageCount());
metadataCombined.setLanguage(metadata.getLanguage() != null ? metadata.getLanguage() : metadataCombined.getLanguage()); metadataCombined.setLanguage(metadata.getLanguage() != null ? metadata.getLanguage() : metadataCombined.getLanguage());
metadataCombined.setRating(metadata.getRating() != null ? metadata.getRating() : metadataCombined.getRating()); metadataCombined.setGoodreadsRating(metadata.getGoodreadsRating() != null ? metadata.getGoodreadsRating() : metadataCombined.getGoodreadsRating());
metadataCombined.setRatingCount(metadata.getRatingCount() != null ? metadata.getRatingCount() : metadataCombined.getRatingCount()); metadataCombined.setGoodreadsReviewCount(metadata.getGoodreadsReviewCount() != null ? metadata.getGoodreadsReviewCount() : metadataCombined.getGoodreadsReviewCount());
metadataCombined.setReviewCount(metadata.getReviewCount() != null ? metadata.getReviewCount() : metadataCombined.getReviewCount()); metadataCombined.setAmazonRating(metadata.getAmazonRating() != null ? metadata.getAmazonRating() : metadataCombined.getAmazonRating());
metadataCombined.setAmazonReviewCount(metadata.getAmazonReviewCount() != null ? metadata.getAmazonReviewCount() : metadataCombined.getAmazonReviewCount());
metadataCombined.setHardcoverRating(metadata.getHardcoverRating() != null ? metadata.getHardcoverRating() : metadataCombined.getHardcoverRating());
metadataCombined.setHardcoverReviewCount(metadata.getHardcoverReviewCount() != null ? metadata.getHardcoverReviewCount() : metadataCombined.getHardcoverReviewCount());
metadataCombined.setAwards(metadata.getAwards() != null ? metadata.getAwards() : metadataCombined.getAwards()); metadataCombined.setAwards(metadata.getAwards() != null ? metadata.getAwards() : metadataCombined.getAwards());
metadataCombined.setSeriesName(metadata.getSeriesName() != null ? metadata.getSeriesName() : metadataCombined.getSeriesName()); metadataCombined.setSeriesName(metadata.getSeriesName() != null ? metadata.getSeriesName() : metadataCombined.getSeriesName());
metadataCombined.setSeriesNumber(metadata.getSeriesNumber() != null ? metadata.getSeriesNumber() : metadataCombined.getSeriesNumber()); metadataCombined.setSeriesNumber(metadata.getSeriesNumber() != null ? metadata.getSeriesNumber() : metadataCombined.getSeriesNumber());
@@ -389,11 +392,23 @@ public class BookMetadataService {
case "language": case "language":
existingMetadata.setLanguageLocked(isLocked); existingMetadata.setLanguageLocked(isLocked);
break; break;
case "rating": case "amazonRating":
existingMetadata.setRatingLocked(isLocked); existingMetadata.setAmazonRatingLocked(isLocked);
break; break;
case "reviewCount": case "amazonReviewCount":
existingMetadata.setReviewCountLocked(isLocked); existingMetadata.setAmazonReviewCountLocked(isLocked);
break;
case "goodreadsRating":
existingMetadata.setGoodreadsRatingLocked(isLocked);
break;
case "goodreadsReviewCount":
existingMetadata.setGoodreadsReviewCountLocked(isLocked);
break;
case "hardcoverRating":
existingMetadata.setHardcoverRatingLocked(isLocked);
break;
case "hardcoverReviewCount":
existingMetadata.setHardcoverReviewCountLocked(isLocked);
break; break;
default: default:
throw new IllegalArgumentException("Invalid field name: " + field); throw new IllegalArgumentException("Invalid field name: " + field);
@@ -460,6 +475,6 @@ public class BookMetadataService {
.peek(book -> book.getMetadata().applyLockToAllFields(lock)) .peek(book -> book.getMetadata().applyLockToAllFields(lock))
.toList(); .toList();
bookRepository.saveAll(books); bookRepository.saveAll(books);
return books.stream().map(b ->bookMetadataMapper.toBookMetadata(b.getMetadata(), false)).collect(Collectors.toList()); return books.stream().map(b -> bookMetadataMapper.toBookMetadata(b.getMetadata(), false)).collect(Collectors.toList());
} }
} }
@@ -47,27 +47,21 @@ public class BookMetadataUpdater {
if ((metadata.getTitleLocked() == null || !metadata.getTitleLocked()) && newMetadata.getTitle() != null) { if ((metadata.getTitleLocked() == null || !metadata.getTitleLocked()) && newMetadata.getTitle() != null) {
metadata.setTitle(newMetadata.getTitle().isEmpty() ? null : newMetadata.getTitle()); metadata.setTitle(newMetadata.getTitle().isEmpty() ? null : newMetadata.getTitle());
} }
if ((metadata.getSubtitleLocked() == null || !metadata.getSubtitleLocked()) && newMetadata.getSubtitle() != null) { if ((metadata.getSubtitleLocked() == null || !metadata.getSubtitleLocked()) && newMetadata.getSubtitle() != null) {
metadata.setSubtitle(newMetadata.getSubtitle().isBlank() ? null : newMetadata.getSubtitle()); metadata.setSubtitle(newMetadata.getSubtitle().isBlank() ? null : newMetadata.getSubtitle());
} }
if ((metadata.getPublisherLocked() == null || !metadata.getPublisherLocked()) && newMetadata.getPublisher() != null) { if ((metadata.getPublisherLocked() == null || !metadata.getPublisherLocked()) && newMetadata.getPublisher() != null) {
metadata.setPublisher(newMetadata.getPublisher().isBlank() ? null : newMetadata.getPublisher()); metadata.setPublisher(newMetadata.getPublisher().isBlank() ? null : newMetadata.getPublisher());
} }
if ((metadata.getPublishedDateLocked() == null || !metadata.getPublishedDateLocked()) && newMetadata.getPublishedDate() != null) { if ((metadata.getPublishedDateLocked() == null || !metadata.getPublishedDateLocked()) && newMetadata.getPublishedDate() != null) {
metadata.setPublishedDate(newMetadata.getPublishedDate()); metadata.setPublishedDate(newMetadata.getPublishedDate());
} }
if ((metadata.getLanguageLocked() == null || !metadata.getLanguageLocked()) && newMetadata.getLanguage() != null) { if ((metadata.getLanguageLocked() == null || !metadata.getLanguageLocked()) && newMetadata.getLanguage() != null) {
metadata.setLanguage(newMetadata.getLanguage().isBlank() ? null : newMetadata.getLanguage()); metadata.setLanguage(newMetadata.getLanguage().isBlank() ? null : newMetadata.getLanguage());
} }
if ((metadata.getIsbn10Locked() == null || !metadata.getIsbn10Locked()) && newMetadata.getIsbn10() != null) { if ((metadata.getIsbn10Locked() == null || !metadata.getIsbn10Locked()) && newMetadata.getIsbn10() != null) {
metadata.setIsbn10(newMetadata.getIsbn10().isBlank() ? null : newMetadata.getIsbn10()); metadata.setIsbn10(newMetadata.getIsbn10().isBlank() ? null : newMetadata.getIsbn10());
} }
if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) { if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) {
metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13()); metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13());
} }
@@ -77,47 +71,36 @@ public class BookMetadataUpdater {
if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) { if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) {
metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription()); metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription());
} }
if ((metadata.getPageCountLocked() == null || !metadata.getPageCountLocked()) && newMetadata.getPageCount() != null) { if ((metadata.getPageCountLocked() == null || !metadata.getPageCountLocked()) && newMetadata.getPageCount() != null) {
metadata.setPageCount(newMetadata.getPageCount()); metadata.setPageCount(newMetadata.getPageCount());
} }
if ((metadata.getAmazonRatingLocked() == null || !metadata.getAmazonRatingLocked()) && newMetadata.getAmazonRating() != null) { if ((metadata.getAmazonRatingLocked() == null || !metadata.getAmazonRatingLocked()) && newMetadata.getAmazonRating() != null) {
metadata.setAmazonRating(newMetadata.getAmazonRating()); metadata.setAmazonRating(newMetadata.getAmazonRating());
} }
if ((metadata.getAmazonReviewCountLocked() == null || !metadata.getAmazonReviewCountLocked()) && newMetadata.getAmazonReviewCount() != null) { if ((metadata.getAmazonReviewCountLocked() == null || !metadata.getAmazonReviewCountLocked()) && newMetadata.getAmazonReviewCount() != null) {
metadata.setAmazonReviewCount(newMetadata.getAmazonReviewCount()); metadata.setAmazonReviewCount(newMetadata.getAmazonReviewCount());
} }
if ((metadata.getGoodreadsRatingLocked() == null || !metadata.getGoodreadsRatingLocked()) && newMetadata.getGoodreadsRating() != null) { if ((metadata.getGoodreadsRatingLocked() == null || !metadata.getGoodreadsRatingLocked()) && newMetadata.getGoodreadsRating() != null) {
metadata.setGoodreadsRating(newMetadata.getGoodreadsRating()); metadata.setGoodreadsRating(newMetadata.getGoodreadsRating());
} }
if ((metadata.getGoodreadsReviewCountLocked() == null || !metadata.getGoodreadsReviewCountLocked()) && newMetadata.getGoodreadsReviewCount() != null) { if ((metadata.getGoodreadsReviewCountLocked() == null || !metadata.getGoodreadsReviewCountLocked()) && newMetadata.getGoodreadsReviewCount() != null) {
metadata.setGoodreadsReviewCount(newMetadata.getGoodreadsReviewCount()); metadata.setGoodreadsReviewCount(newMetadata.getGoodreadsReviewCount());
} }
if ((metadata.getHardcoverRatingLocked() == null || !metadata.getHardcoverRatingLocked()) && newMetadata.getHardcoverRating() != null) { if ((metadata.getHardcoverRatingLocked() == null || !metadata.getHardcoverRatingLocked()) && newMetadata.getHardcoverRating() != null) {
metadata.setHardcoverRating(newMetadata.getHardcoverRating()); metadata.setHardcoverRating(newMetadata.getHardcoverRating());
} }
if ((metadata.getHardcoverReviewCountLocked() == null || !metadata.getHardcoverReviewCountLocked()) && newMetadata.getHardcoverReviewCount() != null) { if ((metadata.getHardcoverReviewCountLocked() == null || !metadata.getHardcoverReviewCountLocked()) && newMetadata.getHardcoverReviewCount() != null) {
metadata.setHardcoverReviewCount(newMetadata.getHardcoverReviewCount()); metadata.setHardcoverReviewCount(newMetadata.getHardcoverReviewCount());
} }
if ((metadata.getSeriesNameLocked() == null || !metadata.getSeriesNameLocked()) && newMetadata.getSeriesName() != null) { if ((metadata.getSeriesNameLocked() == null || !metadata.getSeriesNameLocked()) && newMetadata.getSeriesName() != null) {
metadata.setSeriesName(newMetadata.getSeriesName()); metadata.setSeriesName(newMetadata.getSeriesName());
} }
if ((metadata.getSeriesNumberLocked() == null || !metadata.getSeriesNumberLocked()) && newMetadata.getSeriesNumber() != null) { if ((metadata.getSeriesNumberLocked() == null || !metadata.getSeriesNumberLocked()) && newMetadata.getSeriesNumber() != null) {
metadata.setSeriesNumber(newMetadata.getSeriesNumber()); metadata.setSeriesNumber(newMetadata.getSeriesNumber());
} }
if ((metadata.getSeriesTotalLocked() == null || !metadata.getSeriesTotalLocked()) && newMetadata.getSeriesTotal() != null) { if ((metadata.getSeriesTotalLocked() == null || !metadata.getSeriesTotalLocked()) && newMetadata.getSeriesTotal() != null) {
metadata.setSeriesTotal(newMetadata.getSeriesTotal()); metadata.setSeriesTotal(newMetadata.getSeriesTotal());
} }
if (newMetadata.getAwards() != null && !newMetadata.getAwards().isEmpty()) { if (newMetadata.getAwards() != null && !newMetadata.getAwards().isEmpty()) {
HashSet<BookAwardEntity> newAwards = new HashSet<>(); HashSet<BookAwardEntity> newAwards = new HashSet<>();
newMetadata.getAwards() newMetadata.getAwards()
@@ -293,7 +293,7 @@ public class AmazonBookParser implements BookParser {
if (seriesNameElement != null) { if (seriesNameElement != null) {
return seriesNameElement.text(); return seriesNameElement.text();
} else { } else {
log.warn("Failed to parse seriesName: Element not found."); log.debug("Failed to parse seriesName: Element not found.");
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to parse seriesName: {}", e.getMessage()); log.warn("Failed to parse seriesName: {}", e.getMessage());
@@ -311,7 +311,7 @@ public class AmazonBookParser implements BookParser {
return Float.parseFloat(parts[1]); return Float.parseFloat(parts[1]);
} }
} else { } else {
log.warn("Failed to parse seriesNumber: Element not found."); log.debug("Failed to parse seriesNumber: Element not found.");
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to parse seriesNumber: {}", e.getMessage()); log.warn("Failed to parse seriesNumber: {}", e.getMessage());
@@ -329,7 +329,7 @@ public class AmazonBookParser implements BookParser {
return Integer.parseInt(parts[3]); return Integer.parseInt(parts[3]);
} }
} else { } else {
log.warn("Failed to parse seriesTotal: Element not found."); log.debug("Failed to parse seriesTotal: Element not found.");
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to parse seriesTotal: {}", e.getMessage()); log.warn("Failed to parse seriesTotal: {}", e.getMessage());
@@ -343,7 +343,7 @@ public class AmazonBookParser implements BookParser {
if (languageElement != null) { if (languageElement != null) {
return languageElement.text(); return languageElement.text();
} }
log.warn("Failed to parse language: Element not found."); log.debug("Failed to parse language: Element not found.");
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to parse language: {}", e.getMessage()); log.warn("Failed to parse language: {}", e.getMessage());
} }
@@ -24,6 +24,8 @@ public class HardcoverParser implements BookParser {
@Override @Override
public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
log.info("Hardcover: Fetching metadata for book {}", fetchMetadataRequest.getTitle());
List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle()); List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle());
return hits.stream().map(hit -> { return hits.stream().map(hit -> {
@@ -78,6 +80,6 @@ public class HardcoverParser implements BookParser {
@Override @Override
public BookMetadata fetchTopMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { public BookMetadata fetchTopMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
List<BookMetadata> bookMetadata = fetchMetadata(book, fetchMetadataRequest); List<BookMetadata> bookMetadata = fetchMetadata(book, fetchMetadataRequest);
return bookMetadata.getFirst(); return bookMetadata.isEmpty() ? null : bookMetadata.getFirst();
} }
} }
@@ -7,6 +7,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -51,14 +52,25 @@ public class HardcoverBookSearchService {
body.setQuery(graphqlQuery); body.setQuery(graphqlQuery);
body.setOperationName("SearchBooks"); body.setOperationName("SearchBooks");
GraphQLResponse response = restClient.post() try {
.uri("") GraphQLResponse response = restClient.post()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .uri("")
.header(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(body) .header(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken)
.retrieve() .body(body)
.body(GraphQLResponse.class); .retrieve()
.body(GraphQLResponse.class);
return response.getData().getSearch().getResults().getHits(); if (response == null || response.getData() == null || response.getData().getSearch() == null || response.getData().getSearch().getResults() == null) {
log.warn("Empty or malformed response from Hardcover API");
return Collections.emptyList();
}
return response.getData().getSearch().getResults().getHits();
} catch (RestClientException e) {
log.error("Failed to fetch data from Hardcover API, Error: {}", e.getMessage());
return Collections.emptyList();
}
} }
} }
@@ -457,9 +457,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
bookIds: this.selectedBooks bookIds: this.selectedBooks
}, },
}); });
this.dynamicDialogRef.onClose.subscribe(() => {
this.selectedBooks.clear();
});
} }
updateMetadata() { updateMetadata() {
@@ -133,8 +133,10 @@
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button> <p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
<p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined <p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined
(onClick)="download(metadata.bookId)"></p-button> (onClick)="download(metadata.bookId)"></p-button>
<p-splitbutton *ngIf="userData.permissions.canEmailBook || userData.permissions.admin" label="Quick Send" icon="pi pi-send" [model]="items" <p-splitbutton *ngIf="userData.permissions.canEmailBook || userData.permissions.admin" label="Quick Send" icon="pi pi-send" [model]="emailMenuItems"
(onClick)="quickSend(metadata.bookId)" outlined severity="info"/> (onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
<p-splitbutton *ngIf="userData.permissions.canEditMetadata || userData.permissions.admin" label="Quick Refresh" icon="pi pi-bolt" [model]="refreshMenuItems"
(onClick)="quickRefresh(metadata.bookId)" outlined severity="info"/>
</div> </div>
</div> </div>
</div> </div>
@@ -24,6 +24,9 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Editor} from 'primeng/editor'; import {Editor} from 'primeng/editor';
import {ProgressBar} from 'primeng/progressbar'; import {ProgressBar} from 'primeng/progressbar';
import {ToggleButton} from 'primeng/togglebutton'; import {ToggleButton} from 'primeng/togglebutton';
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
@Component({ @Component({
selector: 'app-metadata-viewer', selector: 'app-metadata-viewer',
@@ -50,13 +53,14 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
private destroyRef = inject(DestroyRef); private destroyRef = inject(DestroyRef);
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$; metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
items: MenuItem[] | undefined; emailMenuItems: MenuItem[] | undefined;
refreshMenuItems: MenuItem[] | undefined;
bookInSeries: Book[] = []; bookInSeries: Book[] = [];
isExpanded = false; isExpanded = false;
showFilePath = false; showFilePath = false;
ngOnInit(): void { ngOnInit(): void {
this.items = [ this.emailMenuItems = [
{ {
label: 'Custom Send', label: 'Custom Send',
command: () => { command: () => {
@@ -80,6 +84,24 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
} }
]; ];
this.refreshMenuItems = [
{
label: 'Granular Refresh',
icon: 'pi pi-database',
command: () => {
this.dialogService.open(MetadataFetchOptionsComponent, {
header: 'Metadata Refresh Options',
modal: true,
closable: true,
data: {
bookIds: [this.book!.id],
metadataRefreshType: MetadataRefreshType.BOOKS,
},
});
},
}
];
this.metadata$ this.metadata$
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((metadata) => { .subscribe((metadata) => {
@@ -134,6 +156,15 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
this.bookService.downloadFile(bookId); this.bookService.downloadFile(bookId);
} }
quickRefresh(bookId: number) {
const metadataRefreshRequest: MetadataRefreshRequest = {
quick: true,
refreshType: MetadataRefreshType.BOOKS,
bookIds: [bookId],
};
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
}
quickSend(bookId: number) { quickSend(bookId: number) {
this.emailService.emailBookQuick(bookId).subscribe({ this.emailService.emailBookQuick(bookId).subscribe({
next: () => { next: () => {
@@ -191,7 +222,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
getProgressPercent(): number | undefined { getProgressPercent(): number | undefined {
if (this.book?.bookType === 'PDF') { if (this.book?.bookType === 'PDF') {
return this.book.pdfProgress?.percentage; return this.book.pdfProgress?.percentage;
} else if(this.book?.bookType === 'CBX') { } else if (this.book?.bookType === 'CBX') {
return this.book?.cbxProgress?.percentage; return this.book?.cbxProgress?.percentage;
} else { } else {
return this.book?.epubProgress?.percentage; return this.book?.epubProgress?.percentage;
@@ -201,9 +232,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
copyFilePath() { copyFilePath() {
if (this.book?.filePath) { if (this.book?.filePath) {
navigator.clipboard.writeText(this.book.filePath).then(() => { navigator.clipboard.writeText(this.book.filePath).then(() => {
this.messageService.add({ severity: 'success', summary: 'Copied', detail: 'File path copied to clipboard.' }); this.messageService.add({severity: 'success', summary: 'Copied', detail: 'File path copied to clipboard.'});
}, () => { }, () => {
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to copy file path.' }); this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to copy file path.'});
}); });
} }
} }
@@ -219,12 +250,18 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
if (!fileType) return 'bg-gray-500 text-white'; if (!fileType) return 'bg-gray-500 text-white';
switch (fileType.toLowerCase()) { switch (fileType.toLowerCase()) {
case 'pdf': return 'bg-red-700 text-white'; case 'pdf':
case 'epub': return 'bg-yellow-600 text-gray-900'; return 'bg-red-700 text-white';
case 'cbz': return 'bg-green-700 text-white'; case 'epub':
case 'cbr': return 'bg-purple-700 text-white'; return 'bg-yellow-600 text-gray-900';
case 'cb7': return 'bg-blue-700 text-white'; case 'cbz':
default: return 'bg-gray-600 text-white'; return 'bg-green-700 text-white';
case 'cbr':
return 'bg-purple-700 text-white';
case 'cb7':
return 'bg-blue-700 text-white';
default:
return 'bg-gray-600 text-white';
} }
} }
@@ -72,7 +72,7 @@
</div> </div>
<div class="flex flex-row gap-6"> <div class="flex flex-row gap-6">
<p-button severity="warn" outlined="true" label="Reset" (onClick)="reset()"></p-button> <p-button severity="warn" outlined="true" label="Reset" (onClick)="reset()"></p-button>
<p-button label="Save" outlined="true" (onClick)="submit()"></p-button> <p-button [label]="submitButtonLabel" outlined="true" (onClick)="submit()"></p-button>
</div> </div>
</div> </div>
@@ -36,6 +36,7 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
private messageService = inject(MessageService); private messageService = inject(MessageService);
@Input() currentMetadataOptions!: MetadataRefreshOptions; @Input() currentMetadataOptions!: MetadataRefreshOptions;
@Input() submitButtonLabel!: string;
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
@@ -1,5 +1,7 @@
<div class="flex flex-col space-y-6"> <div class="flex flex-col space-y-6">
<app-metadata-advanced-fetch-options
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)"></app-metadata-advanced-fetch-options> (metadataOptionsSubmitted)="onMetadataSubmit($event)"
[currentMetadataOptions]="currentMetadataOptions"
[submitButtonLabel]="'Start Refresh'">
</app-metadata-advanced-fetch-options>
</div> </div>
@@ -1,10 +1,12 @@
import {Component, inject} from '@angular/core'; import {Component, inject, Input} from '@angular/core';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component'; import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model'; import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum'; import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model'; import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
import {BookService} from '../../../service/book.service'; import {BookService} from '../../../service/book.service';
import {AppSettingsService} from '../../../../core/service/app-settings.service';
import {filter, take} from 'rxjs/operators';
@Component({ @Component({
selector: 'app-metadata-fetch-options', selector: 'app-metadata-fetch-options',
@@ -19,15 +21,23 @@ export class MetadataFetchOptionsComponent {
libraryId!: number; libraryId!: number;
bookIds!: number[]; bookIds!: number[];
metadataRefreshType!: MetadataRefreshType; metadataRefreshType!: MetadataRefreshType;
currentMetadataOptions!: MetadataRefreshOptions;
private dynamicDialogConfig = inject(DynamicDialogConfig); private dynamicDialogConfig = inject(DynamicDialogConfig);
private dynamicDialogRef = inject(DynamicDialogRef); private dynamicDialogRef = inject(DynamicDialogRef);
private bookService = inject(BookService); private bookService = inject(BookService);
private appSettingsService = inject(AppSettingsService);
constructor() { constructor() {
this.libraryId = this.dynamicDialogConfig.data.libraryId; this.libraryId = this.dynamicDialogConfig.data.libraryId;
this.bookIds = this.dynamicDialogConfig.data.bookIds; this.bookIds = this.dynamicDialogConfig.data.bookIds;
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType; this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
this.appSettingsService.appSettings$.pipe(
filter(settings => settings != null),
take(1)
).subscribe(settings => {
this.currentMetadataOptions = settings?.metadataRefreshOptions;
});
} }
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) { onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) {
@@ -170,7 +170,11 @@
style="cursor: pointer;"> style="cursor: pointer;">
</i> </i>
</p> </p>
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)" [currentMetadataOptions]="currentMetadataOptions"></app-metadata-advanced-fetch-options> <app-metadata-advanced-fetch-options
(metadataOptionsSubmitted)="onMetadataSubmit($event)"
[currentMetadataOptions]="currentMetadataOptions"
[submitButtonLabel]="'Save'">
</app-metadata-advanced-fetch-options>
</div> </div>
</div> </div>