Update campaign_results.min.js

pull/2990/head
BlkPh0x 2023-10-10 13:35:04 +11:00 committed by GitHub
parent 54781b920b
commit 2541c7190b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 38 deletions

View File

@ -198,6 +198,8 @@ function completeCampaign() {
} }
}) })
} }
// Exports campaign results as a CSV file
function exportAsCleanCSV(scope) { function exportAsCleanCSV(scope) {
var csvScope = null; var csvScope = null;
var filename = campaign.name + ' - ' + capitalize(scope) + '.csv'; var filename = campaign.name + ' - ' + capitalize(scope) + '.csv';
@ -289,44 +291,40 @@ function exportAsCleanCSV(scope) {
// exportAsCSV('events'); // exportAsCSV('events');
// exportAsCSV('cleanresults'); // Add this line to export clean results // exportAsCSV('cleanresults'); // Add this line to export clean results
function exportAsCSV(scope) {
// Exports campaign results as a CSV file exportHTML = $("#exportButton").html()
exportAsCSV(scope) { var csvScope = null
exportHTML = $("#exportButton").html(); var filename = campaign.name + ' - ' + capitalize(scope) + '.csv'
var csvScope = null;
var filename = campaign.name + " - " + capitalize(scope) + ".csv";
switch (scope) { switch (scope) {
case "results": case "results":
csvScope = campaign.results; csvScope = campaign.results
break; break;
case "events": case "events":
csvScope = campaign.timeline; csvScope = campaign.timeline
break; break;
} }
if (!csvScope) { if (!csvScope) {
return; return
} }
$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>')
$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>'); var csvString = Papa.unparse(csvScope, {
'escapeFormulae': true
var csvString = Papa.unparse(csvScope, { escapeFormulae: true }); })
var csvData = new Blob([csvString], { type: "text/csv;charset=utf-8;" }); var csvData = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
if (navigator.msSaveBlob) { if (navigator.msSaveBlob) {
navigator.msSaveBlob(csvData, filename); navigator.msSaveBlob(csvData, filename);
} else { } else {
var csvURL = window.URL.createObjectURL(csvData); var csvURL = window.URL.createObjectURL(csvData);
var dlLink = document.createElement("a"); var dlLink = document.createElement('a');
dlLink.href = csvURL; dlLink.href = csvURL;
dlLink.setAttribute("download", filename); dlLink.setAttribute('download', filename)
document.body.appendChild(dlLink); document.body.appendChild(dlLink)
dlLink.click(); dlLink.click();
document.body.removeChild(dlLink); document.body.removeChild(dlLink)
} }
$("#exportButton").html(exportHTML)
$("#exportButton").html(exportHTML);
} }
function replay(event_idx) { function replay(event_idx) {