@@ -276,6 +276,71 @@ class IndicatorHandler {
276
276
return request ;
277
277
}
278
278
279
+ prepareDataLayerPayload ( form_mode ) {
280
+ var payload = {
281
+ event : "submitSelectedIndicators" ,
282
+ formMode : form_mode ,
283
+ numIndicators : this . indicators . length ,
284
+ numCovidcastIndicators : this . getCovidcastIndicators ( ) . length ,
285
+ numFluviewIndicators : this . getFluviewIndicators ( ) . length ,
286
+ numNIDSSFluIndicators : this . getNIDSSFluIndicators ( ) . length ,
287
+ numNIDSSDengueIndicators : this . getNIDSSDengueIndicators ( ) . length ,
288
+ numFlusurvIndicators : this . getFlusurvIndicators ( ) . length ,
289
+ formStartDate : document . getElementById ( "start_date" ) . value ,
290
+ formEndDate : document . getElementById ( "end_date" ) . value ,
291
+ apiKey : document . getElementById ( "apiKey" ) . value ? document . getElementById ( "apiKey" ) . value : "Not provided" ,
292
+ clientId : clientId ? clientId : "Not available" ,
293
+ } ;
294
+ var covidcastGeoValues = $ ( "#geographic_value" ) . select2 ( "data" )
295
+ if ( covidcastGeoValues !== undefined && covidcastGeoValues !== null ) {
296
+ covidcastGeoValues = Object . values (
297
+ covidcastGeoValues
298
+ . flat ( )
299
+ . map ( ( { id } ) => id
300
+ ) ) ;
301
+ payload . covidcastGeoValues = covidcastGeoValues ;
302
+ }
303
+ var fluviewGeoValues = $ ( "#fluviewLocations" ) . select2 ( "data" )
304
+ if ( fluviewGeoValues !== undefined && fluviewGeoValues !== null ) {
305
+ fluviewGeoValues = Object . values (
306
+ fluviewGeoValues
307
+ . flat ( )
308
+ . map ( ( { id } ) => id
309
+ ) ) ;
310
+ payload . fluviewGeoValues = fluviewGeoValues ;
311
+ }
312
+ var nidssFluGeoValues = $ ( "#nidssFluLocations" ) . select2 ( "data" )
313
+ if ( nidssFluGeoValues !== undefined && nidssFluGeoValues !== null ) {
314
+ nidssFluGeoValues = Object . values (
315
+ nidssFluGeoValues
316
+ . flat ( )
317
+ . map ( ( { id } ) => id
318
+ ) ) ;
319
+ payload . nidssFluGeoValues = nidssFluGeoValues ;
320
+ }
321
+ var nidssDengueGeoValues = $ ( "#nidssDengueLocations" ) . select2 ( "data" )
322
+ if ( nidssDengueGeoValues !== undefined && nidssDengueGeoValues !== null ) {
323
+ nidssDengueGeoValues = Object . values (
324
+ nidssDengueGeoValues
325
+ . flat ( )
326
+ . map ( ( { id } ) => id
327
+ ) ) ;
328
+ payload . nidssDengueGeoValues = nidssDengueGeoValues ;
329
+ }
330
+ var flusurvGeoValues = $ ( "#flusurvLocations" ) . select2 ( "data" )
331
+ if ( flusurvGeoValues !== undefined && flusurvGeoValues !== null ) {
332
+ flusurvGeoValues = Object . values (
333
+ flusurvGeoValues
334
+ . flat ( )
335
+ . map ( ( { id } ) => id
336
+ ) ) ;
337
+ payload . flusurvGeoValues = flusurvGeoValues ;
338
+ }
339
+
340
+ return payload ;
341
+
342
+ }
343
+
279
344
showfluviewLocations ( ) {
280
345
var fluviewLocationselect = `
281
346
<div class="row margin-top-1rem" id="fluviewDiv">
@@ -376,8 +441,8 @@ class IndicatorHandler {
376
441
nidssFluLocations : nidssFluLocations ,
377
442
nidssDengueLocations : nidssDengueLocations ,
378
443
flusurvLocations : flusurvLocations ,
379
- apiKey : document . getElementById ( "apiKey" ) . value ,
380
- clientId : clientId ,
444
+ apiKey : document . getElementById ( "apiKey" ) . value ? document . getElementById ( "apiKey" ) . value : "Not provided" ,
445
+ clientId : clientId ? clientId : "Not available" ,
381
446
} ;
382
447
const csrftoken = Cookies . get ( "csrftoken" ) ;
383
448
$ . ajax ( {
@@ -388,19 +453,9 @@ class IndicatorHandler {
388
453
contentType : "application/json" ,
389
454
headers : { "X-CSRFToken" : csrftoken } ,
390
455
data : JSON . stringify ( submitData ) ,
391
- } ) . done ( function ( data ) {
392
- const payload = {
393
- event : "submitSelectedIndicators" ,
394
- formMode : "epivis" ,
395
- covidcastGeoValues : JSON . stringify ( submitData [ "covidCastGeographicValues" ] ) ,
396
- fluviewGeoValues : JSON . stringify ( submitData [ "fluviewLocations" ] ) ,
397
- nidssFluLocations : JSON . stringify ( submitData [ "nidssFluLocations" ] ) ,
398
- nidssDengueLocations : JSON . stringify ( submitData [ "nidssDengueLocations" ] ) ,
399
- flusurvLocations : JSON . stringify ( submitData [ "flusurvLocations" ] ) ,
400
- epivisUrl : data [ "epivis_url" ] ,
401
- apiKey : submitData [ "apiKey" ] ? submitData [ "apiKey" ] : "Not provided" ,
402
- clientId : clientId ? clientId : "Not available" ,
403
- }
456
+ } ) . done ( ( data ) => {
457
+ const payload = this . prepareDataLayerPayload ( "epivis" ) ;
458
+ console . log ( payload ) ;
404
459
dataLayerPush ( payload ) ;
405
460
window . open ( data [ "epivis_url" ] , '_blank' ) . focus ( ) ;
406
461
} ) ;
@@ -425,8 +480,8 @@ class IndicatorHandler {
425
480
nidssFluLocations : nidssFluLocations ,
426
481
nidssDengueLocations : nidssDengueLocations ,
427
482
flusurvLocations : flusurvLocations ,
428
- apiKey : document . getElementById ( "apiKey" ) . value ,
429
- clientId : clientId ,
483
+ apiKey : document . getElementById ( "apiKey" ) . value ? document . getElementById ( "apiKey" ) . value : "Not provided" ,
484
+ clientId : clientId ? clientId : "Not available" ,
430
485
}
431
486
const csrftoken = Cookies . get ( "csrftoken" ) ;
432
487
$ . ajax ( {
@@ -437,20 +492,8 @@ class IndicatorHandler {
437
492
contentType : "application/json" ,
438
493
headers : { "X-CSRFToken" : csrftoken } ,
439
494
data : JSON . stringify ( submitData ) ,
440
- } ) . done ( function ( data ) {
441
- const payload = {
442
- event : "submitSelectedIndicators" ,
443
- formMode : "export" ,
444
- formStartDate : submitData [ "start_date" ] ,
445
- formEndDate : submitData [ "end_date" ] ,
446
- covidcastGeoValues : JSON . stringify ( submitData [ "covidCastGeographicValues" ] ) ,
447
- fluviewGeoValues : JSON . stringify ( submitData [ "fluviewLocations" ] ) ,
448
- nidssFluLocations : JSON . stringify ( submitData [ "nidssFluLocations" ] ) ,
449
- nidssDengueLocations : JSON . stringify ( submitData [ "nidssDengueLocations" ] ) ,
450
- flusurvLocations : JSON . stringify ( submitData [ "flusurvLocations" ] ) ,
451
- apiKey : submitData [ "apiKey" ] ? submitData [ "apiKey" ] : "Not provided" ,
452
- clientId : clientId ? clientId : "Not available" ,
453
- }
495
+ } ) . done ( ( data ) => {
496
+ const payload = this . prepareDataLayerPayload ( "export" ) ;
454
497
dataLayerPush ( payload ) ;
455
498
$ ( '#modeSubmitResult' ) . html ( data [ "data_export_block" ] ) ;
456
499
} ) ;
@@ -476,8 +519,8 @@ class IndicatorHandler {
476
519
nidssFluLocations : nidssFluLocations ,
477
520
nidssDengueLocations : nidssDengueLocations ,
478
521
flusurvLocations : flusurvLocations ,
479
- apiKey : document . getElementById ( "apiKey" ) . value ,
480
- clientId : clientId ,
522
+ apiKey : document . getElementById ( "apiKey" ) . value ? document . getElementById ( "apiKey" ) . value : "Not provided" ,
523
+ clientId : clientId ? clientId : "Not available" ,
481
524
}
482
525
const csrftoken = Cookies . get ( "csrftoken" ) ;
483
526
$ . ajax ( {
@@ -487,20 +530,8 @@ class IndicatorHandler {
487
530
contentType : "application/json" ,
488
531
headers : { "X-CSRFToken" : csrftoken } ,
489
532
data : JSON . stringify ( submitData ) ,
490
- } ) . done ( function ( data ) {
491
- const payload = {
492
- event : "submitSelectedIndicators" ,
493
- formMode : "preview" ,
494
- formStartDate : submitData [ "start_date" ] ,
495
- formEndDate : submitData [ "end_date" ] ,
496
- covidcastGeoValues : JSON . stringify ( submitData [ "covidCastGeographicValues" ] ) ,
497
- fluviewGeoValues : JSON . stringify ( submitData [ "fluviewLocations" ] ) ,
498
- nidssFluLocations : JSON . stringify ( submitData [ "nidssFluLocations" ] ) ,
499
- nidssDengueLocations : JSON . stringify ( submitData [ "nidssDengueLocations" ] ) ,
500
- flusurvLocations : JSON . stringify ( submitData [ "flusurvLocations" ] ) ,
501
- apiKey : submitData [ "apiKey" ] ? submitData [ "apiKey" ] : "Not provided" ,
502
- clientId : clientId ? clientId : "Not available" ,
503
- }
533
+ } ) . done ( ( data ) => {
534
+ const payload = this . prepareDataLayerPayload ( "previewData" ) ;
504
535
dataLayerPush ( payload ) ;
505
536
$ ( '#loader' ) . hide ( ) ;
506
537
$ ( '#modeSubmitResult' ) . html ( JSON . stringify ( data , null , 2 ) ) ;
@@ -527,8 +558,8 @@ class IndicatorHandler {
527
558
nidssFluLocations : nidssFluLocations ,
528
559
nidssDengueLocations : nidssDengueLocations ,
529
560
flusurvLocations : flusurvLocations ,
530
- apiKey : document . getElementById ( "apiKey" ) . value ,
531
- clientId : clientId ,
561
+ apiKey : document . getElementById ( "apiKey" ) . value ? document . getElementById ( "apiKey" ) . value : "Not provided" ,
562
+ clientId : clientId ? clientId : "Not available" ,
532
563
}
533
564
const csrftoken = Cookies . get ( "csrftoken" ) ;
534
565
var createQueryCodePython = `<h4>PYTHON PACKAGE</h4>`
@@ -546,20 +577,8 @@ class IndicatorHandler {
546
577
contentType : "application/json" ,
547
578
headers : { "X-CSRFToken" : csrftoken } ,
548
579
data : JSON . stringify ( submitData ) ,
549
- } ) . done ( function ( data ) {
550
- const payload = {
551
- event : "submitSelectedIndicators" ,
552
- formMode : "queryCode" ,
553
- formStartDate : submitData [ "start_date" ] ,
554
- formEndDate : submitData [ "end_date" ] ,
555
- covidcastGeoValues : JSON . stringify ( submitData [ "covidCastGeographicValues" ] ) ,
556
- fluviewGeoValues : JSON . stringify ( submitData [ "fluviewLocations" ] ) ,
557
- nidssFluLocations : JSON . stringify ( submitData [ "nidssFluLocations" ] ) ,
558
- nidssDengueLocations : JSON . stringify ( submitData [ "nidssDengueLocations" ] ) ,
559
- flusurvLocations : JSON . stringify ( submitData [ "flusurvLocations" ] ) ,
560
- apiKey : submitData [ "apiKey" ] ? submitData [ "apiKey" ] : "Not provided" ,
561
- clientId : clientId ? clientId : "Not available" ,
562
- }
580
+ } ) . done ( ( data ) => {
581
+ const payload = this . prepareDataLayerPayload ( "createQueryCode" ) ;
563
582
dataLayerPush ( payload ) ;
564
583
createQueryCodePython += data [ "python_code_blocks" ] . join ( "<br>" ) ;
565
584
createQueryCodeR += data [ "r_code_blocks" ] . join ( "<br>" ) ;
0 commit comments