From d714635e69b35e7af9aba232b53c439b724865f8 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Fri, 29 Jan 2016 13:18:06 -0600 Subject: [PATCH] Added ability to export raw events. Fixes #102 --- static/js/app/campaign_results.js | 18 ++++++++++++++---- templates/campaign_results.html | 9 ++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/static/js/app/campaign_results.js b/static/js/app/campaign_results.js index 06e127ce..440b3439 100644 --- a/static/js/app/campaign_results.js +++ b/static/js/app/campaign_results.js @@ -73,20 +73,30 @@ function deleteCampaign() { } // Exports campaign results as a CSV file -function exportAsCSV() { +function exportAsCSV(scope) { exportHTML = $("#exportButton").html() + var csvScope = null + switch (scope) { + case "results": + csvScope = campaign.results + break; + case "events": + csvScope = campaign.timeline + break; + } + if (!csvScope){return} $("#exportButton").html('') - var csvString = Papa.unparse(campaign.results, {}) + var csvString = Papa.unparse(csvScope, {}) var csvData = new Blob([csvString], { type: 'text/csv;charset=utf-8;' }); if (navigator.msSaveBlob) { - navigator.msSaveBlob(csvData, 'results.csv'); + navigator.msSaveBlob(csvData, scope + '.csv'); } else { var csvURL = window.URL.createObjectURL(csvData); var dlLink = document.createElement('a'); dlLink.href = csvURL; - dlLink.setAttribute('download', 'results.csv'); + dlLink.setAttribute('download', scope + '.csv'); dlLink.click(); } $("#exportButton").html(exportHTML) diff --git a/templates/campaign_results.html b/templates/campaign_results.html index f1877273..1ddf4a7c 100644 --- a/templates/campaign_results.html +++ b/templates/campaign_results.html @@ -33,9 +33,16 @@ Back - + +