mirror of
https://github.com/nasa/openmct.git
synced 2025-02-22 02:06:49 +00:00
[CSV Export] Sketch in exportService
This commit is contained in:
parent
15eb4b047f
commit
cec6295d24
@ -19,8 +19,22 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define*/
|
/*global define,Blob*/
|
||||||
|
|
||||||
define(['csv'], function (CSV) {
|
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;
|
||||||
});
|
});
|
||||||
|
@ -32,7 +32,12 @@ define([
|
|||||||
services: [
|
services: [
|
||||||
{
|
{
|
||||||
key: "exportService",
|
key: "exportService",
|
||||||
implementation: ExportService
|
implementation: function () {
|
||||||
|
return new ExportService(function (blob, name) {
|
||||||
|
// TODO: Replace with FileSaver.js
|
||||||
|
console.log(blob, name);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user