Ver código fonte

fix(events): fixed handling of onAppEvents when used from rootScope, must supply localscope, can now be used in isolate scope scenarios

Torkel Ödegaard 10 anos atrás
pai
commit
3d85e85f29

+ 9 - 2
public/app/controllers/grafanaCtrl.js

@@ -33,9 +33,16 @@ function (angular, config, _, $, store) {
       $controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData);
     };
 
-    $rootScope.onAppEvent = function(name, callback) {
+    $rootScope.onAppEvent = function(name, callback, localScope) {
       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) {

+ 0 - 2
public/app/core/core.ts

@@ -18,8 +18,6 @@
 
 export * from './directives/array_join'
 export * from './directives/give_focus'
-
-export * from './routes/bundle_loader'
 export * from './filters/filters'
 
 

+ 2 - 2
public/app/features/annotations/annotationsSrv.js

@@ -13,8 +13,8 @@ define([
     var self = this;
 
     this.init = function() {
-      $rootScope.onAppEvent('refresh', this.clearCache);
-      $rootScope.onAppEvent('setup-dashboard', this.clearCache);
+      $rootScope.onAppEvent('refresh', this.clearCache, $rootScope);
+      $rootScope.onAppEvent('setup-dashboard', this.clearCache, $rootScope);
     };
 
     this.clearCache = function() {

+ 1 - 1
public/app/features/dashlinks/module.js

@@ -159,7 +159,7 @@ function (angular, _) {
     };
 
     updateDashLinks();
-    $rootScope.onAppEvent('dash-links-updated', updateDashLinks);
+    $rootScope.onAppEvent('dash-links-updated', updateDashLinks, $rootScope);
   });
 
   module.controller('DashLinkEditorCtrl', function($scope, $rootScope) {

+ 1 - 1
public/app/features/templating/templateValuesSrv.js

@@ -18,7 +18,7 @@ function (angular, _, kbn) {
       if (variable) {
         self.updateAutoInterval(variable);
       }
-    });
+    }, $rootScope);
 
     this.init = function(dashboard) {
       this.variables = dashboard.templating.list;

+ 1 - 1
public/app/plugins/datasource/elasticsearch/bucketAgg.js

@@ -20,7 +20,7 @@ function (angular, _, queryDef) {
     $rootScope.onAppEvent('elastic-query-updated', function() {
       $scope.validateModel();
       $scope.updateOrderByOptions();
-    });
+    }, $scope);
 
     $scope.init = function() {
       $scope.agg = bucketAggs[$scope.index];

+ 1 - 1
public/app/plugins/datasource/elasticsearch/metricAgg.js

@@ -22,7 +22,7 @@ function (angular, _, queryDef) {
     $rootScope.onAppEvent('elastic-query-updated', function() {
       $scope.index = _.indexOf(metricAggs, $scope.agg);
       $scope.validateModel();
-    });
+    }, $scope);
 
     $scope.validateModel = function() {
       $scope.isFirst = $scope.index === 0;

+ 4 - 4
public/app/services/alertSrv.js

@@ -13,14 +13,14 @@ function (angular, _) {
     this.init = function() {
       $rootScope.onAppEvent('alert-error', function(e, alert) {
         self.set(alert[0], alert[1], 'error');
-      });
+      }, $rootScope);
       $rootScope.onAppEvent('alert-warning', function(e, alert) {
         self.set(alert[0], alert[1], 'warning', 5000);
-      });
+      }, $rootScope);
       $rootScope.onAppEvent('alert-success', function(e, alert) {
         self.set(alert[0], alert[1], 'success', 3000);
-      });
-      $rootScope.onAppEvent('confirm-modal', this.showConfirmModal);
+      }, $rootScope);
+      $rootScope.onAppEvent('confirm-modal', this.showConfirmModal, $rootScope);
     };
 
     // List of all alert objects

+ 1 - 1
public/app/services/utilSrv.js

@@ -9,7 +9,7 @@ function (angular) {
   module.service('utilSrv', function($rootScope, $modal, $q) {
 
     this.init = function() {
-      $rootScope.onAppEvent('show-modal', this.showModal);
+      $rootScope.onAppEvent('show-modal', this.showModal, $rootScope);
     };
 
     this.showModal = function(e, options) {