show session numbers in book (#2696)

This commit is contained in:
WorldTeacher
2026-02-11 10:22:01 -07:00
committed by GitHub
parent aac8246bcf
commit 7e6ad212b0
4 changed files with 16 additions and 24 deletions
@@ -12,17 +12,13 @@
} @else {
<p-table
[value]="sessions"
[lazy]="true"
[paginator]="true"
[rows]="rows"
[totalRecords]="totalRecords"
[loading]="loading"
[first]="first"
(onLazyLoad)="onPageChange($event)"
[showCurrentPageReport]="true"
[currentPageReportTemplate]="t('pageReport')"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} sessions"
class="p-datatable-sm">
<ng-template #header>
<ng-template pTemplate="header">
<tr>
<th>{{ t('headerSession') }}</th>
<th>{{ t('headerType') }}</th>
@@ -32,7 +28,7 @@
<th>{{ t('headerLocation') }}</th>
</tr>
</ng-template>
<ng-template #body let-session>
<ng-template pTemplate="body" let-session>
<tr>
<td>
<div class="session-time">
@@ -18,29 +18,29 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
private readonly t = inject(TranslocoService);
sessions: ReadingSessionResponse[] = [];
totalRecords = 0;
first = 0;
rows = 5;
loading = false;
get pageReportTemplate(): string {
return this.t.translate('metadata.readingSessions.pageReport');
}
ngOnInit() {
this.loadSessions();
}
ngOnChanges(changes: SimpleChanges) {
if (changes['bookId'] && !changes['bookId'].firstChange) {
this.first = 0;
this.loadSessions();
}
}
loadSessions(page: number = 0) {
loadSessions() {
this.loading = true;
this.readingSessionService.getSessionsByBookId(this.bookId, page, this.rows)
this.readingSessionService.getSessionsByBookId(this.bookId, 0, 9999)
.subscribe({
next: (response) => {
this.sessions = response.content;
this.totalRecords = response.totalElements;
this.loading = false;
},
error: () => {
@@ -49,13 +49,6 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
});
}
onPageChange(event: { first?: number; rows?: number | null }): void {
if (event.first === undefined || event.rows === undefined || event.rows === null) return;
this.first = event.first;
const page = Math.floor(event.first / event.rows);
this.loadSessions(page);
}
formatDuration(seconds: number): string {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);