@@ -12,10 +12,6 @@ import { ActivityState, LoadActivities } from '../../../activities-management/st
12
12
13
13
import * as entryActions from '../../store/entry.actions' ;
14
14
15
- import * as moment from 'moment' ;
16
- import { ToastrService } from 'ngx-toastr' ;
17
- import { formatDate } from '@angular/common' ;
18
-
19
15
type Merged = TechnologyState & ProjectState & ActivityState ;
20
16
21
17
@Component ( {
@@ -30,75 +26,56 @@ export class EntryFieldsComponent implements OnInit {
30
26
activeEntry ;
31
27
newData ;
32
28
33
- constructor (
34
- private formBuilder : FormBuilder ,
35
- private store : Store < Merged > ,
36
- private actionsSubject$ : ActionsSubject ,
37
- private toastrService : ToastrService
38
- ) {
29
+ constructor ( private formBuilder : FormBuilder , private store : Store < Merged > , private actionsSubject$ : ActionsSubject ) {
39
30
this . entryForm = this . formBuilder . group ( {
40
31
description : '' ,
41
32
uri : '' ,
42
33
activity_id : '' ,
43
- start_hour : '' ,
44
- start_date : '' ,
45
34
} ) ;
46
35
}
47
36
48
37
ngOnInit ( ) : void {
49
38
this . store . dispatch ( new LoadActivities ( ) ) ;
50
39
51
- this . actionsSubject$
52
- . pipe ( filter ( ( action : any ) => action . type === ActivityManagementActionTypes . LOAD_ACTIVITIES_SUCCESS ) )
53
- . subscribe ( ( action ) => {
54
- this . activities = action . payload ;
55
- this . store . dispatch ( new LoadActiveEntry ( ) ) ;
56
- } ) ;
40
+ this . actionsSubject$ . pipe (
41
+ filter ( ( action : any ) => ( action . type === ActivityManagementActionTypes . LOAD_ACTIVITIES_SUCCESS ) )
42
+ ) . subscribe ( ( action ) => {
43
+ this . activities = action . payload ;
44
+ this . store . dispatch ( new LoadActiveEntry ( ) ) ;
45
+ } ) ;
57
46
58
- this . actionsSubject$
59
- . pipe (
60
- filter ( ( action : any ) => (
61
- action . type === EntryActionTypes . CREATE_ENTRY_SUCCESS ||
62
- action . type === EntryActionTypes . UPDATE_ENTRY_SUCCESS
63
- ) )
64
- ) . subscribe ( ( action ) => {
65
- if ( ! action . payload . end_date ) {
66
- this . store . dispatch ( new LoadActiveEntry ( ) ) ;
67
- this . store . dispatch ( new entryActions . LoadEntriesSummary ( ) ) ;
68
- }
69
- } ) ;
47
+ this . actionsSubject$ . pipe (
48
+ filter ( ( action : any ) => ( action . type === EntryActionTypes . CREATE_ENTRY_SUCCESS ) )
49
+ ) . subscribe ( ( action ) => {
50
+ if ( ! action . payload . end_date ) {
51
+ this . store . dispatch ( new LoadActiveEntry ( ) ) ;
52
+ }
53
+ } ) ;
70
54
71
- this . actionsSubject$
72
- . pipe ( filter ( ( action : any ) => action . type === EntryActionTypes . LOAD_ACTIVE_ENTRY_SUCCESS ) )
73
- . subscribe ( ( action ) => {
74
- this . activeEntry = action . payload ;
75
- this . setDataToUpdate ( this . activeEntry ) ;
76
- this . newData = {
77
- id : this . activeEntry . id ,
78
- project_id : this . activeEntry . project_id ,
79
- uri : this . activeEntry . uri ,
80
- activity_id : this . activeEntry . activity_id ,
81
- start_date : this . activeEntry . start_date ,
82
- start_hour : formatDate ( this . activeEntry . start_date , 'HH:mm:ss' , 'en' ) ,
83
- } ;
84
- } ) ;
55
+ this . actionsSubject$ . pipe (
56
+ filter ( ( action : any ) => ( action . type === EntryActionTypes . LOAD_ACTIVE_ENTRY_SUCCESS ) )
57
+ ) . subscribe ( ( action ) => {
58
+ this . activeEntry = action . payload ;
59
+ this . setDataToUpdate ( this . activeEntry ) ;
60
+ this . newData = {
61
+ id : this . activeEntry . id ,
62
+ project_id : this . activeEntry . project_id ,
63
+ uri : this . activeEntry . uri ,
64
+ activity_id : this . activeEntry . activity_id ,
65
+ } ;
66
+ } ) ;
85
67
}
86
68
87
69
get activity_id ( ) {
88
70
return this . entryForm . get ( 'activity_id' ) ;
89
71
}
90
72
91
- get start_hour ( ) {
92
- return this . entryForm . get ( 'start_hour' ) ;
93
- }
94
-
95
73
setDataToUpdate ( entryData : NewEntry ) {
96
74
if ( entryData ) {
97
75
this . entryForm . patchValue ( {
98
76
description : entryData . description ,
99
77
uri : entryData . uri ,
100
78
activity_id : entryData . activity_id ,
101
- start_hour : formatDate ( entryData . start_date , 'HH:mm:ss' , 'en' ) ,
102
79
} ) ;
103
80
if ( entryData . technologies ) {
104
81
this . selectedTechnologies = entryData . technologies ;
@@ -116,19 +93,6 @@ export class EntryFieldsComponent implements OnInit {
116
93
this . store . dispatch ( new entryActions . UpdateEntryRunning ( { ...this . newData , ...this . entryForm . value } ) ) ;
117
94
}
118
95
119
- onUpdateStartHour ( ) {
120
- const startDate = formatDate ( this . activeEntry . start_date , 'yyyy-MM-dd' , 'en' ) ;
121
- const newHourEntered = new Date ( `${ startDate } T${ this . entryForm . value . start_hour . trim ( ) } ` ) . toISOString ( ) ;
122
- const isEntryDateInTheFuture = moment ( newHourEntered ) . isAfter ( moment ( ) ) ;
123
- if ( isEntryDateInTheFuture ) {
124
- this . toastrService . error ( 'You cannot start a time-entry in the future' ) ;
125
- this . entryForm . patchValue ( { start_hour : this . newData . start_hour } ) ;
126
- return ;
127
- }
128
- this . entryForm . patchValue ( { start_date : newHourEntered } ) ;
129
- this . store . dispatch ( new entryActions . UpdateEntryRunning ( { ...this . newData , ...this . entryForm . value } ) ) ;
130
- }
131
-
132
96
onTechnologyAdded ( $event : string [ ] ) {
133
97
this . store . dispatch ( new entryActions . UpdateEntryRunning ( { ...this . newData , technologies : $event } ) ) ;
134
98
}
0 commit comments