Skip to content

Commit

Permalink
Merge pull request #35117 from dimagi/jls/b5-export-1
Browse files Browse the repository at this point in the history
[B5] Exports: split files into B3 and B5 versions
  • Loading branch information
orangejenny authored Sep 13, 2024
2 parents 120b1c5 + b43d3a8 commit 2b20f0e
Show file tree
Hide file tree
Showing 100 changed files with 7,398 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = function (grunt) {
*/
var apps = [
'app_manager',
'export/ko',
'export/ko/bootstrap3',
'export/ko/bootstrap5',
'notifications/bootstrap3',
'notifications/bootstrap5',
'reports_core/choiceListUtils',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
hqDefine('export/js/customize_export_new', [
hqDefine('export/js/bootstrap3/customize_export_new', [
'jquery',
'knockout',
'hqwebapp/js/initial_page_data',
'export/js/models',
'export/js/bootstrap3/models',
'hqwebapp/js/toggles',
'export/js/const',
], function (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hqDefine("export/js/download_data_files",[
hqDefine("export/js/bootstrap3/download_data_files",[
'jquery',
'hqwebapp/js/bootstrap3/alert_user',
'hqwebapp/js/initial_page_data',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* downloadProgressModel: Controls the progress bar, etc. once the user has clicked 'Prepare Export'.
* Includes functionality to email the user when the export is done, rather than them waiting for it.
*/
hqDefine('export/js/download_export', [
hqDefine('export/js/bootstrap3/download_export', [
'jquery',
'knockout',
'underscore',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* bulk export, which is a page-level action (you can select exports across panels to bulk export).
* It also controls filter editing (for daily saved / dashboard feeds).
*/
hqDefine("export/js/export_list", [
hqDefine("export/js/bootstrap3/export_list", [
'jquery',
'knockout',
'underscore',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
hqDefine("export/js/export_list_main", [
hqDefine("export/js/bootstrap3/export_list_main", [
'jquery',
'hqwebapp/js/initial_page_data',
'analytix/js/kissmetrix',
'hqwebapp/js/bootstrap3/main',
'export/js/create_export',
'export/js/export_list',
'export/js/bootstrap3/export_list',
'hqwebapp/js/select_2_ajax_widget', // for case owner & user filters in DashboardFeedFilterForm
], function (
$,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hqDefine('export/js/incremental_export', [
hqDefine('export/js/bootstrap3/incremental_export', [
"jquery",
"hqwebapp/js/initial_page_data",
"hqwebapp/js/bootstrap3/crud_paginated_list_init",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
*/

hqDefine('export/js/models', [
hqDefine('export/js/bootstrap3/models', [
'jquery',
'knockout',
'underscore',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
hqDefine('export/js/bootstrap5/customize_export_new', [
'jquery',
'knockout',
'hqwebapp/js/initial_page_data',
'export/js/bootstrap5/models',
'hqwebapp/js/toggles',
'export/js/const',
], function (
$,
ko,
initialPageData,
models,
toggles,
constants
) {
$(function () {
var customExportView = new models.ExportInstance(
initialPageData.get('export_instance'),
{
saveUrl: initialPageData.get('full_path'),
hasExcelDashboardAccess: initialPageData.get('has_excel_dashboard_access'),
hasDailySavedAccess: initialPageData.get('has_daily_saved_export_access'),
formatOptions: initialPageData.get('format_options'),
sharingOptions: initialPageData.get('sharing_options'),
hasOtherOwner: initialPageData.get('has_other_owner'),
numberOfAppsToProcess: initialPageData.get('number_of_apps_to_process'),
geoProperties: initialPageData.get('geo_properties'),
}
);
initialPageData.registerUrl(
"build_schema", "/a/---/data/export/build_full_schema/"
);
$('#customize-export').koApplyBindings(customExportView);
$('.export-tooltip').tooltip(); /* todo B5: plugin:tooltip */

if (toggles.toggleEnabled('SUPPORT_GEO_JSON_EXPORT')) {
const exportFormat = initialPageData.get('export_instance').export_format;
if (exportFormat === constants.EXPORT_FORMATS.GEOJSON) {
$("#select-geo-property").show();
$("#split-multiselects-checkbox-div").hide();
$("#split-multiselects-checkbox").prop("checked", false);
}

$('#format-select').change(function () {
const selectedValue = $(this).val();
if (selectedValue === constants.EXPORT_FORMATS.GEOJSON) {
$("#select-geo-property").show();
// Hiding and unchecking this checkbox is a temporary measure
$("#split-multiselects-checkbox-div").hide();
$("#split-multiselects-checkbox").prop("checked", false);
} else {
$("#select-geo-property").hide();
$("#split-multiselects-checkbox-div").show();
}
});
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
hqDefine("export/js/bootstrap5/download_data_files",[
'jquery',
'hqwebapp/js/bootstrap5/alert_user',
'hqwebapp/js/initial_page_data',
'hqwebapp/js/assert_properties',
], function ($, alertUserModule, initialPageData, assertProperties) {
var alertUser = alertUserModule.alert_user;
/**
* Copies the URL of a data file to the clipboard
*
* The function will first attempt to copy the URL to the clipboard without
* any further user interaction. If that fails, the user will be given a
* dialog box with the URL selected, and prompted to press Ctrl-C and Enter.
*
* @param url: The URL to be copied to the clipboard
* @param textareaElem: A hidden <textarea> element containing the URL
*/
var copyDataFileUrl = function () {
assertProperties.assertRequired($(this).data(), ['id', 'name']);

var url = window.location.origin + initialPageData.reverse('download_data_file',$(this).data("id"), $(this).data("name"));
var textareaElem = $('#url_'.concat($(this).data("id")));

var showCopyDialog = function () {
window.prompt(gettext("Copy to clipboard: Ctrl-C, Enter (Mac: Cmd-C, Enter)"), url);
};
try {
// Most browsers since Sept 2015
textareaElem.show();
textareaElem.select();
var copied = document.execCommand("copy");
textareaElem.hide();
if (copied) {
alertUser(gettext("Data file URL copied to clipboard."), "success", true);
} else {
showCopyDialog();
}
} catch (err) {
// Older browsers
showCopyDialog();
}
};

/**
* Makes an async DELETE request to url, and on success deletes rowElem.
*
* @param url: The URL to send the DELETE request to
* @param rowElem: The <tr> element of the data file to remove on successful deletion
*/
var deleteDataFile = function () {
assertProperties.assertRequired($(this).data(), ['id','name']);
var url = initialPageData.reverse('download_data_file', $(this).data("id"), $(this).data("name"));
var rowElem = $('#row_'.concat($(this).data("id")));

$.ajax({
url: url,
type: "DELETE",
success: function () {
rowElem.remove();
alertUser(gettext("Data file deleted."), "success", true);
},
});
};
$(document).on('click', '.copy-data-file', copyDataFileUrl);
$(document).on('click', '.delete-data-file', deleteDataFile);

});
Loading

0 comments on commit 2b20f0e

Please sign in to comment.