1
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
+ import { EntryActionTypes , LoadActiveEntry , UpdateCurrentOrLastEntry , UpdateEntry } from './../../store/entry.actions' ;
3
+ import { filter , map } from 'rxjs/operators' ;
4
4
import { Component , OnDestroy , OnInit } from '@angular/core' ;
5
5
import { FormBuilder , FormGroup } from '@angular/forms' ;
6
6
import { Store , ActionsSubject , select } from '@ngrx/store' ;
@@ -15,7 +15,11 @@ import { ToastrService } from 'ngx-toastr';
15
15
import { formatDate } from '@angular/common' ;
16
16
import { getTimeEntriesDataSource } from '../../store/entry.selectors' ;
17
17
import { 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
+
19
23
20
24
type Merged = TechnologyState & ProjectState & ActivityState ;
21
25
@@ -35,12 +39,16 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
35
39
loadActivitiesSubscription : Subscription ;
36
40
loadActiveEntrySubscription : Subscription ;
37
41
actionSetDateSubscription : Subscription ;
42
+ isEnableToggleSubscription : Subscription ;
43
+ isTestUser : boolean ;
38
44
39
45
constructor (
40
46
private formBuilder : FormBuilder ,
41
47
private store : Store < Merged > ,
42
48
private actionsSubject$ : ActionsSubject ,
43
- private toastrService : ToastrService
49
+ private toastrService : ToastrService ,
50
+ private azureService : AzureAdB2CService ,
51
+ private featureManagerService : FeatureManagerService
44
52
) {
45
53
this . entryForm = this . formBuilder . group ( {
46
54
description : '' ,
@@ -60,6 +68,11 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
60
68
this . activities = action . payload ;
61
69
this . store . dispatch ( new LoadActiveEntry ( ) ) ;
62
70
} ) ;
71
+
72
+ this . isEnableToggleSubscription = this . isFeatureToggleActivated ( ) . subscribe ( ( flag ) => {
73
+ this . isTestUser = flag ;
74
+ } ) ;
75
+
63
76
this . loadActiveEntrySubscription = this . actionsSubject$
64
77
. pipe (
65
78
filter (
@@ -145,10 +158,20 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
145
158
return ;
146
159
}
147
160
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
+ }
149
168
this . showTimeInbuttons = false ;
150
169
}
151
170
171
+ getOwnerId ( ) {
172
+ return this . azureService . getUserId ( ) ;
173
+ }
174
+
152
175
private getLastEntry ( ) {
153
176
const lastEntry$ = this . store . pipe ( select ( getTimeEntriesDataSource ) ) ;
154
177
lastEntry$ . subscribe ( ( entry ) => {
@@ -178,4 +201,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
178
201
this . loadActiveEntrySubscription . unsubscribe ( ) ;
179
202
this . actionSetDateSubscription . unsubscribe ( ) ;
180
203
}
204
+
205
+ isFeatureToggleActivated ( ) : Observable < boolean > {
206
+ return this . featureManagerService . isToggleEnabledForUser ( 'update-entries' )
207
+ . pipe ( map ( ( enabled : boolean ) => enabled ) ) ;
208
+ }
181
209
}
0 commit comments