@@ -11,12 +11,9 @@ import {
1111} from '@angular/core' ;
1212import { FormBuilder , FormGroup } from '@angular/forms' ;
1313import { Store , select } from '@ngrx/store' ;
14- import * as actions from '../../store/technology.actions' ;
1514import { formatDate } from '@angular/common' ;
1615
17- import { allTechnologies } from '../../store/technology.selectors' ;
18- import { Technology , Project , Activity } from '../../models' ;
19-
16+ import { Project , Activity } from '../../models' ;
2017import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
2118import { TechnologyState } from '../../store/technology.reducers' ;
2219import { LoadActivities , ActivityState , allActivities } from '../../../activities-management/store' ;
@@ -40,7 +37,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4037 @ViewChild ( 'closeModal' ) closeModal : ElementRef ;
4138 @ViewChild ( 'list' ) list : ElementRef ;
4239 entryForm : FormGroup ;
43- technology : Technology ;
4440 selectedTechnologies : string [ ] = [ ] ;
4541 isLoading = false ;
4642 listProjects : Project [ ] = [ ] ;
@@ -56,8 +52,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
5652 }
5753 } ) ;
5854 this . entryForm = this . formBuilder . group ( {
59- project : '' ,
60- activity : '' ,
55+ project_id : '' ,
56+ activity_id : '' ,
6157 description : '' ,
6258 start_date : '' ,
6359 end_date : '' ,
@@ -69,11 +65,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6965 }
7066
7167 ngOnInit ( ) : void {
72- const technologies$ = this . store . pipe ( select ( allTechnologies ) ) ;
73- technologies$ . subscribe ( ( response ) => {
74- this . isLoading = response . isLoading ;
75- this . technology = response . technologyList ;
76- } ) ;
7768
7869 this . store . dispatch ( new projectActions . LoadProjects ( ) ) ;
7970 const projects$ = this . store . pipe ( select ( getProjects ) ) ;
@@ -90,15 +81,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
9081 const updateError$ = this . store . pipe ( select ( getUpdateError ) ) ;
9182 updateError$ . subscribe ( ( updateError ) => {
9283 if ( updateError != null && ! updateError ) {
93- this . closeEntryModal ( ) ;
9484 this . store . dispatch ( new entryActions . CleanEntryUpdateError ( null ) ) ;
85+ this . closeEntryModal ( ) ;
9586 }
9687 } ) ;
9788 const createError$ = this . store . pipe ( select ( getCreateError ) ) ;
9889 createError$ . subscribe ( ( createError ) => {
9990 if ( createError != null && ! createError ) {
100- this . closeEntryModal ( ) ;
10191 this . store . dispatch ( new entryActions . CleanEntryCreateError ( null ) ) ;
92+ this . closeEntryModal ( ) ;
10293 }
10394 } ) ;
10495 }
@@ -107,11 +98,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
10798 this . hoursValidation = false ;
10899 if ( this . entryToEdit ) {
109100 this . selectedTechnologies = this . entryToEdit . technologies ;
110- const project = this . listProjects . find ( ( p ) => p . id === this . entryToEdit . project_id ) ;
111- const activity = this . activities . find ( ( a ) => a . id === this . entryToEdit . activity_id ) ;
112101 this . entryForm . setValue ( {
113- project : project ? project . name : '' ,
114- activity : activity ? activity . name : '' ,
102+ project_id : this . entryToEdit . project_id ,
103+ activity_id : this . entryToEdit . activity_id ,
115104 description : this . entryToEdit . description ,
116105 start_date : this . entryToEdit . start_date ? formatDate ( this . entryToEdit . start_date , 'yyyy-MM-dd' , 'en' ) : '' ,
117106 start_hour : this . entryToEdit . start_date ? formatDate ( this . entryToEdit . start_date , 'HH:mm' , 'en' ) : '00:00' ,
@@ -123,8 +112,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
123112 } else {
124113 this . selectedTechnologies = [ ] ;
125114 this . entryForm . setValue ( {
126- project : '' ,
127- activity : '' ,
115+ project_id : '' ,
116+ activity_id : '' ,
128117 description : '' ,
129118 start_date : formatDate ( new Date ( ) , 'yyyy-MM-dd' , 'en' ) ,
130119 start_hour : '00:00' ,
@@ -136,22 +125,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
136125 }
137126 }
138127
139- getTechnologies ( value ) {
140- if ( value . length >= 2 ) {
141- this . showlist = true ;
142- this . store . dispatch ( new actions . FindTechnology ( value ) ) ;
143- }
144- }
145-
146128 onTechnologiesUpdated ( $event : string [ ] ) {
147129 this . selectedTechnologies = $event ;
148130 }
149131
150- get project ( ) {
151- return this . entryForm . get ( 'project ' ) ;
132+ get project_id ( ) {
133+ return this . entryForm . get ( 'project_id ' ) ;
152134 }
153- get activity ( ) {
154- return this . entryForm . get ( 'activity ' ) ;
135+ get activity_id ( ) {
136+ return this . entryForm . get ( 'activity_id ' ) ;
155137 }
156138
157139 get start_date ( ) {
@@ -176,12 +158,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
176158 }
177159
178160 onSubmit ( ) {
179- const activity = this . activities . find ( ( a ) => a . name === this . entryForm . value . activity ) ;
180- const project = this . listProjects . find ( ( p ) => p . name === this . entryForm . value . project ) ;
181161 const entry = {
182- project_id : project ? project . id : null ,
183- activity_id : activity ? activity . id : null ,
184- technologies : this . selectedTechnologies ,
162+ project_id : this . entryForm . value . project_id ,
163+ activity_id : this . entryForm . value . activity_id ,
164+ technologies : this . selectedTechnologies ? this . selectedTechnologies : [ ] ,
185165 description : this . entryForm . value . description ,
186166 start_date : `${ this . entryForm . value . start_date } T${ this . entryForm . value . start_hour } ` ,
187167 end_date : `${ this . entryForm . value . end_date } T${ this . entryForm . value . end_hour } ` ,
0 commit comments