Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminapetersen committed Sep 6, 2017
1 parent e088dbd commit 4d1a986
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 179 deletions.
68 changes: 22 additions & 46 deletions app/scripts/directives/notifications/notificationDrawerWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@
// projName: { notifications }
};

// internal notifications have different types than API events
// this map normalizes
var notificationEventTypeMap = {
success: 'Normal',
error: 'Warning'
};

// this map takes the normalized type & assigns icons
var iconClassByEventSeverity = {
Normal: 'pficon pficon-info',
Warning: 'pficon pficon-warning-triangle-o'
};

var projects = {};

var hideIfNoProject = function(projectName) {
Expand All @@ -90,7 +77,7 @@

var makeProjectGroup = function(projectName, notifications) {
return {
heading: $filter('displayName')(projects[projectName]) || projectName,
heading: $filter('displayName')(projects[projectName]),
project: projects[projectName],
notifications: notifications
};
Expand All @@ -113,14 +100,14 @@
// returns a map of filtered events ONLY.
// will worry about unread, actions, etc in render.
var formatAndFilterEvents = function(events) {
return _.reduce(
events,
function(result, event) {
return _.reduce(events, function(result, event) {
if(EventsService.isImportantEvent(event) && !EventsService.isCleared(event)) {
result[event.metadata.uid] = {
actions: null,
uid: event.metadata.uid,
unread: !EventsService.isRead(event),
type: event.type,
timestamp: event.lastTimestamp,
event: event
};
}
Expand Down Expand Up @@ -161,6 +148,7 @@
var deregisterEventsWatch = function() {
if(eventsWatcher) {
DataService.unwatch(eventsWatcher);
eventsWatcher = null;
}
};

Expand All @@ -175,21 +163,20 @@
};

var notificationWatchCallback = function(event, notification) {
var uid = notification.id || _.uniqueId('notification-');
var project = notification.namespace || $routeParams.project;
notificationsMap[project] = notificationsMap[project] || {};
notificationsMap[project][uid] = {

notificationsMap[project][notification.id] = {
actions: null,
unread: true,
uid: uid,
// emulating an API event to simplify the template
event: {
lastTimestamp: notification.lastTimestamp || moment.parseZone(new Date()).utc().format(),
message: notification.message,
namespace: project,
type: notificationEventTypeMap[notification.type] || 'Normal',
links: notification.links
}
// using uid to match API events and have one filed to pass
// to EventsService for read/cleared, etc
uid: notification.id,
type: notification.type,
timestamp: notification.timestamp,
message: notification.message,
namespace: project,
links: notification.links
};
render();
};
Expand All @@ -201,15 +188,10 @@
}
};

// NotificationsService notifications are minimal, they do no necessarily contain projectName info.
// ATM tacking this on via watching the current project.
var watchNotifications = function(projectName, cb) {
var watchNotifications = _.once(function(projectName, cb) {
deregisterNotificationListener();
if(!projectName) {
return;
}
notificationListener = $rootScope.$on('NotificationsService.onNotificationAdded', cb);
};
});

var reset = function() {
getProject($routeParams.project).then(function() {
Expand All @@ -234,15 +216,15 @@
onMarkAllRead: function(group) {
_.each(group.notifications, function(notification) {
notification.unread = false;
EventsService.markRead(notification.event);
EventsService.markRead(notification.uid);
});
render();
$rootScope.$emit('NotificationDrawerWrapper.onMarkAllRead');
},
onClearAll: function(group) {
_.each(group.notifications, function(notification) {
EventsService.markRead(notification.event);
EventsService.markCleared(notification.event);
EventsService.markRead(notification.uid);
EventsService.markCleared(notification.uid);
});
group.notifications = [];
render();
Expand All @@ -253,21 +235,15 @@
notificationBodyInclude: 'views/directives/notifications/notification-body.html',
customScope: {
clear: function(notification, index, group) {
EventsService.markCleared(notification.event);
EventsService.markCleared(notification.uid);
group.notifications.splice(index, 1);
countUnreadNotifications();
},
markRead: function(notification) {
notification.unread = false;
EventsService.markRead(notification.event);
EventsService.markRead(notification.uid);
countUnreadNotifications();
},
getNotficationStatusIconClass: function(event) {
return iconClassByEventSeverity[event.type] || iconClassByEventSeverity.info;
},
getStatusForCount: function(countKey) {
return iconClassByEventSeverity[countKey] || iconClassByEventSeverity.info;
},
close: function() {
drawer.drawerHidden = true;
}
Expand Down
16 changes: 8 additions & 8 deletions app/scripts/services/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ angular.module('openshiftConsole')
return EVENTS_TO_SHOW_BY_REASON[reason];
};

var markRead = function(event) {
_.set(cachedEvents, [event.metadata.uid, READ], true);
var markRead = function(id) {
_.set(cachedEvents, [id, READ], true);
BrowserStore.saveJSON('session','events', cachedEvents);
};

var markCleared = function(event) {
_.set(cachedEvents, [event.metadata.uid, CLEARED], true);
var markCleared = function(id) {
_.set(cachedEvents, [id, CLEARED], true);
BrowserStore.saveJSON('session','events', cachedEvents);
};

var isRead = function(event) {
return _.get(cachedEvents, [event.metadata.uid, READ]);
var isRead = function(id) {
return _.get(cachedEvents, [id, READ]);
};

var isCleared = function(event) {
return _.get(cachedEvents, [event.metadata.uid, CLEARED]);
var isCleared = function(id) {
return _.get(cachedEvents, [id, CLEARED]);
};

return {
Expand Down
25 changes: 11 additions & 14 deletions app/views/directives/notifications/notification-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
tabindex="0"
ng-click="$ctrl.customScope.clear(notification, $index, notificationGroup)">
<span class="sr-only">Clear notification</span>
<span
ng-if="notification.event"
aria-hidden="true"
class="pull-left pficon pficon-close"></span>
<span aria-hidden="true" class="pull-left pficon pficon-close"></span>
</a>
<div
uib-dropdown
Expand Down Expand Up @@ -46,21 +43,19 @@
</div>

<span
ng-if="notification.event"
aria-hidden="true"
class="pull-left"
ng-class="$ctrl.customScope.getNotficationStatusIconClass(notification.event)"></span>
class="pull-left {{notification.type | alertIcon}}"
aria-hidden="true"></span>
<span class="sr-only">{{notification.event.type}}</span>
<div class="drawer-pf-notification-content">

<div
ng-if="notification.event"
class="drawer-pf-notification-message"
ng-attr-title="{{notification.event.message}}">
<div>
<span ng-if="notification.event.reason">
{{notification.event.reason | humanize}} &mdash; <span ng-if="notification.event.involvedObject">{{notification.event.involvedObject.kind | humanize}}</span>
</span>

<span
ng-if="notification.event.involvedObject"
ng-init="eventObjUrl = (notification.event | navigateEventInvolvedObjectURL)">
Expand All @@ -73,17 +68,19 @@
</a>
<span ng-if="!(eventObjUrl)">{{notification.event.involvedObject.name}}</span>
</span>

<span ng-if="!(notification.event.involvedObject)">
{{notification.event.message}}
<span ng-if="notification.event.links">
{{notification.message}}
<span ng-if="notification.links">
<a
ng-repeat="link in notification.event.links"
ng-repeat="link in notification.links"
href=""
ng-click="link.onClick()">
{{link.label}}
</a>
</span>
</span>

</div>
<div
ng-if="notification.event.count > 1"
Expand All @@ -100,8 +97,8 @@
{{notification.event.message}}
</span>
<div class="drawer-pf-notification-info">
<span class="date">{{notification.event.lastTimestamp | date:'shortDate'}}</span>
<span class="time">{{notification.event.lastTimestamp | date:'mediumTime'}}</span>
<span class="date">{{notification.timestamp | date:'shortDate'}}</span>
<span class="time">{{notification.timestamp | date:'mediumTime'}}</span>
</div>
</div>
</div>
Loading

0 comments on commit 4d1a986

Please sign in to comment.