Skip to content

Commit 7398454

Browse files
committed
feat: TT-344 add pagination to time-entries tab
1 parent d8daaae commit 7398454

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@
4242
</div>
4343
</div>
4444
</ng-template>
45+
4546
<ng-template #listView>
4647
<div id="listView">
47-
<table class="table table-sm table-striped mb-0" *ngIf="timeEntriesDataSource$ | async as dataSource">
48+
<table
49+
class="table table-sm table-striped mb-0"
50+
datatable
51+
[dtTrigger]="dtTrigger"
52+
[dtOptions]="dtOptions"
53+
*ngIf="(timeEntriesDataSource$ | async) as dataSource">
4854
<thead class="thead-blue">
4955
<tr class="d-flex">
5056
<th class="col">Date</th>
@@ -95,6 +101,7 @@
95101
</div>
96102
</ng-template>
97103
</div>
104+
98105
<div class="modal fade" id="editRecordsByDate" tabindex="-1" role="dialog">
99106
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
100107
<div class="modal-content" cdkDrag (cdkDragEnded)="resetDraggablePosition($event)">

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
1+
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { ActionsSubject, select, Store } from '@ngrx/store';
3+
import { DataTableDirective } from 'angular-datatables';
34
import { ToastrService } from 'ngx-toastr';
4-
import { Observable, Subscription } from 'rxjs';
5+
import { Observable, Subscription, Subject } from 'rxjs';
56
import { delay, filter } from 'rxjs/operators';
67
import { ProjectSelectedEvent } from '../../shared/components/details-fields/project-selected-event';
78
import { SaveEntryEvent } from '../../shared/components/details-fields/save-entry-event';
@@ -20,7 +21,12 @@ import { CalendarView } from 'angular-calendar';
2021
templateUrl: './time-entries.component.html',
2122
styleUrls: ['./time-entries.component.scss'],
2223
})
23-
export class TimeEntriesComponent implements OnInit, OnDestroy {
24+
export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
25+
dtOptions: any = {};
26+
dtTrigger: Subject<any> = new Subject();
27+
@ViewChild(DataTableDirective, { static: false })
28+
dtElement: DataTableDirective;
29+
rerenderTableSubscription: Subscription;
2430
entryId: string;
2531
entry: Entry;
2632
activeTimeEntry: Entry;
@@ -52,9 +58,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
5258
this.actualDate = new Date();
5359
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
5460
}
55-
ngOnDestroy(): void {
56-
this.entriesSubscription.unsubscribe();
57-
}
61+
5862
ngOnInit(): void {
5963
this.loadActiveEntry();
6064
this.isFeatureToggleCalendarActive = (this.cookiesService.get(FeatureToggle.TIME_TRACKER_CALENDAR) === 'true');
@@ -69,7 +73,31 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
6973
this.loadActiveEntry();
7074
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
7175
});
76+
this.rerenderTableSubscription = this.timeEntriesDataSource$.subscribe((ds) => {
77+
this.rerenderDataTable();
78+
});
7279
}
80+
81+
ngAfterViewInit(): void {
82+
this.rerenderDataTable();
83+
}
84+
85+
ngOnDestroy(): void {
86+
this.rerenderTableSubscription.unsubscribe();
87+
this.entriesSubscription.unsubscribe();
88+
}
89+
90+
private rerenderDataTable(): void {
91+
if (this.dtElement && this.dtElement.dtInstance) {
92+
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
93+
dtInstance.destroy();
94+
this.dtTrigger.next();
95+
});
96+
} else {
97+
this.dtTrigger.next();
98+
}
99+
}
100+
73101
newEntry() {
74102
if (this.wasEditingExistingTimeEntry) {
75103
this.entry = null;

0 commit comments

Comments
 (0)