Complete global vs individual settings
This commit is contained in:
@@ -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