@@ -20,15 +20,13 @@ import { ProjectSelectedEvent } from './project-selected-event';
20
20
import { get } from 'lodash' ;
21
21
import { DATE_FORMAT } from 'src/environments/environment' ;
22
22
23
-
24
23
type Merged = TechnologyState & ProjectState & ActivityState & EntryState ;
25
24
@Component ( {
26
25
selector : 'app-details-fields' ,
27
26
templateUrl : './details-fields.component.html' ,
28
27
styleUrls : [ './details-fields.component.scss' ] ,
29
28
} )
30
29
export class DetailsFieldsComponent implements OnChanges , OnInit {
31
-
32
30
keyword = 'search_field' ;
33
31
@Input ( ) entryToEdit : Entry ;
34
32
@Input ( ) canMarkEntryAsWIP : boolean ;
@@ -43,8 +41,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
43
41
goingToWorkOnThis = false ;
44
42
shouldRestartEntry = false ;
45
43
46
- constructor ( private formBuilder : FormBuilder , private store : Store < Merged > ,
47
- private actionsSubject$ : ActionsSubject , private toastrService : ToastrService ) {
44
+ constructor (
45
+ private formBuilder : FormBuilder ,
46
+ private store : Store < Merged > ,
47
+ private actionsSubject$ : ActionsSubject ,
48
+ private toastrService : ToastrService
49
+ ) {
48
50
this . entryForm = this . formBuilder . group ( {
49
51
project_id : [ '' , Validators . required ] ,
50
52
project_name : [ '' , Validators . required ] ,
@@ -66,11 +68,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
66
68
if ( projects ) {
67
69
this . listProjects = [ ] ;
68
70
projects . forEach ( ( project ) => {
69
- const projectWithSearchField = { ...project } ;
70
- projectWithSearchField . search_field = `${ project . customer_name } - ${ project . name } ` ;
71
- this . listProjects . push ( projectWithSearchField ) ;
72
- }
73
- ) ;
71
+ const projectWithSearchField = { ...project } ;
72
+ projectWithSearchField . search_field = `${ project . customer_name } - ${ project . name } ` ;
73
+ this . listProjects . push ( projectWithSearchField ) ;
74
+ } ) ;
74
75
}
75
76
} ) ;
76
77
@@ -95,31 +96,32 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
95
96
}
96
97
} ) ;
97
98
98
- this . actionsSubject$ . pipe (
99
- filter ( ( action : any ) => (
100
- action . type === EntryActionTypes . CREATE_ENTRY_SUCCESS ||
101
- action . type === EntryActionTypes . UPDATE_ENTRY_SUCCESS
102
- ) )
103
- ) . subscribe ( ( ) => {
104
- this . cleanForm ( ) ;
105
- } ) ;
99
+ this . actionsSubject$
100
+ . pipe (
101
+ filter (
102
+ ( action : any ) =>
103
+ action . type === EntryActionTypes . CREATE_ENTRY_SUCCESS ||
104
+ action . type === EntryActionTypes . UPDATE_ENTRY_SUCCESS
105
+ )
106
+ )
107
+ . subscribe ( ( ) => {
108
+ this . cleanForm ( ) ;
109
+ } ) ;
106
110
}
107
111
108
112
onClearedComponent ( event ) {
109
- this . entryForm . patchValue (
110
- {
111
- project_id : '' ,
112
- project_name : '' ,
113
- } ) ;
113
+ this . entryForm . patchValue ( {
114
+ project_id : '' ,
115
+ project_name : '' ,
116
+ } ) ;
114
117
}
115
118
116
119
onSelectedProject ( item ) {
117
- this . projectSelected . emit ( { projectId : item . id } ) ;
118
- this . entryForm . patchValue (
119
- {
120
- project_id : item . id ,
121
- project_name : item . search_field ,
122
- } ) ;
120
+ this . projectSelected . emit ( { projectId : item . id } ) ;
121
+ this . entryForm . patchValue ( {
122
+ project_id : item . id ,
123
+ project_name : item . search_field ,
124
+ } ) ;
123
125
}
124
126
125
127
ngOnChanges ( ) : void {
@@ -197,7 +199,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
197
199
this . closeModal ?. nativeElement ?. click ( ) ;
198
200
}
199
201
200
- dateToSubmit ( date , hour ) {
202
+ dateToSubmit ( date , hour ) {
201
203
const entryFormDate = this . entryForm . value [ date ] ;
202
204
const updatedHour = this . entryForm . value [ hour ] ;
203
205
const initialDate = this . entryToEdit [ date ] ;
@@ -246,7 +248,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
246
248
onGoingToWorkOnThisChange ( event : any ) {
247
249
this . goingToWorkOnThis = event . currentTarget . checked ;
248
250
if ( ! this . goingToWorkOnThis ) {
249
- this . entryForm . patchValue ( { end_hour : formatDate ( new Date ( ) , 'HH:mm:ss' , 'en' ) } ) ;
251
+ this . entryForm . patchValue ( {
252
+ end_date : formatDate ( get ( this . entryToEdit , 'start_date' , '' ) , DATE_FORMAT , 'en' ) ,
253
+ end_hour : formatDate ( get ( this . entryToEdit , 'start_date' , '00:00' ) , 'HH:mm' , 'en' ) ,
254
+ } ) ;
250
255
}
251
256
this . shouldRestartEntry = ! this . entryToEdit ?. running && this . goingToWorkOnThis ;
252
257
}
0 commit comments