11import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
22import { EntryActionTypes , LoadActiveEntry } from './../../store/entry.actions' ;
3- import { filter } from 'rxjs/operators' ;
4- import { Component , OnInit } from '@angular/core' ;
3+ import { filter , map } from 'rxjs/operators' ;
4+ import { Component , OnDestroy , OnInit } from '@angular/core' ;
55import { FormBuilder , FormGroup } from '@angular/forms' ;
66import { Store , ActionsSubject , select } from '@ngrx/store' ;
77import { Activity , NewEntry } from '../../../shared/models' ;
88import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
99import { TechnologyState } from '../../../shared/store/technology.reducers' ;
1010import { ActivityState , LoadActivities } from '../../../activities-management/store' ;
11+ import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service' ;
1112
1213import * as entryActions from '../../store/entry.actions' ;
1314import { get } from 'lodash' ;
@@ -16,6 +17,7 @@ import { ToastrService } from 'ngx-toastr';
1617import { formatDate } from '@angular/common' ;
1718import { getTimeEntriesDataSource } from '../../store/entry.selectors' ;
1819import { DATE_FORMAT } from 'src/environments/environment' ;
20+ import { Subscription } from 'rxjs' ;
1921
2022type Merged = TechnologyState & ProjectState & ActivityState ;
2123
@@ -24,16 +26,24 @@ type Merged = TechnologyState & ProjectState & ActivityState;
2426 templateUrl : './entry-fields.component.html' ,
2527 styleUrls : [ './entry-fields.component.scss' ] ,
2628} )
27- export class EntryFieldsComponent implements OnInit {
29+ export class EntryFieldsComponent implements OnInit , OnDestroy {
2830 entryForm : FormGroup ;
2931 selectedTechnologies : string [ ] = [ ] ;
3032 activities : Activity [ ] = [ ] ;
3133 activeEntry ;
3234 newData ;
3335 lastEntry ;
3436 showTimeInbuttons = false ;
37+ loadActivitiesSubscribe : Subscription ;
38+ loadActiveEntrySubscribe : Subscription ;
39+ actionSetDateSubscribe : Subscription ;
40+ loadActivitiesSubject ;
41+ loadActiveEntrySubject ;
42+ actionSetDateSubject ;
43+ exponentialGrowth : Boolean ;
3544
3645 constructor (
46+ private featureManagerService : FeatureManagerService ,
3747 private formBuilder : FormBuilder ,
3848 private store : Store < Merged > ,
3949 private actionsSubject$ : ActionsSubject ,
@@ -48,17 +58,24 @@ export class EntryFieldsComponent implements OnInit {
4858 } ) ;
4959 }
5060
51- ngOnInit ( ) : void {
61+ async ngOnInit ( ) : Promise < void > {
62+
63+ this . exponentialGrowth = await this . isFeatureToggleActivated ( ) ;
64+
65+ console . log ( this . exponentialGrowth ) ;
66+
5267 this . store . dispatch ( new LoadActivities ( ) ) ;
5368 this . store . dispatch ( new entryActions . LoadEntries ( new Date ( ) . getMonth ( ) + 1 , new Date ( ) . getFullYear ( ) ) ) ;
54- this . actionsSubject$
69+ this . loadActivitiesSubject = this . actionsSubject$
5570 . pipe ( filter ( ( action : any ) => action . type === ActivityManagementActionTypes . LOAD_ACTIVITIES_SUCCESS ) )
5671 . subscribe ( ( action ) => {
5772 this . activities = action . payload ;
5873 this . store . dispatch ( new LoadActiveEntry ( ) ) ;
5974 } ) ;
6075
61- this . actionsSubject$
76+ this . exponentialGrowth ? this . loadActivitiesSubscribe = this . loadActivitiesSubject : this . loadActivitiesSubject ;
77+
78+ this . loadActiveEntrySubject = this . actionsSubject$
6279 . pipe (
6380 filter (
6481 ( action : any ) =>
@@ -77,7 +94,9 @@ export class EntryFieldsComponent implements OnInit {
7794 }
7895 } ) ;
7996
80- this . actionsSubject$
97+ this . exponentialGrowth ? this . loadActiveEntrySubscribe = this . loadActiveEntrySubject : this . loadActiveEntrySubject ;
98+
99+ this . actionSetDateSubject = this . actionsSubject$
81100 . pipe ( filter ( ( action : any ) => action . type === EntryActionTypes . LOAD_ACTIVE_ENTRY_SUCCESS ) )
82101 . subscribe ( ( action ) => {
83102 this . activeEntry = action . payload ;
@@ -91,6 +110,8 @@ export class EntryFieldsComponent implements OnInit {
91110 start_hour : formatDate ( this . activeEntry . start_date , 'HH:mm' , 'en' ) ,
92111 } ;
93112 } ) ;
113+
114+ this . exponentialGrowth ? this . actionSetDateSubscribe = this . actionSetDateSubject : this . actionSetDateSubject ;
94115 }
95116
96117 get activity_id ( ) {
@@ -174,4 +195,23 @@ export class EntryFieldsComponent implements OnInit {
174195 onTechnologyRemoved ( $event : string [ ] ) {
175196 this . store . dispatch ( new entryActions . UpdateEntryRunning ( { ...this . newData , technologies : $event } ) ) ;
176197 }
198+
199+
200+ ngOnDestroy ( ) : void {
201+ console . log ( this . exponentialGrowth ) ;
202+ if ( this . exponentialGrowth ) {
203+ this . loadActivitiesSubscribe . unsubscribe ( ) ;
204+ this . loadActiveEntrySubscribe . unsubscribe ( ) ;
205+ this . actionSetDateSubscribe . unsubscribe ( ) ;
206+ }
207+ console . log ( 'Entry Fields OnDestroy' ) ;
208+ }
209+
210+ isFeatureToggleActivated ( ) {
211+ return this . featureManagerService . isToggleEnabledForUser ( 'exponential-growth' ) . pipe (
212+ map ( ( enabled ) => {
213+ return enabled === true ? true : false ;
214+ } )
215+ ) . toPromise ( ) ;
216+ }
177217}
0 commit comments