Complete global vs individual settings
This commit is contained in:
+1
-1
@@ -8,4 +8,4 @@ import lombok.Data;
|
||||
public class BookViewerSettings {
|
||||
private PdfViewerPreferences pdfSettings;
|
||||
private EpubViewerPreferences epubSettings;
|
||||
}
|
||||
}
|
||||
+14
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+26
-5
@@ -19,17 +19,38 @@ public class AppSettingService {
|
||||
|
||||
public AppSettings getAppSettings() {
|
||||
List<AppSettingEntity> settings = appSettingsRepository.findAll();
|
||||
Map<String, Map<String, String>> settingsMap = settings.stream().collect(Collectors.groupingBy(AppSettingEntity::getCategory, Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal)));
|
||||
AppSettings appSettings = new AppSettings();
|
||||
Map<String, Map<String, String>> settingsMap = settings.stream()
|
||||
.collect(Collectors.groupingBy(AppSettingEntity::getCategory,
|
||||
Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal)));
|
||||
|
||||
AppSettings.AppSettingsBuilder appSettingsBuilder = AppSettings.builder();
|
||||
|
||||
if (settingsMap.containsKey("epub")) {
|
||||
Map<String, String> 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<String, String> 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<String, String> 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
|
||||
|
||||
+4
-2
@@ -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) {
|
||||
|
||||
+6
-4
@@ -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;
|
||||
}
|
||||
|
||||
+4
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
+3
-5
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,4 +26,4 @@ public class DateUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,4 +84,4 @@ public class FileService {
|
||||
return appProperties.getPathConfig() + "/thumbs/missing/m.jpg";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+1
-15
@@ -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,
|
||||
|
||||
@@ -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');
|
||||
('pdf', 'sidebar', 'true');
|
||||
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES ('reader_setting', 'pdf', 'individual'),
|
||||
('reader_setting', 'epub', 'individual');
|
||||
@@ -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 {
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
[inputId]="item"
|
||||
name="spread"
|
||||
[value]="item"
|
||||
[(ngModel)]="selectedPdf"
|
||||
(ngModelChange)="onPdfIndividualOrGlobalChange()">
|
||||
[(ngModel)]="selectedPdfScope"
|
||||
(ngModelChange)="onPdfScopeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="item">{{ item }}</label>
|
||||
</div>
|
||||
@@ -33,8 +33,8 @@
|
||||
[inputId]="item"
|
||||
name="spread"
|
||||
[value]="item"
|
||||
[(ngModel)]="selectedEpub"
|
||||
(ngModelChange)="onEpubIndividualOrGlobalChange()">
|
||||
[(ngModel)]="selectedEpubScope"
|
||||
(ngModelChange)="onEpubScopeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="item">{{ item }}</label>
|
||||
</div>
|
||||
|
||||
@@ -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<AppSettings | null> = 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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user