@@ -276,6 +276,71 @@ class IndicatorHandler {
276276 return request ;
277277 }
278278
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+
279344 showfluviewLocations ( ) {
280345 var fluviewLocationselect = `
281346 <div class="row margin-top-1rem" id="fluviewDiv">
@@ -376,8 +441,8 @@ class IndicatorHandler {
376441 nidssFluLocations : nidssFluLocations ,
377442 nidssDengueLocations : nidssDengueLocations ,
378443 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" ,
381446 } ;
382447 const csrftoken = Cookies . get ( "csrftoken" ) ;
383448 $ . ajax ( {
@@ -388,19 +453,9 @@ class IndicatorHandler {
388453 contentType : "application/json" ,
389454 headers : { "X-CSRFToken" : csrftoken } ,
390455 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 ) ;
404459 dataLayerPush ( payload ) ;
405460 window . open ( data [ "epivis_url" ] , '_blank' ) . focus ( ) ;
406461 } ) ;
@@ -425,8 +480,8 @@ class IndicatorHandler {
425480 nidssFluLocations : nidssFluLocations ,
426481 nidssDengueLocations : nidssDengueLocations ,
427482 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" ,
430485 }
431486 const csrftoken = Cookies . get ( "csrftoken" ) ;
432487 $ . ajax ( {
@@ -437,20 +492,8 @@ class IndicatorHandler {
437492 contentType : "application/json" ,
438493 headers : { "X-CSRFToken" : csrftoken } ,
439494 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" ) ;
454497 dataLayerPush ( payload ) ;
455498 $ ( '#modeSubmitResult' ) . html ( data [ "data_export_block" ] ) ;
456499 } ) ;
@@ -476,8 +519,8 @@ class IndicatorHandler {
476519 nidssFluLocations : nidssFluLocations ,
477520 nidssDengueLocations : nidssDengueLocations ,
478521 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" ,
481524 }
482525 const csrftoken = Cookies . get ( "csrftoken" ) ;
483526 $ . ajax ( {
@@ -487,20 +530,8 @@ class IndicatorHandler {
487530 contentType : "application/json" ,
488531 headers : { "X-CSRFToken" : csrftoken } ,
489532 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" ) ;
504535 dataLayerPush ( payload ) ;
505536 $ ( '#loader' ) . hide ( ) ;
506537 $ ( '#modeSubmitResult' ) . html ( JSON . stringify ( data , null , 2 ) ) ;
@@ -527,8 +558,8 @@ class IndicatorHandler {
527558 nidssFluLocations : nidssFluLocations ,
528559 nidssDengueLocations : nidssDengueLocations ,
529560 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" ,
532563 }
533564 const csrftoken = Cookies . get ( "csrftoken" ) ;
534565 var createQueryCodePython = `<h4>PYTHON PACKAGE</h4>`
@@ -546,20 +577,8 @@ class IndicatorHandler {
546577 contentType : "application/json" ,
547578 headers : { "X-CSRFToken" : csrftoken } ,
548579 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" ) ;
563582 dataLayerPush ( payload ) ;
564583 createQueryCodePython += data [ "python_code_blocks" ] . join ( "<br>" ) ;
565584 createQueryCodeR += data [ "r_code_blocks" ] . join ( "<br>" ) ;
0 commit comments