2015-09-05 09:05:09 +02:00
|
|
|
define([
|
|
|
|
|
'angular',
|
|
|
|
|
'lodash',
|
2015-09-05 15:41:04 +02:00
|
|
|
'./queryDef'
|
2015-09-05 09:05:09 +02:00
|
|
|
],
|
2015-09-05 15:41:04 +02:00
|
|
|
function (angular, _, queryDef) {
|
2015-09-05 09:05:09 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var module = angular.module('grafana.directives');
|
|
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q) {
|
|
|
|
|
var metricAggs = $scope.target.metrics;
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.metricAggTypes = queryDef.metricAggTypes;
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.init = function() {
|
|
|
|
|
$scope.agg = metricAggs[$scope.index];
|
|
|
|
|
if (!$scope.agg.field) {
|
|
|
|
|
$scope.agg.field = 'select field';
|
2015-09-05 09:05:09 +02:00
|
|
|
}
|
2015-09-05 15:41:04 +02:00
|
|
|
}
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.$watchCollection("target.metrics", function() {
|
|
|
|
|
$scope.isFirst = $scope.index === 0;
|
|
|
|
|
$scope.isLast = $scope.index === metricAggs.length - 1;
|
|
|
|
|
$scope.isSingle = metricAggs.length === 1;
|
|
|
|
|
});
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.toggleOptions = function() {
|
|
|
|
|
$scope.showOptions = !$scope.showOptions;
|
|
|
|
|
}
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.addMetricAgg = function() {
|
|
|
|
|
var addIndex = metricAggs.length;
|
2015-09-05 12:24:14 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
var id = _.reduce($scope.target.bucketAggs.concat($scope.target.metrics), function(max, val) {
|
|
|
|
|
return parseInt(val.id) > max ? parseInt(val.id) : max;
|
|
|
|
|
}, 0);
|
2015-09-05 12:24:14 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
metricAggs.splice(addIndex, 0, {type: "count", field: "select field", id: (id+1).toString()});
|
|
|
|
|
};
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.removeMetricAgg = function() {
|
|
|
|
|
metricAggs.splice($scope.index, 1);
|
|
|
|
|
$scope.onChange();
|
|
|
|
|
};
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
$scope.init();
|
2015-09-05 09:05:09 +02:00
|
|
|
|
2015-09-05 15:41:04 +02:00
|
|
|
});
|
2015-09-05 09:05:09 +02:00
|
|
|
|
|
|
|
|
});
|