Implement cover size selection and regeneration
This commit is contained in:
committed by
Aditya Chandel
parent
bf87f030f8
commit
9e6640f27f
@@ -0,0 +1,32 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
<p class="text-xl pb-4 pt-6">Book Cover Image</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Resolution:
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Specifies the resolution of the generated cover image. Higher resolutions result in sharper images but may increase file size. This setting will apply to future books, or else use 'Regenerate' button."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
[options]="resolutionOptions"
|
||||
[(ngModel)]="selectedResolution"
|
||||
(ngModelChange)="onResolutionChange()"
|
||||
placeholder="Select Resolution">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="text-lg py-1">Regenerate Covers?
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="This option will regenerate the covers for all EPUB and PDF books (except locked ones) using the selected resolution and image quality."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<p-button label="Regenerate" icon="pi pi-refresh" (onClick)="regenerateCovers()"></p-button>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Divider} from "primeng/divider";
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {AppSettingsService} from '../core/service/app-settings.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettings} from '../core/model/app-settings.model';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {BookService} from '../book/service/book.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-global-preferences',
|
||||
imports: [
|
||||
Divider,
|
||||
DropdownModule,
|
||||
FormsModule,
|
||||
Select,
|
||||
Button,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './global-preferences.component.html',
|
||||
styleUrl: './global-preferences.component.scss'
|
||||
})
|
||||
export class GlobalPreferencesComponent implements OnInit {
|
||||
|
||||
resolutionOptions = [
|
||||
{label: '250x350', value: '250x350'},
|
||||
{label: '375x525', value: '375x525'},
|
||||
{label: '500x700', value: '500x700'},
|
||||
{label: '625x875', value: '625x875'}
|
||||
];
|
||||
|
||||
selectedResolution: string | undefined = '250x350';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.subscribe(settings => {
|
||||
if (settings?.coverSettings) {
|
||||
this.selectedResolution = settings.coverSettings.resolution;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onResolutionChange(): void {
|
||||
if (this.selectedResolution) {
|
||||
this.onSaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
onSaveSettings(): void {
|
||||
const settingsToSave = [
|
||||
{key: 'cover_image_resolution', newValue: this.selectedResolution}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Settings Saved', detail: 'The settings were successfully saved!'});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'There was an error saving the settings.'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
regenerateCovers(): void {
|
||||
this.bookService.regenerateCovers().subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Cover Regeneration Started',
|
||||
detail: 'Book covers are being regenerated.'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to start cover regeneration.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user