module.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ## Sort
  3. This will probably be removed in the near future since it only interacts with
  4. the table panel and the table panel already implements all of its functionality.
  5. It only interacts with the table panel in any case
  6. ### Parameters
  7. * label :: The label to stick over the drop down
  8. * sort :: An array where the first elemetn is the field to sort on an the second
  9. is the direction ('asc' or 'desc')
  10. ### Group Events
  11. #### Sends
  12. * sort :: An array where the first elemetn is the field to sort on an the second
  13. is the direction ('asc' or 'desc')
  14. #### Receives
  15. * fields :: An array containing the fields in a table. This will be concat'd +
  16. uniqued with the curent list.
  17. */
  18. angular.module('kibana.sort', [])
  19. .controller('sort', function($scope, eventBus) {
  20. // Set and populate defaults
  21. var _d = {
  22. label : "Sort",
  23. sort : ['_score','desc'],
  24. group : "default"
  25. }
  26. _.defaults($scope.panel,_d);
  27. $scope.init = function() {
  28. $scope.fields = [];
  29. eventBus.register($scope,'fields',function(event, fields) {
  30. $scope.panel.sort = _.clone(fields.sort);
  31. $scope.fields = _.union(fields.all,$scope.fields);
  32. });
  33. }
  34. $scope.set_sort = function() {
  35. eventBus.broadcast($scope.$id,$scope.panel.group,"sort",$scope.panel.sort)
  36. }
  37. $scope.toggle_sort = function() {
  38. $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
  39. $scope.set_sort();
  40. }
  41. })