Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
origin-web-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Java-于龙
origin-web-common
Commits
9a05daa0
Commit
9a05daa0
authored
Jun 22, 2017
by
Samuel Padgett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve toast notification performance
parent
b51786f7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
175 additions
and
82 deletions
+175
-82
origin-web-common-services.js
dist/origin-web-common-services.js
+4
-4
origin-web-common-ui.js
dist/origin-web-common-ui.js
+54
-23
origin-web-common.js
dist/origin-web-common.js
+58
-27
origin-web-common.min.js
dist/origin-web-common.min.js
+0
-0
templates.js
dist/scripts/templates.js
+1
-1
toast-notifications.html
src/components/toast-notifications/toast-notifications.html
+1
-1
toastNotifications.js
src/components/toast-notifications/toastNotifications.js
+51
-21
dataService.js
src/services/dataService.js
+4
-4
notificationsService.js
src/ui-services/notificationsService.js
+2
-1
No files found.
dist/origin-web-common-services.js
View file @
9a05daa0
...
@@ -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.'
,
...
...
dist/origin-web-common-ui.js
View file @
9a05daa0
...
@@ -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
);
});
});
...
...
dist/origin-web-common.js
View file @
9a05daa0
...
@@ -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
(
NotificationsServic
e
,
$timeout
)
{
.
directive
(
'toastNotifications'
,
[
"NotificationsService"
,
"$
rootScope"
,
"$timeout"
,
function
(
NotificationsService
,
$rootScop
e
,
$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
);
});
});
...
...
dist/origin-web-common.min.js
View file @
9a05daa0
This diff is collapsed.
Click to expand it.
dist/scripts/templates.js
View file @
9a05daa0
...
@@ -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"
+
...
...
src/components/toast-notifications/toast-notifications.html
View file @
9a05daa0
<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)"
>
...
...
src/components/toast-notifications/toastNotifications.js
View file @
9a05daa0
'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
;
}
});
}
}
};
};
});
});
src/services/dataService.js
View file @
9a05daa0
...
@@ -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.'
,
...
...
src/ui-services/notificationsService.js
View file @
9a05daa0
...
@@ -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
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment