mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(events): fixed handling of onAppEvents when used from rootScope, must supply localscope, can now be used in isolate scope scenarios
This commit is contained in:
parent
69db9e0d45
commit
3d85e85f29
@ -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) {
|
||||
|
@ -18,8 +18,6 @@
|
||||
|
||||
export * from './directives/array_join'
|
||||
export * from './directives/give_focus'
|
||||
|
||||
export * from './routes/bundle_loader'
|
||||
export * from './filters/filters'
|
||||
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -18,7 +18,7 @@ function (angular, _, kbn) {
|
||||
if (variable) {
|
||||
self.updateAutoInterval(variable);
|
||||
}
|
||||
});
|
||||
}, $rootScope);
|
||||
|
||||
this.init = function(dashboard) {
|
||||
this.variables = dashboard.templating.list;
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user