[CSV Export] Sketch in exportService

This commit is contained in:
Victor Woeltjen 2016-02-05 13:02:21 -08:00
parent 15eb4b047f
commit cec6295d24
2 changed files with 21 additions and 2 deletions

View File

@ -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;
});

View File

@ -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);
});
}
}
]
}