diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookViewerSettings.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookViewerSettings.java index 5a872b208..0dc1f0bad 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookViewerSettings.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookViewerSettings.java @@ -8,4 +8,4 @@ import lombok.Data; public class BookViewerSettings { private PdfViewerPreferences pdfSettings; private EpubViewerPreferences epubSettings; -} +} \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/AppSettings.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/AppSettings.java index 6ba7a5cc9..a349b2005 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/AppSettings.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/AppSettings.java @@ -1,6 +1,5 @@ package com.adityachandel.booklore.model.dto.settings; -import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -13,6 +12,7 @@ import lombok.NoArgsConstructor; public class AppSettings { private EpubSettings epub; private PdfSettings pdf; + private ReaderSettings readerSettings; @Data @Builder @@ -33,4 +33,17 @@ public class AppSettings { private String zoom; private Boolean sidebar; } + + @Data + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class ReaderSettings { + private SettingScope pdfScope; + private SettingScope epubScope; + } + + public enum SettingScope { + Global, Individual + } } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java index 5ffac11a0..d021d1824 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java @@ -19,17 +19,38 @@ public class AppSettingService { public AppSettings getAppSettings() { List settings = appSettingsRepository.findAll(); - Map> settingsMap = settings.stream().collect(Collectors.groupingBy(AppSettingEntity::getCategory, Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal))); - AppSettings appSettings = new AppSettings(); + Map> settingsMap = settings.stream() + .collect(Collectors.groupingBy(AppSettingEntity::getCategory, + Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal))); + + AppSettings.AppSettingsBuilder appSettingsBuilder = AppSettings.builder(); + if (settingsMap.containsKey("epub")) { Map epubSettings = settingsMap.get("epub"); - appSettings.setEpub(new AppSettings.EpubSettings(epubSettings.get("theme"), epubSettings.get("fontSize"), epubSettings.get("font"))); + appSettingsBuilder.epub(AppSettings.EpubSettings.builder() + .theme(epubSettings.get("theme")) + .fontSize(epubSettings.get("fontSize")) + .font(epubSettings.get("font")) + .build()); } + if (settingsMap.containsKey("pdf")) { Map pdfSettings = settingsMap.get("pdf"); - appSettings.setPdf(new AppSettings.PdfSettings(pdfSettings.get("spread"), pdfSettings.get("zoom"), Boolean.parseBoolean(pdfSettings.get("sidebar")))); + appSettingsBuilder.pdf(AppSettings.PdfSettings.builder() + .spread(pdfSettings.get("spread")) + .zoom(pdfSettings.get("zoom")) + .sidebar(Boolean.parseBoolean(pdfSettings.get("sidebar"))) + .build()); } - return appSettings; + + if (settingsMap.containsKey("reader_setting")) { + Map readerSetting = settingsMap.get("reader_setting"); + appSettingsBuilder.readerSettings(AppSettings.ReaderSettings.builder() + .pdfScope(AppSettings.SettingScope.valueOf(readerSetting.get("pdf"))) + .epubScope(AppSettings.SettingScope.valueOf(readerSetting.get("epub"))) + .build()); + } + return appSettingsBuilder.build(); } @Transactional diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java index 96b409e5c..2f8fc47a8 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java @@ -8,6 +8,8 @@ import com.adityachandel.booklore.model.entity.LibraryPathEntity; import com.adityachandel.booklore.model.enums.BookFileType; import com.adityachandel.booklore.model.websocket.Topic; import com.adityachandel.booklore.repository.LibraryRepository; +import com.adityachandel.booklore.service.fileprocessor.EpubProcessor; +import com.adityachandel.booklore.service.fileprocessor.PdfProcessor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -30,8 +32,8 @@ public class FileUploadService { private static final String EPUB_MIME_TYPE = "application/epub+zip"; private final LibraryRepository libraryRepository; - private final PdfFileProcessor pdfProcessor; - private final EpubFileProcessor epubProcessor; + private final PdfProcessor pdfProcessor; + private final EpubProcessor epubProcessor; private final NotificationService notificationService; public Book uploadFile(MultipartFile file, long libraryId, long pathId) { diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java index 7d944e04a..e1b4033ae 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java @@ -10,6 +10,8 @@ import com.adityachandel.booklore.model.enums.BookFileType; import com.adityachandel.booklore.model.websocket.Topic; import com.adityachandel.booklore.repository.BookRepository; import com.adityachandel.booklore.repository.LibraryRepository; +import com.adityachandel.booklore.service.fileprocessor.EpubProcessor; +import com.adityachandel.booklore.service.fileprocessor.PdfProcessor; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -32,8 +34,8 @@ public class LibraryProcessingService { private final LibraryRepository libraryRepository; private final NotificationService notificationService; - private final PdfFileProcessor pdfFileProcessor; - private final EpubFileProcessor epubFileProcessor; + private final PdfProcessor pdfProcessor; + private final EpubProcessor epubProcessor; private final BookRepository bookRepository; @@ -81,9 +83,9 @@ public class LibraryProcessingService { @Transactional protected Book processLibraryFile(LibraryFile libraryFile) { if (libraryFile.getBookFileType() == BookFileType.PDF) { - return pdfFileProcessor.processFile(libraryFile, false); + return pdfProcessor.processFile(libraryFile, false); } else if (libraryFile.getBookFileType() == BookFileType.EPUB) { - return epubFileProcessor.processFile(libraryFile, false); + return epubProcessor.processFile(libraryFile, false); } return null; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/EpubFileProcessor.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/EpubProcessor.java similarity index 96% rename from booklore-api/src/main/java/com/adityachandel/booklore/service/EpubFileProcessor.java rename to booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/EpubProcessor.java index fa257bb3a..6a58c21a4 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/EpubFileProcessor.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/EpubProcessor.java @@ -1,4 +1,4 @@ -package com.adityachandel.booklore.service; +package com.adityachandel.booklore.service.fileprocessor; import com.adityachandel.booklore.mapper.BookMapper; import com.adityachandel.booklore.model.LibraryFile; @@ -7,7 +7,7 @@ import com.adityachandel.booklore.model.entity.BookEntity; import com.adityachandel.booklore.model.entity.BookMetadataEntity; import com.adityachandel.booklore.model.enums.BookFileType; import com.adityachandel.booklore.repository.BookRepository; -import com.adityachandel.booklore.service.fileprocessing.FileProcessingUtils; +import com.adityachandel.booklore.service.BookCreatorService; import io.documentnode.epub4j.domain.Identifier; import io.documentnode.epub4j.domain.Metadata; import io.documentnode.epub4j.domain.Resource; @@ -35,7 +35,7 @@ import java.util.stream.Collectors; @Slf4j @Service @AllArgsConstructor -public class EpubFileProcessor implements FileProcessor { +public class EpubProcessor implements FileProcessor { private final BookRepository bookRepository; private final BookCreatorService bookCreatorService; @@ -92,7 +92,7 @@ public class EpubFileProcessor implements FileProcessor { .collect(Collectors.toSet()); } - private void setBookMetadata(io.documentnode.epub4j.domain.Book book, BookEntity bookEntity){ + private void setBookMetadata(io.documentnode.epub4j.domain.Book book, BookEntity bookEntity) { BookMetadataEntity bookMetadata = bookEntity.getMetadata(); Metadata epubMetadata = book.getMetadata(); @@ -162,5 +162,4 @@ public class EpubFileProcessor implements FileProcessor { return false; } } - } \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessing/FileProcessingUtils.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessingUtils.java similarity index 94% rename from booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessing/FileProcessingUtils.java rename to booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessingUtils.java index 5f0c9d5bc..af31050bf 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessing/FileProcessingUtils.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessingUtils.java @@ -1,9 +1,8 @@ -package com.adityachandel.booklore.service.fileprocessing; +package com.adityachandel.booklore.service.fileprocessor; import com.adityachandel.booklore.config.AppProperties; import com.adityachandel.booklore.model.entity.BookMetadataEntity; import lombok.AllArgsConstructor; -import org.apache.pdfbox.rendering.ImageType; import org.springframework.stereotype.Service; import javax.imageio.ImageIO; diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileProcessor.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessor.java similarity index 78% rename from booklore-api/src/main/java/com/adityachandel/booklore/service/FileProcessor.java rename to booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessor.java index bace90e8e..f7d32622d 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileProcessor.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/FileProcessor.java @@ -1,4 +1,4 @@ -package com.adityachandel.booklore.service; +package com.adityachandel.booklore.service.fileprocessor; import com.adityachandel.booklore.model.LibraryFile; import com.adityachandel.booklore.model.dto.Book; diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/PdfFileProcessor.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/PdfProcessor.java similarity index 94% rename from booklore-api/src/main/java/com/adityachandel/booklore/service/PdfFileProcessor.java rename to booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/PdfProcessor.java index 9adeed74b..053ab67f4 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/PdfFileProcessor.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/fileprocessor/PdfProcessor.java @@ -1,13 +1,12 @@ -package com.adityachandel.booklore.service; +package com.adityachandel.booklore.service.fileprocessor; import com.adityachandel.booklore.mapper.BookMapper; import com.adityachandel.booklore.model.LibraryFile; import com.adityachandel.booklore.model.dto.Book; import com.adityachandel.booklore.model.entity.BookEntity; -import com.adityachandel.booklore.model.entity.BookMetadataEntity; import com.adityachandel.booklore.model.enums.BookFileType; import com.adityachandel.booklore.repository.BookRepository; -import com.adityachandel.booklore.service.fileprocessing.FileProcessingUtils; +import com.adityachandel.booklore.service.BookCreatorService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.pdfbox.Loader; @@ -30,7 +29,7 @@ import java.util.stream.Collectors; @Slf4j @Service @AllArgsConstructor -public class PdfFileProcessor implements FileProcessor { +public class PdfProcessor implements FileProcessor { private final BookRepository bookRepository; private final BookCreatorService bookCreatorService; @@ -107,5 +106,4 @@ public class PdfFileProcessor implements FileProcessor { BufferedImage coverImage = new PDFRenderer(document).renderImageWithDPI(0, 300, ImageType.RGB); return fileProcessingUtils.saveCoverImage(coverImage, bookId); } - } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/util/DateUtils.java b/booklore-api/src/main/java/com/adityachandel/booklore/util/DateUtils.java index 0e91933fb..862f38efe 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/util/DateUtils.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/util/DateUtils.java @@ -26,4 +26,4 @@ public class DateUtils { return null; } } -} +} \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java b/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java index c7f34ba11..8d3954efb 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java @@ -84,4 +84,4 @@ public class FileService { return appProperties.getPathConfig() + "/thumbs/missing/m.jpg"; } -} +} \ No newline at end of file diff --git a/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql b/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql index b0757d33d..4fc7e12cd 100644 --- a/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql +++ b/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql @@ -1,4 +1,3 @@ --- Create the library table CREATE TABLE IF NOT EXISTS library ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -7,7 +6,6 @@ CREATE TABLE IF NOT EXISTS library icon VARCHAR(64) NOT NULL ); --- Create the library_path table CREATE TABLE IF NOT EXISTS library_path ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -16,7 +14,6 @@ CREATE TABLE IF NOT EXISTS library_path CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id) ); --- Create the book table CREATE TABLE IF NOT EXISTS book ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -33,11 +30,9 @@ CREATE TABLE IF NOT EXISTS book CONSTRAINT unique_file_library UNIQUE (file_name, library_id) ); --- Create indexes for the book table CREATE INDEX IF NOT EXISTS idx_library_id ON book (library_id); CREATE INDEX IF NOT EXISTS idx_last_read_time ON book (last_read_time); --- Create the book_metadata table CREATE TABLE IF NOT EXISTS book_metadata ( book_id BIGINT NOT NULL PRIMARY KEY, @@ -56,7 +51,6 @@ CREATE TABLE IF NOT EXISTS book_metadata CONSTRAINT fk_book_metadata FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE ); --- Create the author table CREATE TABLE IF NOT EXISTS author ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -64,14 +58,12 @@ CREATE TABLE IF NOT EXISTS author CONSTRAINT unique_name UNIQUE (name) ); --- Create the category table CREATE TABLE IF NOT EXISTS category ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL UNIQUE ); --- Create the book_viewer_setting table CREATE TABLE IF NOT EXISTS pdf_viewer_preference ( book_id BIGINT PRIMARY KEY, @@ -86,11 +78,10 @@ CREATE TABLE IF NOT EXISTS epub_viewer_preference book_id BIGINT PRIMARY KEY, theme VARCHAR(128) NULL, font VARCHAR(128) NULL, - font_size TINYINT NULL, + font_size INT NULL, CONSTRAINT fk_epub_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE ); --- Create the book_metadata_category_mapping table CREATE TABLE IF NOT EXISTS book_metadata_category_mapping ( book_id BIGINT NOT NULL, @@ -100,7 +91,6 @@ CREATE TABLE IF NOT EXISTS book_metadata_category_mapping CONSTRAINT fk_book_metadata_category_mapping_category FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE ); --- Create the book_metadata_author_mapping table CREATE TABLE IF NOT EXISTS book_metadata_author_mapping ( book_id BIGINT NOT NULL, @@ -110,11 +100,9 @@ CREATE TABLE IF NOT EXISTS book_metadata_author_mapping CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE ); --- Create indexes for the book_metadata_author_mapping table CREATE INDEX IF NOT EXISTS idx_book_metadata_id ON book_metadata_author_mapping (book_id); CREATE INDEX IF NOT EXISTS idx_author_id ON book_metadata_author_mapping (author_id); --- Create the shelf table CREATE TABLE IF NOT EXISTS shelf ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -123,7 +111,6 @@ CREATE TABLE IF NOT EXISTS shelf icon VARCHAR(64) NOT NULL ); --- Create the book_shelf_mapping table CREATE TABLE IF NOT EXISTS book_shelf_mapping ( book_id BIGINT NOT NULL, @@ -133,7 +120,6 @@ CREATE TABLE IF NOT EXISTS book_shelf_mapping CONSTRAINT fk_book_shelf_mapping_shelf FOREIGN KEY (shelf_id) REFERENCES shelf (id) ON DELETE CASCADE ); --- Create the app_settings table CREATE TABLE app_settings ( id BIGINT AUTO_INCREMENT PRIMARY KEY, diff --git a/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql b/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql index 28e16f534..84d9f8cea 100644 --- a/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql +++ b/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql @@ -9,4 +9,8 @@ VALUES ('epub', 'theme', 'white'), INSERT INTO app_settings (category, name, val) VALUES ('pdf', 'spread', 'odd'), ('pdf', 'zoom', 'page-fit'), - ('pdf', 'sidebar', 'true'); \ No newline at end of file + ('pdf', 'sidebar', 'true'); + +INSERT INTO app_settings (category, name, val) +VALUES ('reader_setting', 'pdf', 'individual'), + ('reader_setting', 'epub', 'individual'); \ No newline at end of file diff --git a/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts b/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts index 47365baad..39b159674 100644 --- a/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts +++ b/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts @@ -4,7 +4,7 @@ import {NgxExtendedPdfViewerModule, ScrollModeType} from 'ngx-extended-pdf-viewe import {BookService} from '../../service/book.service'; import {AppSettingsService} from '../../../core/service/app-settings.service'; import {filter, forkJoin, Subscription, take} from 'rxjs'; -import {PdfViewerSetting} from '../../model/book.model'; +import {BookSetting, PdfViewerSetting} from '../../model/book.model'; @Component({ selector: 'app-pdf-viewer', @@ -34,10 +34,12 @@ export class PdfViewerComponent implements OnInit, OnDestroy { ngOnInit(): void { this.route.paramMap.subscribe((params) => { this.bookId = +params.get('bookId')!; + this.appSettingsService.appSettings$ .pipe( filter((appSettings) => appSettings !== null), - take(1)) + take(1) + ) .subscribe((appSettings) => { const book$ = this.bookService.getBookByIdFromAPI(this.bookId, false); const pdf$ = this.bookService.getPdfData(this.bookId); @@ -48,15 +50,19 @@ export class PdfViewerComponent implements OnInit, OnDestroy { const pdfData = results[1]; const individualPdfSettings = results[2]?.pdfSettings; const globalPdfSettings = appSettings.pdf; - - console.log(individualPdfSettings); - console.log(globalPdfSettings); + const pdfScope = appSettings?.readerSettings?.pdfScope; this.page = pdf.pdfProgress || 1; - this.zoom = individualPdfSettings?.zoom || globalPdfSettings?.zoom || 'page-fit'; - this.sidebarVisible = individualPdfSettings?.sidebarVisible ?? globalPdfSettings?.sidebar ?? true; - this.spread = individualPdfSettings?.spread || globalPdfSettings?.spread || 'odd'; + if (pdfScope === 'Global') { + this.zoom = globalPdfSettings?.zoom || 'page-fit'; + this.sidebarVisible = globalPdfSettings?.sidebar ?? true; + this.spread = globalPdfSettings?.spread || 'odd'; + } else { + this.zoom = individualPdfSettings?.zoom || globalPdfSettings?.zoom || 'page-fit'; + this.sidebarVisible = individualPdfSettings?.sidebarVisible ?? globalPdfSettings?.sidebar ?? true; + this.spread = individualPdfSettings?.spread || globalPdfSettings?.spread || 'odd'; + } this.isInitialLoad = false; this.bookData = pdfData; this.updateLastReadTime(); @@ -99,12 +105,14 @@ export class PdfViewerComponent implements OnInit, OnDestroy { private updateViewerSetting(): void { if (this.isInitialLoad) return; - const updatedViewerSetting: PdfViewerSetting = { - sidebarVisible: this.sidebarVisible, - spread: this.spread, - zoom: this.zoom, - }; - this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe(); + const bookSetting: BookSetting = { + pdfSettings: { + sidebarVisible: this.sidebarVisible, + spread: this.spread, + zoom: this.zoom, + } + } + this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe(); } ngOnDestroy(): void { diff --git a/booklore-ui/src/app/core/component/settings/settings.component.html b/booklore-ui/src/app/core/component/settings/settings.component.html index 6c767e08d..1bbbdc5fd 100644 --- a/booklore-ui/src/app/core/component/settings/settings.component.html +++ b/booklore-ui/src/app/core/component/settings/settings.component.html @@ -19,8 +19,8 @@ [inputId]="item" name="spread" [value]="item" - [(ngModel)]="selectedPdf" - (ngModelChange)="onPdfIndividualOrGlobalChange()"> + [(ngModel)]="selectedPdfScope" + (ngModelChange)="onPdfScopeChange()"> @@ -33,8 +33,8 @@ [inputId]="item" name="spread" [value]="item" - [(ngModel)]="selectedEpub" - (ngModelChange)="onEpubIndividualOrGlobalChange()"> + [(ngModel)]="selectedEpubScope" + (ngModelChange)="onEpubScopeChange()"> diff --git a/booklore-ui/src/app/core/component/settings/settings.component.ts b/booklore-ui/src/app/core/component/settings/settings.component.ts index e027919d3..1b4bf1c70 100644 --- a/booklore-ui/src/app/core/component/settings/settings.component.ts +++ b/booklore-ui/src/app/core/component/settings/settings.component.ts @@ -58,8 +58,8 @@ export class SettingsComponent implements OnInit { selectedTheme!: any; fontSize: number = 100; selectedFont: any; - selectedPdf!: string; - selectedEpub!: string; + selectedPdfScope!: string; + selectedEpubScope!: string; private appSettingsService = inject(AppSettingsService); appSettings$: Observable = this.appSettingsService.appSettings$; @@ -87,6 +87,11 @@ export class SettingsComponent implements OnInit { this.fontSize = Number(epubSettings.fontSize); this.selectedFont = this.fonts.find(f => f.key === epubSettings.font)?.key; } + + if (settings.readerSettings) { + this.selectedPdfScope = settings.readerSettings.pdfScope; + this.selectedEpubScope = settings.readerSettings.epubScope; + } } onThemeChange(): void { @@ -113,6 +118,14 @@ export class SettingsComponent implements OnInit { this.appSettingsService.saveAppSetting('epub', 'fontSize', this.fontSize); } + onPdfScopeChange(): void { + this.appSettingsService.saveAppSetting('reader_setting', 'pdf', this.selectedPdfScope); + } + + onEpubScopeChange(): void { + this.appSettingsService.saveAppSetting('reader_setting', 'epub', this.selectedEpubScope); + } + increaseFontSize(): void { if (this.fontSize < 250) { this.fontSize += 10; @@ -126,12 +139,4 @@ export class SettingsComponent implements OnInit { this.onFontSizeChange(); } } - - onPdfIndividualOrGlobalChange() { - - } - - onEpubIndividualOrGlobalChange() { - - } } diff --git a/booklore-ui/src/app/core/model/app-settings.model.ts b/booklore-ui/src/app/core/model/app-settings.model.ts index db7e64fb8..183f63e1b 100644 --- a/booklore-ui/src/app/core/model/app-settings.model.ts +++ b/booklore-ui/src/app/core/model/app-settings.model.ts @@ -12,7 +12,13 @@ export interface PdfSettings { page: number; } +export interface ReaderSettings { + pdfScope: 'Global' | 'Individual'; + epubScope: 'Global' | 'Individual'; +} + export interface AppSettings { epub?: EpubSettings; pdf?: PdfSettings; + readerSettings?: ReaderSettings; } diff --git a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts index 1a513248e..e132db0e3 100644 --- a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts +++ b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts @@ -79,6 +79,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy { const epubData = results[1]; const individualSetting = results[2]?.epubSettings; const globalSetting = appSettings.epub; + const epubScope = appSettings?.readerSettings?.epubScope; this.epub = epub; const fileReader = new FileReader(); @@ -110,10 +111,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy { this.rendition.themes.register(name, theme); }); - this.selectedTheme = individualSetting?.theme || globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme; - this.selectedFontType = individualSetting?.font || globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType; - this.fontSize = individualSetting?.fontSize || globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize; - + if (epubScope === 'Global') { + this.selectedTheme = globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme; + this.selectedFontType = globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType; + this.fontSize = globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize; + } else { + this.selectedTheme = individualSetting?.theme || globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme; + this.selectedFontType = individualSetting?.font || globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType; + this.fontSize = individualSetting?.fontSize || globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize; + } + this.rendition.themes.select(this.selectedTheme); this.rendition.themes.fontSize(`${this.fontSize}%`); this.rendition.themes.font(this.selectedFontType);