@@ -19,8 +19,6 @@ import {ActivatedRoute, Params, Router} from "@angular/router";
1919
2020@Injectable ( )
2121export class ResultSelectionStore {
22- from : Date ;
23- to : Date ;
2422 _resultSelectionCommand$ : BehaviorSubject < ResultSelectionCommand > ;
2523 _remainingResultSelection$ : BehaviorSubject < RemainingResultSelection > ;
2624
@@ -68,10 +66,15 @@ export class ResultSelectionStore {
6866 selectedTimeFrameInterval : 'interval'
6967 } ;
7068
71- constructor ( private resultSelectionService : ResultSelectionService , route : ActivatedRoute , private router : Router ) {
72- this . _resultSelectionCommand$ = new BehaviorSubject < ResultSelectionCommand > ( { } ) ;
69+ constructor ( private resultSelectionService : ResultSelectionService , private route : ActivatedRoute , private router : Router ) {
70+ this . _resultSelectionCommand$ = new BehaviorSubject < ResultSelectionCommand > ( { caller : Caller . EventResult } ) ;
7371 this . _remainingResultSelection$ = new BehaviorSubject < RemainingResultSelection > ( { } ) ;
74- route . queryParams . subscribe ( ( params : Params ) => {
72+
73+ this . readQueryParams ( ) ;
74+ }
75+
76+ readQueryParams ( ) : void {
77+ this . route . queryParams . subscribe ( ( params : Params ) => {
7578 if ( params ) {
7679 params = this . renameParamKeys ( this . oldToNewChartKeyMap , params ) ;
7780 this . validQuery = this . checkQuery ( params ) ;
@@ -101,22 +104,9 @@ export class ResultSelectionStore {
101104 this . _remainingResultSelection$ . next ( remainingResultSelection ) ;
102105 }
103106 } ) ;
104-
105- if ( ! this . validQuery ) {
106- let defaultFrom = new Date ( ) ;
107- let defaultTo = new Date ( ) ;
108- defaultFrom . setDate ( defaultTo . getDate ( ) - 3 ) ;
109-
110- const resultSelectionCommand : ResultSelectionCommand = {
111- from : defaultFrom ,
112- to : defaultTo ,
113- caller : Caller . EventResult
114- } ;
115- this . _resultSelectionCommand$ . next ( resultSelectionCommand ) ;
116- }
117107 }
118108
119- writeQueryParams ( additionalParams ?: Params ) {
109+ writeQueryParams ( additionalParams ?: Params ) : void {
120110 this . router . navigate ( [ ] , {
121111 queryParams : {
122112 from : this . resultSelectionCommand . from . toISOString ( ) ,
@@ -157,27 +147,6 @@ export class ResultSelectionStore {
157147 } ) ;
158148 }
159149
160- private checkQuery ( params : Params ) : boolean {
161- const dates : Date [ ] = [ new Date ( params . from ) , new Date ( params . to ) ] ;
162- const datesValid : boolean = dates . every ( this . isValidDate ) ;
163- const jobGroupIdsValid : boolean = ! ! params . jobGroupIds ;
164-
165- return datesValid && jobGroupIdsValid ;
166- }
167-
168- private isValidDate ( date : Date ) {
169- return date instanceof Date && ! isNaN ( date . getTime ( ) )
170- }
171-
172- private renameParamKeys = ( keysMap , object ) =>
173- Object . keys ( object ) . reduce (
174- ( acc , key ) => ( {
175- ...acc ,
176- ...{ [ keysMap [ key ] || key ] : object [ key ] }
177- } ) ,
178- { }
179- ) ;
180-
181150 setResultSelectionCommandTimeFrame ( timeFrame : Date [ ] ) : void {
182151 this . setResultSelectionCommand ( { ...this . resultSelectionCommand , from : timeFrame [ 0 ] , to : timeFrame [ 1 ] } ) ;
183152 }
@@ -216,6 +185,27 @@ export class ResultSelectionStore {
216185 return this . _remainingResultSelection$ . getValue ( ) ;
217186 }
218187
188+ private checkQuery ( params : Params ) : boolean {
189+ const dates : Date [ ] = [ new Date ( params . from ) , new Date ( params . to ) ] ;
190+ const datesValid : boolean = dates . every ( this . isValidDate ) ;
191+ const jobGroupIdsValid : boolean = ! ! params . jobGroupIds ;
192+
193+ return datesValid && jobGroupIdsValid ;
194+ }
195+
196+ private isValidDate ( date : Date ) {
197+ return date instanceof Date && ! isNaN ( date . getTime ( ) )
198+ }
199+
200+ private renameParamKeys = ( keysMap , object ) =>
201+ Object . keys ( object ) . reduce (
202+ ( acc , key ) => ( {
203+ ...acc ,
204+ ...{ [ keysMap [ key ] || key ] : object [ key ] }
205+ } ) ,
206+ { }
207+ ) ;
208+
219209 private setRemainingResultSelection ( newState : RemainingResultSelection ) : void {
220210 this . dataAvailable$ . next ( true ) ;
221211 this . _remainingResultSelection$ . next ( newState ) ;
0 commit comments