Skip to content

Commit 1fc4563

Browse files
Updated directives to components, adding NotificationService, reworking sort
1 parent 51028b3 commit 1fc4563

File tree

8 files changed

+390
-122
lines changed

8 files changed

+390
-122
lines changed

app/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<!-- Add your site or application content here -->
3939

4040
<toast-notifications></toast-notifications>
41+
<div class="navbar-pf-vertical">
42+
<notification-drawer-wrapper></notification-drawer-wrapper>
43+
</div>
4144
<div ng-view>
4245
<!-- Include default simple nav and shaded background as a placeholder until API discovery finishes -->
4346
<nav class="navbar navbar-pf-alt top-header" role="navigation">

app/scripts/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
9090
service_catalog_landing_page: false,
9191
// Set to `true` when the template service broker is enabled for the cluster in master-config.yaml
9292
template_service_broker: false,
93-
pod_presets: false
93+
pod_presets: false,
94+
events_in_notification_drawer: false
9495
},
9596

9697
SAMPLE_PIPELINE_TEMPLATE: {

app/scripts/directives/notifications/notificationCounter.js

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,94 @@
22

33
angular
44
.module('openshiftConsole')
5-
.directive('notificationCounter', function() {
6-
return {
7-
restrict: 'AE',
8-
scope: {},
9-
controller:
10-
function($scope, $routeParams, $rootScope, notifications) {
11-
$scope.count = 0;
12-
$scope.countDisplay = $scope.count;
5+
.component('notificationCounter', {
6+
templateUrl: 'views/directives/notifications/notification-counter.html',
7+
bindings: {},
8+
controller: [
9+
'$routeParams',
10+
'$rootScope',
11+
'Constants',
12+
'DataService',
13+
function($routeParams, $rootScope, Constants, DataService) {
14+
var ENABLE_EVENTS = _.get(Constants, 'ENABLE_TECH_PREVIEW_FEATURE.events_in_notification_drawer');
15+
var counter = this;
1316
var drawerHidden = true;
1417

15-
$scope.onClick = function() {
16-
$scope.$applyAsync(function() {
17-
$scope.count = 0;
18+
var rootScopeWatches = [];
19+
// this one is treated separately from the rootScopeWatches as
20+
// it may need to be updated outside of the lifecycle of init/destroy
21+
var notificationListener;
22+
23+
var eventsWatcher;
24+
25+
var deregisterEventsWatch = function() {
26+
if(eventsWatcher) {
27+
DataService.unwatch(eventsWatcher);
28+
}
29+
};
30+
31+
var watchEvents = function(projectName, cb) {
32+
if(projectName && ENABLE_EVENTS) {
33+
eventsWatcher = DataService.watch('events', {namespace: projectName}, _.debounce(cb, 50), { skipDigest: true });
34+
}
35+
};
36+
37+
var watchNotifications = function(projectName, cb) {
38+
if(!projectName) {
39+
return;
40+
}
41+
notificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', cb);
42+
};
43+
44+
var deregisterNotificationListener = function() {
45+
notificationListener && notificationListener();
46+
};
47+
48+
var deregisterRootScopeWatches = function() {
49+
_.each(rootScopeWatches, function(deregister) {
50+
deregister();
1851
});
52+
};
53+
54+
var toggleVisibility = function(projectName) {
55+
if(!projectName) {
56+
counter.hideCounter = true;
57+
}
58+
counter.showNewNotificationIndicator = true;
59+
};
60+
61+
counter.onClick = function() {
1962
drawerHidden = !drawerHidden;
63+
counter.showNewNotificationIndicator = false;
2064
$rootScope.$emit('notification-drawer:show', {
2165
drawerHidden: drawerHidden
2266
});
2367
};
2468

25-
// TODO: just need to know if there is a "new" notification worth viewing,
26-
// don't need to give the user a ping for every time the watch returns data
27-
var subscription = notifications.subscribe($routeParams.project, function(groups) {
28-
$scope.groups = groups;
29-
$scope.count++;
30-
$scope.countDisplay = $scope.count < 100 ?
31-
$scope.count:
32-
'! !'; // TODO: a "too many!" indicator
33-
});
34-
35-
$scope.$on('$destroy', function() {
36-
notifications.unsubscribe(subscription);
37-
});
38-
},
39-
templateUrl: 'views/directives/notifications/notification-counter.html'
40-
};
69+
var genericEventCallback = function() {
70+
counter.showNewNotificationIndicator = true;
71+
};
72+
73+
var reset = function() {
74+
deregisterEventsWatch();
75+
deregisterNotificationListener();
76+
watchEvents($routeParams.project, genericEventCallback);
77+
watchNotifications($routeParams.project, genericEventCallback);
78+
toggleVisibility($routeParams.project);
79+
};
80+
81+
counter.$onInit = function() {
82+
reset();
83+
rootScopeWatches.push($rootScope.$on("$routeChangeSuccess", function () {
84+
reset();
85+
}));
86+
};
87+
88+
counter.$onDestroy = function() {
89+
deregisterEventsWatch();
90+
deregisterNotificationListener();
91+
deregisterRootScopeWatches();
92+
};
93+
}
94+
]
4195
});

0 commit comments

Comments
 (0)