Merge pull request #1764 from matiaspando/feature/generateCSV
Generate CVS file from transaction history
This commit is contained in:
commit
8036bb9144
2 changed files with 84 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
|
|
||||||
$rootScope.title = 'History';
|
$rootScope.title = 'History';
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
$scope.generating = false;
|
||||||
$scope.lastShowed = false;
|
$scope.lastShowed = false;
|
||||||
|
|
||||||
$scope.currentPage = 1;
|
$scope.currentPage = 1;
|
||||||
|
|
@ -19,11 +20,83 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
$scope.alternativeCurrency = [];
|
$scope.alternativeCurrency = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.selectPage = function(page) {
|
$scope.selectPage = function(page) {
|
||||||
$scope.currentPage = page;
|
$scope.currentPage = page;
|
||||||
$scope.update();
|
$scope.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$scope.downloadHistory = function() {
|
||||||
|
|
||||||
|
if (window.cordova) {
|
||||||
|
log.info('Not available on mobile');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var w = $rootScope.wallet;
|
||||||
|
if (!w) return;
|
||||||
|
|
||||||
|
$scope.generating = true;
|
||||||
|
w.getTransactionHistory(function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
if (!res) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var unit = w.settings.unitName;
|
||||||
|
var data = res.items;
|
||||||
|
var filename = "copay_history.csv";
|
||||||
|
var csvContent = "data:text/csv;charset=utf-8,";
|
||||||
|
csvContent += "Date,Amount(" + unit + "),Action,AddressTo,Comment\n";
|
||||||
|
|
||||||
|
data.forEach(function(it, index) {
|
||||||
|
var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + it.addressTo + ',' + formatString(it.comment);
|
||||||
|
csvContent += index < data.length ? dataString + "\n" : dataString;
|
||||||
|
});
|
||||||
|
|
||||||
|
var encodedUri = encodeURI(csvContent);
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.setAttribute("href", encodedUri);
|
||||||
|
link.setAttribute("download", filename);
|
||||||
|
|
||||||
|
link.click();
|
||||||
|
$scope.generating = false;
|
||||||
|
$scope.$digest();
|
||||||
|
|
||||||
|
function formatDate(date) {
|
||||||
|
var dateObj = new Date(date);
|
||||||
|
if (!dateObj) {
|
||||||
|
log.error('Error formating a date');
|
||||||
|
return 'DateError'
|
||||||
|
}
|
||||||
|
if (!dateObj.toJSON()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return dateObj.toJSON().substring(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatString(str) {
|
||||||
|
if (!str) return '';
|
||||||
|
|
||||||
|
if (str.indexOf('"') !== -1) {
|
||||||
|
//replace all
|
||||||
|
str = str.replace(new RegExp('"', 'g'), '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
//escaping commas
|
||||||
|
str = '\"' + str + '\"';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.update = function() {
|
$scope.update = function() {
|
||||||
$scope.getTransactions();
|
$scope.getTransactions();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@
|
||||||
<div
|
<div
|
||||||
class="row"
|
class="row"
|
||||||
ng-if="blockchain_txs[0].txid">
|
ng-if="blockchain_txs[0].txid">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns"></div>
|
||||||
|
|
||||||
<div class="panel"
|
<div class="panel"
|
||||||
ng-repeat="btx in blockchain_txs | orderBy:'-ts'" ng-click="btx.showDetails = !btx.showDetails">
|
ng-repeat="btx in blockchain_txs | orderBy:'-ts'" ng-click="btx.showDetails = !btx.showDetails">
|
||||||
<div class="row size-14">
|
<div class="row size-14">
|
||||||
|
|
@ -99,6 +98,16 @@
|
||||||
<a href="http://{{getShortNetworkName()}}.insight.is/tx/{{btx.txid}}" target="_blank" class="right"> More details <i class="icon-arrow-right2 vm"></i> </a>
|
<a href="http://{{getShortNetworkName()}}.insight.is/tx/{{btx.txid}}" target="_blank" class="right"> More details <i class="icon-arrow-right2 vm"></i> </a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div ng-if="generating" class="right size-12">
|
||||||
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
|
<span translate>Generating file...</span>
|
||||||
|
</div>
|
||||||
|
<div ng-if="!generating" class="right size-12">
|
||||||
|
<a class="text-gray" href="#!/history" ng-click="downloadHistory();">
|
||||||
|
<i class="fi-download"></i>
|
||||||
|
<span translate>Download</span>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<pagination page="currentPage" total-items="totalItems" items-per-page="itemsPerPage" on-select-page="selectPage(page)" max-size="10" />
|
<pagination page="currentPage" total-items="totalItems" items-per-page="itemsPerPage" on-select-page="selectPage(page)" max-size="10" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue