module.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * multi :: Allow input of multiple queries? true/false
  10. * multi_arrange :: How to arrange multu query string panels, 'vertical' or 'horizontal'
  11. ### Group Events
  12. #### Sends
  13. * query :: Always broadcast as an array, even in multi: false
  14. #### Receives
  15. * query :: An array of queries. This is probably needs to be fixed.
  16. */
  17. angular.module('kibana.query', [])
  18. .controller('query', function($scope, eventBus, query, $rootScope) {
  19. // Set and populate defaults
  20. var _d = {
  21. status : "Experimental",
  22. label : "Search",
  23. query : "*",
  24. group : "default",
  25. history : [],
  26. remember: 10 // max: 100, angular strap can't take a variable for items param
  27. }
  28. _.defaults($scope.panel,_d);
  29. $scope.queries = query;
  30. $scope.init = function() {
  31. }
  32. $scope.refresh = function(query) {
  33. $rootScope.$broadcast('refresh')
  34. }
  35. $scope.render = function(query) {
  36. $rootScope.$broadcast('render')
  37. }
  38. $scope.add_query = function() {
  39. if (_.isArray($scope.panel.query))
  40. $scope.panel.query.push("")
  41. else {
  42. $scope.panel.query = new Array($scope.panel.query)
  43. $scope.panel.query.push("")
  44. }
  45. }
  46. var update_history = function(query) {
  47. if($scope.panel.remember > 0) {
  48. $scope.panel.history = _.union(query.reverse(),$scope.panel.history)
  49. var _length = $scope.panel.history.length
  50. if(_length > $scope.panel.remember) {
  51. $scope.panel.history = $scope.panel.history.slice(0,$scope.panel.remember)
  52. }
  53. }
  54. }
  55. });