module.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. ## Fields
  3. Allows for enabling and disabling of fields in the table panel as well as a
  4. micro anaylsis panel for analyzing the events in the table panel
  5. ### Parameters
  6. * style :: a hash containing css styles
  7. * arrange :: the layout pf the panel 'horizontal' or 'vertical'
  8. * micropanel_position :: where to place the micropanel in relation to the field
  9. ### Group Events
  10. #### Recieves
  11. * table_documents :: An object containing the documents in the table panel
  12. #### Sends
  13. * fields :: an object containing the sort order, existing fields and selected fields
  14. */
  15. angular.module('kibana.fields', [])
  16. .controller('fields', function($scope, eventBus, $timeout) {
  17. // Set and populate defaults
  18. var _d = {
  19. group : "default",
  20. style : {},
  21. arrange : 'vertical',
  22. micropanel_position : 'right',
  23. }
  24. _.defaults($scope.panel,_d);
  25. $scope.init = function() {
  26. $scope.Math = Math;
  27. $scope.fields = [];
  28. eventBus.register($scope,'fields', function(event, fields) {
  29. $scope.panel.sort = _.clone(fields.sort);
  30. $scope.fields = fields.all,
  31. $scope.active = _.clone(fields.active);
  32. });
  33. eventBus.register($scope,'table_documents', function(event, docs) {
  34. $scope.panel.query = docs.query;
  35. $scope.docs = docs.docs;
  36. $scope.index = docs.index;
  37. });
  38. eventBus.register($scope,"get_fields", function(event,id) {
  39. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
  40. });
  41. }
  42. $scope.reload_list = function () {
  43. var temp = _.clone($scope.fields);
  44. $scope.fields = []
  45. $timeout(function(){
  46. $scope.fields = temp;
  47. },10)
  48. }
  49. $scope.toggle_micropanel = function(field) {
  50. $scope.micropanel = {
  51. field: field,
  52. values : top_field_values($scope.docs,field,10),
  53. related : get_related_fields($scope.docs,field),
  54. count: _.countBy($scope.docs,function(doc){
  55. return _.contains(_.keys(doc),field)})['true'],
  56. }
  57. }
  58. $scope.toggle_sort = function() {
  59. $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
  60. }
  61. $scope.toggle_field = function(field) {
  62. if (_.indexOf($scope.active,field) > -1)
  63. $scope.active = _.without($scope.active,field)
  64. else
  65. $scope.active.push(field)
  66. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active)
  67. }
  68. $scope.build_search = function(field, value,negate) {
  69. $scope.panel.query = [add_to_query($scope.panel.query,field,value,negate)]
  70. eventBus.broadcast($scope.$id,$scope.panel.group,'query',$scope.panel.query);
  71. }
  72. $scope.is_active = function(field) {
  73. return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : '';
  74. }
  75. })