Fixed CSV/TSV export. Please test.

Thanks to xet7 !

Related #3173
This commit is contained in:
Lauri Ojansivu 2020-10-20 18:59:41 +03:00
parent 9d97494cfc
commit d7333dec84
2 changed files with 47 additions and 30 deletions

View file

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

View file

@ -1,4 +1,4 @@
//const stringify = require('csv-stringify'); const Papa = require('papaparse');
// exporter maybe is broken since Gridfs introduced, add fs and path // exporter maybe is broken since Gridfs introduced, add fs and path
export class Exporter { export class Exporter {
@ -192,6 +192,40 @@ export class Exporter {
const result = this.build(); const result = this.build();
const columnHeaders = []; const columnHeaders = [];
const cardRows = []; 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( columnHeaders.push(
'Title', 'Title',
'Description', 'Description',
@ -240,6 +274,7 @@ export class Exporter {
} }
i++; i++;
}); });
cardRows.push([[columnHeaders]]);
/* TODO: Try to get translations working. /* TODO: Try to get translations working.
These currently only bring English translations. These currently only bring English translations.
TAPi18n.__('title'), TAPi18n.__('title'),
@ -264,24 +299,6 @@ export class Exporter {
TAPi18n.__('archived'), 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 => { result.cards.forEach(card => {
const currentRow = []; const currentRow = [];
currentRow.push(card.title); currentRow.push(card.title);
@ -385,10 +402,10 @@ export class Exporter {
currentRow.push(customFieldValuesToPush[valueIndex]); currentRow.push(customFieldValuesToPush[valueIndex]);
} }
} }
stringifier.write(currentRow); cardRows.push([[currentRow]]);
}); });
stringifier.end();
return cardRows[0]; return Papa.unparse(cardRows, papaconfig);
} }
canExport(user) { canExport(user) {