Fix save csv file nodewebkit
This commit is contained in:
parent
ec5a478bf2
commit
2b968b0a12
2 changed files with 16 additions and 13 deletions
|
|
@ -495,8 +495,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="!index.isCordova" class="m20t text-center">
|
||||
<input id="export_file" type="file" nwsaveas="Copay-{{index.alias || index.walletName}}.csv" accept=".csv" style="display:none" nwworkingdir=""/>
|
||||
<div ng-if="!index.isCordova && index.txHistory[0] && !index.updatingTxHistory" class="m20t text-center">
|
||||
<input id="export_file" type="file" nwsaveas="Copay-{{index.alias || index.walletName}}.csv" accept=".csv" style="display:none">
|
||||
<a class="text-gray" ng-click="index.csvHistory();">
|
||||
<i class="fi-page-export-csv"></i>
|
||||
<span translate>Download CSV file</span>
|
||||
|
|
|
|||
|
|
@ -540,11 +540,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
function saveFile(name, data) {
|
||||
var chooser = document.querySelector(name);
|
||||
chooser.addEventListener("change", function(evt) {
|
||||
console.log(this.value); // get your file name
|
||||
var fs = require('fs'); // save it now
|
||||
var fs = require('fs');
|
||||
fs.writeFile(this.value, data, function(err) {
|
||||
if (err) {
|
||||
alert("error"+err);
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
|
|
@ -582,6 +581,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
log.info('Not available on mobile');
|
||||
return;
|
||||
}
|
||||
var isNode = nodeWebkit.isDefined();
|
||||
var fc = profileService.focusedClient;
|
||||
if (!fc.isComplete()) return;
|
||||
var self = this;
|
||||
|
|
@ -602,16 +602,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
var data = txs;
|
||||
var satToBtc = 1 / 100000000;
|
||||
var filename = 'Copay-' + (self.alias || self.walletName ) + '.csv';
|
||||
var csvContent = "data:text/csv;charset=utf-8,";
|
||||
csvContent += "Date,Destination,Note,Amount,Currency,Spot Value,Total Value,Tax Type,Category\n";
|
||||
var csvContent = '';
|
||||
if (!isNode) csvContent = 'data:text/csv;charset=utf-8,';
|
||||
csvContent += 'Date,Destination,Note,Amount,Currency,Spot Value,Total Value,Tax Type,Category\n';
|
||||
|
||||
var _amount;
|
||||
var dataString;
|
||||
data.forEach(function(it, index) {
|
||||
var _amount = (it.action == 'sent' ? '-' : '') + (it.amount * satToBtc).toFixed(8);
|
||||
var dataString = formatDate(it.time * 1000) + ',' + formatString(it.addressTo) + ',' + formatString(it.message) + ',' + _amount + ',BTC,,,,';
|
||||
_amount = (it.action == 'sent' ? '-' : '') + (it.amount * satToBtc).toFixed(8);
|
||||
dataString = formatDate(it.time * 1000) + ',' + formatString(it.addressTo) + ',' + formatString(it.message) + ',' + _amount + ',BTC,,,,';
|
||||
csvContent += index < data.length ? dataString + "\n" : dataString;
|
||||
});
|
||||
|
||||
if (nodeWebkit.isDefined()) {
|
||||
if (isNode) {
|
||||
saveFile('#export_file', csvContent);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue