Clear up to 1k unread notifications

This commit is contained in:
Johannes Zellner
2022-05-23 17:36:44 +02:00
parent c5b022cc19
commit 663e117da1
2 changed files with 14 additions and 20 deletions

View File

@@ -6,7 +6,7 @@
<div class="title-toolbar">
<button class="btn btn-default" ng-click="showPrevPage()" ng-disabled="busy || currentPage <= 1"><i class="fa fa-angle-double-left"></i> {{ 'main.pagination.prev' | tr }}</button>
<button class="btn btn-default" ng-click="showNextPage()" ng-disabled="busy || perPage > notifications.length">{{ 'main.pagination.next' | tr }} <i class="fa fa-angle-double-right"></i></button>
<button class="btn btn-primary" ng-click="clearAll()" ng-disabled="!hasUnread || clearAllBusy"><i class="fa fa-circle-notch fa-spin" ng-show="clearAllBusy"></i><i class="fa fa-check" ng-hide="clearAllBusy"></i> {{ 'notifications.markAllAsRead' | tr }}</button>
<button class="btn btn-primary" ng-click="clearAll()" ng-disabled="!$parent.notificationCount || clearAllBusy"><i class="fa fa-circle-notch fa-spin" ng-show="clearAllBusy"></i><i class="fa fa-check" ng-hide="clearAllBusy"></i> {{ 'notifications.markAllAsRead' | tr }}</button>
</div>
</h1>
</div>

View File

@@ -11,7 +11,6 @@ angular.module('Application').controller('NotificationsController', ['$scope', '
$scope.notifications = [];
$scope.activeNotification = null;
$scope.busy = true;
$scope.hasUnread = false;
$scope.currentPage = 1;
$scope.perPage = 20;
@@ -30,7 +29,6 @@ angular.module('Application').controller('NotificationsController', ['$scope', '
});
$scope.notifications = result;
$scope.hasUnread = !!result.find(function (n) { return !n.acknowledged; });
$scope.busy = false;
});
@@ -62,26 +60,22 @@ angular.module('Application').controller('NotificationsController', ['$scope', '
$scope.clearAll = function () {
$scope.clearAllBusy = true;
async.eachLimit($scope.notifications, 20, function (notification, callback) {
if (notification.acknowledged) return callback();
Client.ackNotification(notification.id, true, function (error) {
if (error) {
console.error(error);
} else {
notification.acknowledged = true;
}
callback();
});
}, function (error) {
Client.getNotifications({ acknowledged: false }, 1, 1000, function (error, results) { // hopefully 1k unread is sufficient
if (error) console.error(error);
// refresh the main navbar indicator
$scope.$parent.notificationAcknowledged();
async.eachLimit(results, 20, function (notification, callback) {
Client.ackNotification(notification.id, true, function (error) {
if (error) console.error(error);
callback();
});
}, function (error) {
if (error) console.error(error);
$scope.hasUnread = false;
$scope.clearAllBusy = false;
// refresh the main navbar indicator
$scope.$parent.notificationAcknowledged();
$scope.clearAllBusy = false;
});
});
};