module.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. });
  37. eventBus.register($scope,"get_fields", function(event,id) {
  38. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
  39. });
  40. }
  41. $scope.reload_list = function () {
  42. var temp = _.clone($scope.fields);
  43. $scope.fields = []
  44. $timeout(function(){
  45. $scope.fields = temp;
  46. },10)
  47. }
  48. $scope.toggle_micropanel = function(field) {
  49. $scope.micropanel = {
  50. field: field,
  51. values : top_field_values($scope.docs,field,10),
  52. related : get_related_fields($scope.docs,field),
  53. count: _.countBy($scope.docs,function(doc){
  54. return _.contains(_.keys(doc),field)})['true'],
  55. }
  56. }
  57. $scope.toggle_sort = function() {
  58. $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
  59. }
  60. $scope.toggle_field = function(field) {
  61. if (_.indexOf($scope.active,field) > -1)
  62. $scope.active = _.without($scope.active,field)
  63. else
  64. $scope.active.push(field)
  65. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active)
  66. }
  67. $scope.build_search = function(field, value,negate) {
  68. $scope.panel.query = [add_to_query($scope.panel.query,field,value,negate)]
  69. eventBus.broadcast($scope.$id,$scope.panel.group,'query',$scope.panel.query);
  70. }
  71. $scope.is_active = function(field) {
  72. return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : '';
  73. }
  74. })