Added ability to export as CSV. Fixes #34

pull/85/head
Jordan Wright 2016-01-20 18:45:53 -06:00
parent 1b5fb638ea
commit 655faaf72b
3 changed files with 32 additions and 16 deletions

View File

@ -56,6 +56,26 @@ function deleteCampaign() {
}
}
// Exports campaign results as a CSV file
function exportAsCSV() {
exportHTML = $("#exportButton").html()
$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>')
var csvString = Papa.unparse(campaign.results, {})
var csvData = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
if (navigator.msSaveBlob) {
navigator.msSaveBlob(csvData, 'results.csv');
} else {
var csvURL = window.URL.createObjectURL(csvData);
var dlLink = document.createElement('a');
dlLink.href = csvURL;
dlLink.setAttribute('download', 'results.csv');
dlLink.click();
}
$("#exportButton").html(exportHTML)
}
$(document).ready(function() {
campaign.id = window.location.pathname.split('/').slice(-1)[0]
api.campaignId.get(campaign.id)

6
static/js/papaparse.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -30,22 +30,11 @@
<h1 class="page-header" id="page-title">Results for campaign.name</h1>
</div>
<div class="row">
<!--
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-cogs fa-lg"></i>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Export</a>
</li>
<li><a href="#">Relaunch</a>
</li>
</ul>
</div>
-->
<button type="button" class="btn btn-danger" data-toggle="tooltip" data-placement="right" title="Delete Campaign" onclick="deleteCampaign()">
<i class="fa fa-trash-o fa-lg"></i>
<button type="button" id="exportButton" class="btn btn-primary" onclick="exportAsCSV()">
<i class="fa fa-file-excel-o"></i> Export CSV
</button>
<button type="button" class="btn btn-danger" data-toggle="tooltip" onclick="deleteCampaign()">
<i class="fa fa-trash-o fa-lg"></i> Delete
</button>
</div>
<br />
@ -114,5 +103,6 @@
<script src="/js/d3.min.js"></script>
<script src="/js/topojson.min.js"></script>
<script src="/js/datamaps.min.js"></script>
<script src="/js/papaparse.min.js"></script>
<script src="/js/app/campaign_results.js"></script>
{{end}}