From b498e1975e4968515c2f0c87624e9e8a541f2085 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Sat, 27 Jul 2013 16:09:04 -0700 Subject: [PATCH] removed eventBus completely, fix field list auto complete --- js/controllers.js | 2 +- js/services.js | 81 +++----------------------------------- panels/fields/module.js | 81 +------------------------------------- panels/histogram/module.js | 4 +- panels/table/module.js | 12 ++---- 5 files changed, 15 insertions(+), 165 deletions(-) diff --git a/js/controllers.js b/js/controllers.js index 3615ee7b74765..8b631d07ec979 100644 --- a/js/controllers.js +++ b/js/controllers.js @@ -3,7 +3,7 @@ 'use strict'; angular.module('kibana.controllers', []) -.controller('DashCtrl', function($scope, $rootScope, $http, $timeout, $route, ejsResource, eventBus, +.controller('DashCtrl', function($scope, $rootScope, $http, $timeout, $route, ejsResource, fields, dashboard) { var _d = { diff --git a/js/services.js b/js/services.js index 49cd92aa3e992..0a9ce721294ac 100644 --- a/js/services.js +++ b/js/services.js @@ -4,86 +4,17 @@ 'use strict'; angular.module('kibana.services', []) -.service('eventBus', function($rootScope) { +.service('fields', function() { - // An array of registed types - var _types = []; - - this.broadcast = function(from,to,type,data) { - if(_.isUndefined(data)) { - data = from; - } - - var packet = { - time: new Date(), - type: type, - from: from, - to: to, - data: data - }; - - if(_.contains(_types,'$kibana_debug')) { - $rootScope.$broadcast('$kibana_debug',packet); - } - - $rootScope.$broadcast(type,{ - from: from, - to: to, - data: data - }); - }; - - // This sets up an $on listener that checks to see if the event (packet) is - // addressed to the scope in question and runs the registered function if it - // is. - this.register = function(scope,type,fn) { - - _types = _.union(_types,[type]); - - scope.$on(type,function(event,packet){ - var _id = scope.$id; - var _to = packet.to; - var _from = packet.from; - var _type = packet.type; - var _time = packet.time; - var _group = (!(_.isUndefined(scope.panel))) ? scope.panel.group : ["NONE"]; + // Save a reference to this + var self = this; - if(!(_.isArray(_to))) { - _to = [_to]; - } - if(!(_.isArray(_group))) { - _group = [_group]; - } + this.list = []; - // Transmit event only if the sender is not the receiver AND one of the following: - // 1) Receiver has group in _to 2) Receiver's $id is in _to - // 3) Event is addressed to ALL 4) Receiver is in ALL group - if((_.intersection(_to,_group).length > 0 || - _.indexOf(_to,_id) > -1 || - _.indexOf(_group,'ALL') > -1 || - _.indexOf(_to,'ALL') > -1) && - _from !== _id - ) { - fn(event,packet.data,{time:_time,to:_to,from:_from,type:_type}); - } - }); - }; -}) -/* - Service: fields - Provides a global list of all seen fields for use in editor panels -*/ -.factory('fields', function($rootScope) { - var fields = { - list : [] + this.add_fields = function(f) { + self.list = _.union(f,self.list); }; - $rootScope.$on('fields', function(event,f) { - fields.list = _.union(f.data.all,fields.list); - }); - - return fields; - }) .service('kbnIndex',function($http) { diff --git a/panels/fields/module.js b/panels/fields/module.js index b64d14c3a7af3..8651d6c3b36d1 100644 --- a/panels/fields/module.js +++ b/panels/fields/module.js @@ -5,24 +5,12 @@ ## Fields (DEPRECATED) - - ### Parameters - * style :: a hash containing css styles - * arrange :: the layout pf the panel 'horizontal' or 'vertical' - * micropanel_position :: where to place the micropanel in relation to the field - - ### Group Events - #### Recieves - * table_documents :: An object containing the documents in the table panel - #### Sends - * fields :: an object containing the sort order, existing fields and selected fields - */ 'use strict'; angular.module('kibana.fields', []) -.controller('fields', function($scope, eventBus, $timeout, dashboard, filterSrv) { +.controller('fields', function($scope, $timeout, dashboard, filterSrv) { $scope.panelMeta = { status : "Deprecated", @@ -41,72 +29,7 @@ angular.module('kibana.fields', []) _.defaults($scope.panel,_d); $scope.init = function() { - $scope.Math = Math; - $scope.fields = []; - eventBus.register($scope,'fields', function(event, fields) { - $scope.panel.sort = _.clone(fields.sort); - $scope.fields = fields.all; - $scope.active = _.clone(fields.active); - }); - eventBus.register($scope,'table_documents', function(event, docs) { - $scope.panel.query = docs.query; - $scope.docs = docs.docs; - $scope.index = docs.index; - }); - eventBus.register($scope,"get_fields", function(event,id) { - eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active); - }); - }; - - $scope.reload_list = function () { - var temp = _.clone($scope.fields); - $scope.fields = []; - $timeout(function(){ - $scope.fields = temp; - },10); - - }; - - $scope.toggle_micropanel = function(field) { - $scope.micropanel = { - field: field, - values : kbn.top_field_values($scope.docs,field,10), - related : kbn.get_related_fields($scope.docs,field), - count: _.countBy($scope.docs,function(doc){return _.contains(_.keys(doc),field);})['true'] - }; - }; - - $scope.toggle_sort = function() { - $scope.panel.sort[1] = $scope.panel.sort[1] === 'asc' ? 'desc' : 'asc'; - }; - - $scope.toggle_field = function(field) { - if (_.indexOf($scope.active,field) > -1) { - $scope.active = _.without($scope.active,field); - } else { - $scope.active.push(field); - } - eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active); - }; - - $scope.build_search = function(field,value,mandate) { - var query; - if(_.isArray(value)) { - query = field+":(" + _.map(value,function(v){return "\""+v+"\"";}).join(",") + ")"; - } else { - query = field+":"+angular.toJson(value); - } - filterSrv.set({type:'querystring',query:query,mandate:mandate}); - dashboard.refresh(); - }; - - $scope.fieldExists = function(field,mandate) { - filterSrv.set({type:'exists',field:field,mandate:mandate}); - dashboard.refresh(); - }; - - $scope.is_active = function(field) { - return _.indexOf($scope.active,field) > -1 ? ['label','label-info'] : ''; + // Place holder until I remove this }; }); \ No newline at end of file diff --git a/panels/histogram/module.js b/panels/histogram/module.js index 88ba12b94ebc8..7505b920ce79e 100644 --- a/panels/histogram/module.js +++ b/panels/histogram/module.js @@ -34,7 +34,7 @@ 'use strict'; angular.module('kibana.histogram', []) -.controller('histogram', function($scope, eventBus, querySrv, dashboard, filterSrv) { +.controller('histogram', function($scope, querySrv, dashboard, filterSrv) { $scope.panelMeta = { status : "Stable", @@ -263,7 +263,7 @@ angular.module('kibana.histogram', []) }; }) -.directive('histogramChart', function(dashboard, eventBus, filterSrv, $rootScope) { +.directive('histogramChart', function(dashboard, filterSrv, $rootScope) { return { restrict: 'A', template: '
', diff --git a/panels/table/module.js b/panels/table/module.js index 5416948536bc6..ee80e73e2dedd 100644 --- a/panels/table/module.js +++ b/panels/table/module.js @@ -16,18 +16,13 @@ to fit the table, or if the table will scroll to fit the row (height) * sortable :: Allow sorting? * spyable :: Show the 'eye' icon that reveals the last ES query for this panel - ### Group Events - #### Sends - * table_documents :: An array containing all of the documents in the table. - Only used by the fields panel so far. - #### Receives - * selected_fields :: An array of fields to show + */ 'use strict'; angular.module('kibana.table', []) -.controller('table', function($rootScope, $scope, eventBus, fields, querySrv, dashboard, filterSrv) { +.controller('table', function($rootScope, $scope, fields, querySrv, dashboard, filterSrv) { $scope.panelMeta = { status: "Stable", @@ -214,8 +209,9 @@ angular.module('kibana.table', []) return; } - // This breaks, use $scope.data for this $scope.all_fields = kbn.get_all_fields(_.pluck($scope.data,'_source')); + fields.add_fields($scope.all_fields); + console.log(fields); // If we're not sorting in reverse chrono order, query every index for // size*pages results