Просмотр исходного кода

Fixed CSV/TSV export. Please test.

Thanks to xet7 !

Related #3173
Lauri Ojansivu 4 лет назад
Родитель
Сommit
d7333dec84
2 измененных файлов с 47 добавлено и 30 удалено
  1. 8 8
      client/components/sidebar/sidebar.jade
  2. 39 22
      models/exporter.js

+ 8 - 8
client/components/sidebar/sidebar.jade

@@ -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
-    //  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
     li
       a.html-export-board
       a.html-export-board
         i.fa.fa-archive
         i.fa.fa-archive

+ 39 - 22
models/exporter.js

@@ -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) {