Skip to content

Commit 0e16fb4

Browse files
committed
Correctly hide/show quota notifications per project
1 parent c31be18 commit 0e16fb4

File tree

6 files changed

+114
-129
lines changed

6 files changed

+114
-129
lines changed

app/scripts/directives/notifications/notificationDrawerWrapper.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
$rootScope,
3232
Constants,
3333
DataService,
34-
EventsService) {
34+
EventsService,
35+
NotificationsService) {
3536

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

104106
var formatAPIEvents = function(apiEvents) {
@@ -241,6 +243,7 @@
241243
onClearAll: function(group) {
242244
_.each(group.notifications, function(notification) {
243245
notification.unread = false;
246+
NotificationsService.hideNotification(notification.uid);
244247
EventsService.markRead(notification.uid);
245248
EventsService.markCleared(notification.uid);
246249
});
@@ -304,8 +307,9 @@
304307
// event to signal the drawer to clear a notification
305308
rootScopeWatches.push($rootScope.$on('NotificationDrawerWrapper.clear', function(event, notification) {
306309
EventsService.markCleared(notification.uid);
310+
NotificationsService.hideNotification(notification.uid);
307311
removeNotificationFromGroup(notification);
308-
drawer.countUnreadNotifications();
312+
countUnreadNotifications();
309313
}));
310314
};
311315

app/scripts/services/quota.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ angular.module("openshiftConsole")
317317

318318
if(hardValue <= usedValue) {
319319
notifications.push({
320-
id: "quota-limit-reached-" + quotaKey,
320+
id: projectName + "-quota-limit-reached-" + quotaKey,
321321
namespace: projectName,
322322
type: (hardValue < usedValue ? 'warning' : 'info'),
323323
message: getNotificaitonMessage(used, usedValue, hard, hardValue, quotaKey),

app/scripts/services/resourceAlerts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ angular.module("openshiftConsole")
7474
var setQuotaNotifications = function(quotas, clusterQuotas, projectName) {
7575
var notifications = QuotaService.getQuotaNotifications(quotas, clusterQuotas, projectName);
7676
_.each(notifications, function(notification) {
77-
if(!NotificationsService.isNotificationPermanentlyHidden(notification)) {
77+
// Only add a quota notification if it wasn't specifically set to be hidden by user
78+
if(!NotificationsService.isNotificationHidden(notification)) {
7879
NotificationsService.addNotification(notification);
7980
}
8081
});

dist/scripts/scripts.js

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,7 +3598,7 @@ var t = e.status.total || e.status;
35983598
_.each(t.hard, function(e, s) {
35993599
var c = m(e), l = _.get(t, [ "used", s ]), d = m(l);
36003600
"resourcequotas" !== s && c && d && c <= d && i.push({
3601-
id: "quota-limit-reached-" + s,
3601+
id: o + "-quota-limit-reached-" + s,
36023602
namespace: o,
36033603
type: c < d ? "warning" : "info",
36043604
message: I(0, d, e, c, s),
@@ -4217,7 +4217,7 @@ return a && u(t, n, a, "warning"), r && u(t, n, r, "error"), o && u(t, n, o, "er
42174217
setQuotaNotifications: function(e, t, n) {
42184218
var a = o.getQuotaNotifications(e, t, n);
42194219
_.each(a, function(e) {
4220-
r.isNotificationPermanentlyHidden(e) || r.addNotification(e);
4220+
r.isNotificationHidden(e) || r.addNotification(e);
42214221
});
42224222
}
42234223
};
@@ -14389,37 +14389,37 @@ u(), d();
1438914389
}(), function() {
1439014390
angular.module("openshiftConsole").component("notificationDrawerWrapper", {
1439114391
templateUrl: "views/directives/notifications/notification-drawer-wrapper.html",
14392-
controller: [ "$filter", "$interval", "$location", "$timeout", "$routeParams", "$rootScope", "Constants", "DataService", "EventsService", "NotificationsService", function(e, t, n, a, r, o, i, s, c) {
14393-
var l, u, d = _.get(i, "DISABLE_GLOBAL_EVENT_WATCH"), m = e("isIE")() || e("isEdge")(), p = this, f = [], g = {}, h = {}, v = {}, y = function(e) {
14394-
e || (p.drawerHidden = !0);
14395-
}, b = function(e, t) {
14392+
controller: [ "$filter", "$interval", "$location", "$timeout", "$routeParams", "$rootScope", "Constants", "DataService", "EventsService", "NotificationsService", function(e, t, n, a, r, o, i, s, c, l) {
14393+
var u, d, m = _.get(i, "DISABLE_GLOBAL_EVENT_WATCH"), p = e("isIE")() || e("isEdge")(), f = this, g = [], h = {}, v = {}, y = {}, b = function(e) {
14394+
e || (f.drawerHidden = !0);
14395+
}, C = function(e, t) {
1439614396
return _.get(e, "params.project") !== _.get(t, "params.project");
14397-
}, C = function(e) {
14397+
}, S = function(e) {
1439814398
return s.get("projects", e, {}, {
1439914399
errorNotification: !1
1440014400
}).then(function(e) {
14401-
return v[e.metadata.name] = e, e;
14401+
return y[e.metadata.name] = e, e;
1440214402
});
14403-
}, S = function(t, n) {
14403+
}, w = function(t, n) {
1440414404
return {
14405-
heading: e("displayName")(v[t]),
14406-
project: v[t],
14405+
heading: e("displayName")(y[t]),
14406+
project: y[t],
1440714407
notifications: n
1440814408
};
14409-
}, w = function(e) {
14409+
}, k = function(e) {
1441014410
return _.filter(e, "unread");
14411-
}, k = function() {
14412-
_.each(p.notificationGroups, function(e) {
14413-
e.totalUnread = w(e.notifications).length, e.hasUnread = !!e.totalUnread, o.$emit("NotificationDrawerWrapper.onUnreadNotifications", e.totalUnread);
14411+
}, j = function() {
14412+
_.each(f.notificationGroups, function(e) {
14413+
e.totalUnread = k(e.notifications).length, e.hasUnread = !!e.totalUnread, o.$emit("NotificationDrawerWrapper.onUnreadNotifications", e.totalUnread);
1441414414
});
14415-
}, j = function(e) {
14416-
_.each(p.notificationGroups, function(t) {
14415+
}, P = function(e) {
14416+
_.each(f.notificationGroups, function(t) {
1441714417
_.remove(t.notifications, {
1441814418
uid: e.uid,
1441914419
namespace: e.namespace
1442014420
});
14421-
});
14422-
}, P = function(e) {
14421+
}), delete v[r.project][e.uid];
14422+
}, R = function(e) {
1442314423
return _.map(e, function(e) {
1442414424
return {
1442514425
actions: null,
@@ -14432,33 +14432,33 @@ firstTimestamp: e.firstTimestamp,
1443214432
event: e
1443314433
};
1443414434
});
14435-
}, R = function(e) {
14435+
}, I = function(e) {
1443614436
return _.reduce(e, function(e, t) {
1443714437
return c.isImportantAPIEvent(t) && !c.isCleared(t.metadata.uid) && (e[t.metadata.uid] = t), e;
1443814438
}, {});
14439-
}, I = function(e, t) {
14439+
}, E = function(e, t) {
1444014440
var n = r.project;
1444114441
return _.assign({}, e[n], t[n]);
14442-
}, E = function(e) {
14442+
}, T = function(e) {
1444314443
return _.orderBy(e, [ "event.lastTimestamp", "event.firstTimestamp" ], [ "desc", "desc" ]);
14444-
}, T = function() {
14444+
}, N = function() {
1444514445
o.$evalAsync(function() {
14446-
p.notificationGroups = [ S(r.project, E(I(g, h))) ], k();
14446+
f.notificationGroups = [ w(r.project, T(E(h, v))) ], j();
1444714447
});
14448-
}, N = function() {
14449-
_.each(f, function(e) {
14450-
e();
14451-
}), f = [];
1445214448
}, D = function() {
14453-
u && (s.unwatch(u), u = null);
14449+
_.each(g, function(e) {
14450+
e();
14451+
}), g = [];
1445414452
}, A = function() {
14455-
l && l(), l = null;
14456-
}, $ = function(e) {
14457-
g[r.project] = P(R(e.by("metadata.name"))), T();
14458-
}, B = function(e, t) {
14453+
d && (s.unwatch(d), d = null);
14454+
}, $ = function() {
14455+
u && u(), u = null;
14456+
}, B = function(e) {
14457+
h[r.project] = R(I(e.by("metadata.name"))), N();
14458+
}, L = function(e, t) {
1445914459
if (t.showInDrawer) {
1446014460
var n = t.namespace || r.project, a = t.id || _.uniqueId("notification_") + Date.now();
14461-
h[n] = h[n] || {}, h[n][a] = {
14461+
v[n] = v[n] || {}, v[n][a] = {
1446214462
actions: t.actions,
1446314463
unread: !c.isRead(a),
1446414464
trackByID: t.trackByID,
@@ -14470,22 +14470,22 @@ isHTML: t.isHTML,
1447014470
details: t.details,
1447114471
namespace: n,
1447214472
links: t.links
14473-
}, T();
14473+
}, N();
1447414474
}
14475-
}, L = function(e, t) {
14476-
D(), e && (u = s.watch("events", {
14475+
}, U = function(e, t) {
14476+
A(), e && (d = s.watch("events", {
1447714477
namespace: e
1447814478
}, _.debounce(t, 400), {
1447914479
skipDigest: !0
1448014480
}));
14481-
}, U = _.once(function(e, t) {
14482-
A(), l = o.$on("NotificationsService.onNotificationAdded", t);
14483-
}), O = function() {
14484-
C(r.project).then(function() {
14485-
L(r.project, $), U(r.project, B), y(r.project), T();
14481+
}, O = _.once(function(e, t) {
14482+
$(), u = o.$on("NotificationsService.onNotificationAdded", t);
14483+
}), F = function() {
14484+
S(r.project).then(function() {
14485+
U(r.project, B), O(r.project, L), b(r.project), N();
1448614486
});
1448714487
};
14488-
angular.extend(p, {
14488+
angular.extend(f, {
1448914489
drawerHidden: !0,
1449014490
allowExpand: !0,
1449114491
drawerExpanded: !1,
@@ -14494,52 +14494,52 @@ hasUnread: !1,
1449414494
showClearAll: !0,
1449514495
showMarkAllRead: !0,
1449614496
onClose: function() {
14497-
p.drawerHidden = !0;
14497+
f.drawerHidden = !0;
1449814498
},
1449914499
onMarkAllRead: function(e) {
1450014500
_.each(e.notifications, function(e) {
1450114501
e.unread = !1, c.markRead(e.uid);
14502-
}), T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14502+
}), N(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1450314503
},
1450414504
onClearAll: function(e) {
1450514505
_.each(e.notifications, function(e) {
14506-
e.unread = !1, c.markRead(e.uid), c.markCleared(e.uid);
14507-
}), g[r.project] = {}, h[r.project] = {}, T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14506+
e.unread = !1, l.hideNotification(e.uid), c.markRead(e.uid), c.markCleared(e.uid);
14507+
}), h[r.project] = {}, v[r.project] = {}, N(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1450814508
},
1450914509
notificationGroups: [],
1451014510
headingInclude: "views/directives/notifications/header.html",
1451114511
notificationBodyInclude: "views/directives/notifications/notification-body.html",
1451214512
customScope: {
1451314513
clear: function(e, t, n) {
14514-
c.markCleared(e.uid), n.notifications.splice(t, 1), k();
14514+
c.markCleared(e.uid), n.notifications.splice(t, 1), j();
1451514515
},
1451614516
markRead: function(e) {
14517-
e.unread = !1, c.markRead(e.uid), k();
14517+
e.unread = !1, c.markRead(e.uid), j();
1451814518
},
1451914519
close: function() {
14520-
p.drawerHidden = !0;
14520+
f.drawerHidden = !0;
1452114521
},
1452214522
onLinkClick: function(e) {
14523-
e.onClick(), p.drawerHidden = !0;
14523+
e.onClick(), f.drawerHidden = !0;
1452414524
},
14525-
countUnreadNotifications: k
14525+
countUnreadNotifications: j
1452614526
}
1452714527
});
14528-
var F = function() {
14529-
r.project && O(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14530-
b(t, n) && (p.customScope.projectName = r.project, O());
14531-
})), f.push(o.$on("NotificationDrawerWrapper.toggle", function() {
14532-
p.drawerHidden = !p.drawerHidden;
14533-
})), f.push(o.$on("NotificationDrawerWrapper.hide", function() {
14534-
p.drawerHidden = !0;
14535-
})), f.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
14536-
c.markCleared(t.uid), j(t), p.countUnreadNotifications();
14528+
var x = function() {
14529+
r.project && F(), g.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14530+
C(t, n) && (f.customScope.projectName = r.project, F());
14531+
})), g.push(o.$on("NotificationDrawerWrapper.toggle", function() {
14532+
f.drawerHidden = !f.drawerHidden;
14533+
})), g.push(o.$on("NotificationDrawerWrapper.hide", function() {
14534+
f.drawerHidden = !0;
14535+
})), g.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
14536+
c.markCleared(t.uid), l.hideNotification(t.uid), P(t), j();
1453714537
}));
1453814538
};
14539-
p.$onInit = function() {
14540-
d || m || F();
14541-
}, p.$onDestroy = function() {
14542-
A(), D(), N();
14539+
f.$onInit = function() {
14540+
m || p || x();
14541+
}, f.$onDestroy = function() {
14542+
$(), A(), D();
1454314543
};
1454414544
} ]
1454514545
});

0 commit comments

Comments
 (0)