Skip to content

Commit

Permalink
Correctly hide/show quota notifications per project
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaylor113 committed Oct 5, 2017
1 parent c31be18 commit 0e16fb4
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$rootScope,
Constants,
DataService,
EventsService) {
EventsService,
NotificationsService) {

// kill switch if watching events is too expensive
var DISABLE_GLOBAL_EVENT_WATCH = _.get(Constants, 'DISABLE_GLOBAL_EVENT_WATCH');
Expand Down Expand Up @@ -99,6 +100,7 @@
_.each(drawer.notificationGroups, function(group) {
_.remove(group.notifications, { uid: notification.uid, namespace: notification.namespace });
});
delete notificationsMap[$routeParams.project][notification.uid];
};

var formatAPIEvents = function(apiEvents) {
Expand Down Expand Up @@ -241,6 +243,7 @@
onClearAll: function(group) {
_.each(group.notifications, function(notification) {
notification.unread = false;
NotificationsService.hideNotification(notification.uid);
EventsService.markRead(notification.uid);
EventsService.markCleared(notification.uid);
});
Expand Down Expand Up @@ -304,8 +307,9 @@
// event to signal the drawer to clear a notification
rootScopeWatches.push($rootScope.$on('NotificationDrawerWrapper.clear', function(event, notification) {
EventsService.markCleared(notification.uid);
NotificationsService.hideNotification(notification.uid);
removeNotificationFromGroup(notification);
drawer.countUnreadNotifications();
countUnreadNotifications();
}));
};

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/services/quota.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ angular.module("openshiftConsole")

if(hardValue <= usedValue) {
notifications.push({
id: "quota-limit-reached-" + quotaKey,
id: projectName + "-quota-limit-reached-" + quotaKey,
namespace: projectName,
type: (hardValue < usedValue ? 'warning' : 'info'),
message: getNotificaitonMessage(used, usedValue, hard, hardValue, quotaKey),
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/services/resourceAlerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ angular.module("openshiftConsole")
var setQuotaNotifications = function(quotas, clusterQuotas, projectName) {
var notifications = QuotaService.getQuotaNotifications(quotas, clusterQuotas, projectName);
_.each(notifications, function(notification) {
if(!NotificationsService.isNotificationPermanentlyHidden(notification)) {
// Only add a quota notification if it wasn't specifically set to be hidden by user
if(!NotificationsService.isNotificationHidden(notification)) {
NotificationsService.addNotification(notification);
}
});
Expand Down
130 changes: 65 additions & 65 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ var t = e.status.total || e.status;
_.each(t.hard, function(e, s) {
var c = m(e), l = _.get(t, [ "used", s ]), d = m(l);
"resourcequotas" !== s && c && d && c <= d && i.push({
id: "quota-limit-reached-" + s,
id: o + "-quota-limit-reached-" + s,
namespace: o,
type: c < d ? "warning" : "info",
message: I(0, d, e, c, s),
Expand Down Expand Up @@ -4217,7 +4217,7 @@ return a && u(t, n, a, "warning"), r && u(t, n, r, "error"), o && u(t, n, o, "er
setQuotaNotifications: function(e, t, n) {
var a = o.getQuotaNotifications(e, t, n);
_.each(a, function(e) {
r.isNotificationPermanentlyHidden(e) || r.addNotification(e);
r.isNotificationHidden(e) || r.addNotification(e);
});
}
};
Expand Down Expand Up @@ -14389,37 +14389,37 @@ u(), d();
}(), function() {
angular.module("openshiftConsole").component("notificationDrawerWrapper", {
templateUrl: "views/directives/notifications/notification-drawer-wrapper.html",
controller: [ "$filter", "$interval", "$location", "$timeout", "$routeParams", "$rootScope", "Constants", "DataService", "EventsService", "NotificationsService", function(e, t, n, a, r, o, i, s, c) {
var l, u, d = _.get(i, "DISABLE_GLOBAL_EVENT_WATCH"), m = e("isIE")() || e("isEdge")(), p = this, f = [], g = {}, h = {}, v = {}, y = function(e) {
e || (p.drawerHidden = !0);
}, b = function(e, t) {
controller: [ "$filter", "$interval", "$location", "$timeout", "$routeParams", "$rootScope", "Constants", "DataService", "EventsService", "NotificationsService", function(e, t, n, a, r, o, i, s, c, l) {
var u, d, m = _.get(i, "DISABLE_GLOBAL_EVENT_WATCH"), p = e("isIE")() || e("isEdge")(), f = this, g = [], h = {}, v = {}, y = {}, b = function(e) {
e || (f.drawerHidden = !0);
}, C = function(e, t) {
return _.get(e, "params.project") !== _.get(t, "params.project");
}, C = function(e) {
}, S = function(e) {
return s.get("projects", e, {}, {
errorNotification: !1
}).then(function(e) {
return v[e.metadata.name] = e, e;
return y[e.metadata.name] = e, e;
});
}, S = function(t, n) {
}, w = function(t, n) {
return {
heading: e("displayName")(v[t]),
project: v[t],
heading: e("displayName")(y[t]),
project: y[t],
notifications: n
};
}, w = function(e) {
}, k = function(e) {
return _.filter(e, "unread");
}, k = function() {
_.each(p.notificationGroups, function(e) {
e.totalUnread = w(e.notifications).length, e.hasUnread = !!e.totalUnread, o.$emit("NotificationDrawerWrapper.onUnreadNotifications", e.totalUnread);
}, j = function() {
_.each(f.notificationGroups, function(e) {
e.totalUnread = k(e.notifications).length, e.hasUnread = !!e.totalUnread, o.$emit("NotificationDrawerWrapper.onUnreadNotifications", e.totalUnread);
});
}, j = function(e) {
_.each(p.notificationGroups, function(t) {
}, P = function(e) {
_.each(f.notificationGroups, function(t) {
_.remove(t.notifications, {
uid: e.uid,
namespace: e.namespace
});
});
}, P = function(e) {
}), delete v[r.project][e.uid];
}, R = function(e) {
return _.map(e, function(e) {
return {
actions: null,
Expand All @@ -14432,33 +14432,33 @@ firstTimestamp: e.firstTimestamp,
event: e
};
});
}, R = function(e) {
}, I = function(e) {
return _.reduce(e, function(e, t) {
return c.isImportantAPIEvent(t) && !c.isCleared(t.metadata.uid) && (e[t.metadata.uid] = t), e;
}, {});
}, I = function(e, t) {
}, E = function(e, t) {
var n = r.project;
return _.assign({}, e[n], t[n]);
}, E = function(e) {
}, T = function(e) {
return _.orderBy(e, [ "event.lastTimestamp", "event.firstTimestamp" ], [ "desc", "desc" ]);
}, T = function() {
}, N = function() {
o.$evalAsync(function() {
p.notificationGroups = [ S(r.project, E(I(g, h))) ], k();
f.notificationGroups = [ w(r.project, T(E(h, v))) ], j();
});
}, N = function() {
_.each(f, function(e) {
e();
}), f = [];
}, D = function() {
u && (s.unwatch(u), u = null);
_.each(g, function(e) {
e();
}), g = [];
}, A = function() {
l && l(), l = null;
}, $ = function(e) {
g[r.project] = P(R(e.by("metadata.name"))), T();
}, B = function(e, t) {
d && (s.unwatch(d), d = null);
}, $ = function() {
u && u(), u = null;
}, B = function(e) {
h[r.project] = R(I(e.by("metadata.name"))), N();
}, L = function(e, t) {
if (t.showInDrawer) {
var n = t.namespace || r.project, a = t.id || _.uniqueId("notification_") + Date.now();
h[n] = h[n] || {}, h[n][a] = {
v[n] = v[n] || {}, v[n][a] = {
actions: t.actions,
unread: !c.isRead(a),
trackByID: t.trackByID,
Expand All @@ -14470,22 +14470,22 @@ isHTML: t.isHTML,
details: t.details,
namespace: n,
links: t.links
}, T();
}, N();
}
}, L = function(e, t) {
D(), e && (u = s.watch("events", {
}, U = function(e, t) {
A(), e && (d = s.watch("events", {
namespace: e
}, _.debounce(t, 400), {
skipDigest: !0
}));
}, U = _.once(function(e, t) {
A(), l = o.$on("NotificationsService.onNotificationAdded", t);
}), O = function() {
C(r.project).then(function() {
L(r.project, $), U(r.project, B), y(r.project), T();
}, O = _.once(function(e, t) {
$(), u = o.$on("NotificationsService.onNotificationAdded", t);
}), F = function() {
S(r.project).then(function() {
U(r.project, B), O(r.project, L), b(r.project), N();
});
};
angular.extend(p, {
angular.extend(f, {
drawerHidden: !0,
allowExpand: !0,
drawerExpanded: !1,
Expand All @@ -14494,52 +14494,52 @@ hasUnread: !1,
showClearAll: !0,
showMarkAllRead: !0,
onClose: function() {
p.drawerHidden = !0;
f.drawerHidden = !0;
},
onMarkAllRead: function(e) {
_.each(e.notifications, function(e) {
e.unread = !1, c.markRead(e.uid);
}), T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
}), N(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
},
onClearAll: function(e) {
_.each(e.notifications, function(e) {
e.unread = !1, c.markRead(e.uid), c.markCleared(e.uid);
}), g[r.project] = {}, h[r.project] = {}, T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
e.unread = !1, l.hideNotification(e.uid), c.markRead(e.uid), c.markCleared(e.uid);
}), h[r.project] = {}, v[r.project] = {}, N(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
},
notificationGroups: [],
headingInclude: "views/directives/notifications/header.html",
notificationBodyInclude: "views/directives/notifications/notification-body.html",
customScope: {
clear: function(e, t, n) {
c.markCleared(e.uid), n.notifications.splice(t, 1), k();
c.markCleared(e.uid), n.notifications.splice(t, 1), j();
},
markRead: function(e) {
e.unread = !1, c.markRead(e.uid), k();
e.unread = !1, c.markRead(e.uid), j();
},
close: function() {
p.drawerHidden = !0;
f.drawerHidden = !0;
},
onLinkClick: function(e) {
e.onClick(), p.drawerHidden = !0;
e.onClick(), f.drawerHidden = !0;
},
countUnreadNotifications: k
countUnreadNotifications: j
}
});
var F = function() {
r.project && O(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
b(t, n) && (p.customScope.projectName = r.project, O());
})), f.push(o.$on("NotificationDrawerWrapper.toggle", function() {
p.drawerHidden = !p.drawerHidden;
})), f.push(o.$on("NotificationDrawerWrapper.hide", function() {
p.drawerHidden = !0;
})), f.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
c.markCleared(t.uid), j(t), p.countUnreadNotifications();
var x = function() {
r.project && F(), g.push(o.$on("$routeChangeSuccess", function(e, t, n) {
C(t, n) && (f.customScope.projectName = r.project, F());
})), g.push(o.$on("NotificationDrawerWrapper.toggle", function() {
f.drawerHidden = !f.drawerHidden;
})), g.push(o.$on("NotificationDrawerWrapper.hide", function() {
f.drawerHidden = !0;
})), g.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
c.markCleared(t.uid), l.hideNotification(t.uid), P(t), j();
}));
};
p.$onInit = function() {
d || m || F();
}, p.$onDestroy = function() {
A(), D(), N();
f.$onInit = function() {
m || p || x();
}, f.$onDestroy = function() {
$(), A(), D();
};
} ]
});
Expand Down
Loading

0 comments on commit 0e16fb4

Please sign in to comment.