module.js 3.2 KB

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