WIP: Checkpoint epub progress
This commit is contained in:
@@ -18,5 +18,7 @@ public class Book {
|
|||||||
private Instant lastReadTime;
|
private Instant lastReadTime;
|
||||||
private Instant addedOn;
|
private Instant addedOn;
|
||||||
private BookMetadata metadata;
|
private BookMetadata metadata;
|
||||||
|
private Integer pdfProgress;
|
||||||
|
private String epubProgress;
|
||||||
private List<Shelf> shelves;
|
private List<Shelf> shelves;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ public class BookEntity {
|
|||||||
@Column(name = "added_on")
|
@Column(name = "added_on")
|
||||||
private Instant addedOn;
|
private Instant addedOn;
|
||||||
|
|
||||||
|
@Column(name = "epub_progress")
|
||||||
|
private String epubProgress;
|
||||||
|
|
||||||
|
@Column(name = "pdf_progress")
|
||||||
|
private Integer pdfProgress;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "book_shelf_mapping",
|
name = "book_shelf_mapping",
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ CREATE TABLE IF NOT EXISTS book
|
|||||||
(
|
(
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
file_name VARCHAR(255) NOT NULL,
|
file_name VARCHAR(255) NOT NULL,
|
||||||
|
book_type VARCHAR(6) NOT NULL,
|
||||||
library_id BIGINT NOT NULL,
|
library_id BIGINT NOT NULL,
|
||||||
path VARCHAR(1000) NOT NULL,
|
path VARCHAR(1000) NOT NULL,
|
||||||
last_read_time TIMESTAMP NULL,
|
|
||||||
added_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
added_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
book_type VARCHAR(6) NOT NULL,
|
last_read_time TIMESTAMP NULL,
|
||||||
|
pdf_progress INT NULL,
|
||||||
|
epub_progress VARCHAR(1000) NULL,
|
||||||
|
|
||||||
CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE,
|
CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE,
|
||||||
CONSTRAINT unique_file_library UNIQUE (file_name, library_id),
|
CONSTRAINT unique_file_library UNIQUE (file_name, library_id),
|
||||||
INDEX idx_library_id (library_id),
|
INDEX idx_library_id (library_id),
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export interface Book {
|
|||||||
shelves?: Shelf[];
|
shelves?: Shelf[];
|
||||||
lastReadTime?: string;
|
lastReadTime?: string;
|
||||||
addedOn?: string;
|
addedOn?: string;
|
||||||
|
epubProgress?: string;
|
||||||
|
pdfProgress?: number;
|
||||||
bookType: BookType;
|
bookType: BookType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<div class="epub-viewer-container">
|
<div class="epub-viewer-container">
|
||||||
|
|
||||||
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars"></p-button>
|
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars" severity="secondary"></p-button>
|
||||||
|
|
||||||
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters">
|
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters">
|
||||||
<ul class="chapter-list">
|
<ul class="chapter-list">
|
||||||
<li *ngFor="let chapter of chapters" (click)="navigateToChapter(chapter); $event.stopPropagation()" class="chapter-item">
|
<li *ngFor="let chapter of chapters" (click)="navigateToChapter(chapter); $event.stopPropagation()" class="chapter-item">
|
||||||
@@ -10,14 +9,14 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</p-drawer>
|
</p-drawer>
|
||||||
|
|
||||||
<p-button class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog"></p-button>
|
<p-button class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog" severity="secondary"></p-button>
|
||||||
<p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings">
|
<p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="settings-content">
|
<div class="settings-content">
|
||||||
<p>Font Size: {{ fontSize }}%</p>
|
<p>Font Size: {{ fontSize }}%</p>
|
||||||
<div class="flex flex-row gap-4">
|
<div class="flex flex-row gap-4">
|
||||||
<p-button icon="pi pi-minus" (click)="decreaseFontSize()"></p-button>
|
<p-button icon="pi pi-minus" (click)="decreaseFontSize()" severity="info"></p-button>
|
||||||
<p-button icon="pi pi-plus" (click)="increaseFontSize()"></p-button>
|
<p-button icon="pi pi-plus" (click)="increaseFontSize()" severity="info"></p-button>
|
||||||
</div>
|
</div>
|
||||||
<p-divider></p-divider>
|
<p-divider></p-divider>
|
||||||
<label for="font-type">Font Type:</label>
|
<label for="font-type">Font Type:</label>
|
||||||
|
|||||||
@@ -8,19 +8,14 @@ import {FormsModule} from '@angular/forms';
|
|||||||
import {Divider} from 'primeng/divider';
|
import {Divider} from 'primeng/divider';
|
||||||
import {DropdownModule} from 'primeng/dropdown';
|
import {DropdownModule} from 'primeng/dropdown';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
import {Book} from '../../book/model/book.model';
|
||||||
|
import {BookService} from '../../book/service/book.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-epub-viewer',
|
selector: 'app-epub-viewer',
|
||||||
templateUrl: './epub-viewer.component.html',
|
templateUrl: './epub-viewer.component.html',
|
||||||
styleUrls: ['./epub-viewer.component.scss'],
|
styleUrls: ['./epub-viewer.component.scss'],
|
||||||
imports: [
|
imports: [Drawer, Button, NgForOf, FormsModule, Divider, DropdownModule]
|
||||||
Drawer,
|
|
||||||
Button,
|
|
||||||
NgForOf,
|
|
||||||
FormsModule,
|
|
||||||
Divider,
|
|
||||||
DropdownModule
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
export class EpubViewerComponent implements OnInit, OnDestroy {
|
export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
@@ -30,8 +25,10 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
isSettingsDrawerVisible: boolean = false;
|
isSettingsDrawerVisible: boolean = false;
|
||||||
private book: any;
|
private book: any;
|
||||||
private rendition: any;
|
private rendition: any;
|
||||||
private keyListener: (e: KeyboardEvent) => void = () => {};
|
private keyListener: (e: KeyboardEvent) => void = () => {
|
||||||
|
};
|
||||||
fontSize: number = 120;
|
fontSize: number = 120;
|
||||||
|
bookLoreBook: Book | undefined
|
||||||
|
|
||||||
fontTypes: any[] = [
|
fontTypes: any[] = [
|
||||||
{label: 'Serif', value: 'serif'},
|
{label: 'Serif', value: 'serif'},
|
||||||
@@ -42,15 +39,22 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
];
|
];
|
||||||
selectedFontType: string = 'serif';
|
selectedFontType: string = 'serif';
|
||||||
|
|
||||||
constructor(private epubService: EpubService, private route: ActivatedRoute) {
|
constructor(private epubService: EpubService, private route: ActivatedRoute, private bookService: BookService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.paramMap.subscribe((params) => {
|
this.route.paramMap.subscribe((params) => {
|
||||||
|
this.loadBook(+params.get('bookId')!)
|
||||||
this.loadEpub(+params.get('bookId')!);
|
this.loadEpub(+params.get('bookId')!);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadBook(bookId: number): void {
|
||||||
|
this.bookService.getBookById(bookId).subscribe((book) => {
|
||||||
|
this.bookLoreBook = book;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loadEpub(bookId: number): void {
|
loadEpub(bookId: number): void {
|
||||||
this.epubService.downloadEpub(bookId).subscribe(
|
this.epubService.downloadEpub(bookId).subscribe(
|
||||||
(data: Blob) => {
|
(data: Blob) => {
|
||||||
@@ -72,9 +76,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
height: '100%',
|
height: '100%',
|
||||||
allowScriptedContent: true,
|
allowScriptedContent: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(this.bookLoreBook?.epubProgress) {
|
||||||
|
this.rendition.display(this.bookLoreBook?.epubProgress);
|
||||||
|
} else {
|
||||||
this.rendition.display();
|
this.rendition.display();
|
||||||
|
}
|
||||||
|
|
||||||
this.setupKeyListener();
|
this.setupKeyListener();
|
||||||
this.updateFontSize();
|
this.updateFontSize();
|
||||||
|
this.trackProgress();
|
||||||
};
|
};
|
||||||
fileReader.readAsArrayBuffer(data);
|
fileReader.readAsArrayBuffer(data);
|
||||||
},
|
},
|
||||||
@@ -91,6 +102,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
document.removeEventListener('keyup', this.keyListener);
|
document.removeEventListener('keyup', this.keyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private trackProgress(): void {
|
||||||
|
if (this.rendition) {
|
||||||
|
this.rendition.on('relocated', (location: any) => {
|
||||||
|
const percentage = location.start.percentage.toFixed(2);
|
||||||
|
console.log(`Reading progress: ${percentage * 100}%`);
|
||||||
|
console.log('Current location:', location);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateFontSize(): void {
|
updateFontSize(): void {
|
||||||
if (this.rendition) {
|
if (this.rendition) {
|
||||||
this.rendition.themes.fontSize(`${this.fontSize}%`);
|
this.rendition.themes.fontSize(`${this.fontSize}%`);
|
||||||
|
|||||||
Reference in New Issue
Block a user