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
Next Next commit
fix: TT-304 Handle message: the data could not be load
  • Loading branch information
Edgar Guaman committed Aug 13, 2021
commit 61fe9162be874c54411a8f3c88a9d016d87cd279
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
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();
}
}
}