Commit 3d85e85f by Torkel Ödegaard

fix(events): fixed handling of onAppEvents when used from rootScope, must supply…

fix(events): fixed handling of onAppEvents when used from rootScope, must supply localscope, can now be used in isolate scope scenarios
parent 69db9e0d
...@@ -33,9 +33,16 @@ function (angular, config, _, $, store) { ...@@ -33,9 +33,16 @@ function (angular, config, _, $, store) {
$controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData); $controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData);
}; };
$rootScope.onAppEvent = function(name, callback) { $rootScope.onAppEvent = function(name, callback, localScope) {
var unbind = $rootScope.$on(name, callback); var unbind = $rootScope.$on(name, callback);
this.$on('$destroy', unbind); var callerScope = this;
if (callerScope.$id === 1 && !localScope) {
console.log('warning rootScope onAppEvent called without localscope');
}
if (localScope) {
callerScope = localScope;
}
callerScope.$on('$destroy', unbind);
}; };
$rootScope.appEvent = function(name, payload) { $rootScope.appEvent = function(name, payload) {
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
export * from './directives/array_join' export * from './directives/array_join'
export * from './directives/give_focus' export * from './directives/give_focus'
export * from './routes/bundle_loader'
export * from './filters/filters' export * from './filters/filters'
...@@ -13,8 +13,8 @@ define([ ...@@ -13,8 +13,8 @@ define([
var self = this; var self = this;
this.init = function() { this.init = function() {
$rootScope.onAppEvent('refresh', this.clearCache); $rootScope.onAppEvent('refresh', this.clearCache, $rootScope);
$rootScope.onAppEvent('setup-dashboard', this.clearCache); $rootScope.onAppEvent('setup-dashboard', this.clearCache, $rootScope);
}; };
this.clearCache = function() { this.clearCache = function() {
......
...@@ -159,7 +159,7 @@ function (angular, _) { ...@@ -159,7 +159,7 @@ function (angular, _) {
}; };
updateDashLinks(); updateDashLinks();
$rootScope.onAppEvent('dash-links-updated', updateDashLinks); $rootScope.onAppEvent('dash-links-updated', updateDashLinks, $rootScope);
}); });
module.controller('DashLinkEditorCtrl', function($scope, $rootScope) { module.controller('DashLinkEditorCtrl', function($scope, $rootScope) {
......
...@@ -18,7 +18,7 @@ function (angular, _, kbn) { ...@@ -18,7 +18,7 @@ function (angular, _, kbn) {
if (variable) { if (variable) {
self.updateAutoInterval(variable); self.updateAutoInterval(variable);
} }
}); }, $rootScope);
this.init = function(dashboard) { this.init = function(dashboard) {
this.variables = dashboard.templating.list; this.variables = dashboard.templating.list;
......
...@@ -20,7 +20,7 @@ function (angular, _, queryDef) { ...@@ -20,7 +20,7 @@ function (angular, _, queryDef) {
$rootScope.onAppEvent('elastic-query-updated', function() { $rootScope.onAppEvent('elastic-query-updated', function() {
$scope.validateModel(); $scope.validateModel();
$scope.updateOrderByOptions(); $scope.updateOrderByOptions();
}); }, $scope);
$scope.init = function() { $scope.init = function() {
$scope.agg = bucketAggs[$scope.index]; $scope.agg = bucketAggs[$scope.index];
......
...@@ -22,7 +22,7 @@ function (angular, _, queryDef) { ...@@ -22,7 +22,7 @@ function (angular, _, queryDef) {
$rootScope.onAppEvent('elastic-query-updated', function() { $rootScope.onAppEvent('elastic-query-updated', function() {
$scope.index = _.indexOf(metricAggs, $scope.agg); $scope.index = _.indexOf(metricAggs, $scope.agg);
$scope.validateModel(); $scope.validateModel();
}); }, $scope);
$scope.validateModel = function() { $scope.validateModel = function() {
$scope.isFirst = $scope.index === 0; $scope.isFirst = $scope.index === 0;
......
...@@ -13,14 +13,14 @@ function (angular, _) { ...@@ -13,14 +13,14 @@ function (angular, _) {
this.init = function() { this.init = function() {
$rootScope.onAppEvent('alert-error', function(e, alert) { $rootScope.onAppEvent('alert-error', function(e, alert) {
self.set(alert[0], alert[1], 'error'); self.set(alert[0], alert[1], 'error');
}); }, $rootScope);
$rootScope.onAppEvent('alert-warning', function(e, alert) { $rootScope.onAppEvent('alert-warning', function(e, alert) {
self.set(alert[0], alert[1], 'warning', 5000); self.set(alert[0], alert[1], 'warning', 5000);
}); }, $rootScope);
$rootScope.onAppEvent('alert-success', function(e, alert) { $rootScope.onAppEvent('alert-success', function(e, alert) {
self.set(alert[0], alert[1], 'success', 3000); self.set(alert[0], alert[1], 'success', 3000);
}); }, $rootScope);
$rootScope.onAppEvent('confirm-modal', this.showConfirmModal); $rootScope.onAppEvent('confirm-modal', this.showConfirmModal, $rootScope);
}; };
// List of all alert objects // List of all alert objects
......
...@@ -9,7 +9,7 @@ function (angular) { ...@@ -9,7 +9,7 @@ function (angular) {
module.service('utilSrv', function($rootScope, $modal, $q) { module.service('utilSrv', function($rootScope, $modal, $q) {
this.init = function() { this.init = function() {
$rootScope.onAppEvent('show-modal', this.showModal); $rootScope.onAppEvent('show-modal', this.showModal, $rootScope);
}; };
this.showModal = function(e, options) { this.showModal = function(e, options) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment