refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
@if (isLoading) {
|
||||
<div class="loading-container">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!isLoading) {
|
||||
<ngx-extended-pdf-viewer
|
||||
[src]="bookData"
|
||||
[authorization]="authorization"
|
||||
[textLayer]="true"
|
||||
[showHandToolButton]="true"
|
||||
[height]="'auto'"
|
||||
[theme]="isDarkTheme ? 'dark' : 'light'"
|
||||
[page]="page"
|
||||
[rotation]="rotation"
|
||||
[zoom]="zoom"
|
||||
[spread]="spread"
|
||||
[enablePrint]="canPrint"
|
||||
[customToolbar]="additionalButtons"
|
||||
(pagesLoaded)="onPdfPagesLoaded($event)"
|
||||
(pageChange)="onPageChange($event)"
|
||||
(zoomChange)="onZoomChange($event)"
|
||||
(spreadChange)="onSpreadChange($event)"
|
||||
(annotationEditorEvent)="onAnnotationEditorEvent()">
|
||||
</ngx-extended-pdf-viewer>
|
||||
|
||||
<ng-template #additionalButtons>
|
||||
<div id="toolbarViewer">
|
||||
<div id="toolbarViewerLeft">
|
||||
<pdf-toggle-sidebar></pdf-toggle-sidebar>
|
||||
<pdf-find-button></pdf-find-button>
|
||||
<pdf-paging-area></pdf-paging-area>
|
||||
</div>
|
||||
<pdf-zoom-toolbar></pdf-zoom-toolbar>
|
||||
<div id="toolbarViewerRight" [class.pdf-dark]="isDarkTheme">
|
||||
<pdf-hand-tool></pdf-hand-tool>
|
||||
<pdf-select-tool></pdf-select-tool>
|
||||
<pdf-rotate-page></pdf-rotate-page>
|
||||
@if (canPrint) {
|
||||
<pdf-print></pdf-print>
|
||||
}
|
||||
<pdf-no-spread></pdf-no-spread>
|
||||
<pdf-even-spread></pdf-even-spread>
|
||||
<pdf-odd-spread></pdf-odd-spread>
|
||||
<pdf-infinite-scroll></pdf-infinite-scroll>
|
||||
<pdf-horizontal-scroll></pdf-horizontal-scroll>
|
||||
<pdf-vertical-scroll-mode></pdf-vertical-scroll-mode>
|
||||
<pdf-wrapped-scroll-mode></pdf-wrapped-scroll-mode>
|
||||
<pdf-single-page-mode></pdf-single-page-mode>
|
||||
<pdf-book-mode></pdf-book-mode>
|
||||
<div class="verticalToolbarSeparator hiddenSmallView"></div>
|
||||
<pdf-toggle-secondary-toolbar></pdf-toggle-secondary-toolbar>
|
||||
<div class="verticalToolbarSeparator"></div>
|
||||
<pdf-highlight-editor></pdf-highlight-editor>
|
||||
<pdf-text-editor></pdf-text-editor>
|
||||
<pdf-draw-editor></pdf-draw-editor>
|
||||
<div class="verticalToolbarSeparator"></div>
|
||||
<button class="toolbar-btn" [title]="isDarkTheme ? ('readerPdf.toolbar.switchToLightMode' | transloco) : ('readerPdf.toolbar.switchToDarkMode' | transloco)" (click)="isDarkTheme = !isDarkTheme">
|
||||
@if (isDarkTheme) {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>
|
||||
</svg>
|
||||
} @else {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>
|
||||
</svg>
|
||||
}
|
||||
</button>
|
||||
<button id="closePdfReaderButton" class="close-reader-btn" [title]="'readerPdf.toolbar.closePdfReader' | transloco" (click)="closeReader()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M18 6 6 18"/><path d="m6 6 12 12"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
.loading-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
background: #1a1a1a;
|
||||
}
|
||||
|
||||
::ng-deep .toolbar-btn,
|
||||
::ng-deep .close-reader-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #2a2a2a;
|
||||
cursor: pointer;
|
||||
margin-left: 4px;
|
||||
margin-right: 2px;
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .pdf-dark .toolbar-btn,
|
||||
::ng-deep .pdf-dark .close-reader-btn {
|
||||
color: #e8e8e8;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .close-reader-btn:hover {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {NgxExtendedPdfViewerModule, NgxExtendedPdfViewerService, pdfDefaultOptions, ZoomType} from 'ngx-extended-pdf-viewer';
|
||||
import {PageTitleService} from "../../../shared/service/page-title.service";
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {forkJoin, from, Subject, Subscription} from 'rxjs';
|
||||
import {debounceTime, map, switchMap} from 'rxjs/operators';
|
||||
import {BookSetting} from '../../book/model/book.model';
|
||||
import {UserService} from '../../settings/user-management/user.service';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {PdfAnnotationService} from '../../../shared/service/pdf-annotation.service';
|
||||
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService, TranslocoPipe} from '@jsverse/transloco';
|
||||
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-reader',
|
||||
standalone: true,
|
||||
imports: [NgxExtendedPdfViewerModule, ProgressSpinner, TranslocoPipe],
|
||||
templateUrl: './pdf-reader.component.html',
|
||||
styleUrl: './pdf-reader.component.scss',
|
||||
})
|
||||
export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
constructor() {
|
||||
pdfDefaultOptions.rangeChunkSize = 512 * 1024;
|
||||
pdfDefaultOptions.disableAutoFetch = true;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
totalPages: number = 0;
|
||||
isDarkTheme = true;
|
||||
canPrint = false;
|
||||
|
||||
rotation: 0 | 90 | 180 | 270 = 0;
|
||||
authorization = '';
|
||||
|
||||
page!: number;
|
||||
spread!: 'off' | 'even' | 'odd';
|
||||
zoom!: ZoomType;
|
||||
|
||||
bookData!: string;
|
||||
bookId!: number;
|
||||
bookFileId?: number;
|
||||
private altBookType?: string;
|
||||
private appSettingsSubscription!: Subscription;
|
||||
private annotationSaveSubject = new Subject<void>();
|
||||
private annotationSaveSubscription!: Subscription;
|
||||
private annotationsLoaded = false;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private authService = inject(AuthService);
|
||||
private messageService = inject(MessageService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private readingSessionService = inject(ReadingSessionService);
|
||||
private location = inject(Location);
|
||||
private pdfViewerService = inject(NgxExtendedPdfViewerService);
|
||||
private pdfAnnotationService = inject(PdfAnnotationService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.annotationSaveSubscription = this.annotationSaveSubject
|
||||
.pipe(debounceTime(1500))
|
||||
.subscribe(() => this.persistAnnotations());
|
||||
|
||||
this.route.paramMap.pipe(
|
||||
switchMap((params) => {
|
||||
this.isLoading = true;
|
||||
this.bookId = +params.get('bookId')!;
|
||||
this.altBookType = this.route.snapshot.queryParamMap.get('bookType') ?? undefined;
|
||||
|
||||
return from(this.bookService.ensureBookDetail(this.bookId, false)).pipe(
|
||||
switchMap((book) => {
|
||||
if (this.altBookType) {
|
||||
const altFile = book.alternativeFormats?.find(f => f.bookType === this.altBookType);
|
||||
this.bookFileId = altFile?.id;
|
||||
} else {
|
||||
this.bookFileId = book.primaryFile?.id;
|
||||
}
|
||||
|
||||
return forkJoin([
|
||||
this.bookService.getBookSetting(this.bookId, this.bookFileId!),
|
||||
this.userService.getMyself()
|
||||
]).pipe(map(([bookSetting, myself]) => ({book, bookSetting, myself})));
|
||||
})
|
||||
);
|
||||
})
|
||||
).subscribe({
|
||||
next: ({book, bookSetting, myself}) => {
|
||||
const pdfMeta = book;
|
||||
const pdfPrefs = bookSetting;
|
||||
|
||||
this.pageTitle.setBookPageTitle(pdfMeta);
|
||||
|
||||
const globalOrIndividual = myself.userSettings.perBookSetting.pdf;
|
||||
if (globalOrIndividual === 'Global') {
|
||||
this.zoom = myself.userSettings.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = myself.userSettings.pdfReaderSetting.pageSpread || 'odd';
|
||||
} else {
|
||||
this.zoom = pdfPrefs.pdfSettings?.zoom || myself.userSettings.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = pdfPrefs.pdfSettings?.spread || myself.userSettings.pdfReaderSetting.pageSpread || 'odd';
|
||||
}
|
||||
this.canPrint = myself.permissions.canDownload || myself.permissions.admin;
|
||||
this.page = pdfMeta.pdfProgress?.page || 1;
|
||||
this.bookData = this.altBookType
|
||||
? `${API_CONFIG.BASE_URL}/api/v1/books/${this.bookId}/content?bookType=${this.altBookType}`
|
||||
: `${API_CONFIG.BASE_URL}/api/v1/books/${this.bookId}/content`;
|
||||
const token = this.authService.getInternalAccessToken();
|
||||
this.authorization = token ? `Bearer ${token}` : '';
|
||||
this.isLoading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('readerPdf.toast.failedToLoadBook')});
|
||||
this.isLoading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onPageChange(page: number): void {
|
||||
if (page !== this.page) {
|
||||
this.page = page;
|
||||
this.updateProgress();
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.readingSessionService.updateProgress(this.page.toString(), percentage);
|
||||
}
|
||||
}
|
||||
|
||||
onZoomChange(zoom: ZoomType): void {
|
||||
if (zoom !== this.zoom) {
|
||||
this.zoom = zoom;
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
}
|
||||
|
||||
onSpreadChange(spread: 'off' | 'even' | 'odd'): void {
|
||||
if (spread !== this.spread) {
|
||||
this.spread = spread;
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
}
|
||||
|
||||
private updateViewerSetting(): void {
|
||||
const bookSetting: BookSetting = {
|
||||
pdfSettings: {
|
||||
spread: this.spread,
|
||||
zoom: this.zoom,
|
||||
}
|
||||
}
|
||||
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
||||
}
|
||||
|
||||
updateProgress(): void {
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.bookService.savePdfProgress(this.bookId, this.page, percentage, this.bookFileId).subscribe();
|
||||
}
|
||||
|
||||
onPdfPagesLoaded(event: { pagesCount: number }): void {
|
||||
this.totalPages = event.pagesCount;
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.readingSessionService.startSession(this.bookId, "PDF", this.page.toString(), percentage);
|
||||
this.readingSessionService.updateProgress(this.page.toString(), percentage);
|
||||
this.loadAnnotations();
|
||||
}
|
||||
|
||||
onAnnotationEditorEvent(): void {
|
||||
if (this.annotationsLoaded) {
|
||||
this.annotationSaveSubject.next();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.readingSessionService.isSessionActive()) {
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.readingSessionService.endSession(this.page.toString(), percentage);
|
||||
}
|
||||
|
||||
this.annotationSaveSubscription?.unsubscribe();
|
||||
this.persistAnnotations();
|
||||
|
||||
if (this.appSettingsSubscription) {
|
||||
this.appSettingsSubscription.unsubscribe();
|
||||
}
|
||||
this.updateProgress();
|
||||
}
|
||||
|
||||
closeReader = (): void => {
|
||||
if (this.readingSessionService.isSessionActive()) {
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.readingSessionService.endSession(this.page.toString(), percentage);
|
||||
}
|
||||
this.location.back();
|
||||
}
|
||||
|
||||
private loadAnnotations(): void {
|
||||
this.pdfAnnotationService.getAnnotations(this.bookId).subscribe({
|
||||
next: (response) => {
|
||||
if (response?.data) {
|
||||
const annotations = JSON.parse(response.data);
|
||||
for (const annotation of annotations) {
|
||||
this.pdfViewerService.addEditorAnnotation(annotation);
|
||||
}
|
||||
}
|
||||
this.annotationsLoaded = true;
|
||||
},
|
||||
error: () => {
|
||||
this.annotationsLoaded = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private persistAnnotations(): void {
|
||||
if (!this.annotationsLoaded || !this.bookId) {
|
||||
return;
|
||||
}
|
||||
const serialized = this.pdfViewerService.getSerializedAnnotations();
|
||||
if (serialized && serialized.length > 0) {
|
||||
const cleaned = serialized.map(({id, ...rest}: any) => rest);
|
||||
const data = JSON.stringify(cleaned);
|
||||
this.pdfAnnotationService.saveAnnotations(this.bookId, data).subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user