@@ -3577,12 +3577,14 @@ this.recline.View = this.recline.View || {};
35773577 self . model . query ( { sort : sort } ) ;
35783578 } ) ;
35793579
3580- this . _slickHandler . subscribe ( this . grid . onColumnsReordered , function (
3581- e ,
3582- args
3583- ) {
3584- self . state . set ( { columnsOrder : _ . pluck ( self . grid . getColumns ( ) , "id" ) } ) ;
3585- } ) ;
3580+ this . _slickHandler . subscribe (
3581+ this . grid . onColumnsReordered ,
3582+ function ( e , args ) {
3583+ self . state . set ( {
3584+ columnsOrder : _ . pluck ( self . grid . getColumns ( ) , "id" ) ,
3585+ } ) ;
3586+ }
3587+ ) ;
35863588
35873589 this . grid . onColumnsResized . subscribe ( function ( e , args ) {
35883590 var columns = args . grid . getColumns ( ) ;
@@ -4792,13 +4794,6 @@ this.recline.View = this.recline.View || {};
47924794 var self = this ;
47934795 e . preventDefault ( ) ;
47944796
4795- //preloads Papaparse and caches it
4796- var src = "https://unpkg.com/[email protected] /papaparse.min.js" ; 4797- $ . getScript ( src ) ;
4798- $ . ajaxSetup ( {
4799- cache : true ,
4800- } ) ;
4801-
48024797 // var format = this.$el.find(".select-format").val();
48034798 var fields = self . model . queryState . attributes . fields ;
48044799 var query = CKAN . _normalizeQuery ( self . model . queryState . attributes ) ;
@@ -4819,8 +4814,9 @@ this.recline.View = this.recline.View || {};
48194814 } ,
48204815 extractFile : function ( self , sql_query ) {
48214816 var base_path = self . model . attributes . endpoint || self . options . site_url ;
4817+ //console.log(base_path);
48224818 var endpoint = `${ base_path } /3/action/datastore_search_sql?sql=${ sql_query } ` ; // USE BASE_PATH IN PRODUCTION
4823- // var endpoint = `https://ckan.nhs.staging.datopian.com/api/3/action/datastore_search_sql?sql=${sql_query}`;
4819+ //var endpoint = `https://ckan.nhs.staging.datopian.com/api/3/action/datastore_search_sql?sql=${sql_query}`;
48244820 self . progress ( ) ;
48254821
48264822 fetch ( endpoint )
@@ -4853,33 +4849,40 @@ this.recline.View = this.recline.View || {};
48534849 } ,
48544850 exportCSVFile : function ( resp_json , filename , self ) {
48554851 var exported_filename = filename + ".csv" ;
4856- try {
4857- let csv = Papa . unparse ( resp_json ) ;
4858- var blob = new Blob ( [ csv ] , {
4859- type : "text/csv;charset=utf-8;" ,
4860- } ) ;
4861- if ( navigator . msSaveBlob ) {
4862- // IE 10+
4863- navigator . msSaveBlob ( blob , exported_filename ) ;
4864- } else {
4865- var link = document . createElement ( "a" ) ;
4866- if ( link . download !== undefined ) {
4867- // Browsers that support HTML5 download attribute
4868- var url = URL . createObjectURL ( blob ) ;
4869- link . setAttribute ( "href" , url ) ;
4870- link . setAttribute ( "download" , exported_filename ) ;
4871- link . style . visibility = "hidden" ;
4872- document . body . appendChild ( link ) ;
4873- link . click ( ) ;
4874- document . body . removeChild ( link ) ;
4852+ var src = "https://unpkg.com/[email protected] /papaparse.min.js" ; 4853+ $ . getScript ( src , function ( ) {
4854+ try {
4855+ let csv = Papa . unparse ( resp_json ) ;
4856+ var blob = new Blob ( [ csv ] , {
4857+ type : "text/csv;charset=utf-8;" ,
4858+ } ) ;
4859+ if ( navigator . msSaveBlob ) {
4860+ // IE 10+
4861+ navigator . msSaveBlob ( blob , exported_filename ) ;
4862+ } else {
4863+ var link = document . createElement ( "a" ) ;
4864+ if ( link . download !== undefined ) {
4865+ // Browsers that support HTML5 download attribute
4866+ var url = URL . createObjectURL ( blob ) ;
4867+ link . setAttribute ( "href" , url ) ;
4868+ link . setAttribute ( "download" , exported_filename ) ;
4869+ link . style . visibility = "hidden" ;
4870+ document . body . appendChild ( link ) ;
4871+ link . click ( ) ;
4872+ document . body . removeChild ( link ) ;
4873+ }
48754874 }
4875+ self . progress ( true ) ;
4876+ } catch ( error ) {
4877+ console . warn ( error ) ;
4878+ self . progress ( true ) ;
4879+ self . showErrorModal ( ) ;
48764880 }
4877- self . progress ( true ) ;
4878- } catch ( error ) {
4879- console . warn ( error ) ;
4880- self . progress ( true ) ;
4881- self . showErrorModal ( ) ;
4882- }
4881+ } ) ;
4882+ //caches Papaparse
4883+ $ . ajaxSetup ( {
4884+ cache : true ,
4885+ } ) ;
48834886 } ,
48844887 showErrorModal : function ( ) {
48854888 var modal = document . getElementsByClassName ( "modal" ) [ 0 ] ;
@@ -4983,7 +4986,7 @@ this.recline.View = this.recline.View || {};
49834986 }
49844987
49854988 if ( q != "" ) {
4986- let where_q = "" ;
4989+ let where_q = " WHERE " ;
49874990 for ( const [ key , value ] of Object . entries ( filters ) ) {
49884991 if ( this . get_field_type ( value ) == "string" ) {
49894992 where_q_str += ` LOWER(${ key } ) like LOWER("${ value . slice (
@@ -5003,15 +5006,13 @@ this.recline.View = this.recline.View || {};
50035006 return where_str ;
50045007 } ,
50055008 get_field_type : function ( value ) {
5006-
5007- if ( typeof value == "string" ) {
5008- return "string" ;
5009- }
50105009
5011- if ( typeof value == "number" ) {
5012- return "num"
5010+ if ( isNaN ( Number ( value ) ) ) {
5011+ return "string" ;
5012+ } else {
5013+ return "num" ;
50135014 }
5014-
5015+
50155016 } ,
50165017 } ) ;
50175018} ) ( jQuery , recline . View ) ;
0 commit comments