influxTargetCtrl.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define([
  2. 'angular'
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('kibana.controllers');
  7. var seriesList = null;
  8. module.controller('InfluxTargetCtrl', function($scope, $timeout) {
  9. $scope.init = function() {
  10. if (!$scope.target.function) {
  11. $scope.target.function = 'mean';
  12. }
  13. $scope.rawQuery = false;
  14. $scope.functions = ['count', 'mean', 'sum', 'min', 'max', 'mode', 'distinct', 'median', 'derivative', 'stddev', 'first', 'last'];
  15. $scope.oldSeries = $scope.target.series;
  16. $scope.$on('typeahead-updated', function(){
  17. $timeout($scope.get_data);
  18. });
  19. };
  20. $scope.showQuery = function () {
  21. $scope.target.rawQuery = true;
  22. };
  23. $scope.hideQuery = function () {
  24. $scope.target.rawQuery = false;
  25. };
  26. // Cannot use typeahead and ng-change on blur at the same time
  27. $scope.seriesBlur = function() {
  28. if ($scope.oldSeries !== $scope.target.series) {
  29. $scope.oldSeries = $scope.target.series;
  30. $scope.get_data();
  31. }
  32. };
  33. // called outside of digest
  34. $scope.listColumns = function(query, callback) {
  35. if (!$scope.columnList) {
  36. $scope.$apply(function() {
  37. $scope.datasource.listColumns($scope.target.series).then(function(columns) {
  38. $scope.columnList = columns;
  39. callback(columns);
  40. });
  41. });
  42. }
  43. else {
  44. return $scope.columnList;
  45. }
  46. };
  47. $scope.listSeries = function(query, callback) {
  48. if (!seriesList) {
  49. seriesList = [];
  50. $scope.datasource.listSeries().then(function(series) {
  51. seriesList = series;
  52. callback(seriesList);
  53. });
  54. }
  55. else {
  56. return seriesList;
  57. }
  58. };
  59. $scope.duplicate = function() {
  60. var clone = angular.copy($scope.target);
  61. $scope.panel.targets.push(clone);
  62. };
  63. });
  64. });