Merge branch 'v4.4.x'

This commit is contained in:
Daniel Lee 2017-08-23 15:19:51 +02:00
commit bf4ffe41b0
4 changed files with 31 additions and 12 deletions

View File

@ -7,8 +7,8 @@ declare var window: any;
const DEFAULT_DATETIME_FORMAT: String = 'YYYY-MM-DDTHH:mm:ssZ';
export function exportSeriesListToCsv(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT) {
var text = 'Series;Time;Value\n';
export function exportSeriesListToCsv(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT, excel = false) {
var text = excel ? 'sep=;\n' : '' + 'Series;Time;Value\n';
_.each(seriesList, function(series) {
_.each(series.datapoints, function(dp) {
text += series.alias + ';' + moment(dp[1]).format(dateTimeFormat) + ';' + dp[0] + '\n';
@ -17,8 +17,8 @@ export function exportSeriesListToCsv(seriesList, dateTimeFormat = DEFAULT_DATET
saveSaveBlob(text, 'grafana_data_export.csv');
}
export function exportSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT) {
var text = 'Time;';
export function exportSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT, excel = false) {
var text = excel ? 'sep=;\n' : '' + 'Time;';
// add header
_.each(seriesList, function(series) {
text += series.alias + ';';
@ -52,8 +52,8 @@ export function exportSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAUL
saveSaveBlob(text, 'grafana_data_export.csv');
}
export function exportTableDataToCsv(table) {
var text = '';
export function exportTableDataToCsv(table, excel = false) {
var text = excel ? 'sep=;\n' : '';
// add header
_.each(table.columns, function(column) {
text += (column.title || column.text) + ';';

View File

@ -11,17 +11,21 @@
<div class="modal-content">
<div class="p-t-2">
<div class="gf-form">
<div class="gf-form" ng-hide="ctrl.panel === 'table'">
<label class="gf-form-label width-10">Mode</label>
<div class="gf-form-select-wrapper">
<select class="gf-form-input" ng-model="ctrl.asRows" ng-options="f.value as f.text for f in [{text: 'Series as rows', value: true}, {text: 'Series as columns', value: false}]">
</select>
</div>
</div>
<div class="gf-form">
<div class="gf-form" ng-hide="ctrl.panel === 'table'">
<label class="gf-form-label width-10">Date Time Format</label>
<input type="text" class="gf-form-input" ng-model="ctrl.dateTimeFormat">
</div>
<gf-form-switch class="gf-form"
label="Export To Excel" label-class="width-12" switch-class="max-width-6"
checked="ctrl.excel">
</gf-form-switch>
</div>
<div class="gf-form-button-row text-center">

View File

@ -6,17 +6,24 @@ import appEvents from 'app/core/app_events';
export class ExportDataModalCtrl {
private data: any[];
private panel: string;
asRows: Boolean = true;
dateTimeFormat: String = 'YYYY-MM-DDTHH:mm:ssZ';
excel: false;
/** @ngInject */
constructor(private $scope) { }
export() {
if (this.asRows) {
fileExport.exportSeriesListToCsv(this.data, this.dateTimeFormat);
if (this.panel === 'table') {
fileExport.exportTableDataToCsv(this.data, this.excel);
} else {
fileExport.exportSeriesListToCsvColumns(this.data, this.dateTimeFormat);
if (this.asRows) {
fileExport.exportSeriesListToCsv(this.data, this.dateTimeFormat, this.excel);
} else {
fileExport.exportSeriesListToCsvColumns(this.data, this.dateTimeFormat, this.excel);
}
}
this.dismiss();
}
@ -32,6 +39,7 @@ export function exportDataModal() {
controller: ExportDataModalCtrl,
controllerAs: 'ctrl',
scope: {
panel: '<',
data: '<' // The difference to '=' is that the bound properties are not watched
},
bindToController: true

View File

@ -150,7 +150,14 @@ class TablePanelCtrl extends MetricsPanelCtrl {
}
exportCsv() {
FileExport.exportTableDataToCsv(this.renderer.render_values());
var scope = this.$scope.$new(true);
scope.tableData = this.renderer.render_values();
scope.panel = 'table';
this.publishAppEvent('show-modal', {
templateHtml: '<export-data-modal panel="panel" data="tableData"></export-data-modal>',
scope,
modalClass: 'modal--narrow'
});
}
link(scope, elem, attrs, ctrl) {