query_ctrl.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. define([
  2. 'angular',
  3. 'lodash',
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.controllers');
  8. module.controller('PrometheusQueryCtrl', function($scope) {
  9. $scope.init = function() {
  10. var target = $scope.target;
  11. target.expr = target.expr || '';
  12. target.intervalFactor = target.intervalFactor || 2;
  13. $scope.metric = '';
  14. $scope.resolutions = _.map([1,2,3,4,5,10], function(f) {
  15. return {factor: f, label: '1/' + f};
  16. });
  17. $scope.$on('typeahead-updated', function() {
  18. $scope.$apply($scope.inputMetric);
  19. $scope.refreshMetricData();
  20. });
  21. };
  22. $scope.refreshMetricData = function() {
  23. if (!_.isEqual($scope.oldTarget, $scope.target)) {
  24. $scope.oldTarget = angular.copy($scope.target);
  25. $scope.get_data();
  26. }
  27. };
  28. $scope.inputMetric = function() {
  29. $scope.target.expr += $scope.target.metric;
  30. $scope.metric = '';
  31. };
  32. $scope.suggestMetrics = function(query, callback) {
  33. $scope.datasource
  34. .performSuggestQuery(query)
  35. .then(callback);
  36. };
  37. $scope.init();
  38. });
  39. });