From c8c9e0a7e77e0168ae57f309f41958626c190d65 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Thu, 10 Dec 2015 17:03:46 +0100 Subject: [PATCH] feat(elasticsearch): improve pipeline aggs structure --- .../datasource/elasticsearch/metric_agg.js | 9 ++++--- .../elasticsearch/partials/metricAgg.html | 26 +++++++++---------- .../datasource/elasticsearch/query_def.js | 17 ++++++------ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index 9ac70580e51..8bd1b596245 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -13,15 +13,12 @@ function (angular, _, queryDef) { $scope.metricAggTypes = queryDef.metricAggTypes; $scope.extendedStats = queryDef.extendedStats; - $scope.pipelineSettings = []; - $scope.pipelineAggOptions = []; $scope.init = function() { $scope.agg = metricAggs[$scope.index]; $scope.validateModel(); $scope.updatePipelineAggOptions(); - $scope.pipelineSettings = queryDef.getPipelineSettings($scope.agg); }; $scope.updatePipelineAggOptions = function() { @@ -44,7 +41,11 @@ function (angular, _, queryDef) { $scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'select metric'; $scope.agg.field = $scope.agg.pipelineAgg; $scope.settingsLinkText = 'Options'; - delete $scope.agg.field; + + _.each(queryDef.getPipelineOptions($scope.agg), function(opt) { + $scope.agg.settings[opt.text] = $scope.agg.settings[opt.text] || opt.default; + }); + } else if (!$scope.agg.field) { $scope.agg.field = 'select field'; } diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index ecbfa3d7df1..009e5ff65f5 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html @@ -34,9 +34,9 @@
-
+
    -
  • +
  • Based on
  • @@ -45,18 +45,16 @@
-
-
-
    -
  • - {{stat.text}} -
  • -
  • - -
  • -
-
-
+
+
    +
  • + Window +
  • +
  • + +
  • +
+
    diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index 361dbfd5e1d..2cd7e97e145 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -68,24 +68,25 @@ function (_) { {text: '1d', value: '1d'}, ], - pipelineAggs: ['moving_avg', 'derivative'], - - pipelineSettings: { - 'moving_avg' : ['model', 'gap_policy', 'window', 'minimize'], + pipelineOptions: { + 'moving_avg' : [ + {text: 'window', default: 5} + ], 'derivative': [] }, - getPipelineSettings: function(metric) { - if (this.isPipelineAgg(metric) === false) { + getPipelineOptions: function(metric) { + if (!this.isPipelineAgg(metric)) { return []; } - return this.pipelineSettings[metric.type]; + return this.pipelineOptions[metric.type]; }, isPipelineAgg: function(metric) { if (metric.type) { - return this.pipelineAggs.indexOf(metric.type) > -1; + var po = this.pipelineOptions[metric.type]; + return po !== null && po !== undefined; } return false;