module.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*
  4. ## query
  5. ### Parameters
  6. * label :: The label to stick over the field
  7. * query :: A string or an array of querys. String if multi is off, array if it is on
  8. This should be fixed, it should always be an array even if its only
  9. one element
  10. */
  11. 'use strict';
  12. angular.module('kibana.query', [])
  13. .controller('query', function($scope, querySrv, $rootScope) {
  14. $scope.panelMeta = {
  15. status : "Stable",
  16. description : "Manage all of the queries on the dashboard. You almost certainly need one of "+
  17. "these somewhere. This panel allows you to add, remove, label, pin and color queries"
  18. };
  19. // Set and populate defaults
  20. var _d = {
  21. label : "Search",
  22. query : "*",
  23. pinned : true,
  24. history : [],
  25. remember: 10 // max: 100, angular strap can't take a variable for items param
  26. };
  27. _.defaults($scope.panel,_d);
  28. $scope.querySrv = querySrv;
  29. $scope.init = function() {
  30. };
  31. $scope.refresh = function(query) {
  32. update_history(_.pluck($scope.querySrv.list,'query'));
  33. $rootScope.$broadcast('refresh');
  34. };
  35. $scope.render = function(query) {
  36. $rootScope.$broadcast('render');
  37. };
  38. $scope.toggle_pin = function(id) {
  39. querySrv.list[id].pin = querySrv.list[id].pin ? false : true;
  40. };
  41. var update_history = function(query) {
  42. if($scope.panel.remember > 0) {
  43. $scope.panel.history = _.union(query.reverse(),$scope.panel.history);
  44. var _length = $scope.panel.history.length;
  45. if(_length > $scope.panel.remember) {
  46. $scope.panel.history = $scope.panel.history.slice(0,$scope.panel.remember);
  47. }
  48. }
  49. };
  50. });