module.js 3.1 KB

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