Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: TT-304 Handle message: the data could not be load (#716)
* fix: TT-304 Handle message: the data could not be load

* test: TT-304 Creating an unit test to coverage the new feature

Co-authored-by: Edgar Guaman <[email protected]>
  • Loading branch information
edgardavid2015 and Edgar Guaman authored Aug 13, 2021
commit d2fc2a0bb6fc9a0d4c1e1f5f1180d514a0e1e3f4
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</ng-template>
<ng-template #listView>
<div id="listView">
<table class="table table-sm table-striped mb-0" *ngIf="timeEntriesDataSource$ | async as dataSource">
<table class="table table-sm table-striped mb-0" datatable [dtTrigger]="dtTrigger" [dtOptions]="dtOptions" *ngIf="timeEntriesDataSource$ | async as dataSource">
<thead class="thead-blue">
<tr class="d-flex">
<th class="col">Date</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,4 +668,11 @@ describe('TimeEntriesComponent', () => {

expect(HTMLTimeEntriesView).not.toBeNull();
});

it('after the component is initialized it should initialize the table', () => {
spyOn(component.dtTrigger, 'next');
component.ngAfterViewInit();

expect(component.dtTrigger.next).toHaveBeenCalled();
});
});
36 changes: 33 additions & 3 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { ActionsSubject, select, Store } from '@ngrx/store';
import { ToastrService } from 'ngx-toastr';
import { Observable, Subscription } from 'rxjs';
import { Observable, Subscription, Subject } from 'rxjs';
import { delay, filter } from 'rxjs/operators';
import { ProjectSelectedEvent } from '../../shared/components/details-fields/project-selected-event';
import { SaveEntryEvent } from '../../shared/components/details-fields/save-entry-event';
Expand All @@ -14,12 +14,13 @@ import { EntryActionTypes } from './../../time-clock/store/entry.actions';
import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../time-clock/store/entry.selectors';
import { CookieService } from 'ngx-cookie-service';
import { FeatureToggle } from './../../../../environments/enum';
import { DataTableDirective } from 'angular-datatables';
@Component({
selector: 'app-time-entries',
templateUrl: './time-entries.component.html',
styleUrls: ['./time-entries.component.scss'],
})
export class TimeEntriesComponent implements OnInit, OnDestroy {
export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
entryId: string;
entry: Entry;
activeTimeEntry: Entry;
Expand All @@ -38,6 +39,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedYear: number;
selectedMonthAsText: string;
isActiveEntryOverlapping = false;
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject();
@ViewChild(DataTableDirective, { static: false })
dtElement: DataTableDirective;
rerenderTableSubscription: Subscription;
constructor(
private store: Store<EntryState>,
private toastrService: ToastrService,
Expand All @@ -49,8 +55,18 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
this.entriesSubscription.unsubscribe();
this.rerenderTableSubscription.unsubscribe();
this.dtTrigger.unsubscribe();
}
ngOnInit(): void {
this.dtOptions = {
scrollY: '325px',
paging: false,
responsive: true,
};
this.rerenderTableSubscription = this.timeEntriesDataSource$.subscribe((ds) => {
this.rerenderDataTable();
});
this.loadActiveEntry();
this.isFeatureToggleCalendarActive = (this.cookiesService.get(FeatureToggle.TIME_TRACKER_CALENDAR) === 'true');
this.entriesSubscription = this.actionsSubject$.pipe(
Expand All @@ -65,6 +81,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
});
}
ngAfterViewInit(): void {
this.rerenderDataTable();
}
newEntry() {
if (this.wasEditingExistingTimeEntry) {
this.entry = null;
Expand Down Expand Up @@ -216,4 +235,15 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
});
}
}

private rerenderDataTable(): void {
if (this.dtElement && this.dtElement.dtInstance) {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.destroy();
this.dtTrigger.next();
});
} else {
this.dtTrigger.next();
}
}
}