module.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. angular.module('kibana.stringquery', [])
  2. .controller('stringquery', function($scope, eventBus) {
  3. // Set and populate defaults
  4. var _d = {
  5. label : "Search",
  6. query : "*",
  7. size : 100,
  8. sort : ['_score','desc'],
  9. group : "default",
  10. multi : false,
  11. multi_arrange: 'horizontal',
  12. }
  13. _.defaults($scope.panel,_d);
  14. var _groups = _.isArray($scope.panel.group) ?
  15. $scope.panel.group : [$scope.panel.group];
  16. $scope.init = function() {
  17. // I don't like this compromise. I'm not totally sure what this panel
  18. // Should do if its in multi query mode and receives a query. For now, just
  19. // replace the first one, though I feel like that isn't right.
  20. eventBus.register($scope,'query',function(event,query) {
  21. if (_.isArray($scope.panel.query))
  22. $scope.panel.query[0] = query
  23. else
  24. $scope.panel.query = query;
  25. });
  26. }
  27. $scope.send_query = function(query) {
  28. eventBus.broadcast($scope.$id,$scope.panel.group,'query',query)
  29. }
  30. $scope.add_query = function() {
  31. if (_.isArray($scope.panel.query))
  32. $scope.panel.query.push("")
  33. else {
  34. $scope.panel.query = new Array($scope.panel.query)
  35. $scope.panel.query.push("")
  36. }
  37. }
  38. $scope.set_multi = function(multi) {
  39. $scope.panel.query = multi ?
  40. new Array($scope.panel.query) : $scope.panel.query[0];
  41. }
  42. $scope.set_sort = function(field) {
  43. if($scope.panel.sort[0] === field)
  44. $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
  45. else
  46. $scope.panel.sort[0] = field;
  47. }
  48. $scope.remove_query = function(index) {
  49. $scope.panel.query.splice(index,1);
  50. }
  51. });