|
54 | 54 | // projName: { notifications }
|
55 | 55 | };
|
56 | 56 |
|
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 |
| - |
70 | 57 | var projects = {};
|
71 | 58 |
|
72 | 59 | var hideIfNoProject = function(projectName) {
|
|
90 | 77 |
|
91 | 78 | var makeProjectGroup = function(projectName, notifications) {
|
92 | 79 | return {
|
93 |
| - heading: $filter('displayName')(projects[projectName]) || projectName, |
| 80 | + heading: $filter('displayName')(projects[projectName]), |
94 | 81 | project: projects[projectName],
|
95 | 82 | notifications: notifications
|
96 | 83 | };
|
|
113 | 100 | // returns a map of filtered events ONLY.
|
114 | 101 | // will worry about unread, actions, etc in render.
|
115 | 102 | var formatAndFilterEvents = function(events) {
|
116 |
| - return _.reduce( |
117 |
| - events, |
118 |
| - function(result, event) { |
| 103 | + return _.reduce(events, function(result, event) { |
119 | 104 | if(EventsService.isImportantEvent(event) && !EventsService.isCleared(event)) {
|
120 | 105 | result[event.metadata.uid] = {
|
121 | 106 | actions: null,
|
122 | 107 | uid: event.metadata.uid,
|
123 | 108 | unread: !EventsService.isRead(event),
|
| 109 | + type: event.type, |
| 110 | + timestamp: event.lastTimestamp, |
124 | 111 | event: event
|
125 | 112 | };
|
126 | 113 | }
|
|
161 | 148 | var deregisterEventsWatch = function() {
|
162 | 149 | if(eventsWatcher) {
|
163 | 150 | DataService.unwatch(eventsWatcher);
|
| 151 | + eventsWatcher = null; |
164 | 152 | }
|
165 | 153 | };
|
166 | 154 |
|
|
175 | 163 | };
|
176 | 164 |
|
177 | 165 | var notificationWatchCallback = function(event, notification) {
|
178 |
| - var uid = notification.id || _.uniqueId('notification-'); |
179 | 166 | var project = notification.namespace || $routeParams.project;
|
180 | 167 | notificationsMap[project] = notificationsMap[project] || {};
|
181 |
| - notificationsMap[project][uid] = { |
| 168 | + |
| 169 | + notificationsMap[project][notification.id] = { |
182 | 170 | actions: null,
|
183 | 171 | 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 |
193 | 180 | };
|
194 | 181 | render();
|
195 | 182 | };
|
|
201 | 188 | }
|
202 | 189 | };
|
203 | 190 |
|
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) { |
207 | 192 | deregisterNotificationListener();
|
208 |
| - if(!projectName) { |
209 |
| - return; |
210 |
| - } |
211 | 193 | notificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', cb);
|
212 |
| - }; |
| 194 | + }); |
213 | 195 |
|
214 | 196 | var reset = function() {
|
215 | 197 | getProject($routeParams.project).then(function() {
|
|
234 | 216 | onMarkAllRead: function(group) {
|
235 | 217 | _.each(group.notifications, function(notification) {
|
236 | 218 | notification.unread = false;
|
237 |
| - EventsService.markRead(notification.event); |
| 219 | + EventsService.markRead(notification.uid); |
238 | 220 | });
|
239 | 221 | render();
|
240 | 222 | $rootScope.$emit('NotificationDrawerWrapper.onMarkAllRead');
|
241 | 223 | },
|
242 | 224 | onClearAll: function(group) {
|
243 | 225 | _.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); |
246 | 228 | });
|
247 | 229 | group.notifications = [];
|
248 | 230 | render();
|
|
253 | 235 | notificationBodyInclude: 'views/directives/notifications/notification-body.html',
|
254 | 236 | customScope: {
|
255 | 237 | clear: function(notification, index, group) {
|
256 |
| - EventsService.markCleared(notification.event); |
| 238 | + EventsService.markCleared(notification.uid); |
257 | 239 | group.notifications.splice(index, 1);
|
258 | 240 | countUnreadNotifications();
|
259 | 241 | },
|
260 | 242 | markRead: function(notification) {
|
261 | 243 | notification.unread = false;
|
262 |
| - EventsService.markRead(notification.event); |
| 244 | + EventsService.markRead(notification.uid); |
263 | 245 | countUnreadNotifications();
|
264 | 246 | },
|
265 |
| - getNotficationStatusIconClass: function(event) { |
266 |
| - return iconClassByEventSeverity[event.type] || iconClassByEventSeverity.info; |
267 |
| - }, |
268 |
| - getStatusForCount: function(countKey) { |
269 |
| - return iconClassByEventSeverity[countKey] || iconClassByEventSeverity.info; |
270 |
| - }, |
271 | 247 | close: function() {
|
272 | 248 | drawer.drawerHidden = true;
|
273 | 249 | }
|
|
0 commit comments