@@ -903,47 +903,32 @@ function BlackboxLogViewer() {
903903 reader . readAsText ( file ) ;
904904 }
905905
906- function exportCsv ( file , options = { } ) {
907-
908- function onSuccess ( data ) {
909- console . debug ( "CSV export finished in" , ( performance . now ( ) - startTime ) / 1000 , "secs" ) ;
906+ function createExportCallback ( fileExtension , fileType , file , startTime ) {
907+ const callback = function ( data ) {
908+ console . debug ( `${ fileExtension . toUpperCase ( ) } export finished in ${ ( performance . now ( ) - startTime ) / 1000 } secs` ) ;
910909 if ( ! data ) {
911910 console . debug ( "Empty data, nothing to save" ) ;
912911 return ;
913912 }
914- let blob = new Blob ( [ data ] , { type : 'text/csv' } ) ,
913+ let blob = new Blob ( [ data ] , { type : fileType } ) ,
915914 e = document . createEvent ( 'MouseEvents' ) ,
916915 a = document . createElement ( 'a' ) ;
917- a . download = file || $ ( ".log-filename" ) . text ( ) + ".csv" ;
916+ a . download = file || $ ( ".log-filename" ) . text ( ) + "." + fileExtension ;
918917 a . href = window . URL . createObjectURL ( blob ) ;
919- a . dataset . downloadurl = [ 'text/csv' , a . download , a . href ] . join ( ':' ) ;
918+ a . dataset . downloadurl = [ fileType , a . download , a . href ] . join ( ':' ) ;
920919 e . initMouseEvent ( 'click' , true , false , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ;
921920 a . dispatchEvent ( e ) ;
922- }
921+ }
922+ return callback ;
923+ }
923924
924- let startTime = performance . now ( ) ;
925+ function exportCsv ( file , options = { } ) {
926+ const onSuccess = createExportCallback ( 'csv' , 'text/csv' , file , performance . now ( ) ) ;
925927 CsvExporter ( flightLog , options ) . dump ( onSuccess ) ;
926928 }
927929
928930 function exportGpx ( file ) {
929-
930- function onSuccess ( data ) {
931- console . debug ( "Gpx export finished in" , ( performance . now ( ) - startTime ) / 1000 , "secs" ) ;
932- if ( ! data ) {
933- console . debug ( "Empty data, nothing to save" ) ;
934- return ;
935- }
936- let blob = new Blob ( [ data ] , { type : 'GPX File' } ) ,
937- e = document . createEvent ( 'MouseEvents' ) ,
938- a = document . createElement ( 'a' ) ;
939- a . download = file || $ ( ".log-filename" ) . text ( ) + ".gpx" ;
940- a . href = window . URL . createObjectURL ( blob ) ;
941- a . dataset . downloadurl = [ 'GPX File' , a . download , a . href ] . join ( ':' ) ;
942- e . initMouseEvent ( 'click' , true , false , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ;
943- a . dispatchEvent ( e ) ;
944- }
945-
946- let startTime = performance . now ( ) ;
931+ const onSuccess = createExportCallback ( 'gpx' , 'GPX File' , file , performance . now ( ) ) ;
947932 GpxExporter ( flightLog ) . dump ( onSuccess ) ;
948933 }
949934
0 commit comments