1
- import { getActiveTimeEntry } from './../../store/entry.selectors' ;
1
+ import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
2
+ import { EntryActionTypes , LoadActiveEntry } from './../../store/entry.actions' ;
3
+ import { filter } from 'rxjs/operators' ;
2
4
import { Component , OnInit } from '@angular/core' ;
3
5
import { FormBuilder , FormGroup } from '@angular/forms' ;
4
- import { select , Store } from '@ngrx/store' ;
6
+ import { Store , ActionsSubject } from '@ngrx/store' ;
5
7
6
8
import { Activity , NewEntry } from '../../../shared/models' ;
7
9
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
8
10
import { TechnologyState } from '../../../shared/store/technology.reducers' ;
9
- import { ActivityState , allActivities , LoadActivities } from '../../../activities-management/store' ;
11
+ import { ActivityState , LoadActivities } from '../../../activities-management/store' ;
10
12
11
13
import * as entryActions from '../../store/entry.actions' ;
12
14
@@ -24,37 +26,44 @@ export class EntryFieldsComponent implements OnInit {
24
26
activeEntry ;
25
27
newData ;
26
28
27
- constructor ( private formBuilder : FormBuilder , private store : Store < Merged > ) {
29
+ constructor ( private formBuilder : FormBuilder , private store : Store < Merged > , private actionsSubject$ : ActionsSubject ) {
28
30
this . entryForm = this . formBuilder . group ( {
29
31
description : '' ,
30
32
uri : '' ,
31
- activity_id : '-1 ' ,
33
+ activity_id : '' ,
32
34
} ) ;
33
35
}
34
36
35
37
ngOnInit ( ) : void {
36
38
this . store . dispatch ( new LoadActivities ( ) ) ;
37
- const activities$ = this . store . pipe ( select ( allActivities ) ) ;
38
- activities$ . subscribe ( ( response ) => {
39
- this . activities = response ;
40
- this . loadActiveEntry ( ) ;
39
+
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 ( ) ) ;
41
45
} ) ;
42
- }
43
46
44
- loadActiveEntry ( ) {
45
- const activeEntry$ = this . store . pipe ( select ( getActiveTimeEntry ) ) ;
46
- activeEntry$ . subscribe ( ( response ) => {
47
- if ( response ) {
48
- this . activeEntry = response ;
49
- this . setDataToUpdate ( this . activeEntry ) ;
50
- this . newData = {
51
- id : this . activeEntry . id ,
52
- project_id : this . activeEntry . project_id ,
53
- uri : this . activeEntry . uri ,
54
- activity_id : this . activeEntry . activity_id ,
55
- } ;
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 ( ) ) ;
56
52
}
57
53
} ) ;
54
+
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
+ } ) ;
58
67
}
59
68
60
69
get activity_id ( ) {
0 commit comments