diff --git a/platform/exporters/ExportService.js b/platform/exporters/ExportService.js index a5a7c8a3d3..49ad8c2887 100644 --- a/platform/exporters/ExportService.js +++ b/platform/exporters/ExportService.js @@ -19,8 +19,22 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -/*global define*/ +/*global define,Blob*/ define(['csv'], function (CSV) { + function ExportService(saveAs) { + this.saveAs = saveAs; + } + + ExportService.prototype.exportCSV = function (rows, options) { + var headers = (options && options.headers) || + (Object.keys((rows[0] || {}).sort())), + filename = (options && options.filename) || "export.csv", + csvText = new CSV(rows, { header: headers }).encode(), + blob = new Blob(csvText, { type: "text/csv" }); + this.saveAs(blob, filename); + }; + + return ExportService; }); diff --git a/platform/exporters/bundle.js b/platform/exporters/bundle.js index 62c2f690ee..1de3d0eef7 100644 --- a/platform/exporters/bundle.js +++ b/platform/exporters/bundle.js @@ -32,7 +32,12 @@ define([ services: [ { key: "exportService", - implementation: ExportService + implementation: function () { + return new ExportService(function (blob, name) { + // TODO: Replace with FileSaver.js + console.log(blob, name); + }); + } } ] }