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' ;
24import { Component , OnInit } from '@angular/core' ;
35import { FormBuilder , FormGroup } from '@angular/forms' ;
4- import { select , Store } from '@ngrx/store' ;
6+ import { Store , ActionsSubject } from '@ngrx/store' ;
57
68import { Activity , NewEntry } from '../../../shared/models' ;
79import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
810import { TechnologyState } from '../../../shared/store/technology.reducers' ;
9- import { ActivityState , allActivities , LoadActivities } from '../../../activities-management/store' ;
11+ import { ActivityState , LoadActivities } from '../../../activities-management/store' ;
1012
1113import * as entryActions from '../../store/entry.actions' ;
1214
@@ -24,37 +26,44 @@ export class EntryFieldsComponent implements OnInit {
2426 activeEntry ;
2527 newData ;
2628
27- constructor ( private formBuilder : FormBuilder , private store : Store < Merged > ) {
29+ constructor ( private formBuilder : FormBuilder , private store : Store < Merged > , private actionsSubject$ : ActionsSubject ) {
2830 this . entryForm = this . formBuilder . group ( {
2931 description : '' ,
3032 uri : '' ,
31- activity_id : '-1 ' ,
33+ activity_id : '' ,
3234 } ) ;
3335 }
3436
3537 ngOnInit ( ) : void {
3638 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 ( ) ) ;
4145 } ) ;
42- }
4346
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 ( ) ) ;
5652 }
5753 } ) ;
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+ } ) ;
5867 }
5968
6069 get activity_id ( ) {
0 commit comments