@@ -10,11 +10,11 @@ interface Session {
10
10
}
11
11
12
12
interface Main {
13
- default_period : Partial < DefaultPeriod > ;
13
+ default_period : Period ;
14
14
}
15
15
16
16
interface Dashboard {
17
- default_period : Partial < DefaultPeriod > ;
17
+ default_period : Partial < Period > ;
18
18
home : Partial < Home > ;
19
19
api : Partial < Api > ;
20
20
app : Partial < App > ;
@@ -23,26 +23,131 @@ interface Dashboard {
23
23
}
24
24
25
25
interface Api {
26
- default_period : Partial < DefaultPeriod > ;
26
+ default_period : Period ;
27
27
}
28
28
29
29
interface App {
30
- default_period : Partial < DefaultPeriod > ;
30
+ default_period : Partial < Period > ;
31
31
}
32
32
33
33
interface Database {
34
- default_period : Partial < DefaultPeriod > ;
34
+ default_period : Partial < Period > ;
35
35
}
36
36
37
37
interface User {
38
- default_period : Partial < DefaultPeriod > ;
38
+ default_period : Partial < Period > ;
39
39
}
40
40
41
41
interface Home {
42
- default_period : Partial < DefaultPeriod > ;
42
+ default_period : Partial < Period > ;
43
43
}
44
44
45
- interface DefaultPeriod {
46
- start : Date ;
47
- end : Date ;
45
+ export class QueryParams {
46
+ constructor ( public _period : Period , public _env : string , public _servers : string [ ] ) {
47
+ }
48
+
49
+ set period ( period : Period ) {
50
+ this . _period = period ;
51
+ }
52
+
53
+ get period ( ) : Period {
54
+ return this . _period ;
55
+ }
56
+
57
+ get env ( ) : string {
58
+ return this . _env ;
59
+ }
60
+
61
+ set servers ( servers : string [ ] ) {
62
+ this . _servers = servers ;
63
+ }
64
+
65
+ get servers ( ) : string [ ] {
66
+ return this . _servers ;
67
+ }
68
+
69
+ buildParams ( ) : { [ key : string ] : any } {
70
+ let params = { ...this . period . buildParams ( ) } ;
71
+ if ( this . servers && this . servers . length > 0 ) {
72
+ params = { ...params , server : this . servers . length == 1 ? this . servers [ 0 ] : this . servers } ;
73
+ }
74
+ if ( this . env ) {
75
+ params = { ...params , env : this . env } ;
76
+ }
77
+ return params ;
78
+ }
79
+
80
+ buildPath ( ) : string {
81
+ return Object . entries ( this . buildParams ( ) ) . map ( v => {
82
+ if ( Array . isArray ( v [ 1 ] ) ) {
83
+ if ( v [ 1 ] . length ) return v [ 1 ] . map ( a => `${ v [ 0 ] } =${ a } ` ) . join ( '&' ) ;
84
+ else return null ;
85
+ }
86
+ return `${ v [ 0 ] } =${ v [ 1 ] } ` ;
87
+ } ) . filter ( s => s != null ) . join ( '&' ) ;
88
+ }
89
+ }
90
+
91
+ export class IPeriod implements Period {
92
+ constructor ( public _start : Date , public _end : Date ) {
93
+ }
94
+
95
+ set start ( start : Date ) {
96
+ this . _start = start ;
97
+ }
98
+
99
+ get start ( ) : Date {
100
+ return this . _start ;
101
+ }
102
+
103
+ set end ( end : Date ) {
104
+ this . _end = end ;
105
+ }
106
+
107
+ get end ( ) : Date {
108
+ return this . _end ;
109
+ }
110
+
111
+ buildParams ( ) : { start : string , end : string } {
112
+ return { start : this . start . toISOString ( ) , end : this . end . toISOString ( ) } ;
113
+ }
114
+ }
115
+
116
+ export class IStep implements Period {
117
+
118
+ constructor ( public _step : number ) {
119
+ }
120
+
121
+ set start ( start : Date ) {
122
+ console . warn ( "not implemented" ) ;
123
+ }
124
+
125
+ get start ( ) : Date {
126
+ let now = new Date ( ) ;
127
+ return new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) , now . getHours ( ) , now . getMinutes ( ) - this . _step ) ;
128
+ }
129
+
130
+ set end ( end : Date ) {
131
+ console . warn ( "not implemented" ) ;
132
+ }
133
+
134
+ get end ( ) : Date {
135
+ let now = new Date ( ) ;
136
+ now . setSeconds ( 0 , 0 ) ;
137
+ return now ;
138
+ }
139
+
140
+ buildParams ( ) : { step : number } {
141
+ return { step : this . _step } ;
142
+ }
143
+ }
144
+
145
+ export interface Period {
146
+ set start ( value : Date ) ;
147
+ get start ( ) : Date ;
148
+
149
+ set end ( value : Date ) ;
150
+ get end ( ) : Date ;
151
+
152
+ buildParams ( ) : { [ key : string ] : any } ;
48
153
}
0 commit comments