diff --git a/public/app/directives/metric.segment.js b/public/app/directives/metric.segment.js
index 3b5f473b6dc..b6392ec2a0f 100644
--- a/public/app/directives/metric.segment.js
+++ b/public/app/directives/metric.segment.js
@@ -20,8 +20,9 @@ function (angular, app, _, $) {
return {
scope: {
segment: "=",
+ disableCustom: "=",
getAltSegments: "&",
- onValueChanged: "&"
+ onValueChanged: "&",
},
link: function($scope, elem) {
@@ -47,12 +48,13 @@ function (angular, app, _, $) {
segment.fake = false;
segment.expandable = selected.expandable;
}
- else {
+ else if ($scope.disableCustom === false) {
segment.value = value;
segment.html = $sce.trustAsHtml(value);
segment.expandable = true;
segment.fake = false;
}
+
$scope.onValueChanged();
});
};
@@ -81,8 +83,10 @@ function (angular, app, _, $) {
options = _.map($scope.altSegments, function(alt) { return alt.value; });
// add custom values
- if (!segment.fake && _.indexOf(options, segment.value) === -1) {
- options.unshift(segment.value);
+ if ($scope.disableCustom === false) {
+ if (!segment.fake && _.indexOf(options, segment.value) === -1) {
+ options.unshift(segment.value);
+ }
}
callback(options);
@@ -92,7 +96,6 @@ function (angular, app, _, $) {
$scope.updater = function(value) {
if (value === segment.value) {
- console.log('cancel blur');
clearTimeout(cancelBlur);
$input.focus();
return value;
@@ -153,4 +156,48 @@ function (angular, app, _, $) {
}
};
});
+
+ angular
+ .module('grafana.directives')
+ .directive('metricSegmentModel', function(uiSegmentSrv, $q) {
+ return {
+ template: '',
+ restrict: 'E',
+ scope: {
+ property: "=",
+ options: "=",
+ onChange: "&",
+ },
+ link: {
+ pre: function postLink($scope, elem) {
+
+ $scope.valueToSegment = function(value) {
+ var option = _.findWhere($scope.options, {value: value});
+ if (option) {
+ return uiSegmentSrv.newSegment({value: option.text});
+ } else {
+ return uiSegmentSrv.newSegment({value: value});
+ }
+ };
+
+ $scope.getOptions = function() {
+ var optionSegments = _.map($scope.options, function(option) {
+ return uiSegmentSrv.newSegment({value: option.text});
+ });
+ return $q.when(optionSegments);
+ };
+
+ $scope.onSegmentChange = function() {
+ var option = _.findWhere($scope.options, {text: $scope.segment.value});
+ if (option && option.value !== $scope.property) {
+ $scope.property = option.value;
+ $scope.onChange();
+ }
+ };
+
+ $scope.segment = $scope.valueToSegment($scope.property);
+ }
+ }
+ };
+ });
});
diff --git a/public/app/plugins/datasource/elasticsearch/bucketAgg.js b/public/app/plugins/datasource/elasticsearch/bucketAgg.js
index 156f5582aca..7c3954805e8 100644
--- a/public/app/plugins/datasource/elasticsearch/bucketAgg.js
+++ b/public/app/plugins/datasource/elasticsearch/bucketAgg.js
@@ -13,6 +13,11 @@ function (angular, _, $) {
$scope.agg = bucketAggs[$scope.index];
+ $scope.bucketAggTypes = [
+ {text: "Terms", value: 'terms' },
+ {text: "Date Histogram", value: 'date_histogram' },
+ ];
+
$scope.$watch("index", function() {
$scope.isFirst = $scope.index === 0;
$scope.isLast = $scope.index === bucketAggs.length - 1;
@@ -22,18 +27,10 @@ function (angular, _, $) {
$scope.aggOptionsString = "Top 5, Order by: sum @value";
}
- $scope.typeSegment = uiSegmentSrv.newSegment($scope.agg.type);
$scope.fieldSegment = uiSegmentSrv.newSegment($scope.agg.field);
- $scope.getBucketAggTypes = function() {
- return $q.when([
- uiSegmentSrv.newSegment({value: 'terms'}),
- uiSegmentSrv.newSegment({value: 'date_histogram'}),
- ]);
- };
-
$scope.toggleOptions = function() {
- $scope.showOptions = $scope.showOptions;
+ $scope.showOptions = !$scope.showOptions;
}
$scope.addBucketAgg = function() {
diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html
index 68bea648205..8b0662bad7d 100644
--- a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html
+++ b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html
@@ -5,7 +5,7 @@
Then by
-
+
@@ -32,7 +32,7 @@
Order
-
+
diff --git a/public/app/plugins/datasource/elasticsearch/queryCtrl.js b/public/app/plugins/datasource/elasticsearch/queryCtrl.js
index 27d1d1c0952..49547295160 100644
--- a/public/app/plugins/datasource/elasticsearch/queryCtrl.js
+++ b/public/app/plugins/datasource/elasticsearch/queryCtrl.js
@@ -10,6 +10,12 @@ function (angular, _, ElasticQueryBuilder) {
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv, templateSrv, $q) {
+ $scope.metricAggregations = {
+ "Count": { value: 'count' },
+ "Average of": { value: 'avg' },
+ "Max of": { value: 'max' },
+ };
+
$scope.init = function() {
var target = $scope.target;
if (!target) { return; }