11import { formatDate } from '@angular/common' ;
2- import { AfterViewInit , Component , OnDestroy , OnInit , ViewChild } from '@angular/core' ;
3- import { select , Store } from '@ngrx/store' ;
2+ import { AfterViewInit , Component , EventEmitter , OnDestroy , Output , OnInit , ViewChild } from '@angular/core' ;
3+ import { select , Store , ActionsSubject } from '@ngrx/store' ;
44import { DataTableDirective } from 'angular-datatables' ;
55import * as moment from 'moment' ;
66import { Observable , Subject , Subscription } from 'rxjs' ;
7+ import { filter } from 'rxjs/operators' ;
78import { Entry } from 'src/app/modules/shared/models' ;
89import { DataSource } from 'src/app/modules/shared/models/data-source.model' ;
910import { EntryState } from '../../../time-clock/store/entry.reducer' ;
1011import { getReportDataSource } from '../../../time-clock/store/entry.selectors' ;
12+ import { User } from 'src/app/modules/users/models/users' ;
13+ import { LoadUsers , UserActionTypes } from 'src/app/modules/users/store/user.actions' ;
1114
1215@Component ( {
1316 selector : 'app-time-entries-table' ,
1417 templateUrl : './time-entries-table.component.html' ,
1518 styleUrls : [ './time-entries-table.component.scss' ] ,
1619} )
1720export class TimeEntriesTableComponent implements OnInit , OnDestroy , AfterViewInit {
21+ @Output ( ) selectedUserId = new EventEmitter < string > ( ) ;
22+
1823 selectOptionValues = [ 15 , 30 , 50 , 100 , - 1 ] ;
1924 selectOptionNames = [ 15 , 30 , 50 , 100 , 'All' ] ;
25+ users : User [ ] = [ ] ;
2026 dtOptions : any = {
2127 scrollY : '590px' ,
2228 dom : '<"d-flex justify-content-between"B<"d-flex"<"mr-5"l>f>>rtip' ,
@@ -61,14 +67,24 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6167 reportDataSource$ : Observable < DataSource < Entry > > ;
6268 rerenderTableSubscription : Subscription ;
6369
64- constructor ( private store : Store < EntryState > ) {
70+ constructor ( private store : Store < EntryState > , private actionsSubject$ : ActionsSubject , private storeUser : Store < User > ) {
6571 this . reportDataSource$ = this . store . pipe ( select ( getReportDataSource ) ) ;
6672 }
6773
74+ uploadUsers ( ) : void {
75+ this . storeUser . dispatch ( new LoadUsers ( ) ) ;
76+ this . actionsSubject$
77+ . pipe ( filter ( ( action : any ) => action . type === UserActionTypes . LOAD_USERS_SUCCESS ) )
78+ . subscribe ( ( action ) => {
79+ this . users = action . payload ;
80+ } ) ;
81+ }
82+
6883 ngOnInit ( ) : void {
6984 this . rerenderTableSubscription = this . reportDataSource$ . subscribe ( ( ds ) => {
7085 this . rerenderDataTable ( ) ;
7186 } ) ;
87+ this . uploadUsers ( ) ;
7288 }
7389
7490 ngAfterViewInit ( ) : void {
@@ -83,11 +99,11 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8399 private rerenderDataTable ( ) : void {
84100 if ( this . dtElement && this . dtElement . dtInstance ) {
85101 this . dtElement . dtInstance . then ( ( dtInstance : DataTables . Api ) => {
86- dtInstance . destroy ( ) ;
87- this . dtTrigger . next ( ) ;
102+ dtInstance . destroy ( ) ;
103+ this . dtTrigger . next ( ) ;
88104 } ) ;
89105 } else {
90- this . dtTrigger . next ( ) ;
106+ this . dtTrigger . next ( ) ;
91107 }
92108 }
93109
@@ -100,10 +116,15 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
100116 return regex . test ( uri ) ;
101117 }
102118
103- bodyExportOptions ( data , row , column , node ) {
119+ bodyExportOptions ( data , row , column , node ) {
104120 const dataFormated = data . toString ( ) . replace ( / < ( ( .| \n ) { 0 , 200 } ?) > / gi, '' ) ;
105121 const durationColumnIndex = 3 ;
106122 return column === durationColumnIndex ? moment . duration ( dataFormated ) . asHours ( ) . toFixed ( 2 ) : dataFormated ;
107123 }
124+
125+ user ( userId : string ) {
126+ this . selectedUserId . emit ( userId ) ;
127+ }
128+
108129}
109130
0 commit comments