From baf2f9ee1ff66783c39b510c8ab3ac3f4a80a3f9 Mon Sep 17 00:00:00 2001
From: schneefux <schneefux+commit@schneefux.xyz>
Date: Fri, 20 Jul 2018 17:08:40 +0200
Subject: ReportTable: Add CSV download

---
 src/ReportTable.vue | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

(limited to 'src/ReportTable.vue')

diff --git a/src/ReportTable.vue b/src/ReportTable.vue
index 0531ca4..972b006 100644
--- a/src/ReportTable.vue
+++ b/src/ReportTable.vue
@@ -30,6 +30,12 @@
         </b-tooltip>
       </template>
 
+      <template slot="footer">
+        <div class="has-text-right">
+          <button class="button" @click="downloadCsv()">Download CSV</button>
+        </div>
+      </template>
+
       <template slot-scope="props">
         <b-table-column field="Actor" label="Hero" sortable>
           <!-- desktop, table view -->
@@ -131,6 +137,16 @@ export default Vue.component('report-table', {
       return ReportService.getTotalPicks(this.selectedMode);
     },
   },
+  methods: {
+    downloadCsv: function() {
+      const csv = ReportService.getCsv(this.selectedMode);
+      const downloaderElement = document.createElement('a');
+      downloaderElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
+      downloaderElement.target = '_blank';
+      downloaderElement.download = maps.getMode(this.selectedMode) + '.csv';
+      downloaderElement.click();
+    },
+  },
   components: {
     HeroImage,
   },
-- 
cgit v1.3.1

