module.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, dashboard, query, filterSrv) {
  17. // Set and populate defaults
  18. var _d = {
  19. status : "Beta",
  20. group : "default",
  21. style : {},
  22. arrange : 'vertical',
  23. micropanel_position : 'right',
  24. }
  25. _.defaults($scope.panel,_d);
  26. $scope.init = function() {
  27. $scope.Math = Math;
  28. $scope.fields = [];
  29. eventBus.register($scope,'fields', function(event, fields) {
  30. $scope.panel.sort = _.clone(fields.sort);
  31. $scope.fields = fields.all,
  32. $scope.active = _.clone(fields.active);
  33. });
  34. eventBus.register($scope,'table_documents', function(event, docs) {
  35. $scope.panel.query = docs.query;
  36. $scope.docs = docs.docs;
  37. $scope.index = docs.index;
  38. });
  39. eventBus.register($scope,"get_fields", function(event,id) {
  40. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
  41. });
  42. }
  43. $scope.reload_list = function () {
  44. var temp = _.clone($scope.fields);
  45. $scope.fields = []
  46. $timeout(function(){
  47. $scope.fields = temp;
  48. },10)
  49. }
  50. $scope.toggle_micropanel = function(field) {
  51. $scope.micropanel = {
  52. field: field,
  53. values : top_field_values($scope.docs,field,10),
  54. related : get_related_fields($scope.docs,field),
  55. count: _.countBy($scope.docs,function(doc){
  56. return _.contains(_.keys(doc),field)})['true'],
  57. }
  58. }
  59. $scope.toggle_sort = function() {
  60. $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
  61. }
  62. $scope.toggle_field = function(field) {
  63. if (_.indexOf($scope.active,field) > -1)
  64. $scope.active = _.without($scope.active,field)
  65. else
  66. $scope.active.push(field)
  67. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active)
  68. }
  69. $scope.build_search = function(field,value,mandate) {
  70. var query = field+":"+angular.toJson(value)
  71. filterSrv.set({type:'querystring',query:query,mandate:mandate})
  72. dashboard.refresh();
  73. }
  74. $scope.fieldExists = function(field,mandate) {
  75. filterSrv.set({type:'exists',field:field,mandate:mandate})
  76. dashboard.refresh();
  77. }
  78. $scope.is_active = function(field) {
  79. return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : '';
  80. }
  81. })