sync notification UI with backend changes

This commit is contained in:
Girish Ramakrishnan
2021-05-29 12:11:17 -07:00
parent 841c9bc261
commit 5aa6e18ea7
5 changed files with 38 additions and 68 deletions
+4 -4
View File
@@ -1172,7 +1172,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.getNotifications = function (acknowledged, page, perPage, callback) {
Client.prototype.getNotifications = function (options, page, perPage, callback) {
var config = {
params: {
page: page,
@@ -1180,7 +1180,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
}
};
if (typeof acknowledged === 'boolean') config.params.acknowledged = acknowledged;
if (typeof options.acknowledged === 'boolean') config.params.acknowledged = options.acknowledged;
get('/api/v1/notifications', config, function (error, data, status) {
if (error) return callback(error);
@@ -1190,8 +1190,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.ackNotification = function (notificationId, callback) {
post('/api/v1/notifications/' + notificationId, {}, null, function (error, data, status) {
Client.prototype.ackNotification = function (notificationId, acknowledged, callback) {
post('/api/v1/notifications/' + notificationId, { acknowledged: acknowledged }, null, function (error, data, status) {
if (error) return callback(error);
if (status !== 204) return callback(new ClientError(status));
+9 -15
View File
@@ -3,14 +3,14 @@
/* global angular */
/* global $ */
angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', 'Client', function ($scope, $route, $timeout, $location, Client) {
angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', '$interval', 'Client', function ($scope, $route, $timeout, $location, $interval, Client) {
$scope.initialized = false; // used to animate the UI
$scope.user = Client.getUserInfo();
$scope.installedApps = Client.getInstalledApps();
$scope.config = {};
$scope.client = Client;
$scope.subscription = {};
$scope.notifications = [];
$scope.notificationCount = 0;
$scope.hideNavBarActions = $location.path() === '/logs';
$scope.reboot = {
@@ -63,19 +63,16 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
});
};
function refreshNotifications(poll) {
Client.getNotifications(false, 1, 100, function (error, results) {
function refreshNotifications() {
Client.getNotifications({ acknowledged: false }, 1, 100, function (error, results) { // counter maxes out at 100
if (error) console.error(error);
else $scope.notifications = results;
if (poll) $timeout(refreshNotifications, 60 * 1000);
else $scope.notificationCount = results.length;
});
}
// update state of acknowledged notification
$scope.notificationAcknowledged = function (notificationId) {
// remove notification from list
$scope.notifications = $scope.notifications.filter(function (n) { return n.id !== notificationId; });
$scope.notificationAcknowledged = function (ack) {
$scope.notificationCount += (ack ? -1 : +1);
};
function init() {
@@ -140,7 +137,8 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
return;
}
refreshNotifications(true);
$interval(refreshNotifications, 60 * 1000);
refreshNotifications();
$scope.updateSubscriptionStatus();
});
@@ -156,10 +154,6 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
}
});
Client.onReconnect(function () {
refreshNotifications(false);
});
init();
// setup all the dialog focus handling