@@ -8,7 +8,7 @@ import { filter } from 'rxjs/operators';
88import { Entry } from 'src/app/modules/shared/models' ;
99import { DataSource } from 'src/app/modules/shared/models/data-source.model' ;
1010import { EntryState } from '../../../time-clock/store/entry.reducer' ;
11- import { getReportDataSource } from '../../../time-clock/store/entry.selectors' ;
11+ import { getReportDataSource , getResultSumEntriesSelected } from '../../../time-clock/store/entry.selectors' ;
1212import { TotalHours } from '../../models/total-hours-report' ;
1313import { User } from 'src/app/modules/users/models/users' ;
1414import { LoadUsers , UserActionTypes } from 'src/app/modules/users/store/user.actions' ;
@@ -24,7 +24,9 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
2424
2525 selectOptionValues = [ 15 , 30 , 50 , 100 , - 1 ] ;
2626 selectOptionNames = [ 15 , 30 , 50 , 100 , 'All' ] ;
27+ totalTimeSelected : moment . Duration ;
2728 users : User [ ] = [ ] ;
29+
2830 dtOptions : any = {
2931 scrollY : '590px' ,
3032 dom : '<"d-flex justify-content-between"B<"d-flex"<"mr-5"l>f>>rtip' ,
@@ -60,8 +62,8 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6062 filename : `time-entries-${ formatDate ( new Date ( ) , 'MM_dd_yyyy-HH_mm' , 'en' ) } `
6163 } ,
6264 ] ,
63- columnDefs : [ { type : 'date' , targets : 2 } ] ,
64- order : [ [ 1 , 'asc' ] , [ 2 , 'desc' ] , [ 4 , 'desc' ] ]
65+ columnDefs : [ { type : 'date' , targets : 2 } , { orderable : false , targets : [ 0 ] } ] ,
66+ order : [ [ 1 , 'asc' ] , [ 2 , 'desc' ] , [ 4 , 'desc' ] ]
6567 } ;
6668 dtTrigger : Subject < any > = new Subject ( ) ;
6769 @ViewChild ( DataTableDirective , { static : false } )
@@ -70,11 +72,17 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
7072 reportDataSource$ : Observable < DataSource < Entry > > ;
7173 rerenderTableSubscription : Subscription ;
7274 resultSum : TotalHours ;
75+ resultSumEntriesSelected : TotalHours ;
76+ resultSumEntriesSelected$ :Observable < TotalHours > ;
77+ totalHoursSubscription : Subscription ;
7378 dateTimeOffset : ParseDateTimeOffset ;
7479
75- constructor ( private store : Store < EntryState > , private actionsSubject$ : ActionsSubject , private storeUser : Store < User > ) {
76- this . reportDataSource$ = this . store . pipe ( select ( getReportDataSource ) ) ;
77- this . dateTimeOffset = new ParseDateTimeOffset ( ) ;
80+
81+ constructor ( private store : Store < EntryState > , private actionsSubject$ : ActionsSubject , private storeUser : Store < User > ) {
82+ this . reportDataSource$ = this . store . pipe ( select ( getReportDataSource ) ) ;
83+ this . resultSumEntriesSelected$ = this . store . pipe ( select ( getResultSumEntriesSelected ) ) ;
84+ this . dateTimeOffset = new ParseDateTimeOffset ( ) ;
85+ this . resultSumEntriesSelected = new TotalHours ( ) ;
7886 }
7987
8088 uploadUsers ( ) : void {
@@ -88,6 +96,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8896
8997 ngOnInit ( ) : void {
9098 this . rerenderTableSubscription = this . reportDataSource$ . subscribe ( ( ds ) => {
99+ this . totalHoursSubscription = this . resultSumEntriesSelected$ . subscribe ( ( actTotalHours ) => {
100+ this . resultSumEntriesSelected = actTotalHours ;
101+ this . totalTimeSelected = moment . duration ( 0 ) ;
102+ } ) ;
91103 this . sumDates ( ds . data ) ;
92104 this . rerenderDataTable ( ) ;
93105 } ) ;
@@ -153,5 +165,15 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
153165 this . selectedUserId . emit ( userId ) ;
154166 }
155167
168+ sumHoursEntriesSelected ( entry : Entry , checked : boolean ) {
169+ this . resultSumEntriesSelected = new TotalHours ( ) ;
170+ const duration = moment . duration ( moment ( entry . end_date ) . diff ( moment ( entry . start_date ) ) ) ;
171+ this . totalTimeSelected = checked ? this . totalTimeSelected . add ( duration ) : this . totalTimeSelected . subtract ( duration ) ;
172+ const daysTotalInHours = this . totalTimeSelected . days ( ) * 24 ;
173+ this . resultSumEntriesSelected . hours = this . totalTimeSelected . hours ( ) + daysTotalInHours ;
174+ this . resultSumEntriesSelected . minutes = this . totalTimeSelected . minutes ( ) ;
175+ this . resultSumEntriesSelected . seconds = this . totalTimeSelected . seconds ( ) ;
176+ return this . resultSumEntriesSelected ;
177+ }
156178}
157179
0 commit comments