module.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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;
  71. if(_.isArray(value)) {
  72. query = field+":(" + _.map(value,function(v){return "\""+v+"\""}).join(",") + ")";
  73. } else {
  74. query = field+":"+angular.toJson(value);
  75. }
  76. filterSrv.set({type:'querystring',query:query,mandate:mandate})
  77. dashboard.refresh();
  78. }
  79. $scope.fieldExists = function(field,mandate) {
  80. filterSrv.set({type:'exists',field:field,mandate:mandate})
  81. dashboard.refresh();
  82. }
  83. $scope.is_active = function(field) {
  84. return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : '';
  85. }
  86. })