Move notifications into a separate view

This commit is contained in:
Johannes Zellner
2019-01-09 15:18:10 +01:00
parent e36c15f770
commit d2d75b8e41
6 changed files with 115 additions and 101 deletions
+67
View File
@@ -0,0 +1,67 @@
'use strict';
/* global asyncForEach:false */
/* global angular:false */
angular.module('Application').controller('NotificationsController', ['$scope', 'Client', function ($scope, Client) {
$scope.notifications = {
notifications: [],
activeNotification: null,
busy: true,
all: false,
refresh: function () {
Client.getNotifications($scope.notifications.all ? null : false, 1, 20, function (error, result) {
if (error) return console.error(error);
$scope.notifications.notifications = result;
$scope.notifications.busy = false;
});
},
showOld: function () {
$scope.notifications.all = true;
$scope.notifications.refresh();
},
clicked: function (notification) {
if ($scope.notifications.activeNotification === notification) return $scope.notifications.activeNotification = null;
$scope.notifications.activeNotification = notification;
},
ack: function (notification, callback) {
callback = callback || function (error) { if (error) console.error(error); };
Client.ackNotification(notification.id, function (error) {
if (error) return callback(error);
$scope.$parent.notificationAcknowledged(notification.id);
$scope.notifications.refresh();
callback();
});
},
action: function (notification) {
if (notification.action) window.location = notification.action;
},
clearAll: function () {
$scope.notifications.busy = true;
asyncForEach($scope.notifications.notifications, function (notification, callback) {
$scope.notifications.ack(notification, callback);
}, function (error) {
if (error) console.error(error);
$scope.notifications.busy = false;
});
}
};
Client.onReady(function () {
$scope.notifications.refresh();
});
}]);