Skip to content

Commit 4d1a986

Browse files
f
1 parent e088dbd commit 4d1a986

File tree

6 files changed

+110
-179
lines changed

6 files changed

+110
-179
lines changed

app/scripts/directives/notifications/notificationDrawerWrapper.js

+22-46
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@
5454
// projName: { notifications }
5555
};
5656

57-
// internal notifications have different types than API events
58-
// this map normalizes
59-
var notificationEventTypeMap = {
60-
success: 'Normal',
61-
error: 'Warning'
62-
};
63-
64-
// this map takes the normalized type & assigns icons
65-
var iconClassByEventSeverity = {
66-
Normal: 'pficon pficon-info',
67-
Warning: 'pficon pficon-warning-triangle-o'
68-
};
69-
7057
var projects = {};
7158

7259
var hideIfNoProject = function(projectName) {
@@ -90,7 +77,7 @@
9077

9178
var makeProjectGroup = function(projectName, notifications) {
9279
return {
93-
heading: $filter('displayName')(projects[projectName]) || projectName,
80+
heading: $filter('displayName')(projects[projectName]),
9481
project: projects[projectName],
9582
notifications: notifications
9683
};
@@ -113,14 +100,14 @@
113100
// returns a map of filtered events ONLY.
114101
// will worry about unread, actions, etc in render.
115102
var formatAndFilterEvents = function(events) {
116-
return _.reduce(
117-
events,
118-
function(result, event) {
103+
return _.reduce(events, function(result, event) {
119104
if(EventsService.isImportantEvent(event) && !EventsService.isCleared(event)) {
120105
result[event.metadata.uid] = {
121106
actions: null,
122107
uid: event.metadata.uid,
123108
unread: !EventsService.isRead(event),
109+
type: event.type,
110+
timestamp: event.lastTimestamp,
124111
event: event
125112
};
126113
}
@@ -161,6 +148,7 @@
161148
var deregisterEventsWatch = function() {
162149
if(eventsWatcher) {
163150
DataService.unwatch(eventsWatcher);
151+
eventsWatcher = null;
164152
}
165153
};
166154

@@ -175,21 +163,20 @@
175163
};
176164

177165
var notificationWatchCallback = function(event, notification) {
178-
var uid = notification.id || _.uniqueId('notification-');
179166
var project = notification.namespace || $routeParams.project;
180167
notificationsMap[project] = notificationsMap[project] || {};
181-
notificationsMap[project][uid] = {
168+
169+
notificationsMap[project][notification.id] = {
182170
actions: null,
183171
unread: true,
184-
uid: uid,
185-
// emulating an API event to simplify the template
186-
event: {
187-
lastTimestamp: notification.lastTimestamp || moment.parseZone(new Date()).utc().format(),
188-
message: notification.message,
189-
namespace: project,
190-
type: notificationEventTypeMap[notification.type] || 'Normal',
191-
links: notification.links
192-
}
172+
// using uid to match API events and have one filed to pass
173+
// to EventsService for read/cleared, etc
174+
uid: notification.id,
175+
type: notification.type,
176+
timestamp: notification.timestamp,
177+
message: notification.message,
178+
namespace: project,
179+
links: notification.links
193180
};
194181
render();
195182
};
@@ -201,15 +188,10 @@
201188
}
202189
};
203190

204-
// NotificationsService notifications are minimal, they do no necessarily contain projectName info.
205-
// ATM tacking this on via watching the current project.
206-
var watchNotifications = function(projectName, cb) {
191+
var watchNotifications = _.once(function(projectName, cb) {
207192
deregisterNotificationListener();
208-
if(!projectName) {
209-
return;
210-
}
211193
notificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', cb);
212-
};
194+
});
213195

214196
var reset = function() {
215197
getProject($routeParams.project).then(function() {
@@ -234,15 +216,15 @@
234216
onMarkAllRead: function(group) {
235217
_.each(group.notifications, function(notification) {
236218
notification.unread = false;
237-
EventsService.markRead(notification.event);
219+
EventsService.markRead(notification.uid);
238220
});
239221
render();
240222
$rootScope.$emit('NotificationDrawerWrapper.onMarkAllRead');
241223
},
242224
onClearAll: function(group) {
243225
_.each(group.notifications, function(notification) {
244-
EventsService.markRead(notification.event);
245-
EventsService.markCleared(notification.event);
226+
EventsService.markRead(notification.uid);
227+
EventsService.markCleared(notification.uid);
246228
});
247229
group.notifications = [];
248230
render();
@@ -253,21 +235,15 @@
253235
notificationBodyInclude: 'views/directives/notifications/notification-body.html',
254236
customScope: {
255237
clear: function(notification, index, group) {
256-
EventsService.markCleared(notification.event);
238+
EventsService.markCleared(notification.uid);
257239
group.notifications.splice(index, 1);
258240
countUnreadNotifications();
259241
},
260242
markRead: function(notification) {
261243
notification.unread = false;
262-
EventsService.markRead(notification.event);
244+
EventsService.markRead(notification.uid);
263245
countUnreadNotifications();
264246
},
265-
getNotficationStatusIconClass: function(event) {
266-
return iconClassByEventSeverity[event.type] || iconClassByEventSeverity.info;
267-
},
268-
getStatusForCount: function(countKey) {
269-
return iconClassByEventSeverity[countKey] || iconClassByEventSeverity.info;
270-
},
271247
close: function() {
272248
drawer.drawerHidden = true;
273249
}

app/scripts/services/events.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ angular.module('openshiftConsole')
1717
return EVENTS_TO_SHOW_BY_REASON[reason];
1818
};
1919

20-
var markRead = function(event) {
21-
_.set(cachedEvents, [event.metadata.uid, READ], true);
20+
var markRead = function(id) {
21+
_.set(cachedEvents, [id, READ], true);
2222
BrowserStore.saveJSON('session','events', cachedEvents);
2323
};
2424

25-
var markCleared = function(event) {
26-
_.set(cachedEvents, [event.metadata.uid, CLEARED], true);
25+
var markCleared = function(id) {
26+
_.set(cachedEvents, [id, CLEARED], true);
2727
BrowserStore.saveJSON('session','events', cachedEvents);
2828
};
2929

30-
var isRead = function(event) {
31-
return _.get(cachedEvents, [event.metadata.uid, READ]);
30+
var isRead = function(id) {
31+
return _.get(cachedEvents, [id, READ]);
3232
};
3333

34-
var isCleared = function(event) {
35-
return _.get(cachedEvents, [event.metadata.uid, CLEARED]);
34+
var isCleared = function(id) {
35+
return _.get(cachedEvents, [id, CLEARED]);
3636
};
3737

3838
return {

app/views/directives/notifications/notification-body.html

+11-14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
tabindex="0"
88
ng-click="$ctrl.customScope.clear(notification, $index, notificationGroup)">
99
<span class="sr-only">Clear notification</span>
10-
<span
11-
ng-if="notification.event"
12-
aria-hidden="true"
13-
class="pull-left pficon pficon-close"></span>
10+
<span aria-hidden="true" class="pull-left pficon pficon-close"></span>
1411
</a>
1512
<div
1613
uib-dropdown
@@ -46,21 +43,19 @@
4643
</div>
4744

4845
<span
49-
ng-if="notification.event"
50-
aria-hidden="true"
51-
class="pull-left"
52-
ng-class="$ctrl.customScope.getNotficationStatusIconClass(notification.event)"></span>
46+
class="pull-left {{notification.type | alertIcon}}"
47+
aria-hidden="true"></span>
5348
<span class="sr-only">{{notification.event.type}}</span>
5449
<div class="drawer-pf-notification-content">
5550

5651
<div
57-
ng-if="notification.event"
5852
class="drawer-pf-notification-message"
5953
ng-attr-title="{{notification.event.message}}">
6054
<div>
6155
<span ng-if="notification.event.reason">
6256
{{notification.event.reason | humanize}} &mdash; <span ng-if="notification.event.involvedObject">{{notification.event.involvedObject.kind | humanize}}</span>
6357
</span>
58+
6459
<span
6560
ng-if="notification.event.involvedObject"
6661
ng-init="eventObjUrl = (notification.event | navigateEventInvolvedObjectURL)">
@@ -73,17 +68,19 @@
7368
</a>
7469
<span ng-if="!(eventObjUrl)">{{notification.event.involvedObject.name}}</span>
7570
</span>
71+
7672
<span ng-if="!(notification.event.involvedObject)">
77-
{{notification.event.message}}
78-
<span ng-if="notification.event.links">
73+
{{notification.message}}
74+
<span ng-if="notification.links">
7975
<a
80-
ng-repeat="link in notification.event.links"
76+
ng-repeat="link in notification.links"
8177
href=""
8278
ng-click="link.onClick()">
8379
{{link.label}}
8480
</a>
8581
</span>
8682
</span>
83+
8784
</div>
8885
<div
8986
ng-if="notification.event.count > 1"
@@ -100,8 +97,8 @@
10097
{{notification.event.message}}
10198
</span>
10299
<div class="drawer-pf-notification-info">
103-
<span class="date">{{notification.event.lastTimestamp | date:'shortDate'}}</span>
104-
<span class="time">{{notification.event.lastTimestamp | date:'mediumTime'}}</span>
100+
<span class="date">{{notification.timestamp | date:'shortDate'}}</span>
101+
<span class="time">{{notification.timestamp | date:'mediumTime'}}</span>
105102
</div>
106103
</div>
107104
</div>

0 commit comments

Comments
 (0)