show session numbers in book (#2696)
This commit is contained in:
+3
-7
@@ -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">
|
||||
|
||||
+6
-13
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user