@@ -11,12 +11,9 @@ import {
11
11
} from '@angular/core' ;
12
12
import { FormBuilder , FormGroup } from '@angular/forms' ;
13
13
import { Store , select } from '@ngrx/store' ;
14
- import * as actions from '../../store/technology.actions' ;
15
14
import { formatDate } from '@angular/common' ;
16
15
17
- import { allTechnologies } from '../../store/technology.selectors' ;
18
- import { Technology , Project , Activity } from '../../models' ;
19
-
16
+ import { Project , Activity } from '../../models' ;
20
17
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
21
18
import { TechnologyState } from '../../store/technology.reducers' ;
22
19
import { LoadActivities , ActivityState , allActivities } from '../../../activities-management/store' ;
@@ -40,7 +37,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
40
37
@ViewChild ( 'closeModal' ) closeModal : ElementRef ;
41
38
@ViewChild ( 'list' ) list : ElementRef ;
42
39
entryForm : FormGroup ;
43
- technology : Technology ;
44
40
selectedTechnologies : string [ ] = [ ] ;
45
41
isLoading = false ;
46
42
listProjects : Project [ ] = [ ] ;
@@ -56,8 +52,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
56
52
}
57
53
} ) ;
58
54
this . entryForm = this . formBuilder . group ( {
59
- project : '' ,
60
- activity : '' ,
55
+ project_id : '' ,
56
+ activity_id : '' ,
61
57
description : '' ,
62
58
start_date : '' ,
63
59
end_date : '' ,
@@ -69,11 +65,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
69
65
}
70
66
71
67
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
- } ) ;
77
68
78
69
this . store . dispatch ( new projectActions . LoadProjects ( ) ) ;
79
70
const projects$ = this . store . pipe ( select ( getProjects ) ) ;
@@ -90,15 +81,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
90
81
const updateError$ = this . store . pipe ( select ( getUpdateError ) ) ;
91
82
updateError$ . subscribe ( ( updateError ) => {
92
83
if ( updateError != null && ! updateError ) {
93
- this . closeEntryModal ( ) ;
94
84
this . store . dispatch ( new entryActions . CleanEntryUpdateError ( null ) ) ;
85
+ this . closeEntryModal ( ) ;
95
86
}
96
87
} ) ;
97
88
const createError$ = this . store . pipe ( select ( getCreateError ) ) ;
98
89
createError$ . subscribe ( ( createError ) => {
99
90
if ( createError != null && ! createError ) {
100
- this . closeEntryModal ( ) ;
101
91
this . store . dispatch ( new entryActions . CleanEntryCreateError ( null ) ) ;
92
+ this . closeEntryModal ( ) ;
102
93
}
103
94
} ) ;
104
95
}
@@ -107,11 +98,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
107
98
this . hoursValidation = false ;
108
99
if ( this . entryToEdit ) {
109
100
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 ) ;
112
101
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 ,
115
104
description : this . entryToEdit . description ,
116
105
start_date : this . entryToEdit . start_date ? formatDate ( this . entryToEdit . start_date , 'yyyy-MM-dd' , 'en' ) : '' ,
117
106
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 {
123
112
} else {
124
113
this . selectedTechnologies = [ ] ;
125
114
this . entryForm . setValue ( {
126
- project : '' ,
127
- activity : '' ,
115
+ project_id : '' ,
116
+ activity_id : '' ,
128
117
description : '' ,
129
118
start_date : formatDate ( new Date ( ) , 'yyyy-MM-dd' , 'en' ) ,
130
119
start_hour : '00:00' ,
@@ -136,22 +125,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
136
125
}
137
126
}
138
127
139
- getTechnologies ( value ) {
140
- if ( value . length >= 2 ) {
141
- this . showlist = true ;
142
- this . store . dispatch ( new actions . FindTechnology ( value ) ) ;
143
- }
144
- }
145
-
146
128
onTechnologiesUpdated ( $event : string [ ] ) {
147
129
this . selectedTechnologies = $event ;
148
130
}
149
131
150
- get project ( ) {
151
- return this . entryForm . get ( 'project ' ) ;
132
+ get project_id ( ) {
133
+ return this . entryForm . get ( 'project_id ' ) ;
152
134
}
153
- get activity ( ) {
154
- return this . entryForm . get ( 'activity ' ) ;
135
+ get activity_id ( ) {
136
+ return this . entryForm . get ( 'activity_id ' ) ;
155
137
}
156
138
157
139
get start_date ( ) {
@@ -176,12 +158,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
176
158
}
177
159
178
160
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 ) ;
181
161
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 : [ ] ,
185
165
description : this . entryForm . value . description ,
186
166
start_date : `${ this . entryForm . value . start_date } T${ this . entryForm . value . start_hour } ` ,
187
167
end_date : `${ this . entryForm . value . end_date } T${ this . entryForm . value . end_hour } ` ,
0 commit comments