@@ -8,17 +8,33 @@ import {combineLatest, finalize, Subscription} from 'rxjs';
8
8
import { Location } from '@angular/common' ;
9
9
import { Utils } from 'src/app/shared/util' ;
10
10
import { TraceService } from 'src/app/service/trace.service' ;
11
- import { application , makePeriod } from 'src/environments/environment' ;
11
+ import { application , makeDatePeriod , makeDateTimePeriod } from 'src/environments/environment' ;
12
12
import { Constants , Filter , FilterConstants , FilterMap , FilterPreset } from '../../constants' ;
13
13
import { FilterService } from 'src/app/service/filter.service' ;
14
14
import { InstanceMainSession } from 'src/app/model/trace.model' ;
15
15
import { EnvRouter } from "../../../service/router.service" ;
16
16
import { InstanceService } from "../../../service/jquery/instance.service" ;
17
+ import { DateAdapter , MAT_DATE_FORMATS } from "@angular/material/core" ;
18
+ import { CustomDateAdapter } from "../../../shared/material/custom-date-adapter" ;
19
+ import { MY_DATE_FORMATS } from "../../../shared/shared.module" ;
20
+ import { MAT_DATE_RANGE_SELECTION_STRATEGY } from "@angular/material/datepicker" ;
21
+ import { CustomDateRangeSelectionStrategy } from "../../../shared/material/custom-date-range-selection-strategy" ;
17
22
18
23
19
24
@Component ( {
20
25
templateUrl : './search-main.view.html' ,
21
26
styleUrls : [ './search-main.view.scss' ] ,
27
+ providers : [
28
+ {
29
+ provide : DateAdapter , useClass : CustomDateAdapter
30
+ } ,
31
+ {
32
+ provide : MAT_DATE_FORMATS , useValue : MY_DATE_FORMATS
33
+ } ,
34
+ {
35
+ provide : MAT_DATE_RANGE_SELECTION_STRATEGY , useClass : CustomDateRangeSelectionStrategy
36
+ }
37
+ ]
22
38
} )
23
39
export class SearchMainView implements OnInit , OnDestroy {
24
40
private _router = inject ( EnvRouter ) ;
@@ -50,6 +66,9 @@ export class SearchMainView implements OnInit, OnDestroy {
50
66
filter : string = '' ;
51
67
params : Partial < { env : string , start : Date , end : Date , type : string , serveurs : string [ ] } > = { } ;
52
68
69
+ subscriptionServer : Subscription ;
70
+ subscriptionSession : Subscription ;
71
+
53
72
@ViewChild ( MatPaginator ) paginator : MatPaginator ;
54
73
@ViewChild ( MatSort ) sort : MatSort ;
55
74
@@ -60,17 +79,16 @@ export class SearchMainView implements OnInit, OnDestroy {
60
79
this . _activatedRoute . queryParams
61
80
] ) . subscribe ( {
62
81
next : ( [ params , queryParams ] ) => {
63
- console . log ( params . type_main , 'test' )
64
82
this . params . env = queryParams [ 'env' ] || application . default_env ;
65
83
this . params . type = params . type_main ;
66
- this . params . start = queryParams [ 'start' ] ? new Date ( queryParams [ 'start' ] ) : ( application . session . main . default_period || makePeriod ( 0 , 1 ) ) . start ;
67
- this . params . end = queryParams [ 'end' ] ? new Date ( queryParams [ 'end' ] ) : ( application . session . main . default_period || makePeriod ( 0 , 1 ) ) . end ;
84
+ this . params . start = queryParams [ 'start' ] ? new Date ( queryParams [ 'start' ] ) : ( application . session . main . default_period || makeDateTimePeriod ( 1 ) ) . start ;
85
+ this . params . end = queryParams [ 'end' ] ? new Date ( queryParams [ 'end' ] ) : ( application . session . main . default_period || makeDateTimePeriod ( 1 ) ) . end ;
68
86
this . params . serveurs = Array . isArray ( queryParams [ 'appname' ] ) ? queryParams [ 'appname' ] : [ queryParams [ 'appname' ] || '' ] ;
69
87
if ( this . params . serveurs [ 0 ] != '' ) {
70
88
this . patchServerValue ( this . params . serveurs )
71
89
}
72
- this . patchDateValue ( this . params . start , new Date ( this . params . end . getFullYear ( ) , this . params . end . getMonth ( ) , this . params . end . getDate ( ) - 1 ) ) ;
73
- this . subscriptions . push ( this . _instanceService . getApplications ( this . params . type == 'view' ? 'CLIENT' : 'SERVER' )
90
+ this . patchDateValue ( this . params . start , new Date ( this . params . end . getFullYear ( ) , this . params . end . getMonth ( ) , this . params . end . getDate ( ) , this . params . end . getHours ( ) , this . params . end . getMinutes ( ) , this . params . end . getSeconds ( ) , this . params . end . getMilliseconds ( ) - 1 ) ) ;
91
+ this . subscriptionServer = this . _instanceService . getApplications ( this . params . type == 'view' ? 'CLIENT' : 'SERVER' )
74
92
. pipe ( finalize ( ( ) => this . serverNameIsLoading = false ) )
75
93
. subscribe ( {
76
94
next : res => {
@@ -79,20 +97,28 @@ export class SearchMainView implements OnInit, OnDestroy {
79
97
} , error : ( e ) => {
80
98
console . log ( e )
81
99
}
82
- } ) ) ;
100
+ } ) ;
83
101
this . getMainRequests ( ) ;
84
102
this . _location . replaceState ( `${ this . _router . url . split ( '?' ) [ 0 ] } ?env=${ this . params . env } &start=${ this . params . start . toISOString ( ) } &end=${ this . params . end . toISOString ( ) } ${ this . params . serveurs [ 0 ] !== '' ? '&' + this . params . serveurs . map ( name => `appname=${ name } ` ) . join ( '&' ) : '' } ` )
85
103
}
86
104
} ) ;
87
105
}
88
106
107
+ onChangeStart ( event ) {
108
+ this . serverFilterForm . controls . dateRangePicker . controls . end . updateValueAndValidity ( { onlySelf : true } )
109
+ }
110
+
111
+ onChangeEnd ( event ) {
112
+ this . serverFilterForm . controls . dateRangePicker . controls . start . updateValueAndValidity ( { onlySelf : true } )
113
+ }
89
114
90
115
ngOnInit ( ) : void {
91
116
92
117
}
93
118
94
119
ngOnDestroy ( ) : void {
95
- this . subscriptions . forEach ( s => s . unsubscribe ( ) ) ;
120
+ if ( this . subscriptionSession ) this . subscriptionSession . unsubscribe ( ) ;
121
+ if ( this . subscriptionServer ) this . subscriptionServer . unsubscribe ( ) ;
96
122
}
97
123
98
124
getMainRequests ( ) {
@@ -110,7 +136,7 @@ export class SearchMainView implements OnInit, OnDestroy {
110
136
111
137
this . isLoading = true ;
112
138
this . dataSource . data = [ ] ;
113
- this . subscriptions . push ( this . _traceService . getMainSessions ( params ) . subscribe ( ( d : InstanceMainSession [ ] ) => {
139
+ this . subscriptionSession = this . _traceService . getMainSessions ( params ) . subscribe ( ( d : InstanceMainSession [ ] ) => {
114
140
if ( d ) {
115
141
this . dataSource = new MatTableDataSource ( d ) ;
116
142
this . dataSource . paginator = this . paginator ;
@@ -148,24 +174,25 @@ export class SearchMainView implements OnInit, OnDestroy {
148
174
}
149
175
} , error => {
150
176
this . isLoading = false ;
151
- } ) ) ;
177
+ } ) ;
152
178
}
153
179
154
180
155
181
search ( ) {
156
182
if ( this . serverFilterForm . valid ) {
183
+ if ( this . subscriptionSession ) this . subscriptionSession . unsubscribe ( ) ;
157
184
let appname = this . serverFilterForm . getRawValue ( ) . appname ;
158
185
let start = this . serverFilterForm . getRawValue ( ) . dateRangePicker . start ;
159
- let end = this . serverFilterForm . getRawValue ( ) . dateRangePicker . end
160
- let excludedEnd = new Date ( end . getFullYear ( ) , end . getMonth ( ) , end . getDate ( ) + 1 )
186
+ let end = this . serverFilterForm . getRawValue ( ) . dateRangePicker . end ;
187
+ let _end = new Date ( end . getFullYear ( ) , end . getMonth ( ) , end . getDate ( ) , end . getHours ( ) , end . getMinutes ( ) , 59 , 1000 ) ;
161
188
if ( this . params . start . toISOString ( ) != start . toISOString ( )
162
- || this . params . end . toISOString ( ) != excludedEnd . toISOString ( )
189
+ || this . params . end . toISOString ( ) != end . toISOString ( )
163
190
|| ! this . params ?. serveurs ?. every ( ( element , index ) => element === appname [ index ] )
164
191
|| appname . length != this . params ?. serveurs ?. length ) {
165
192
this . _router . navigate ( [ ] , {
166
193
relativeTo : this . _activatedRoute ,
167
194
queryParamsHandling : 'merge' ,
168
- queryParams : { ...( appname !== undefined && { appname } ) , start : start . toISOString ( ) , end : excludedEnd }
195
+ queryParams : { ...( appname !== undefined && { appname } ) , start : start . toISOString ( ) , end : _end . toISOString ( ) }
169
196
} )
170
197
} else {
171
198
this . getMainRequests ( ) ;
@@ -214,7 +241,7 @@ export class SearchMainView implements OnInit, OnDestroy {
214
241
}
215
242
216
243
resetFilters ( ) {
217
- this . patchDateValue ( ( application . session . api . default_period || makePeriod ( 0 ) ) . start , ( application . session . api . default_period || makePeriod ( 0 , 1 ) ) . end ) ;
244
+ this . patchDateValue ( ( application . session . api . default_period || makeDatePeriod ( 0 ) ) . start , ( application . session . api . default_period || makeDatePeriod ( 0 , 1 ) ) . end ) ;
218
245
this . advancedParams = { } ;
219
246
this . _filter . setFilterMap ( { } )
220
247
}
0 commit comments