Commit 9a05daa0 by Samuel Padgett

Improve toast notification performance

parent b51786f7
...@@ -1538,7 +1538,7 @@ angular.module('openshiftCommonServices') ...@@ -1538,7 +1538,7 @@ angular.module('openshiftCommonServices')
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -2083,7 +2083,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -2083,7 +2083,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -2114,7 +2114,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -2114,7 +2114,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -2304,7 +2304,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -2304,7 +2304,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
if (_.get(opts, 'errorNotification', true)) { if (_.get(opts, 'errorNotification', true)) {
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
id: 'websocket_retry_halted', id: 'websocket_retry_halted',
type: 'error', type: 'error',
message: 'Server connection interrupted.', message: 'Server connection interrupted.',
......
...@@ -390,7 +390,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -390,7 +390,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
$templateCache.put('src/components/toast-notifications/toast-notifications.html', $templateCache.put('src/components/toast-notifications/toast-notifications.html',
"<div class=\"toast-notifications-list-pf\">\n" + "<div class=\"toast-notifications-list-pf\">\n" +
" <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden\"\n" + " <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden || notification.isHover\"\n" +
" ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" + " ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" +
" <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" + " <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" +
" <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" + " <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" +
...@@ -1016,49 +1016,79 @@ angular.module('openshiftCommonUI') ...@@ -1016,49 +1016,79 @@ angular.module('openshiftCommonUI')
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.directive('toastNotifications', function(NotificationsService, $timeout) { .directive('toastNotifications', function(NotificationsService, $rootScope, $timeout) {
return { return {
restrict: 'E', restrict: 'E',
scope: {}, scope: {},
templateUrl: 'src/components/toast-notifications/toast-notifications.html', templateUrl: 'src/components/toast-notifications/toast-notifications.html',
link: function($scope) { link: function($scope) {
$scope.notifications = NotificationsService.getNotifications(); $scope.notifications = [];
$scope.close = function(notification) { // A notification is removed if it has hidden set and the user isn't
// currently hovering over it.
var isRemoved = function(notification) {
return notification.hidden && !notification.isHover;
};
var removeNotification = function(notification) {
notification.isHover = false;
notification.hidden = true; notification.hidden = true;
};
// Remove items that are now hidden to keep the array from growing
// indefinitely. We loop over the entire array each digest loop, even
// if everything is hidden, and any watch update triggers a new digest
// loop. If the array grows large, it can hurt performance.
var pruneRemovedNotifications = function() {
$scope.notifications = _.reject($scope.notifications, isRemoved);
};
$scope.close = function(notification) {
removeNotification(notification);
if (_.isFunction(notification.onClose)) { if (_.isFunction(notification.onClose)) {
notification.onClose(); notification.onClose();
} }
}; };
$scope.onClick = function(notification, link) { $scope.onClick = function(notification, link) {
if (_.isFunction(link.onClick)) { if (_.isFunction(link.onClick)) {
// If onClick() returns true, also hide the alert. // If onClick() returns true, also hide the alert.
var close = link.onClick(); var close = link.onClick();
if (close) { if (close) {
notification.hidden = true; removeNotification(notification);
} }
} }
}; };
$scope.setHover = function(notification, isHover) { $scope.setHover = function(notification, isHover) {
notification.isHover = isHover; // Don't change anything if the notification was already removed.
// Avoids a potential issue where the flag is reset during the slide
// out animation.
if (!isRemoved(notification)) {
notification.isHover = isHover;
}
}; };
$scope.$watch('notifications', function() { // Listen for updates from NotificationsService to show a notification.
_.each($scope.notifications, function(notification) { var deregisterNotificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', function(event, notification) {
if (NotificationsService.isAutoDismiss(notification) && !notification.hidden) { $scope.notifications.push(notification);
if (!notification.timerId) { if (NotificationsService.isAutoDismiss(notification)) {
notification.timerId = $timeout(function () { $timeout(function () {
notification.timerId = -1; notification.hidden = true;
if (!notification.isHover) { }, NotificationsService.dismissDelay);
notification.hidden = true; }
}
}, NotificationsService.dismissDelay); // Whenever we add a new notification, also remove any hidden toasts
} else if (notification.timerId === -1 && !notification.isHover) { // so that the array doesn't grow indefinitely.
notification.hidden = true; pruneRemovedNotifications();
} });
}
}); $scope.$on('$destroy', function() {
}, true); if (deregisterNotificationListener) {
deregisterNotificationListener();
deregisterNotificationListener = null;
}
});
} }
}; };
}); });
...@@ -1998,6 +2028,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -1998,6 +2028,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
} }
notifications.push(notification); notifications.push(notification);
$rootScope.$emit('NotificationsService.onNotificationAdded', notification);
}; };
var hideNotification = function (notificationID) { var hideNotification = function (notificationID) {
...@@ -2050,7 +2081,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -2050,7 +2081,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
}; };
// Also handle `addNotification` events on $rootScope, which is used by DataService. // Also handle `addNotification` events on $rootScope, which is used by DataService.
$rootScope.$on('addNotification', function(event, data) { $rootScope.$on('NotificationsService.addNotification', function(event, data) {
addNotification(data); addNotification(data);
}); });
......
...@@ -561,7 +561,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -561,7 +561,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
$templateCache.put('src/components/toast-notifications/toast-notifications.html', $templateCache.put('src/components/toast-notifications/toast-notifications.html',
"<div class=\"toast-notifications-list-pf\">\n" + "<div class=\"toast-notifications-list-pf\">\n" +
" <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden\"\n" + " <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden || notification.isHover\"\n" +
" ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" + " ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" +
" <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" + " <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" +
" <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" + " <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" +
...@@ -1187,49 +1187,79 @@ angular.module('openshiftCommonUI') ...@@ -1187,49 +1187,79 @@ angular.module('openshiftCommonUI')
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.directive('toastNotifications', ["NotificationsService", "$timeout", function(NotificationsService, $timeout) { .directive('toastNotifications', ["NotificationsService", "$rootScope", "$timeout", function(NotificationsService, $rootScope, $timeout) {
return { return {
restrict: 'E', restrict: 'E',
scope: {}, scope: {},
templateUrl: 'src/components/toast-notifications/toast-notifications.html', templateUrl: 'src/components/toast-notifications/toast-notifications.html',
link: function($scope) { link: function($scope) {
$scope.notifications = NotificationsService.getNotifications(); $scope.notifications = [];
$scope.close = function(notification) { // A notification is removed if it has hidden set and the user isn't
// currently hovering over it.
var isRemoved = function(notification) {
return notification.hidden && !notification.isHover;
};
var removeNotification = function(notification) {
notification.isHover = false;
notification.hidden = true; notification.hidden = true;
};
// Remove items that are now hidden to keep the array from growing
// indefinitely. We loop over the entire array each digest loop, even
// if everything is hidden, and any watch update triggers a new digest
// loop. If the array grows large, it can hurt performance.
var pruneRemovedNotifications = function() {
$scope.notifications = _.reject($scope.notifications, isRemoved);
};
$scope.close = function(notification) {
removeNotification(notification);
if (_.isFunction(notification.onClose)) { if (_.isFunction(notification.onClose)) {
notification.onClose(); notification.onClose();
} }
}; };
$scope.onClick = function(notification, link) { $scope.onClick = function(notification, link) {
if (_.isFunction(link.onClick)) { if (_.isFunction(link.onClick)) {
// If onClick() returns true, also hide the alert. // If onClick() returns true, also hide the alert.
var close = link.onClick(); var close = link.onClick();
if (close) { if (close) {
notification.hidden = true; removeNotification(notification);
} }
} }
}; };
$scope.setHover = function(notification, isHover) { $scope.setHover = function(notification, isHover) {
notification.isHover = isHover; // Don't change anything if the notification was already removed.
// Avoids a potential issue where the flag is reset during the slide
// out animation.
if (!isRemoved(notification)) {
notification.isHover = isHover;
}
}; };
$scope.$watch('notifications', function() { // Listen for updates from NotificationsService to show a notification.
_.each($scope.notifications, function(notification) { var deregisterNotificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', function(event, notification) {
if (NotificationsService.isAutoDismiss(notification) && !notification.hidden) { $scope.notifications.push(notification);
if (!notification.timerId) { if (NotificationsService.isAutoDismiss(notification)) {
notification.timerId = $timeout(function () { $timeout(function () {
notification.timerId = -1; notification.hidden = true;
if (!notification.isHover) { }, NotificationsService.dismissDelay);
notification.hidden = true; }
}
}, NotificationsService.dismissDelay); // Whenever we add a new notification, also remove any hidden toasts
} else if (notification.timerId === -1 && !notification.isHover) { // so that the array doesn't grow indefinitely.
notification.hidden = true; pruneRemovedNotifications();
} });
}
}); $scope.$on('$destroy', function() {
}, true); if (deregisterNotificationListener) {
deregisterNotificationListener();
deregisterNotificationListener = null;
}
});
} }
}; };
}]); }]);
...@@ -3262,7 +3292,7 @@ angular.module('openshiftCommonServices') ...@@ -3262,7 +3292,7 @@ angular.module('openshiftCommonServices')
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -3807,7 +3837,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -3807,7 +3837,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -3838,7 +3868,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -3838,7 +3868,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -4028,7 +4058,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -4028,7 +4058,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
if (_.get(opts, 'errorNotification', true)) { if (_.get(opts, 'errorNotification', true)) {
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
id: 'websocket_retry_halted', id: 'websocket_retry_halted',
type: 'error', type: 'error',
message: 'Server connection interrupted.', message: 'Server connection interrupted.',
...@@ -5178,6 +5208,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -5178,6 +5208,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
} }
notifications.push(notification); notifications.push(notification);
$rootScope.$emit('NotificationsService.onNotificationAdded', notification);
}; };
var hideNotification = function (notificationID) { var hideNotification = function (notificationID) {
...@@ -5230,7 +5261,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -5230,7 +5261,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
}; };
// Also handle `addNotification` events on $rootScope, which is used by DataService. // Also handle `addNotification` events on $rootScope, which is used by DataService.
$rootScope.$on('addNotification', function(event, data) { $rootScope.$on('NotificationsService.addNotification', function(event, data) {
addNotification(data); addNotification(data);
}); });
......
...@@ -361,7 +361,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -361,7 +361,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
$templateCache.put('src/components/toast-notifications/toast-notifications.html', $templateCache.put('src/components/toast-notifications/toast-notifications.html',
"<div class=\"toast-notifications-list-pf\">\n" + "<div class=\"toast-notifications-list-pf\">\n" +
" <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden\"\n" + " <div ng-repeat=\"(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))\" ng-if=\"!notification.hidden || notification.isHover\"\n" +
" ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" + " ng-mouseenter=\"setHover(notification, true)\" ng-mouseleave=\"setHover(notification, false)\">\n" +
" <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" + " <div class=\"toast-pf alert {{notification.type | alertStatus}}\" ng-class=\"{'alert-dismissable': !hideCloseButton}\">\n" +
" <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" + " <button ng-if=\"!hideCloseButton\" type=\"button\" class=\"close\" ng-click=\"close(notification)\">\n" +
......
<div class="toast-notifications-list-pf"> <div class="toast-notifications-list-pf">
<div ng-repeat="(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))" ng-if="!notification.hidden" <div ng-repeat="(notificationID, notification) in notifications track by (notificationID + (notification.message || notification.details))" ng-if="!notification.hidden || notification.isHover"
ng-mouseenter="setHover(notification, true)" ng-mouseleave="setHover(notification, false)"> ng-mouseenter="setHover(notification, true)" ng-mouseleave="setHover(notification, false)">
<div class="toast-pf alert {{notification.type | alertStatus}}" ng-class="{'alert-dismissable': !hideCloseButton}"> <div class="toast-pf alert {{notification.type | alertStatus}}" ng-class="{'alert-dismissable': !hideCloseButton}">
<button ng-if="!hideCloseButton" type="button" class="close" ng-click="close(notification)"> <button ng-if="!hideCloseButton" type="button" class="close" ng-click="close(notification)">
......
'use strict'; 'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.directive('toastNotifications', function(NotificationsService, $timeout) { .directive('toastNotifications', function(NotificationsService, $rootScope, $timeout) {
return { return {
restrict: 'E', restrict: 'E',
scope: {}, scope: {},
templateUrl: 'src/components/toast-notifications/toast-notifications.html', templateUrl: 'src/components/toast-notifications/toast-notifications.html',
link: function($scope) { link: function($scope) {
$scope.notifications = NotificationsService.getNotifications(); $scope.notifications = [];
$scope.close = function(notification) { // A notification is removed if it has hidden set and the user isn't
// currently hovering over it.
var isRemoved = function(notification) {
return notification.hidden && !notification.isHover;
};
var removeNotification = function(notification) {
notification.isHover = false;
notification.hidden = true; notification.hidden = true;
};
// Remove items that are now hidden to keep the array from growing
// indefinitely. We loop over the entire array each digest loop, even
// if everything is hidden, and any watch update triggers a new digest
// loop. If the array grows large, it can hurt performance.
var pruneRemovedNotifications = function() {
$scope.notifications = _.reject($scope.notifications, isRemoved);
};
$scope.close = function(notification) {
removeNotification(notification);
if (_.isFunction(notification.onClose)) { if (_.isFunction(notification.onClose)) {
notification.onClose(); notification.onClose();
} }
}; };
$scope.onClick = function(notification, link) { $scope.onClick = function(notification, link) {
if (_.isFunction(link.onClick)) { if (_.isFunction(link.onClick)) {
// If onClick() returns true, also hide the alert. // If onClick() returns true, also hide the alert.
var close = link.onClick(); var close = link.onClick();
if (close) { if (close) {
notification.hidden = true; removeNotification(notification);
} }
} }
}; };
$scope.setHover = function(notification, isHover) { $scope.setHover = function(notification, isHover) {
notification.isHover = isHover; // Don't change anything if the notification was already removed.
// Avoids a potential issue where the flag is reset during the slide
// out animation.
if (!isRemoved(notification)) {
notification.isHover = isHover;
}
}; };
$scope.$watch('notifications', function() { // Listen for updates from NotificationsService to show a notification.
_.each($scope.notifications, function(notification) { var deregisterNotificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', function(event, notification) {
if (NotificationsService.isAutoDismiss(notification) && !notification.hidden) { $scope.notifications.push(notification);
if (!notification.timerId) { if (NotificationsService.isAutoDismiss(notification)) {
notification.timerId = $timeout(function () { $timeout(function () {
notification.timerId = -1; notification.hidden = true;
if (!notification.isHover) { }, NotificationsService.dismissDelay);
notification.hidden = true; }
}
}, NotificationsService.dismissDelay); // Whenever we add a new notification, also remove any hidden toasts
} else if (notification.timerId === -1 && !notification.isHover) { // so that the array doesn't grow indefinitely.
notification.hidden = true; pruneRemovedNotifications();
} });
}
}); $scope.$on('$destroy', function() {
}, true); if (deregisterNotificationListener) {
deregisterNotificationListener();
deregisterNotificationListener = null;
}
});
} }
}; };
}); });
...@@ -418,7 +418,7 @@ angular.module('openshiftCommonServices') ...@@ -418,7 +418,7 @@ angular.module('openshiftCommonServices')
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -963,7 +963,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -963,7 +963,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -994,7 +994,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -994,7 +994,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
} }
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
type: 'error', type: 'error',
message: msg message: msg
}); });
...@@ -1184,7 +1184,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR ...@@ -1184,7 +1184,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
if (_.get(opts, 'errorNotification', true)) { if (_.get(opts, 'errorNotification', true)) {
// Use `$rootScope.$emit` instead of NotificationsService directly // Use `$rootScope.$emit` instead of NotificationsService directly
// so that DataService doesn't add a dependency on `openshiftCommonUI` // so that DataService doesn't add a dependency on `openshiftCommonUI`
$rootScope.$emit('addNotification', { $rootScope.$emit('NotificationsService.addNotification', {
id: 'websocket_retry_halted', id: 'websocket_retry_halted',
type: 'error', type: 'error',
message: 'Server connection interrupted.', message: 'Server connection interrupted.',
......
...@@ -23,6 +23,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -23,6 +23,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
} }
notifications.push(notification); notifications.push(notification);
$rootScope.$emit('NotificationsService.onNotificationAdded', notification);
}; };
var hideNotification = function (notificationID) { var hideNotification = function (notificationID) {
...@@ -75,7 +76,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function() ...@@ -75,7 +76,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
}; };
// Also handle `addNotification` events on $rootScope, which is used by DataService. // Also handle `addNotification` events on $rootScope, which is used by DataService.
$rootScope.$on('addNotification', function(event, data) { $rootScope.$on('NotificationsService.addNotification', function(event, data) {
addNotification(data); addNotification(data);
}); });
......
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