diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index ab1afa6a017..6e149e91384 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -13,6 +13,7 @@ function (angular, _, queryDef) { $scope.metricAggTypes = queryDef.metricAggTypes; $scope.extendedStats = queryDef.extendedStats; + $scope.mavgSourceOptions = []; $scope.init = function() { $scope.agg = metricAggs[$scope.index]; @@ -22,6 +23,7 @@ function (angular, _, queryDef) { $rootScope.onAppEvent('elastic-query-updated', function() { $scope.index = _.indexOf(metricAggs, $scope.agg); $scope.validateModel(); + $scope.updateMovingAverageOptions(); }, $scope); $scope.validateModel = function() { @@ -36,7 +38,8 @@ function (angular, _, queryDef) { switch($scope.agg.type) { case 'moving_avg': { - $scope.agg.aggregation = $scope.agg.aggregation || 'sum'; + $scope.agg.mavgSource = $scope.agg.mavgSource || ''; + $scope.settingsLinkText = 'Moving average options'; break; } case 'percentiles': { @@ -69,6 +72,11 @@ function (angular, _, queryDef) { $scope.toggleOptions = function() { $scope.showOptions = !$scope.showOptions; + $scope.updateMovingAverageOptions(); + }; + + $scope.onChangeInternal = function() { + $scope.onChange(); }; $scope.onTypeChange = function() { @@ -82,13 +90,6 @@ function (angular, _, queryDef) { return $scope.getFields({$fieldType: 'number'}); }; - $scope.getMetrics = function() { - var aggs = [{ text: 'Sum', type: 'sum'}, { text: 'Average', type: 'avg'}]; - - return $q.when(aggs) - .then(uiSegmentSrv.transformToSegments(false)); - }; - $scope.addMetricAgg = function() { var addIndex = metricAggs.length; @@ -100,6 +101,10 @@ function (angular, _, queryDef) { $scope.onChange(); }; + $scope.updateMovingAverageOptions = function() { + $scope.mvagSourceOptions = queryDef.getMovingAverageSourceOptions($scope.target); + }; + $scope.removeMetricAgg = function() { metricAggs.splice($scope.index, 1); $scope.onChange(); diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index fd487d52d3b..2e34b28612d 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html @@ -9,9 +9,6 @@