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