@@ -20,15 +20,13 @@ import { ProjectSelectedEvent } from './project-selected-event';
2020import { get } from 'lodash' ;
2121import { DATE_FORMAT } from 'src/environments/environment' ;
2222
23-
2423type Merged = TechnologyState & ProjectState & ActivityState & EntryState ;
2524@Component ( {
2625 selector : 'app-details-fields' ,
2726 templateUrl : './details-fields.component.html' ,
2827 styleUrls : [ './details-fields.component.scss' ] ,
2928} )
3029export class DetailsFieldsComponent implements OnChanges , OnInit {
31-
3230 keyword = 'search_field' ;
3331 @Input ( ) entryToEdit : Entry ;
3432 @Input ( ) canMarkEntryAsWIP : boolean ;
@@ -43,8 +41,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4341 goingToWorkOnThis = false ;
4442 shouldRestartEntry = false ;
4543
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+ ) {
4850 this . entryForm = this . formBuilder . group ( {
4951 project_id : [ '' , Validators . required ] ,
5052 project_name : [ '' , Validators . required ] ,
@@ -66,11 +68,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6668 if ( projects ) {
6769 this . listProjects = [ ] ;
6870 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+ } ) ;
7475 }
7576 } ) ;
7677
@@ -95,31 +96,32 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
9596 }
9697 } ) ;
9798
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+ } ) ;
106110 }
107111
108112 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+ } ) ;
114117 }
115118
116119 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+ } ) ;
123125 }
124126
125127 ngOnChanges ( ) : void {
@@ -197,7 +199,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
197199 this . closeModal ?. nativeElement ?. click ( ) ;
198200 }
199201
200- dateToSubmit ( date , hour ) {
202+ dateToSubmit ( date , hour ) {
201203 const entryFormDate = this . entryForm . value [ date ] ;
202204 const updatedHour = this . entryForm . value [ hour ] ;
203205 const initialDate = this . entryToEdit [ date ] ;
@@ -246,7 +248,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
246248 onGoingToWorkOnThisChange ( event : any ) {
247249 this . goingToWorkOnThis = event . currentTarget . checked ;
248250 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+ } ) ;
250255 }
251256 this . shouldRestartEntry = ! this . entryToEdit ?. running && this . goingToWorkOnThis ;
252257 }
0 commit comments