Fix book setting logic
This commit is contained in:
+1
-1
@@ -8,6 +8,6 @@ import lombok.Data;
|
||||
public class BookViewerSetting {
|
||||
private int pageNumber;
|
||||
private String zoom;
|
||||
private boolean sidebar_visible;
|
||||
private Boolean sidebar_visible;
|
||||
private String spread;
|
||||
}
|
||||
+1
-1
@@ -31,6 +31,6 @@ public class AppSettings {
|
||||
public static class PdfSettings {
|
||||
private String spread;
|
||||
private String zoom;
|
||||
private boolean sidebar;
|
||||
private Boolean sidebar;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class BookViewerSettingEntity {
|
||||
private String zoom;
|
||||
|
||||
@Column(name = "sidebar_visible")
|
||||
private boolean sidebar_visible;
|
||||
private Boolean sidebar_visible;
|
||||
|
||||
@Column(name = "spread")
|
||||
private String spread;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class BooksService {
|
||||
bookViewerSetting.setPageNumber(bookViewerSettingDTO.getPageNumber());
|
||||
bookViewerSetting.setZoom(bookViewerSettingDTO.getZoom());
|
||||
bookViewerSetting.setSpread(bookViewerSettingDTO.getSpread());
|
||||
bookViewerSetting.setSidebar_visible(bookViewerSettingDTO.isSidebar_visible());
|
||||
bookViewerSetting.setSidebar_visible(bookViewerSettingDTO.getSidebar_visible());
|
||||
bookViewerSettingRepository.save(bookViewerSetting);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ CREATE TABLE IF NOT EXISTS category
|
||||
CREATE TABLE IF NOT EXISTS book_viewer_setting
|
||||
(
|
||||
book_id BIGINT PRIMARY KEY,
|
||||
page_number INT DEFAULT 1,
|
||||
zoom VARCHAR(16) DEFAULT 'page-fit',
|
||||
sidebar_visible BOOLEAN DEFAULT false,
|
||||
spread VARCHAR(16) DEFAULT 'odd',
|
||||
page_number INT NULL,
|
||||
zoom VARCHAR(16) NULL,
|
||||
sidebar_visible BOOLEAN NULL,
|
||||
spread VARCHAR(16) NULL,
|
||||
CONSTRAINT fk_book_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
@@ -108,7 +108,7 @@ CREATE TABLE app_settings
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
category VARCHAR(255) NOT NULL,
|
||||
key1 VARCHAR (255) NOT NULL,
|
||||
key1 VARCHAR(255) NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
UNIQUE (category, key1)
|
||||
);
|
||||
@@ -8,5 +8,5 @@ VALUES ('epub', 'theme', 'white'),
|
||||
|
||||
INSERT INTO app_settings (category, key1, value)
|
||||
VALUES ('pdf', 'spread', 'odd'),
|
||||
('pdf', 'zoom', 'page_fit'),
|
||||
('pdf', 'zoom', 'page-fit'),
|
||||
('pdf', 'sidebar', 'true');
|
||||
@@ -1,12 +1,9 @@
|
||||
import {Component, inject, NgZone, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {NgxExtendedPdfViewerModule, ScrollModeType} from 'ngx-extended-pdf-viewer';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {forkJoin, Observable, of, Subscription} from 'rxjs';
|
||||
import {BookState} from '../../model/state/book-state.model';
|
||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {catchError, switchMap} from 'rxjs/operators';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-viewer',
|
||||
@@ -15,16 +12,18 @@ import {catchError, switchMap} from 'rxjs/operators';
|
||||
templateUrl: './pdf-viewer.component.html',
|
||||
})
|
||||
export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
bookId!: number;
|
||||
handTool = true;
|
||||
page = 1;
|
||||
rotation: 0 | 90 | 180 | 270 = 0;
|
||||
scrollMode: ScrollModeType = ScrollModeType.page;
|
||||
|
||||
sidebarVisible!: boolean;
|
||||
page!: number;
|
||||
spread!: 'off' | 'even' | 'odd';
|
||||
zoom!: number | string;
|
||||
|
||||
private isInitialLoad = true;
|
||||
bookData!: string | Blob;
|
||||
bookId!: number;
|
||||
private appSettingsSubscription!: Subscription;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
@@ -47,7 +46,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
const {pageNumber, zoom, sidebar_visible, spread} = bookSetting;
|
||||
this.page = pageNumber || 1;
|
||||
this.zoom = zoom || appSettings.pdf?.zoom || 'page-fit';
|
||||
this.sidebarVisible = sidebar_visible ?? appSettings.pdf?.sidebar ?? false;
|
||||
this.sidebarVisible = sidebar_visible ?? appSettings.pdf?.sidebar ?? true;
|
||||
this.spread = spread || appSettings.pdf?.spread || 'odd';
|
||||
this.isInitialLoad = false;
|
||||
this.bookService.getBookData(bookId).subscribe({
|
||||
|
||||
@@ -67,6 +67,6 @@ export interface Category {
|
||||
export interface BookSetting {
|
||||
pageNumber: number;
|
||||
zoom: number | string;
|
||||
sidebar_visible: boolean;
|
||||
sidebar_visible: boolean | null;
|
||||
spread: 'off' | 'even' | 'odd';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user