Commit 66db99fa by Torkel Ödegaard

Merge branch 'feature/influxdb-add-where-conditions' of…

Merge branch 'feature/influxdb-add-where-conditions' of github.com:mavimo/grafana into mavimo-feature/influxdb-add-where-conditions
parents 0efafc50 595aab4e
......@@ -18,6 +18,7 @@ function (angular) {
$scope.rawQuery = false;
$scope.functions = ['count', 'mean', 'sum', 'min', 'max', 'mode', 'distinct', 'median', 'derivative', 'stddev', 'first', 'last'];
$scope.operators = ['=', '=~', '>', '<', '!~', '<>'];
$scope.oldSeries = $scope.target.series;
$scope.$on('typeahead-updated', function(){
$timeout($scope.get_data);
......
......@@ -52,12 +52,24 @@
ng-blur="get_data()">
</li>
<li class="grafana-target-segment" ng-hide="target.rawQuery">
label
</li>
<li ng-hide="target.rawQuery">
<input type="text"
class="input-small grafana-target-segment-input"
ng-model="target.label"
spellcheck='false'
placeholder="label"
ng-blur="seriesBlur()">
</li>
<li class="grafana-target-segment" ng-hide="target.rawQuery">
from series
</li>
<li ng-hide="target.rawQuery">
<input type="text"
class="input-medium grafana-target-segment-input"
class="input-small grafana-target-segment-input"
ng-model="target.series"
spellcheck='false'
bs-typeahead="listSeries"
......@@ -72,7 +84,7 @@
<li ng-hide="target.rawQuery">
<input type="text"
class="input-medium grafana-target-segment-input"
class="input-small grafana-target-segment-input"
ng-model="target.column"
placeholder="value column"
spellcheck='false'
......@@ -84,14 +96,44 @@
<li class="grafana-target-segment" ng-hide="target.rawQuery">
function
</li>
<li ng-hide="target.rawQuery">
<select class="input-medium grafana-target-segment-input"
<select class="input-small grafana-target-segment-input"
ng-change="get_data()"
ng-model="target.function"
ng-options="f for f in functions" ></select>
</li>
<li ng-hide="target.rawQuery">
<a class="grafana-target-segment"
ng-click="target.condiction_filter = !target.condiction_filter; get_data();"
role="menuitem">
<i class="icon-filter"></i>
</a>
</li>
<li ng-hide="target.rawQuery" ng-show="target.condiction_filter">
<select class="input-small grafana-target-segment-input"
ng-change="get_data()"
ng-model="target.condition_add"
ng-options="f for f in ['and', 'or']" ></select>
<input type="text"
class="input-small grafana-target-segment-input"
ng-model="target.condition_key"
placeholder="key"
spellcheck='false'
bs-typeahead="listColumns"
data-min-length=0
ng-blur="get_data()">
<select class="input-small grafana-target-segment-input"
ng-change="get_data()"
ng-model="target.condition_op"
ng-options="f for f in operators" ></select>
<input type="text"
class="input-small grafana-target-segment-input"
ng-model="target.condition_value"
placeholder="value"
spellcheck='false'
data-min-length=0
ng-blur="get_data()">
</li>
<li class="grafana-target-segment" ng-hide="target.rawQuery">
group by time
</li>
......
......@@ -60,25 +60,29 @@ function (angular, _, kbn) {
}
query = queryElements.join(" ");
}
else {
var template = "select [[func]]([[column]]) as [[column]]_[[func]] from [[series]] where [[timeFilter]]" +
" group by time([[interval]]) order asc";
var template = "select [[func]]([[column]]) as [[column]]_[[func]] from [[series]] " +
"where [[timeFilter]] [[condition_add]] [[condition_key]] [[condition_op]] [[condition_value]] " +
"group by time([[interval]]) order asc";
var templateData = {
series: target.series,
column: target.column,
func: target.function,
timeFilter: timeFilter,
interval: target.interval || options.interval
interval: target.interval || options.interval,
condition_add: target.condiction_filter ? target.condition_add : '',
condition_key: target.condiction_filter ? target.condition_key : '',
condition_op: target.condiction_filter ? target.condition_op : '',
condition_value: target.condiction_filter ? target.condition_value: ''
};
query = _.template(template, templateData, this.templateSettings);
target.query = query;
}
return this.doInfluxRequest(query).then(handleInfluxQueryResponse);
return this.doInfluxRequest(query, target.label).then(handleInfluxQueryResponse);
}, this);
......@@ -117,7 +121,7 @@ function (angular, _, kbn) {
});
}
InfluxDatasource.prototype.doInfluxRequest = function(query) {
InfluxDatasource.prototype.doInfluxRequest = function(query, label) {
var _this = this;
var deferred = $q.defer();
......@@ -138,6 +142,7 @@ function (angular, _, kbn) {
};
return $http(options).success(function (data) {
data.label = label;
deferred.resolve(data);
});
}, 10);
......@@ -156,9 +161,7 @@ function (angular, _, kbn) {
return;
}
console.log("series:"+series.name + ": "+series.points.length + " points");
var target = series.name + "." + column;
var target = data.label || series.name + "." + column;
var datapoints = [];
for(var i = 0; i < series.points.length; i++) {
......
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