diff --git a/public/app/directives/metric.segment.js b/public/app/directives/metric.segment.js index 3cd8068031f..1697b752a74 100644 --- a/public/app/directives/metric.segment.js +++ b/public/app/directives/metric.segment.js @@ -170,14 +170,14 @@ function (angular, app, _, $) { onChange: "&", }, link: { - pre: function postLink($scope, elem) { + pre: function postLink($scope, elem, attrs) { $scope.valueToSegment = function(value) { var option = _.findWhere($scope.options, {value: value}); if (option) { - return uiSegmentSrv.newSegment({value: option.text}); + return uiSegmentSrv.newSegment({value: option.text, cssClass: attrs.cssClass}); } else { - return uiSegmentSrv.newSegment({value: value}); + return uiSegmentSrv.newSegment({value: value, cssClass: attrs.cssClass}); } }; diff --git a/public/app/plugins/datasource/elasticsearch/bucketAgg.js b/public/app/plugins/datasource/elasticsearch/bucketAgg.js index 818305c427b..f4abdd35a00 100644 --- a/public/app/plugins/datasource/elasticsearch/bucketAgg.js +++ b/public/app/plugins/datasource/elasticsearch/bucketAgg.js @@ -11,24 +11,62 @@ function (angular, _, $) { module.controller('ElasticBucketAggCtrl', function($scope, uiSegmentSrv, $q) { var bucketAggs = $scope.target.bucketAggs; - $scope.agg = bucketAggs[$scope.index]; - $scope.bucketAggTypes = [ {text: "Terms", value: 'terms' }, {text: "Date Histogram", value: 'date_histogram' }, ]; + $scope.orderOptions = [ + {text: "Top", value: 'desc' }, + {text: "Bottom", value: 'asc' }, + ]; + + $scope.sizeOptions = [ + {text: "No limit", value: '0' }, + {text: "1", value: '1' }, + {text: "2", value: '2' }, + {text: "3", value: '4' }, + {text: "5", value: '5' }, + {text: "10", value: '10' }, + {text: "15", value: '15' }, + {text: "20", value: '20' }, + ]; + $scope.$watch("index", function() { $scope.isFirst = $scope.index === 0; $scope.isLast = $scope.index === bucketAggs.length - 1; }); - if ($scope.agg.type === "terms") { - $scope.aggOptionsString = "Top 5, Order by: sum @value"; - } + $scope.init = function() { + $scope.agg = bucketAggs[$scope.index]; + $scope.modelIsValid(); + }; + + $scope.onChangeInternal = function() { + if ($scope.modelIsValid()) { + $scope.onChange(); + } + }; + + $scope.modelIsValid = function() { + if ($scope.agg.type === "terms") { + $scope.aggOptionsString = "Top 5, Order by: sum @value"; + + $scope.agg.order = $scope.agg.order || "desc"; + $scope.agg.size = $scope.agg.size || "0"; + $scope.agg.orderBy = $scope.agg.orderBy || "_count"; + } + return true; + }; $scope.toggleOptions = function() { $scope.showOptions = !$scope.showOptions; + + $scope.orderByOptions = [ + {text: "Doc Count", value: '_count' }, + {text: "Term name", value: '_term' }, + {text: "Average of @value", value: '0' }, + ]; } $scope.addBucketAgg = function() { @@ -48,6 +86,8 @@ function (angular, _, $) { $scope.onChange(); }; + $scope.init(); + }); module.directive('elasticBucketAgg', function() { diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html index 0ac2572ce45..f2c440c1c4b 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html @@ -5,8 +5,8 @@ Then by
  • - - + +
  • {{aggOptionsString}} @@ -32,7 +32,7 @@ Order
  • - +
  • @@ -43,7 +43,7 @@ Size
  • - +
  • @@ -51,10 +51,10 @@