Skip to content

Commit 8d6aac4

Browse files
author
Edgar Guaman
committed
fix: TT-304 Handle message: the data could not be load
1 parent d0c17b3 commit 8d6aac4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</ng-template>
4343
<ng-template #listView>
4444
<div id="listView">
45-
<table class="table table-sm table-striped mb-0" *ngIf="timeEntriesDataSource$ | async as dataSource">
45+
<table class="table table-sm table-striped mb-0" datatable [dtTrigger]="dtTrigger" [dtOptions]="dtOptions" *ngIf="timeEntriesDataSource$ | async as dataSource">
4646
<thead class="thead-blue">
4747
<tr class="d-flex">
4848
<th class="col">Date</th>

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit } from '@angular/core';
22
import { ActionsSubject, select, Store } from '@ngrx/store';
33
import { ToastrService } from 'ngx-toastr';
4-
import { Observable, Subscription } from 'rxjs';
4+
import { Observable, Subscription, Subject } from 'rxjs';
55
import { delay, filter } from 'rxjs/operators';
66
import { ProjectSelectedEvent } from '../../shared/components/details-fields/project-selected-event';
77
import { SaveEntryEvent } from '../../shared/components/details-fields/save-entry-event';
@@ -14,12 +14,13 @@ import { EntryActionTypes } from './../../time-clock/store/entry.actions';
1414
import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../time-clock/store/entry.selectors';
1515
import { CookieService } from 'ngx-cookie-service';
1616
import { FeatureToggle } from './../../../../environments/enum';
17+
import { DataTableDirective } from 'angular-datatables';
1718
@Component({
1819
selector: 'app-time-entries',
1920
templateUrl: './time-entries.component.html',
2021
styleUrls: ['./time-entries.component.scss'],
2122
})
22-
export class TimeEntriesComponent implements OnInit, OnDestroy {
23+
export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
2324
entryId: string;
2425
entry: Entry;
2526
activeTimeEntry: Entry;
@@ -38,6 +39,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
3839
selectedYear: number;
3940
selectedMonthAsText: string;
4041
isActiveEntryOverlapping = false;
42+
dtOptions: any = {};
43+
dtTrigger: Subject<any> = new Subject();
44+
@ViewChild(DataTableDirective, { static: false })
45+
dtElement: DataTableDirective;
46+
rerenderTableSubscription: Subscription;
4147
constructor(
4248
private store: Store<EntryState>,
4349
private toastrService: ToastrService,
@@ -49,8 +55,18 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
4955
}
5056
ngOnDestroy(): void {
5157
this.entriesSubscription.unsubscribe();
58+
this.rerenderTableSubscription.unsubscribe();
59+
this.dtTrigger.unsubscribe();
5260
}
5361
ngOnInit(): void {
62+
this.dtOptions = {
63+
scrollY: '325px',
64+
paging: false,
65+
responsive: true,
66+
};
67+
this.rerenderTableSubscription = this.timeEntriesDataSource$.subscribe((ds) => {
68+
this.rerenderDataTable();
69+
});
5470
this.loadActiveEntry();
5571
this.isFeatureToggleCalendarActive = (this.cookiesService.get(FeatureToggle.TIME_TRACKER_CALENDAR) === 'true');
5672
this.entriesSubscription = this.actionsSubject$.pipe(
@@ -65,6 +81,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
6581
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
6682
});
6783
}
84+
ngAfterViewInit(): void {
85+
this.rerenderDataTable();
86+
}
6887
newEntry() {
6988
if (this.wasEditingExistingTimeEntry) {
7089
this.entry = null;
@@ -216,4 +235,15 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
216235
});
217236
}
218237
}
238+
239+
private rerenderDataTable(): void {
240+
if (this.dtElement && this.dtElement.dtInstance) {
241+
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
242+
dtInstance.destroy();
243+
this.dtTrigger.next();
244+
});
245+
} else {
246+
this.dtTrigger.next();
247+
}
248+
}
219249
}

0 commit comments

Comments
 (0)