Remove zone from pdf reader
This commit is contained in:
@@ -39,10 +39,6 @@ public class BookCreatorService {
|
|||||||
BookViewerSettingEntity bookViewerSetting = BookViewerSettingEntity.builder()
|
BookViewerSettingEntity bookViewerSetting = BookViewerSettingEntity.builder()
|
||||||
.book(bookEntity)
|
.book(bookEntity)
|
||||||
.bookId(bookEntity.getId())
|
.bookId(bookEntity.getId())
|
||||||
.pageNumber(1)
|
|
||||||
.sidebar_visible(true)
|
|
||||||
.spread("odd")
|
|
||||||
.zoom("page-fit")
|
|
||||||
.build();
|
.build();
|
||||||
bookEntity.setMetadata(bookMetadataEntity);
|
bookEntity.setMetadata(bookMetadataEntity);
|
||||||
bookEntity.setViewerSetting(bookViewerSetting);
|
bookEntity.setViewerSetting(bookViewerSetting);
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ VALUES ('epub', 'theme', 'white'),
|
|||||||
('epub', 'font', 'serif');
|
('epub', 'font', 'serif');
|
||||||
|
|
||||||
INSERT INTO app_settings (category, key1, value)
|
INSERT INTO app_settings (category, key1, value)
|
||||||
VALUES ('pdf', 'spread', 'even_spread'),
|
VALUES ('pdf', 'spread', 'odd'),
|
||||||
('pdf', 'zoom', 'page_fit'),
|
('pdf', 'zoom', 'page_fit'),
|
||||||
('pdf', 'sidebar', 'true');
|
('pdf', 'sidebar', 'true');
|
||||||
@@ -7,6 +7,7 @@ import {parseLogNotification} from './shared/websocket/model/log-notification.mo
|
|||||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||||
import {Toast} from 'primeng/toast';
|
import {Toast} from 'primeng/toast';
|
||||||
import {RouterOutlet} from '@angular/router';
|
import {RouterOutlet} from '@angular/router';
|
||||||
|
import {AppSettingsService} from './core/service/app-settings.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -20,6 +21,7 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
this.rxStompService.watch('/topic/book-add').subscribe((message: Message) => {
|
this.rxStompService.watch('/topic/book-add').subscribe((message: Message) => {
|
||||||
this.bookService.handleNewlyCreatedBook(JSON.parse(message.body));
|
this.bookService.handleNewlyCreatedBook(JSON.parse(message.body));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<ngx-extended-pdf-viewer
|
<ngx-extended-pdf-viewer
|
||||||
[src]="getSrc()"
|
[src]="bookData"
|
||||||
[handTool]="handTool"
|
[handTool]="handTool"
|
||||||
[height]="'auto'"
|
[height]="'auto'"
|
||||||
[page]="page"
|
[page]="page"
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ import {Component, NgZone, 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 {forkJoin, Observable, Subscription} from 'rxjs';
|
||||||
|
import {BookState} from '../../model/state/book-state.model';
|
||||||
|
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-pdf-viewer',
|
selector: 'app-pdf-viewer',
|
||||||
@@ -15,17 +19,17 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
page = 1;
|
page = 1;
|
||||||
rotation: 0 | 90 | 180 | 270 = 0;
|
rotation: 0 | 90 | 180 | 270 = 0;
|
||||||
scrollMode: ScrollModeType = ScrollModeType.page;
|
scrollMode: ScrollModeType = ScrollModeType.page;
|
||||||
sidebarVisible = false;
|
sidebarVisible!: boolean;
|
||||||
spread: 'off' | 'even' | 'odd' = 'odd';
|
spread!: 'off' | 'even' | 'odd';
|
||||||
src = '';
|
zoom!: number | string;
|
||||||
zoom: number | string = 'page-fit';
|
|
||||||
private isInitialLoad = true;
|
private isInitialLoad = true;
|
||||||
|
|
||||||
constructor(
|
bookData!: string | Blob;
|
||||||
private bookService: BookService,
|
|
||||||
private zone: NgZone,
|
private appSettingsSubscription!: Subscription;
|
||||||
private route: ActivatedRoute
|
|
||||||
) {}
|
constructor(private bookService: BookService, private route: ActivatedRoute) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.paramMap.subscribe((params) => {
|
this.route.paramMap.subscribe((params) => {
|
||||||
@@ -35,34 +39,23 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.updateLastReadTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
private loadBook(bookId: number): void {
|
private loadBook(bookId: number): void {
|
||||||
this.bookService.getBookById(bookId).subscribe(() => {
|
forkJoin({
|
||||||
this.zone.run(() => {
|
bookSetting: this.bookService.getBookSetting(bookId),
|
||||||
this.bookService.getBookSetting(bookId).subscribe((bookSetting) => {
|
bookData: this.bookService.getBookData(bookId),
|
||||||
|
}).subscribe({
|
||||||
|
next: ({bookSetting, bookData}) => {
|
||||||
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 || 'page-fit';
|
this.zoom = zoom || 'page-fit';
|
||||||
this.sidebarVisible = sidebar_visible || false;
|
this.sidebarVisible = sidebar_visible ?? false;
|
||||||
this.spread = spread || 'odd';
|
this.spread = spread || 'odd';
|
||||||
this.isInitialLoad = false;
|
this.isInitialLoad = false;
|
||||||
});
|
this.bookData = bookData;
|
||||||
});
|
}, error: (e) => {
|
||||||
});
|
console.log('Error loading book!', e)
|
||||||
}
|
}
|
||||||
|
});
|
||||||
private updateViewerSetting(): void {
|
|
||||||
if (this.isInitialLoad) return;
|
|
||||||
const updatedViewerSetting = {
|
|
||||||
pageNumber: this.page,
|
|
||||||
zoom: this.zoom,
|
|
||||||
sidebar_visible: this.sidebarVisible,
|
|
||||||
spread: this.spread,
|
|
||||||
};
|
|
||||||
this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateLastReadTime(): void {
|
private updateLastReadTime(): void {
|
||||||
@@ -70,7 +63,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPageChange(page: number): void {
|
onPageChange(page: number): void {
|
||||||
console.log('page', page);
|
|
||||||
if (page !== this.page) {
|
if (page !== this.page) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
@@ -78,7 +70,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onZoomChange(zoom: string | number): void {
|
onZoomChange(zoom: string | number): void {
|
||||||
console.log('zoom', zoom);
|
|
||||||
if (zoom !== this.zoom) {
|
if (zoom !== this.zoom) {
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
@@ -86,7 +77,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSidebarVisibleChange(visible: boolean): void {
|
onSidebarVisibleChange(visible: boolean): void {
|
||||||
console.log('sidebarVisible', visible);
|
|
||||||
if (visible !== this.sidebarVisible) {
|
if (visible !== this.sidebarVisible) {
|
||||||
this.sidebarVisible = visible;
|
this.sidebarVisible = visible;
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
@@ -100,7 +90,20 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSrc(): string {
|
private updateViewerSetting(): void {
|
||||||
return this.bookService.getBookDataUrl(this.bookId);
|
if (this.isInitialLoad) return;
|
||||||
|
const updatedViewerSetting = {
|
||||||
|
sidebar_visible: this.sidebarVisible,
|
||||||
|
spread: this.spread,
|
||||||
|
zoom: this.zoom,
|
||||||
|
};
|
||||||
|
this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.updateLastReadTime();
|
||||||
|
if (this.appSettingsSubscription) {
|
||||||
|
this.appSettingsSubscription.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,8 +143,9 @@ export class BookService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBookDataUrl(bookId: number): string {
|
getBookData(bookId: number): Observable<Blob> {
|
||||||
return `${this.url}/${bookId}/data`;
|
console.log('Fetching book data...');
|
||||||
|
return this.http.get<Blob>(`${this.url}/${bookId}/data`, { responseType: 'blob' as 'json' });
|
||||||
}
|
}
|
||||||
|
|
||||||
getBookCoverUrl(bookId: number): string {
|
getBookCoverUrl(bookId: number): string {
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import {Button} from 'primeng/button';
|
|||||||
})
|
})
|
||||||
export class SettingsComponent implements OnInit {
|
export class SettingsComponent implements OnInit {
|
||||||
spreads = [
|
spreads = [
|
||||||
{name: 'Even Spread', key: 'even_spread'},
|
{name: 'Even Spread', key: 'even'},
|
||||||
{name: 'Odd Spread', key: 'odd_spread'},
|
{name: 'Odd Spread', key: 'odd'},
|
||||||
{name: 'No Spread', key: 'no_spread'}
|
{name: 'No Spread', key: 'off'}
|
||||||
];
|
];
|
||||||
zooms = [
|
zooms = [
|
||||||
{name: 'Auto Zoom', key: 'auto_zoom'},
|
{name: 'Auto Zoom', key: 'auto_zoom'},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export interface EpubSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PdfSettings {
|
export interface PdfSettings {
|
||||||
spread: string;
|
spread: 'off' | 'even' | 'odd';
|
||||||
zoom: string;
|
zoom: string;
|
||||||
sidebar: boolean;
|
sidebar: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user