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