Commit cf68725c by Torkel Ödegaard

influxdb annotation column mapping is working

parent cf2ef095
<div class="editor-row"> <div class="editor-row">
<div class="section">
<h5>InfluxDB Query <tip>Example: select text from events where [[timeFilter]]</tip></h5>
<div class="editor-option"> <div class="editor-option">
<label class="small">InfluxDB query</label> <input type="text" class="span10" ng-model='currentAnnotation.query' placeholder="select text from events where [[timeFilter]]"></input>
<input type="text" class="span10" ng-model='currentAnnotation.query' placeholder=""></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>
</div> </div>
...@@ -142,8 +142,8 @@ define([ ...@@ -142,8 +142,8 @@ define([
tooltip += '<i>' + moment(options.time).format('YYYY-MM-DD HH:mm:ss') + '</i><br/>'; tooltip += '<i>' + moment(options.time).format('YYYY-MM-DD HH:mm:ss') + '</i><br/>';
if (options.data) { if (options.text) {
tooltip += options.data.replace(/\n/g, '<br/>'); tooltip += options.text.replace(/\n/g, '<br/>');
} }
tooltip += "</small>"; tooltip += "</small>";
......
...@@ -71,27 +71,27 @@ function (_) { ...@@ -71,27 +71,27 @@ function (_) {
var self = this; var self = this;
_.each(this.seriesList, function (series) { _.each(this.seriesList, function (series) {
var titleCol = 0; var titleCol = null;
var tagsCol = 0; var timeCol = null;
var tagsCol = null;
var textCol = null;
_.each(series.columns, function(column, index) { _.each(series.columns, function(column, index) {
if (column === 'time' || column === 'sequence_number') { if (column === 'time') { timeCol = index; return; }
return; if (column === 'sequence_number') { return; }
} if (!titleCol) { titleCol = index; }
if (column === self.annotation.titleColumn) { titleCol = index; return; }
if (!titleCol && column !== 'tags') { if (column === self.annotation.tagsColumn) { tagsCol = index; return; }
titleCol = index; if (column === self.annotation.textColumn) { textCol = index; return; }
}
else {
tagsCol = index;
}
}); });
_.each(series.points, function (point) { _.each(series.points, function (point) {
var data = { var data = {
annotation: self.annotation, annotation: self.annotation,
time: point[0] * 1000, time: point[timeCol] * 1000,
title: point[titleCol] title: point[titleCol],
tags: point[tagsCol],
text: point[textCol]
}; };
if (tagsCol) { if (tagsCol) {
......
...@@ -140,33 +140,56 @@ define([ ...@@ -140,33 +140,56 @@ define([
}); });
describe("when creating annotations from influxdb response", function() { 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({ var series = new InfluxSeries({
seriesList: [ seriesList: [
{ {
columns: ['time', 'text', 'sequence_number'], columns: ['time', 'text', 'sequence_number', 'title', 'tags'],
name: 'events1', name: 'events1',
points: [[1402596000, 'some text', 1], [1402596001, 'asd', 2]] points: [[1402596000, 'some text', 1, 'Hello', 'B'], [1402596001, 'asd', 2, 'Hello2', 'B']]
},
{
columns: ['time', 'tags', 'text'],
name: 'events2',
points: [[1402596000, 'tag1, tag2', 'mu']]
} }
], ],
annotation: {query: 'select'} annotation: {
query: 'select',
titleColumn: 'title',
tagsColumn: 'tags',
textColumn: 'text',
}
}); });
var result = series.getAnnotations(); var result = series.getAnnotations();
it(' should generate 4 annnotations ', function() { it(' should generate 2 annnotations ', function() {
expect(result.length).to.be(3); expect(result.length).to.be(2);
expect(result[0].annotation.query).to.be('select'); 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].title).to.be('some text');
expect(result[0].time).to.be(1402596000000); expect(result[0].time).to.be(1402596000000);
expect(result[1].title).to.be('asd'); expect(result[0].tags).to.be(undefined);
//expect(result[2].tags).to.be('tag1, tag2'); expect(result[0].text).to.be(undefined);
//expect(result[2].title).to.be('mu');
}); });
}); });
......
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