Commit cf68725c by Torkel Ödegaard

influxdb annotation column mapping is working

parent cf2ef095
<div class="editor-row">
<div class="editor-option">
<label class="small">InfluxDB query</label>
<input type="text" class="span10" ng-model='currentAnnotation.query' placeholder=""></input>
<div class="section">
<h5>InfluxDB Query <tip>Example: select text from events where [[timeFilter]]</tip></h5>
<div class="editor-option">
<input type="text" class="span10" ng-model='currentAnnotation.query' placeholder="select text from events where [[timeFilter]]"></input>
</div>
</div>
</div>
<div class="editor-row">
<div class="section">
<h5>Column mappings <tip>If your influxdb query returns more than one column you need to specify the column names bellow. An annotation event is composed of a title, tags, and an additional text field.</tip></h5>
<div class="editor-option">
<label class="small">Title</label>
<input type="text" class="input-small" ng-model='currentAnnotation.titleColumn' placeholder=""></input>
</div>
<div class="editor-option">
<label class="small">Tags</label>
<input type="text" class="input-small" ng-model='currentAnnotation.tagsColumn' placeholder=""></input>
</div>
<div class="editor-option">
<label class="small">Text</label>
<input type="text" class="input-small" ng-model='currentAnnotation.textColumn' placeholder=""></input>
</div>
</div>
</div>
......@@ -142,8 +142,8 @@ define([
tooltip += '<i>' + moment(options.time).format('YYYY-MM-DD HH:mm:ss') + '</i><br/>';
if (options.data) {
tooltip += options.data.replace(/\n/g, '<br/>');
if (options.text) {
tooltip += options.text.replace(/\n/g, '<br/>');
}
tooltip += "</small>";
......
......@@ -71,27 +71,27 @@ function (_) {
var self = this;
_.each(this.seriesList, function (series) {
var titleCol = 0;
var tagsCol = 0;
var titleCol = null;
var timeCol = null;
var tagsCol = null;
var textCol = null;
_.each(series.columns, function(column, index) {
if (column === 'time' || column === 'sequence_number') {
return;
}
if (!titleCol && column !== 'tags') {
titleCol = index;
}
else {
tagsCol = index;
}
if (column === 'time') { timeCol = index; return; }
if (column === 'sequence_number') { return; }
if (!titleCol) { titleCol = index; }
if (column === self.annotation.titleColumn) { titleCol = index; return; }
if (column === self.annotation.tagsColumn) { tagsCol = index; return; }
if (column === self.annotation.textColumn) { textCol = index; return; }
});
_.each(series.points, function (point) {
var data = {
annotation: self.annotation,
time: point[0] * 1000,
title: point[titleCol]
time: point[timeCol] * 1000,
title: point[titleCol],
tags: point[tagsCol],
text: point[textCol]
};
if (tagsCol) {
......
......@@ -140,33 +140,56 @@ define([
});
describe("when creating annotations from influxdb response", function() {
describe('given two series', function() {
describe('given column mapping for all columns', function() {
var series = new InfluxSeries({
seriesList: [
{
columns: ['time', 'text', 'sequence_number'],
columns: ['time', 'text', 'sequence_number', 'title', 'tags'],
name: 'events1',
points: [[1402596000, 'some text', 1], [1402596001, 'asd', 2]]
},
{
columns: ['time', 'tags', 'text'],
name: 'events2',
points: [[1402596000, 'tag1, tag2', 'mu']]
points: [[1402596000, 'some text', 1, 'Hello', 'B'], [1402596001, 'asd', 2, 'Hello2', 'B']]
}
],
annotation: {query: 'select'}
annotation: {
query: 'select',
titleColumn: 'title',
tagsColumn: 'tags',
textColumn: 'text',
}
});
var result = series.getAnnotations();
it(' should generate 4 annnotations ', function() {
expect(result.length).to.be(3);
it(' should generate 2 annnotations ', function() {
expect(result.length).to.be(2);
expect(result[0].annotation.query).to.be('select');
expect(result[0].title).to.be('Hello');
expect(result[0].time).to.be(1402596000000);
expect(result[0].tags).to.be('B');
expect(result[0].text).to.be('some text');
});
});
describe('given no column mapping', function() {
var series = new InfluxSeries({
seriesList: [
{
columns: ['time', 'text', 'sequence_number'],
name: 'events1',
points: [[1402596000, 'some text', 1]]
}
],
annotation: { query: 'select' }
});
var result = series.getAnnotations();
it('should generate 1 annnotation', function() {
expect(result.length).to.be(1);
expect(result[0].title).to.be('some text');
expect(result[0].time).to.be(1402596000000);
expect(result[1].title).to.be('asd');
//expect(result[2].tags).to.be('tag1, tag2');
//expect(result[2].title).to.be('mu');
expect(result[0].tags).to.be(undefined);
expect(result[0].text).to.be(undefined);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment