mirror of
https://git.victorphan.net/basketballcantho/Teedy_custom.git
synced 2026-08-06 06:13:10 +07:00
Alert in navigation bar if there is a new error in logs
This commit is contained in:
@@ -5,7 +5,42 @@
|
||||
*/
|
||||
App.controller('Navigation', function($scope, $http, $state, $rootScope, User, Restangular) {
|
||||
$rootScope.userInfo = User.userInfo();
|
||||
|
||||
|
||||
// Last time when the errors logs was checked
|
||||
$scope.lastLogCheck = new Date().getTime();
|
||||
|
||||
// Number of errors logs
|
||||
$scope.errorNumber = 0;
|
||||
|
||||
// Check repeatedly if there is a new error log
|
||||
setInterval(function() {
|
||||
$scope.$apply(function() {
|
||||
Restangular.one('app/log').get({
|
||||
limit: 100,
|
||||
level: 'ERROR'
|
||||
}).then(function(data) {
|
||||
// Add new errors
|
||||
$scope.errorNumber += _.reduce(data.logs, function(number, log) {
|
||||
if (log.date > $scope.lastLogCheck) {
|
||||
return ++number; // It's a new error
|
||||
}
|
||||
return number; // Not a new error
|
||||
}, 0);
|
||||
|
||||
// Update last check timestamp
|
||||
$scope.lastLogCheck = new Date().getTime();
|
||||
});
|
||||
})
|
||||
}, 10000);
|
||||
|
||||
/**
|
||||
* Navigate to error logs.
|
||||
*/
|
||||
$scope.openLogs = function() {
|
||||
$scope.errorNumber = 0;
|
||||
$state.transitionTo('settings.log');
|
||||
};
|
||||
|
||||
/**
|
||||
* User logout.
|
||||
*/
|
||||
@@ -16,7 +51,10 @@ App.controller('Navigation', function($scope, $http, $state, $rootScope, User, R
|
||||
});
|
||||
$event.preventDefault();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if at least an asynchronous request is in progress.
|
||||
*/
|
||||
$scope.isLoading = function() {
|
||||
return $http.pendingRequests.length > 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user