mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
feat(tablepanel): made annotations transform work
This commit is contained in:
parent
a66825c71f
commit
1bec6c2aae
@ -9,7 +9,7 @@ import {TableModel} from './table_model';
|
||||
|
||||
export class TablePanelCtrl {
|
||||
|
||||
constructor($scope, $rootScope, $q, panelSrv, panelHelper) {
|
||||
constructor($scope, $rootScope, $q, panelSrv, panelHelper, annotationsSrv) {
|
||||
$scope.ctrl = this;
|
||||
$scope.pageIndex = 0;
|
||||
|
||||
@ -36,19 +36,22 @@ export class TablePanelCtrl {
|
||||
$scope.init = function() {
|
||||
_.defaults($scope.panel, panelDefaults);
|
||||
|
||||
if ($scope.panel.columns.length === 0) {
|
||||
}
|
||||
|
||||
panelSrv.init($scope);
|
||||
};
|
||||
|
||||
$scope.refreshData = function(datasource) {
|
||||
panelHelper.updateTimeRange($scope);
|
||||
|
||||
if ($scope.panel.transform === 'annotations') {
|
||||
return annotationsSrv.getAnnotations($scope.dashboard).then(annotations => {
|
||||
$scope.dataRaw = annotations;
|
||||
$scope.render();
|
||||
});
|
||||
}
|
||||
|
||||
return panelHelper.issueMetricQuery($scope, datasource)
|
||||
.then($scope.dataHandler, function(err) {
|
||||
$scope.seriesList = [];
|
||||
$scope.render([]);
|
||||
$scope.render();
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
@ -24,9 +24,22 @@ export class TableRenderer {
|
||||
return null;
|
||||
}
|
||||
|
||||
defaultCellFormater(v) {
|
||||
if (v === null || v === void 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (_.isArray(v)) {
|
||||
v = v.join(', ');
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
createColumnFormater(style) {
|
||||
if (!style) {
|
||||
return v => v;
|
||||
return this.defaultCellFormater;
|
||||
}
|
||||
|
||||
if (style.type === 'date') {
|
||||
@ -60,17 +73,7 @@ export class TableRenderer {
|
||||
};
|
||||
}
|
||||
|
||||
return v => {
|
||||
if (v === null || v === void 0) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
if (_.isArray(v)) {
|
||||
v = v.join(', ');
|
||||
}
|
||||
|
||||
return v;
|
||||
};
|
||||
return this.defaultCellFormater;
|
||||
}
|
||||
|
||||
formatColumnValue(colIndex, value) {
|
||||
@ -88,10 +91,7 @@ export class TableRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
this.formaters[colIndex] = function(v) {
|
||||
return v;
|
||||
};
|
||||
|
||||
this.formaters[colIndex] = this.defaultCellFormater;
|
||||
return this.formaters[colIndex](value);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,8 @@ describe('when rendering table', () => {
|
||||
table.columns = [
|
||||
{text: 'Time'},
|
||||
{text: 'Value'},
|
||||
{text: 'Colored'}
|
||||
{text: 'Colored'},
|
||||
{text: 'Undefined'},
|
||||
];
|
||||
|
||||
var panel = {
|
||||
@ -59,6 +60,11 @@ describe('when rendering table', () => {
|
||||
var html = renderer.renderCell(2, 55);
|
||||
expect(html).to.be('<td style="color:orange">55.0</td>');
|
||||
});
|
||||
|
||||
it('unformated undefined should be rendered as -', () => {
|
||||
var html = renderer.renderCell(3, undefined);
|
||||
expect(html).to.be('<td></td>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -103,8 +103,37 @@ describe('when transforming time series table', () => {
|
||||
expect(table.rows[0][0]).to.be('time');
|
||||
expect(table.rows[0][1]).to.be('message');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Annnotations', () => {
|
||||
var panel = {transform: 'annotations'};
|
||||
var rawData = [
|
||||
{
|
||||
min: 1000,
|
||||
text: 'hej',
|
||||
tags: ['tags', 'asd'],
|
||||
title: 'title',
|
||||
}
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
table = TableModel.transform(rawData, panel);
|
||||
});
|
||||
|
||||
it ('should return 4 columns', () => {
|
||||
expect(table.columns.length).to.be(4);
|
||||
expect(table.columns[0].text).to.be('Time');
|
||||
expect(table.columns[1].text).to.be('Title');
|
||||
expect(table.columns[2].text).to.be('Text');
|
||||
expect(table.columns[3].text).to.be('Tags');
|
||||
});
|
||||
|
||||
it ('should return 1 rows', () => {
|
||||
expect(table.rows.length).to.be(1);
|
||||
expect(table.rows[0][0]).to.be(1000);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -66,6 +66,21 @@ transformers['timeseries_to_columns'] = {
|
||||
|
||||
transformers['annotations'] = {
|
||||
description: 'Annotations',
|
||||
transform: function(data, panel, model) {
|
||||
model.columns.push({text: 'Time', type: 'date'});
|
||||
model.columns.push({text: 'Title'});
|
||||
model.columns.push({text: 'Text'});
|
||||
model.columns.push({text: 'Tags'});
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var evt = data[i];
|
||||
model.rows.push([evt.min, evt.title, evt.text, evt.tags]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
transformers['json'] = {
|
||||
|
Loading…
Reference in New Issue
Block a user