11import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
2- import { EntryActionTypes , LoadActiveEntry } from './../../store/entry.actions' ;
3- import { filter } from 'rxjs/operators' ;
2+ import { EntryActionTypes , LoadActiveEntry , UpdateCurrentOrLastEntry , UpdateEntry } from './../../store/entry.actions' ;
3+ import { filter , map } from 'rxjs/operators' ;
44import { Component , OnDestroy , OnInit } from '@angular/core' ;
55import { FormBuilder , FormGroup } from '@angular/forms' ;
66import { Store , ActionsSubject , select } from '@ngrx/store' ;
@@ -15,7 +15,11 @@ import { ToastrService } from 'ngx-toastr';
1515import { formatDate } from '@angular/common' ;
1616import { getTimeEntriesDataSource } from '../../store/entry.selectors' ;
1717import { DATE_FORMAT } from 'src/environments/environment' ;
18- import { Subscription } from 'rxjs' ;
18+ import { Subscription , Observable } from 'rxjs' ;
19+
20+ import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service' ;
21+ import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service' ;
22+
1923
2024type Merged = TechnologyState & ProjectState & ActivityState ;
2125
@@ -35,12 +39,16 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
3539 loadActivitiesSubscription : Subscription ;
3640 loadActiveEntrySubscription : Subscription ;
3741 actionSetDateSubscription : Subscription ;
42+ isEnableToggleSubscription : Subscription ;
43+ isTestUser : boolean ;
3844
3945 constructor (
4046 private formBuilder : FormBuilder ,
4147 private store : Store < Merged > ,
4248 private actionsSubject$ : ActionsSubject ,
43- private toastrService : ToastrService
49+ private toastrService : ToastrService ,
50+ private azureService : AzureAdB2CService ,
51+ private featureManagerService : FeatureManagerService
4452 ) {
4553 this . entryForm = this . formBuilder . group ( {
4654 description : '' ,
@@ -60,6 +68,11 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6068 this . activities = action . payload ;
6169 this . store . dispatch ( new LoadActiveEntry ( ) ) ;
6270 } ) ;
71+
72+ this . isEnableToggleSubscription = this . isFeatureToggleActivated ( ) . subscribe ( ( flag ) => {
73+ this . isTestUser = flag ;
74+ } ) ;
75+
6376 this . loadActiveEntrySubscription = this . actionsSubject$
6477 . pipe (
6578 filter (
@@ -145,10 +158,20 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
145158 return ;
146159 }
147160 this . entryForm . patchValue ( { start_date : newHourEntered } ) ;
148- this . store . dispatch ( new entryActions . UpdateCurrentOrLastEntry ( { ...this . newData , ...this . entryForm . value } ) ) ;
161+ if ( this . isTestUser ) {
162+ this . newData . owner_id = this . getOwnerId ( ) ;
163+ this . newData . update_last_entry_if_overlap = true ;
164+ this . store . dispatch ( new entryActions . UpdateEntry ( { ...this . newData , ...this . entryForm . value } ) ) ;
165+ } else {
166+ this . store . dispatch ( new entryActions . UpdateCurrentOrLastEntry ( { ...this . newData , ...this . entryForm . value } ) ) ;
167+ }
149168 this . showTimeInbuttons = false ;
150169 }
151170
171+ getOwnerId ( ) {
172+ return this . azureService . getUserId ( ) ;
173+ }
174+
152175 private getLastEntry ( ) {
153176 const lastEntry$ = this . store . pipe ( select ( getTimeEntriesDataSource ) ) ;
154177 lastEntry$ . subscribe ( ( entry ) => {
@@ -178,4 +201,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
178201 this . loadActiveEntrySubscription . unsubscribe ( ) ;
179202 this . actionSetDateSubscription . unsubscribe ( ) ;
180203 }
204+
205+ isFeatureToggleActivated ( ) : Observable < boolean > {
206+ return this . featureManagerService . isToggleEnabledForUser ( 'update-entries' )
207+ . pipe ( map ( ( enabled : boolean ) => enabled ) ) ;
208+ }
181209}
0 commit comments