+
\ No newline at end of file
diff --git a/panels/table/module.html b/panels/table/module.html
index 95f239e935b..4b513697583 100644
--- a/panels/table/module.html
+++ b/panels/table/module.html
@@ -1,5 +1,5 @@
-
{{panel.title}}
+
{{panel.title}}
diff --git a/panels/table/module.js b/panels/table/module.js
index e5a9e19c9f2..685fb4cd5d8 100644
--- a/panels/table/module.js
+++ b/panels/table/module.js
@@ -1,5 +1,5 @@
angular.module('kibana.table', [])
-.controller('table', function($scope, $rootScope, $location) {
+.controller('table', function($scope, eventBus) {
var _id = _.uniqueId();
@@ -15,25 +15,29 @@ angular.module('kibana.table', [])
_.defaults($scope.panel,_d)
$scope.init = function () {
- $scope.$on(_id+"-time", function(event,time){set_time(time)});
- $scope.$on($scope.panel.group+"-time", function(event,time){set_time(time)});
- $scope.$on($scope.panel.group+"-query", function(event, query) {
- console.log($scope.panel)
- $scope.panel.query = query;
- $scope.get_data();
- });
- $scope.$on($scope.panel.group+"-sort", function(event,sort){
- $scope.panel.sort = _.clone(sort);
- });
- $scope.$on($scope.panel.group+"-selected_fields", function(event, fields) {
- $scope.panel.fields = _.clone(fields)
- });
+ $scope.set_listeners($scope.panel.group)
$scope.$watch(function() {
return angular.toJson($scope.panel.sort)
}, function(){$scope.get_data()});
// Now that we're all setup, request the time from our group
- $rootScope.$broadcast($scope.panel.group+"-get_time",_id)
+ eventBus.broadcast($scope.$id,$scope.panel.group,"get_time")
+ }
+
+ $scope.set_listeners = function(group) {
+ eventBus.register($scope,'time',function(event,time) {
+ set_time(time)
+ });
+ eventBus.register($scope,'query',function(event,query) {
+ $scope.panel.query = query;
+ $scope.get_data();
+ });
+ eventBus.register($scope,'sort', function(event,sort){
+ $scope.panel.sort = _.clone(sort);
+ });
+ eventBus.register($scope,'selected_fields', function(event, fields) {
+ $scope.panel.fields = _.clone(fields)
+ });
}
$scope.set_sort = function(field) {
@@ -43,6 +47,14 @@ angular.module('kibana.table', [])
$scope.panel.sort[0] = field;
}
+ $scope.toggle_field = function(field) {
+ if (_.indexOf($scope.panel.fields,field) > -1)
+ $scope.panel.fields = _.without($scope.panel.fields,field)
+ else
+ $scope.panel.fields.push(field)
+ broadcast_fields();
+ }
+
$scope.get_data = function() {
// Make sure we have everything for the request to complete
if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
@@ -71,17 +83,9 @@ angular.module('kibana.table', [])
$scope.panel.error = false;
$scope.hits = results.hits.total;
$scope.data = results.hits.hits;
+ $scope.all_fields = get_all_fields(results);
- // Broadcast a list of all fields. Note that receivers of field array
- // events should be able to receive from multiple sources, merge, dedupe
- // and sort on the fly.
- if (!(_.isUndefined($scope.panel.group)))
- $rootScope.$broadcast(
- $scope.panel.group+"-fields", {
- all : get_all_fields(results),
- sort : $scope.panel.sort,
- active: $scope.panel.fields
- });
+ broadcast_fields();
});
}
@@ -89,6 +93,17 @@ angular.module('kibana.table', [])
console.log(field,dir)
}
+ // Broadcast a list of all fields. Note that receivers of field array
+ // events should be able to receive from multiple sources, merge, dedupe
+ // and sort on the fly if needed.
+ function broadcast_fields() {
+ eventBus.broadcast($scope.$id,$scope.panel.group,"fields", {
+ all : $scope.all_fields,
+ sort : $scope.panel.sort,
+ active: $scope.panel.fields
+ });
+ }
+
function set_time(time) {
$scope.panel.time = time;
$scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
diff --git a/panels/timepicker/module.js b/panels/timepicker/module.js
index 9a2f6502ac9..2276e9b570c 100644
--- a/panels/timepicker/module.js
+++ b/panels/timepicker/module.js
@@ -24,7 +24,7 @@ a pattern
*/
angular.module('kibana.timepicker', [])
-.controller('timepicker', function($scope, $rootScope, $timeout, $http) {
+.controller('timepicker', function($scope, eventBus, $timeout, $http) {
var _id = _.uniqueId();
@@ -78,10 +78,8 @@ angular.module('kibana.timepicker', [])
// In the case that a panel is not ready to receive a time event, it may
// request one be sent by broadcasting a 'get_time' with its _id to its group
// This panel can handle multiple groups
- _.each(_groups,function(group){
- $scope.$on(group+"-get_time", function(event,id) {
- $rootScope.$broadcast(id+"-time", $scope.time)
- });
+ eventBus.register($scope,"get_time", function(event,id) {
+ eventBus.broadcast($scope.$id,id,'time',$scope.time)
});
$scope.$watch('panel.refresh.enable', function() {$scope.refresh()});
@@ -175,9 +173,7 @@ angular.module('kibana.timepicker', [])
indices($scope.time.from,$scope.time.to).then(function (p) {
$scope.time.index = p.join();
// Broadcast time
- _.each(_groups,function(group){
- $rootScope.$broadcast(group+"-time", $scope.time)
- });
+ eventBus.broadcast($scope.$id,$scope.panel.group,'time',$scope.time)
});
// Update panel's string representation of the time object