metricAgg.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'jquery',
  5. ],
  6. function (angular, _, $) {
  7. 'use strict';
  8. var module = angular.module('grafana.directives');
  9. module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q) {
  10. var metricAggs = $scope.target.metrics;
  11. $scope.metricAggTypes = [
  12. {text: "Count", value: 'count' },
  13. {text: "Average of", value: 'avg' },
  14. {text: "Sum of", value: 'sum' },
  15. {text: "Max of", value: 'max' },
  16. {text: "Min of", value: 'min' },
  17. {text: "Standard Deviations", value: 'std_dev' },
  18. ];
  19. $scope.init = function() {
  20. $scope.agg = metricAggs[$scope.index];
  21. if (!$scope.agg.field) {
  22. $scope.agg.field = 'select field';
  23. }
  24. }
  25. $scope.$watchCollection("target.metrics", function() {
  26. $scope.isFirst = $scope.index === 0;
  27. $scope.isLast = $scope.index === metricAggs.length - 1;
  28. $scope.isSingle = metricAggs.length === 1;
  29. });
  30. $scope.toggleOptions = function() {
  31. $scope.showOptions = !$scope.showOptions;
  32. }
  33. $scope.addMetricAgg = function() {
  34. var addIndex = metricAggs.length;
  35. metricAggs.splice(addIndex, 0, {type: "count", field: "select field" });
  36. };
  37. $scope.removeMetricAgg = function() {
  38. metricAggs.splice($scope.index, 1);
  39. $scope.onChange();
  40. };
  41. $scope.init();
  42. });
  43. module.directive('elasticMetricAgg', function() {
  44. return {
  45. templateUrl: 'app/plugins/datasource/elasticsearch/partials/metricAgg.html',
  46. controller: 'ElasticMetricAggCtrl',
  47. restrict: 'E',
  48. scope: {
  49. target: "=",
  50. index: "=",
  51. onChange: "&",
  52. getFields: "&",
  53. },
  54. link: function postLink($scope, elem) {
  55. }
  56. };
  57. });
  58. });