Commit a1afd232 by Torkel Ödegaard

fix(elasticsearch): made interval template variable appear in group by time…

fix(elasticsearch): made interval template variable appear in group by time interval dropdown, fixes #3241
parent 1fa8b745
......@@ -7,6 +7,7 @@ function (angular, _, coreModule) {
'use strict';
coreModule.service('uiSegmentSrv', function($sce, templateSrv) {
var self = this;
function MetricSegment(options) {
if (options === '*' || options.value === '*') {
......@@ -74,6 +75,24 @@ function (angular, _, coreModule) {
});
};
this.transformToSegments = function(addTemplateVars, variableTypeFilter) {
return function(results) {
var segments = _.map(results, function(segment) {
return self.newSegment({ value: segment.text, expandable: segment.expandable });
});
if (addTemplateVars) {
_.each(templateSrv.variables, function(variable) {
if (variableTypeFilter === void 0 || variableTypeFilter === variable.type) {
segments.unshift(self.newSegment({ type: 'template', value: '$' + variable.name, expandable: true }));
}
});
}
return segments;
};
};
this.newSelectMetric = function() {
return new MetricSegment({value: 'select metric', fake: true});
};
......
......@@ -15,7 +15,6 @@ function (angular, _, queryDef) {
$scope.bucketAggTypes = queryDef.bucketAggTypes;
$scope.orderOptions = queryDef.orderOptions;
$scope.sizeOptions = queryDef.sizeOptions;
$scope.intervalOptions = queryDef.intervalOptions;
$rootScope.onAppEvent('elastic-query-updated', function() {
$scope.validateModel();
......@@ -128,6 +127,10 @@ function (angular, _, queryDef) {
}
};
$scope.getIntervalOptions = function() {
return $q.when(uiSegmentSrv.transformToSegments(true, 'interval')(queryDef.intervalOptions));
};
$scope.addBucketAgg = function() {
// if last is date histogram add it before
var lastBucket = bucketAggs[bucketAggs.length - 1];
......
......@@ -41,7 +41,7 @@
Interval
</li>
<li>
<metric-segment-model property="agg.settings.interval" options="intervalOptions" on-change="onChangeInternal()" css-class="last" custom="true"></metric-segment-model>
<metric-segment-model property="agg.settings.interval" get-options="getIntervalOptions()" on-change="onChangeInternal()" css-class="last" custom="true"></metric-segment-model>
</li>
</ul>
<div class="clearfix"></div>
......
define([
'angular',
'lodash',
],
function (angular, _) {
function (angular) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv, templateSrv) {
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) {
$scope.init = function() {
var target = $scope.target;
......@@ -21,7 +20,7 @@ function (angular, _) {
$scope.getFields = function(type) {
var jsonStr = angular.toJson({find: 'fields', type: type});
return $scope.datasource.metricFindQuery(jsonStr)
.then($scope.transformToSegments(false))
.then(uiSegmentSrv.transformToSegments(false))
.then(null, $scope.handleQueryError);
};
......@@ -35,21 +34,6 @@ function (angular, _) {
$scope.appEvent('elastic-query-updated');
};
$scope.transformToSegments = function(addTemplateVars) {
return function(results) {
var segments = _.map(results, function(segment) {
return uiSegmentSrv.newSegment({ value: segment.text, expandable: segment.expandable });
});
if (addTemplateVars) {
_.each(templateSrv.variables, function(variable) {
segments.unshift(uiSegmentSrv.newSegment({ type: 'template', value: '$' + variable.name, expandable: true }));
});
}
return segments;
};
};
$scope.handleQueryError = function(err) {
$scope.parserError = err.message || 'Failed to issue metric query';
return [];
......
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