@@ -5,14 +5,15 @@ import { DataTableDirective } from 'angular-datatables';
55import * as moment from 'moment' ;
66import { Observable , Subject , Subscription } from 'rxjs' ;
77import { filter } from 'rxjs/operators' ;
8- import { Entry } from 'src/app/modules/shared/models' ;
8+ import { Entry , Project } 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' ;
1111import { 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' ;
1515import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-offset/parse-date-time-offset' ;
16+ import { LoadProjects , ProjectActionTypes } from 'src/app/modules/customer-management/components/projects/components/store/project.actions' ;
1617
1718@Component ( {
1819 selector : 'app-time-entries-table' ,
@@ -21,11 +22,13 @@ import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-
2122} )
2223export class TimeEntriesTableComponent implements OnInit , OnDestroy , AfterViewInit {
2324 @Output ( ) selectedUserId = new EventEmitter < string > ( ) ;
25+ @Output ( ) selectedProjectId = new EventEmitter < string > ( ) ;
2426
2527 selectOptionValues = [ 15 , 30 , 50 , 100 , - 1 ] ;
2628 selectOptionNames = [ 15 , 30 , 50 , 100 , 'All' ] ;
2729 totalTimeSelected : moment . Duration ;
2830 users : User [ ] = [ ] ;
31+ projects : Project [ ] = [ ] ;
2932 removeFirstColumn = 'th:not(:first)' ;
3033
3134 dtOptions : any = {
@@ -82,9 +85,13 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8285 resultSumEntriesSelected$ : Observable < TotalHours > ;
8386 totalHoursSubscription : Subscription ;
8487 dateTimeOffset : ParseDateTimeOffset ;
88+ listProjects : Project [ ] = [ ] ;
8589
86-
87- constructor ( private store : Store < EntryState > , private actionsSubject$ : ActionsSubject , private storeUser : Store < User > ) {
90+ constructor ( private store : Store < EntryState > ,
91+ private actionsSubject$ : ActionsSubject ,
92+ private storeUser : Store < User > ,
93+ private storeProject : Store < Project >
94+ ) {
8895 this . reportDataSource$ = this . store . pipe ( select ( getReportDataSource ) ) ;
8996 this . resultSumEntriesSelected$ = this . store . pipe ( select ( getResultSumEntriesSelected ) ) ;
9097 this . dateTimeOffset = new ParseDateTimeOffset ( ) ;
@@ -102,6 +109,23 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
102109 } ) ;
103110 }
104111
112+ uploadProjects ( ) : void {
113+ this . storeProject . dispatch ( new LoadProjects ( ) ) ;
114+ this . actionsSubject$
115+ . pipe ( filter ( ( action : any ) => action . type === ProjectActionTypes . LOAD_PROJECTS_SUCCESS ) )
116+ . subscribe ( ( action ) => {
117+ const sortProjects = [ ...action . payload ] ;
118+ sortProjects . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
119+ this . projects = sortProjects ;
120+ this . projects = this . projects . filter ( project => project . status === 'active' ) ;
121+ this . projects . forEach ( ( project ) => {
122+ const projectWithSearchField = { ...project } ;
123+ projectWithSearchField . search_field = `${ project . customer . name } - ${ project . name } ` ;
124+ this . listProjects . push ( projectWithSearchField ) ;
125+ } ) ;
126+ } ) ;
127+ }
128+
105129 ngOnInit ( ) : void {
106130 this . rerenderTableSubscription = this . reportDataSource$ . subscribe ( ( ds ) => {
107131 this . totalHoursSubscription = this . resultSumEntriesSelected$ . subscribe ( ( actTotalHours ) => {
@@ -112,6 +136,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
112136 this . rerenderDataTable ( ) ;
113137 } ) ;
114138 this . uploadUsers ( ) ;
139+ this . uploadProjects ( ) ;
115140 }
116141
117142 ngAfterViewInit ( ) : void {
@@ -172,6 +197,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
172197 this . selectedUserId . emit ( userId ) ;
173198 }
174199
200+ project ( projectId : string ) {
201+ this . selectedProjectId . emit ( projectId ) ;
202+ }
203+
175204 sumHoursEntriesSelected ( entry : Entry , checked : boolean ) {
176205 this . resultSumEntriesSelected = new TotalHours ( ) ;
177206 const duration = moment . duration ( moment ( entry . end_date ) . diff ( moment ( entry . start_date ) ) ) ;
0 commit comments