module.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*
  4. ## Fields
  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. 'use strict';
  16. angular.module('kibana.fields', [])
  17. .controller('fields', function($scope, eventBus, $timeout, dashboard, filterSrv) {
  18. $scope.panelMeta = {
  19. status : "Deprecating Soon",
  20. description : "Allows for enabling and disabling of fields in the table panel as well as a "+
  21. "micro anaylsis panel for analyzing the events in the table panel. This panel will soon be"+
  22. "combined with the table panel"
  23. };
  24. // Set and populate defaults
  25. var _d = {
  26. group : "default",
  27. style : {},
  28. arrange : 'vertical',
  29. micropanel_position : 'right',
  30. };
  31. _.defaults($scope.panel,_d);
  32. $scope.init = function() {
  33. $scope.Math = Math;
  34. $scope.fields = [];
  35. eventBus.register($scope,'fields', function(event, fields) {
  36. $scope.panel.sort = _.clone(fields.sort);
  37. $scope.fields = fields.all;
  38. $scope.active = _.clone(fields.active);
  39. });
  40. eventBus.register($scope,'table_documents', function(event, docs) {
  41. $scope.panel.query = docs.query;
  42. $scope.docs = docs.docs;
  43. $scope.index = docs.index;
  44. });
  45. eventBus.register($scope,"get_fields", function(event,id) {
  46. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
  47. });
  48. };
  49. $scope.reload_list = function () {
  50. var temp = _.clone($scope.fields);
  51. $scope.fields = [];
  52. $timeout(function(){
  53. $scope.fields = temp;
  54. },10);
  55. };
  56. $scope.toggle_micropanel = function(field) {
  57. $scope.micropanel = {
  58. field: field,
  59. values : kbn.top_field_values($scope.docs,field,10),
  60. related : kbn.get_related_fields($scope.docs,field),
  61. count: _.countBy($scope.docs,function(doc){return _.contains(_.keys(doc),field);})['true']
  62. };
  63. };
  64. $scope.toggle_sort = function() {
  65. $scope.panel.sort[1] = $scope.panel.sort[1] === 'asc' ? 'desc' : 'asc';
  66. };
  67. $scope.toggle_field = function(field) {
  68. if (_.indexOf($scope.active,field) > -1) {
  69. $scope.active = _.without($scope.active,field);
  70. } else {
  71. $scope.active.push(field);
  72. }
  73. eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
  74. };
  75. $scope.build_search = function(field,value,mandate) {
  76. var query;
  77. if(_.isArray(value)) {
  78. query = field+":(" + _.map(value,function(v){return "\""+v+"\"";}).join(",") + ")";
  79. } else {
  80. query = field+":"+angular.toJson(value);
  81. }
  82. filterSrv.set({type:'querystring',query:query,mandate:mandate});
  83. dashboard.refresh();
  84. };
  85. $scope.fieldExists = function(field,mandate) {
  86. filterSrv.set({type:'exists',field:field,mandate:mandate});
  87. dashboard.refresh();
  88. };
  89. $scope.is_active = function(field) {
  90. return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : '';
  91. };
  92. });