diff --git a/public/app/core/utils/file_export.ts b/public/app/core/utils/file_export.ts
index 24b501eee28..dd616ca77e7 100644
--- a/public/app/core/utils/file_export.ts
+++ b/public/app/core/utils/file_export.ts
@@ -1,20 +1,23 @@
///
import _ from 'lodash';
+import moment from 'moment';
declare var window: any;
-export function exportSeriesListToCsv(seriesList) {
+const DEFAULT_DATETIME_FORMAT: String = 'YYYY-MM-DDTHH:mm:ssZ';
+
+export function exportSeriesListToCsv(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT) {
var text = 'sep=;\nSeries;Time;Value\n';
_.each(seriesList, function(series) {
_.each(series.datapoints, function(dp) {
- text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
+ text += series.alias + ';' + moment(dp[1]).format(dateTimeFormat) + ';' + dp[0] + '\n';
});
});
saveSaveBlob(text, 'grafana_data_export.csv');
}
-export function exportSeriesListToCsvColumns(seriesList) {
+export function exportSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT) {
var text = 'sep=;\nTime;';
// add header
_.each(seriesList, function(series) {
@@ -30,7 +33,7 @@ export function exportSeriesListToCsvColumns(seriesList) {
var cIndex = 0;
dataArr.push([]);
_.each(series.datapoints, function(dp) {
- dataArr[0][cIndex] = new Date(dp[1]).toISOString();
+ dataArr[0][cIndex] = moment(dp[1]).format(dateTimeFormat);
dataArr[sIndex][cIndex] = dp[0];
cIndex++;
});
diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js
index c362f9cd032..3315371a78f 100644
--- a/public/app/features/dashboard/all.js
+++ b/public/app/features/dashboard/all.js
@@ -21,4 +21,5 @@ define([
'./ad_hoc_filters',
'./row/row_ctrl',
'./repeat_option/repeat_option',
+ './exportCsvModalCtrl'
], function () {});
diff --git a/public/app/features/dashboard/exportCsvModalCtrl.ts b/public/app/features/dashboard/exportCsvModalCtrl.ts
new file mode 100644
index 00000000000..0e2e2d3f232
--- /dev/null
+++ b/public/app/features/dashboard/exportCsvModalCtrl.ts
@@ -0,0 +1,32 @@
+///
+
+import config from 'app/core/config';
+import angular from 'angular';
+import _ from 'lodash';
+import * as fileExport from 'app/core/utils/file_export';
+
+const module = angular.module('grafana.controllers');
+
+export class ExportCsvModalCtrl {
+ scope: any;
+ seriesList: any = [];
+ /** @ngInject */
+ constructor(private $scope) {
+ this.seriesList = $scope.seriesList;
+ this.$scope = $scope;
+ $scope.asRows = true;
+ $scope.dateTimeFormat = 'YYYY-MM-DDTHH:mm:ssZ';
+ $scope.export = this.export.bind(this);
+ }
+
+ export() {
+ if (this.$scope.asRows) {
+ fileExport.exportSeriesListToCsv(this.seriesList, this.$scope.dateTimeFormat);
+ } else {
+ fileExport.exportSeriesListToCsvColumns(this.seriesList, this.$scope.dateTimeFormat);
+ }
+ this.$scope.dismiss();
+ }
+}
+
+module.controller('ExportCsvModalCtrl', ExportCsvModalCtrl);
diff --git a/public/app/features/dashboard/partials/exportCsvModal.html b/public/app/features/dashboard/partials/exportCsvModal.html
new file mode 100644
index 00000000000..ae3b4dfdf7d
--- /dev/null
+++ b/public/app/features/dashboard/partials/exportCsvModal.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts
index e2dce12168d..89c280ed5e5 100644
--- a/public/app/plugins/panel/graph/module.ts
+++ b/public/app/plugins/panel/graph/module.ts
@@ -11,7 +11,6 @@ import moment from 'moment';
import _ from 'lodash';
import TimeSeries from 'app/core/time_series2';
import config from 'app/core/config';
-import * as fileExport from 'app/core/utils/file_export';
import {MetricsPanelCtrl, alertTab} from 'app/plugins/sdk';
import {DataProcessor} from './data_processor';
import {axesEditorComponent} from './axes_editor';
@@ -147,8 +146,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
onInitPanelActions(actions) {
- actions.push({text: 'Export CSV (series as rows)', click: 'ctrl.exportCsv()'});
- actions.push({text: 'Export CSV (series as columns)', click: 'ctrl.exportCsvColumns()'});
+ actions.push({text: 'Export CSV', click: 'ctrl.exportCsv()'});
actions.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'});
}
@@ -313,13 +311,15 @@ class GraphCtrl extends MetricsPanelCtrl {
}
exportCsv() {
- fileExport.exportSeriesListToCsv(this.seriesList);
- }
+ var scope = this.$scope.$new();
+ scope.seriesList = this.seriesList;
- exportCsvColumns() {
- fileExport.exportSeriesListToCsvColumns(this.seriesList);
+ this.publishAppEvent('show-modal', {
+ src: 'public/app/features/dashboard/partials/exportCsvModal.html',
+ scope,
+ modalClass: 'modal--narrow'
+ });
}
-
}
export {GraphCtrl, GraphCtrl as PanelCtrl};