1- import { Component , OnDestroy , OnInit , ViewChild , AfterViewInit } from '@angular/core' ;
1+ import { Component , OnDestroy , OnInit } from '@angular/core' ;
22import { ActionsSubject , select , Store } from '@ngrx/store' ;
33import { ToastrService } from 'ngx-toastr' ;
4- import { Observable , Subscription , Subject } from 'rxjs' ;
4+ import { Observable , Subscription } from 'rxjs' ;
55import { delay , filter } from 'rxjs/operators' ;
66import { ProjectSelectedEvent } from '../../shared/components/details-fields/project-selected-event' ;
77import { SaveEntryEvent } from '../../shared/components/details-fields/save-entry-event' ;
@@ -14,13 +14,12 @@ import { EntryActionTypes } from './../../time-clock/store/entry.actions';
1414import { getActiveTimeEntry , getTimeEntriesDataSource } from './../../time-clock/store/entry.selectors' ;
1515import { CookieService } from 'ngx-cookie-service' ;
1616import { FeatureToggle } from './../../../../environments/enum' ;
17- import { DataTableDirective } from 'angular-datatables' ;
1817@Component ( {
1918 selector : 'app-time-entries' ,
2019 templateUrl : './time-entries.component.html' ,
2120 styleUrls : [ './time-entries.component.scss' ] ,
2221} )
23- export class TimeEntriesComponent implements OnInit , OnDestroy , AfterViewInit {
22+ export class TimeEntriesComponent implements OnInit , OnDestroy {
2423 entryId : string ;
2524 entry : Entry ;
2625 activeTimeEntry : Entry ;
@@ -39,11 +38,6 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
3938 selectedYear : number ;
4039 selectedMonthAsText : string ;
4140 isActiveEntryOverlapping = false ;
42- dtOptions : any = { } ;
43- dtTrigger : Subject < any > = new Subject ( ) ;
44- @ViewChild ( DataTableDirective , { static : false } )
45- dtElement : DataTableDirective ;
46- rerenderTableSubscription : Subscription ;
4741 constructor (
4842 private store : Store < EntryState > ,
4943 private toastrService : ToastrService ,
@@ -55,18 +49,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
5549 }
5650 ngOnDestroy ( ) : void {
5751 this . entriesSubscription . unsubscribe ( ) ;
58- this . rerenderTableSubscription . unsubscribe ( ) ;
59- this . dtTrigger . unsubscribe ( ) ;
6052 }
6153 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- } ) ;
7054 this . loadActiveEntry ( ) ;
7155 this . isFeatureToggleCalendarActive = ( this . cookiesService . get ( FeatureToggle . TIME_TRACKER_CALENDAR ) === 'true' ) ;
7256 this . entriesSubscription = this . actionsSubject$ . pipe (
@@ -81,9 +65,6 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
8165 this . store . dispatch ( new entryActions . LoadEntries ( this . selectedMonth , this . selectedYear ) ) ;
8266 } ) ;
8367 }
84- ngAfterViewInit ( ) : void {
85- this . rerenderDataTable ( ) ;
86- }
8768 newEntry ( ) {
8869 if ( this . wasEditingExistingTimeEntry ) {
8970 this . entry = null ;
@@ -235,15 +216,4 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
235216 } ) ;
236217 }
237218 }
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- }
249219}
0 commit comments