notifications: move vars/functions up a level
This commit is contained in:
+49
-51
@@ -6,69 +6,67 @@
|
||||
angular.module('Application').controller('NotificationsController', ['$scope', '$timeout', 'Client', function ($scope, $timeout, Client) {
|
||||
$scope.clearAllBusy = false;
|
||||
|
||||
$scope.notifications = {
|
||||
notifications: [],
|
||||
activeNotification: null,
|
||||
busy: true,
|
||||
$scope.notifications = [];
|
||||
$scope.activeNotification = null;
|
||||
$scope.busy = true;
|
||||
|
||||
refresh: function () {
|
||||
Client.getNotifications({}, 1, 100, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
$scope.refresh = function () {
|
||||
Client.getNotifications({}, 1, 100, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
// collapse by default
|
||||
result.forEach(function (r) { r.isCollapsed = true; });
|
||||
// collapse by default
|
||||
result.forEach(function (r) { r.isCollapsed = true; });
|
||||
|
||||
// attempt to parse the message as json
|
||||
result.forEach(function (r) {
|
||||
try {
|
||||
r.messageJson = JSON.parse(r.message);
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
$scope.notifications.notifications = result;
|
||||
|
||||
$scope.notifications.busy = false;
|
||||
// attempt to parse the message as json
|
||||
result.forEach(function (r) {
|
||||
try {
|
||||
r.messageJson = JSON.parse(r.message);
|
||||
} catch (e) {}
|
||||
});
|
||||
},
|
||||
|
||||
ack: function (notification, acked, event) {
|
||||
if (event) event.stopPropagation();
|
||||
$scope.notifications = result;
|
||||
|
||||
if (notification.acknowledged === acked) return;
|
||||
$scope.busy = false;
|
||||
});
|
||||
};
|
||||
|
||||
Client.ackNotification(notification.id, acked, function (error) {
|
||||
if (error) console.error(error);
|
||||
$scope.ack = function (notification, acked, event) {
|
||||
if (event) event.stopPropagation();
|
||||
|
||||
notification.acknowledged = acked;
|
||||
$scope.$parent.notificationAcknowledged(acked);
|
||||
if (notification.acknowledged === acked) return;
|
||||
|
||||
Client.ackNotification(notification.id, acked, function (error) {
|
||||
if (error) console.error(error);
|
||||
|
||||
notification.acknowledged = acked;
|
||||
$scope.$parent.notificationAcknowledged(acked);
|
||||
});
|
||||
};
|
||||
|
||||
$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;
|
||||
$scope.$parent.notificationAcknowledged(true);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
}, function (error) {
|
||||
if (error) console.error(error);
|
||||
|
||||
clearAll: function () {
|
||||
$scope.clearAllBusy = true;
|
||||
|
||||
async.eachLimit($scope.notifications.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;
|
||||
$scope.$parent.notificationAcknowledged(true);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
}, function (error) {
|
||||
if (error) console.error(error);
|
||||
|
||||
$scope.clearAllBusy = false;
|
||||
});
|
||||
}
|
||||
$scope.clearAllBusy = false;
|
||||
});
|
||||
};
|
||||
|
||||
Client.onReady(function () {
|
||||
$scope.notifications.refresh();
|
||||
$scope.refresh();
|
||||
});
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user