module.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. ## query
  3. An experimental panel for the query service
  4. ### Parameters
  5. * label :: The label to stick over the field
  6. * query :: A string or an array of querys. String if multi is off, array if it is on
  7. This should be fixed, it should always be an array even if its only
  8. one element
  9. */
  10. angular.module('kibana.query', [])
  11. .controller('query', function($scope, query, $rootScope) {
  12. // Set and populate defaults
  13. var _d = {
  14. status : "Experimental",
  15. label : "Search",
  16. query : "*",
  17. group : "default",
  18. history : [],
  19. remember: 10 // max: 100, angular strap can't take a variable for items param
  20. }
  21. _.defaults($scope.panel,_d);
  22. $scope.queries = query;
  23. $scope.init = function() {
  24. }
  25. $scope.refresh = function(query) {
  26. $rootScope.$broadcast('refresh')
  27. }
  28. $scope.render = function(query) {
  29. $rootScope.$broadcast('render')
  30. }
  31. $scope.add_query = function() {
  32. if (_.isArray($scope.panel.query))
  33. $scope.panel.query.push("")
  34. else {
  35. $scope.panel.query = new Array($scope.panel.query)
  36. $scope.panel.query.push("")
  37. }
  38. }
  39. var update_history = function(query) {
  40. if($scope.panel.remember > 0) {
  41. $scope.panel.history = _.union(query.reverse(),$scope.panel.history)
  42. var _length = $scope.panel.history.length
  43. if(_length > $scope.panel.remember) {
  44. $scope.panel.history = $scope.panel.history.slice(0,$scope.panel.remember)
  45. }
  46. }
  47. }
  48. });