Skip to content

Commit

Permalink
Notify the user that we are just fetching the first 5000 submissions.…
Browse files Browse the repository at this point in the history
… Pagination is too slow client-side.
  • Loading branch information
hallahan committed Dec 6, 2016
1 parent 6e017e0 commit 83e1b21
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
6 changes: 1 addition & 5 deletions jekyll/js/submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ function doCSV(json) {
// show raw data if people really want it
$(".csv textarea").val(csv);

// download link to entire CSV as data
// thanks to http://jsfiddle.net/terryyounghk/KPEGU/
// and http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
var uri = "data:text/csv;charset=utf-8," + encodeURIComponent(csv);
$("#downloadCsv").attr("href", uri).attr("download", getParam('form') + ".csv");
$("#downloadCsv").attr("href", OMK.csvUrl()).attr("download", getParam('form') + ".csv");
$("#downloadJson").attr("href", OMK.jsonUrl()).attr("download", getParam('form') + ".json");
}

Expand Down
28 changes: 27 additions & 1 deletion jekyll/js/submissions/omk.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ OMK.fetch = function (cb) {
OMK.getFormMetaData(function(metadata) {
OMK.fetchJSON(OMK.jsonUrl() + '?offset=0&limit=' + OMK._PAGINATION_LIMIT, function() {
cb();
// pagination too slow
// OMK.paginate(metadata.total);

if (OMK._PAGINATION_LIMIT < metadata.total) {
var toastOptions = {
style: {
main: {
background: "#f2dede",
color: "#a94442",
'box-shadow': '0 0 0px'
}
}
};
iqwerty.toast.Toast('The data set is large. We have loaded ' + OMK._PAGINATION_LIMIT +
' of ' + metadata.total + ' submissions. Download the ODK CSV or JSON data to get the rest.', toastOptions);
}
});
});
};
Expand All @@ -23,6 +38,11 @@ OMK.jsonUrl = function () {
return json;
};

OMK.csvUrl = function () {
var form = getParam('form');
return OMK.omkServerUrl() + '/omk/odk/submissions/' + form + '.csv';
};

//Function to capitalise first character for strings
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
Expand All @@ -49,8 +69,14 @@ OMK.jsonPaginationUrl = function() {
return OMK.jsonUrl() + '?offset=' + OMK._paginationOffset + '&limit=' + OMK._PAGINATION_LIMIT;
};

/**
* Doing recursive loads of pagination of data is quite slow and halts the UI.
* We're going to disable this for now...
*
* @param total
*/
OMK.paginate = function (total) {
setTimeout(function() {
setTimeout(function() { // timeouts dont completely fix the UI from halting...
OMK._paginationOffset += OMK._PAGINATION_LIMIT;
if (OMK._paginationOffset < total) {
$.get(OMK.jsonPaginationUrl(), function (data, status, xhr) {
Expand Down
3 changes: 0 additions & 3 deletions jekyll/submissions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ <h2 class="rows count mdl-card__title-text"></h2>
</a>

<ul class="mdl-menu mdl-menu--bottom-right- mdl-js-menu mdl-js-ripple-effect" for="odk-options">
<a href="#">
<li class="showRawCSV mdl-menu__item">View CSV</li>
</a>
<a id="downloadCsv" download="data.csv" href="#" class="download">
<li class="mdl-menu__item">Download CSV</li>
</a>
Expand Down
6 changes: 1 addition & 5 deletions pages/js/submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ function doCSV(json) {
// show raw data if people really want it
$(".csv textarea").val(csv);

// download link to entire CSV as data
// thanks to http://jsfiddle.net/terryyounghk/KPEGU/
// and http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
var uri = "data:text/csv;charset=utf-8," + encodeURIComponent(csv);
$("#downloadCsv").attr("href", uri).attr("download", getParam('form') + ".csv");
$("#downloadCsv").attr("href", OMK.csvUrl()).attr("download", getParam('form') + ".csv");
$("#downloadJson").attr("href", OMK.jsonUrl()).attr("download", getParam('form') + ".json");
}

Expand Down
28 changes: 27 additions & 1 deletion pages/js/submissions/omk.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ OMK.fetch = function (cb) {
OMK.getFormMetaData(function(metadata) {
OMK.fetchJSON(OMK.jsonUrl() + '?offset=0&limit=' + OMK._PAGINATION_LIMIT, function() {
cb();
// pagination too slow
// OMK.paginate(metadata.total);

if (OMK._PAGINATION_LIMIT < metadata.total) {
var toastOptions = {
style: {
main: {
background: "#f2dede",
color: "#a94442",
'box-shadow': '0 0 0px'
}
}
};
iqwerty.toast.Toast('The data set is large. We have loaded ' + OMK._PAGINATION_LIMIT +
' of ' + metadata.total + ' submissions. Download the ODK CSV or JSON data to get the rest.', toastOptions);
}
});
});
};
Expand All @@ -23,6 +38,11 @@ OMK.jsonUrl = function () {
return json;
};

OMK.csvUrl = function () {
var form = getParam('form');
return OMK.omkServerUrl() + '/omk/odk/submissions/' + form + '.csv';
};

//Function to capitalise first character for strings
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
Expand All @@ -49,8 +69,14 @@ OMK.jsonPaginationUrl = function() {
return OMK.jsonUrl() + '?offset=' + OMK._paginationOffset + '&limit=' + OMK._PAGINATION_LIMIT;
};

/**
* Doing recursive loads of pagination of data is quite slow and halts the UI.
* We're going to disable this for now...
*
* @param total
*/
OMK.paginate = function (total) {
setTimeout(function() {
setTimeout(function() { // timeouts dont completely fix the UI from halting...
OMK._paginationOffset += OMK._PAGINATION_LIMIT;
if (OMK._paginationOffset < total) {
$.get(OMK.jsonPaginationUrl(), function (data, status, xhr) {
Expand Down
3 changes: 0 additions & 3 deletions pages/submissions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ <h2 class="rows count mdl-card__title-text"></h2>
</a>

<ul class="mdl-menu mdl-menu--bottom-right- mdl-js-menu mdl-js-ripple-effect" for="odk-options">
<a href="#">
<li class="showRawCSV mdl-menu__item">View CSV</li>
</a>
<a id="downloadCsv" download="data.csv" href="#" class="download">
<li class="mdl-menu__item">Download CSV</li>
</a>
Expand Down

0 comments on commit 83e1b21

Please sign in to comment.