Skip to content

Commit 24cc987

Browse files
committed
[ExtractFiles][xs]: Fix papaparse script download
1 parent 10b5508 commit 24cc987

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

ckanext/dataexplorer/public/vendor/recline/recline.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 +4814,7 @@ 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
48234819
// var endpoint = `https://ckan.nhs.staging.datopian.com/api/3/action/datastore_search_sql?sql=${sql_query}`;
48244820
self.progress();
@@ -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];

test.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ host = 0.0.0.0
99
port = 5000
1010

1111
[app:main]
12-
use = config:../ckan/test-core.ini
12+
use = config:../../src/ckan/test-core.ini
1313

1414
# Insert any custom config settings to be used when running your extension's
1515
# tests here.
@@ -46,4 +46,4 @@ level = NOTSET
4646
formatter = generic
4747

4848
[formatter_generic]
49-
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s
49+
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s

0 commit comments

Comments
 (0)