@@ -3,11 +3,9 @@ <h5>Plot / Export data</h5>
3
3
< div class ="row ">
4
4
< div class ="card ">
5
5
< div class ="card-body ">
6
- < form class ="margin-top-1rem " onsubmit ="submitMode(event) " id ="epivis-form ">
6
+ < form class ="margin-top-1rem " onsubmit ="submitMode(event) " id ="dataForm ">
7
7
8
- < div class ="alert alert-warning alert-dismissible fade show " role ="alert " id ="warning-alert ">
9
- < strong > Holy guacamole!</ strong > You should check in on some of those fields below.
10
- </ div >
8
+ < div class ="alert alert-warning alert-dismissible fade show " role ="alert " id ="warning-alert "> </ div >
11
9
12
10
< div class ="row ">
13
11
< div class ="col-2 ">
@@ -17,14 +15,18 @@ <h5>Plot / Export data</h5>
17
15
</ div >
18
16
< div class ="col-10 ">
19
17
< div class ="form-check form-check-inline ">
20
- < input class ="form-check-input " type ="radio " name ="modes " id ="epivis " value ="epivis " checked >
21
- < label class ="form-check-label " for ="epivis "> Plot data</ label >
22
- </ div >
23
- < div class ="form-check form-check-inline ">
24
- < input class ="form-check-input " type ="radio " name ="modes " id ="export " value ="export ">
25
- < label class ="form-check-label " for ="export "> Export data</ label >
26
- </ div >
18
+ < input class ="form-check-input " type ="radio " name ="modes " id ="preview " value ="preview " checked >
19
+ < label class ="form-check-label " for ="preview "> Preview data</ label >
20
+ </ div >
21
+ < div class ="form-check form-check-inline ">
22
+ < input class ="form-check-input " type ="radio " name ="modes " id ="epivis " value ="epivis ">
23
+ < label class ="form-check-label " for ="epivis "> Plot data</ label >
27
24
</ div >
25
+ < div class ="form-check form-check-inline ">
26
+ < input class ="form-check-input " type ="radio " name ="modes " id ="export " value ="export ">
27
+ < label class ="form-check-label " for ="export "> Export data</ label >
28
+ </ div >
29
+ </ div >
28
30
</ div >
29
31
< div class ="row margin-top-1rem ">
30
32
< div class ="col-2 ">
@@ -73,7 +75,19 @@ <h5>Plot / Export data</h5>
73
75
< select id ="geographic_value " name ="geographic_value " class ="form-select " multiple ="multiple "> </ select >
74
76
</ div >
75
77
</ div >
76
- < div class ="row margin-top-1rem " name ="choose_date " style ="display: none; ">
78
+ < div class ="row margin-top-1rem " id ="timeTypeDiv ">
79
+ < div class ="col-2 ">
80
+ < label for ="time_type " class ="form-label ">
81
+ Time Type:
82
+ </ label >
83
+ </ div >
84
+ < div class ="col-10 ">
85
+ < select id ="time_type " name ="time_type " class ="form-select " disabled >
86
+ < option selected > {{ signal.time_type }}</ option >
87
+ </ select >
88
+ </ div >
89
+ </ div >
90
+ < div class ="row margin-top-1rem " name ="choose_date ">
77
91
< div class ="col-2 ">
78
92
< label for ="start_date " class ="form-label ">
79
93
Start Date:
@@ -83,7 +97,7 @@ <h5>Plot / Export data</h5>
83
97
< input type ="date " class ="form-control " id ="start_date " name ="start_date ">
84
98
</ div >
85
99
</ div >
86
- < div class ="row margin-top-1rem " name ="choose_date " style =" display: none; " >
100
+ < div class ="row margin-top-1rem " name ="choose_date ">
87
101
< div class ="col-2 ">
88
102
< label for ="end_date " class ="form-label ">
89
103
End Date:
@@ -98,14 +112,17 @@ <h5>Plot / Export data</h5>
98
112
Submit
99
113
</ button >
100
114
</ div >
115
+ < div class ="row margin-top-1rem ">
116
+ < pre class ="margin-top-1rem "> < code id ="modeSubmitResult "> </ code > </ pre >
117
+ </ div >
101
118
</ form >
102
119
</ div >
103
120
</ div >
104
121
</ div >
105
122
</ section >
106
123
< script >
107
124
var geoValues = [ ] ;
108
- var currentMode = 'epivis ' ;
125
+ var currentMode = 'preview ' ;
109
126
110
127
function getFilteredGeographicValues ( geographicType ) {
111
128
var data = geoValues . reduce ( ( data , geoValue ) => {
@@ -124,7 +141,6 @@ <h5>Plot / Export data</h5>
124
141
} else {
125
142
maximumSelectionLength = 10 ;
126
143
}
127
-
128
144
if ( geographicType ) {
129
145
var data = getFilteredGeographicValues ( geographicType ) ;
130
146
} else {
@@ -141,23 +157,38 @@ <h5>Plot / Export data</h5>
141
157
142
158
document . getElementById ( 'geographic_type' ) . addEventListener ( "change" , ( event ) => {
143
159
$ ( '#geographic_value' ) . empty ( ) ;
160
+ $ ( '#modeSubmitResult' ) . html ( '' ) ;
144
161
initGeographicValueSelect ( currentMode , event . target . value ) ;
145
162
} )
146
163
147
164
function handleModeChange ( mode ) {
148
- document . getElementById ( "epivis-form" ) . reset ( ) ;
165
+ document . getElementById ( "dataForm" ) . reset ( ) ;
166
+ $ ( '#geographic_value' ) . empty ( ) ;
167
+ $ ( '#modeSubmitResult' ) . html ( '' ) ;
149
168
150
169
var choose_dates = document . getElementsByName ( 'choose_date' ) ;
170
+ var time_type = document . getElementById ( 'timeTypeDiv' ) ;
171
+
151
172
if ( mode === 'epivis' ) {
152
173
currentMode = 'epivis' ;
153
174
choose_dates . forEach ( ( el ) => {
154
175
el . style . display = 'none' ;
155
176
} ) ;
156
- } else {
177
+ $ ( '#modeSubmitResult' ) . html ( '' ) ;
178
+ time_type . style . display = 'none' ;
179
+ } else if ( mode === 'export' ) {
157
180
currentMode = 'export' ;
158
181
choose_dates . forEach ( ( el ) => {
159
182
el . style . display = 'flex' ;
160
183
} ) ;
184
+ $ ( '#modeSubmitResult' ) . html ( '' ) ;
185
+ time_type . style . display = 'none' ;
186
+ } else {
187
+ currentMode = 'preview' ;
188
+ choose_dates . forEach ( ( el ) => {
189
+ el . style . display = 'flex' ;
190
+ } ) ;
191
+ time_type . style . display = 'flex' ;
161
192
}
162
193
document . getElementsByName ( "modes" ) . forEach ( ( el ) => {
163
194
if ( currentMode === el . value ) {
@@ -168,10 +199,9 @@ <h5>Plot / Export data</h5>
168
199
169
200
document . getElementsByName ( 'modes' ) . forEach ( ( el ) => {
170
201
el . addEventListener ( 'change' , ( event ) => {
171
- $ ( '#geographic_value' ) . empty ( ) ;
172
202
currentMode = event . target . value ;
173
- initGeographicValueSelect ( event . target . value )
174
- handleModeChange ( event . target . value ) ;
203
+ initGeographicValueSelect ( currentMode )
204
+ handleModeChange ( currentMode ) ;
175
205
} ) ;
176
206
} ) ;
177
207
@@ -221,7 +251,7 @@ <h5>Plot / Export data</h5>
221
251
222
252
epiVisUrl += `#${ urlParamsEncoded } ` ;
223
253
window . open ( epiVisUrl , '_blank' ) . focus ( ) ;
224
- } else {
254
+ } else if ( currentMode === 'export' ) {
225
255
var startDate = document . getElementById ( 'start_date' ) . value ;
226
256
var endDate = document . getElementById ( 'end_date' ) . value ;
227
257
@@ -233,7 +263,42 @@ <h5>Plot / Export data</h5>
233
263
}
234
264
235
265
dataExportUrl += `?signal=${ dataSource } :${ dataSignal } &start_day=${ startDate } &end_day=${ endDate } &geo_type=${ geographicType } &geo_values=${ geographicValue } ` ;
266
+ $ ( '#modeSubmitResult' ) . html ( `Manually fetch data: \n\nwget --content-disposition "${ dataExportUrl } "` ) ;
236
267
window . open ( dataExportUrl , '_blank' ) . focus ( ) ;
268
+ } else {
269
+ var timeType = document . getElementById ( 'time_type' ) . value ;
270
+
271
+ var startDate = document . getElementById ( 'start_date' ) . value . replaceAll ( '-' , '' ) ;
272
+ var endDate = document . getElementById ( 'end_date' ) . value . replaceAll ( '-' , '' ) ;
273
+
274
+ var requestSent = false ;
275
+
276
+ if ( ! requestSent ) {
277
+ $ . ajax ( {
278
+ url : 'https://api.covidcast.cmu.edu/epidata/covidcast/' ,
279
+ type : 'GET' ,
280
+ data : {
281
+ 'time_type' : timeType ,
282
+ 'time_values' : `${ startDate } -${ endDate } ` ,
283
+ 'data_source' : dataSource ,
284
+ 'signal' : dataSignal ,
285
+ 'geo_type' : geographicType ,
286
+ 'geo_values' : geographicValue
287
+ } ,
288
+ success : function ( result ) {
289
+ // Update the page with the response data.
290
+ // This depends on the structure of your response data.
291
+ // For example, if the response data is a string:
292
+ if ( result [ "epidata" ] . length > 1 ) {
293
+ result = { epidata : result [ "epidata" ] . slice ( 0 , 3 ) , result : result [ "result" ] , message : result [ "message" ] }
294
+ } else {
295
+ result = { epidata : result [ "epidata" ] , result : result [ "result" ] , message : result [ "message" ] }
296
+ }
297
+ $ ( '#modeSubmitResult' ) . html ( library . json . prettyPrint ( result ) ) ;
298
+ }
299
+ } ) ;
300
+ requestSent = true ;
301
+ } ;
237
302
}
238
303
}
239
304
0 commit comments