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

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