module.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*
  4. ## query
  5. An experimental panel for the query service
  6. ### Parameters
  7. * label :: The label to stick over the field
  8. * query :: A string or an array of querys. String if multi is off, array if it is on
  9. This should be fixed, it should always be an array even if its only
  10. one element
  11. */
  12. 'use strict';
  13. angular.module('kibana.query', [])
  14. .controller('query', function($scope, querySrv, $rootScope) {
  15. // Set and populate defaults
  16. var _d = {
  17. status : "Experimental",
  18. label : "Search",
  19. query : "*",
  20. pinned : true,
  21. group : "default",
  22. history : [],
  23. remember: 10 // max: 100, angular strap can't take a variable for items param
  24. };
  25. _.defaults($scope.panel,_d);
  26. $scope.querySrv = querySrv;
  27. $scope.init = function() {
  28. };
  29. $scope.refresh = function(query) {
  30. update_history(_.pluck($scope.querySrv.list,'query'));
  31. $rootScope.$broadcast('refresh');
  32. };
  33. $scope.render = function(query) {
  34. $rootScope.$broadcast('render');
  35. };
  36. $scope.toggle_pin = function(id) {
  37. querySrv.list[id].pin = querySrv.list[id].pin ? false : true;
  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. });