Fixed CSV/TSV export. Please test.

Thanks to xet7 !

Related #3173
reviewable/pr3312/r1
Lauri Ojansivu 5 years ago
parent 9d97494cfc
commit d7333dec84
  1. 16
      client/components/sidebar/sidebar.jade
  2. 61
      models/exporter.js

@ -366,14 +366,14 @@ template(name="exportBoard")
a.download-json-link(href="{{exportUrl}}", download="{{exportJsonFilename}}")
i.fa.fa-share-alt
| {{_ 'export-board-json'}}
//li
// a(href="{{exportCsvUrl}}", download="{{exportCsvFilename}}")
// i.fa.fa-share-alt
// | {{_ 'export-board-csv'}}
//li
// a(href="{{exportTsvUrl}}", download="{{exportTsvFilename}}")
// i.fa.fa-share-alt
// | {{_ 'export-board-tsv'}}
li
a(href="{{exportCsvUrl}}", download="{{exportCsvFilename}}")
i.fa.fa-share-alt
| {{_ 'export-board-csv'}}
li
a(href="{{exportTsvUrl}}", download="{{exportTsvFilename}}")
i.fa.fa-share-alt
| {{_ 'export-board-tsv'}}
li
a.html-export-board
i.fa.fa-archive

@ -1,4 +1,4 @@
//const stringify = require('csv-stringify');
const Papa = require('papaparse');
// exporter maybe is broken since Gridfs introduced, add fs and path
export class Exporter {
@ -192,6 +192,40 @@ export class Exporter {
const result = this.build();
const columnHeaders = [];
const cardRows = [];
const papaconfig = {
delimiter, // get parameter (was: auto-detect)
worker: true,
};
/*
newline: "", // auto-detect
quoteChar: '"',
escapeChar: '"',
header: true,
transformHeader: undefined,
dynamicTyping: false,
preview: 0,
encoding: "",
comments: false,
step: undefined,
complete: undefined,
error: undefined,
download: false,
downloadRequestHeaders: undefined,
downloadRequestBody: undefined,
skipEmptyLines: false,
chunk: undefined,
chunkSize: undefined,
fastMode: undefined,
beforeFirstChunk: undefined,
withCredentials: undefined,
transform: undefined
};
*/
//delimitersToGuess: [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP]
columnHeaders.push(
'Title',
'Description',
@ -240,6 +274,7 @@ export class Exporter {
}
i++;
});
cardRows.push([[columnHeaders]]);
/* TODO: Try to get translations working.
These currently only bring English translations.
TAPi18n.__('title'),
@ -264,24 +299,6 @@ export class Exporter {
TAPi18n.__('archived'),
*/
const stringifier = stringify({
header: true,
delimiter,
columns: columnHeaders,
});
stringifier.on('readable', function() {
let row;
while ((row = stringifier.read())) {
cardRows.push(row);
}
});
stringifier.on('error', function(err) {
// eslint-disable-next-line no-console
console.error(err.message);
});
result.cards.forEach(card => {
const currentRow = [];
currentRow.push(card.title);
@ -385,10 +402,10 @@ export class Exporter {
currentRow.push(customFieldValuesToPush[valueIndex]);
}
}
stringifier.write(currentRow);
cardRows.push([[currentRow]]);
});
stringifier.end();
return cardRows[0];
return Papa.unparse(cardRows, papaconfig);
}
canExport(user) {

Loading…
Cancel
Save