From 54a7caeb828d28ee342686ff8499b469eb86e1d6 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Tue, 11 Nov 2014 11:19:08 -0300 Subject: [PATCH] Improved csv format --- js/controllers/history.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/js/controllers/history.js b/js/controllers/history.js index 58d450a95..85c221d40 100644 --- a/js/controllers/history.js +++ b/js/controllers/history.js @@ -28,20 +28,37 @@ angular.module('copayApp.controllers').controller('HistoryController', $scope.downloadHistory = function() { + + if (window.cordova) { + log.info('Not available on mobile'); + return; + } + var data = $scope.blockchain_txs; - var csvContent = "data:text/csv;charset=utf-8,"; + var filename = "copay_history.csv"; + var csvContent = "data:text/csv;charset=utf-8,Date,Amount,Action,AddressTo\n"; data.forEach(function(it, index) { - var dataString = it.ts + ',' + it.amount + ',' + it.action + ',' + it.addressTo; + var dataString = formatDate(it.ts) + ',' + it.amount + ',' + it.action + ',' + it.addressTo; csvContent += index < data.length ? dataString + "\n" : dataString; }); var encodedUri = encodeURI(csvContent); var link = document.createElement("a"); link.setAttribute("href", encodedUri); - link.setAttribute("download", "my_data.csv"); + link.setAttribute("download", filename); link.click(); + + + function formatDate(date) { + var dateObj = new Date(date); + if (!dateObj) { + log.error('Error formating a date'); + return 'DateError' + } + return dateObj.toJSON().substring(0, 10); + } };