Alert in navigation bar if there is a new error in logs

This commit is contained in:
jendib 2013-08-22 17:41:47 +02:00
parent a858699391
commit 62a5840777
5 changed files with 50 additions and 3 deletions

View File

@ -1,2 +1 @@
- Check regulary for > INFO logs (client)
- Show number of files on documents list (client/server) - Show number of files on documents list (client/server)

View File

@ -110,6 +110,7 @@ public class AppResource extends BaseResource {
throw new ForbiddenClientException(); throw new ForbiddenClientException();
} }
checkBaseFunction(BaseFunction.ADMIN); checkBaseFunction(BaseFunction.ADMIN);
// TODO Change level by minLevel (returns all logs above)
// Get the memory appender // Get the memory appender
Logger logger = Logger.getRootLogger(); Logger logger = Logger.getRootLogger();

View File

@ -5,7 +5,42 @@
*/ */
App.controller('Navigation', function($scope, $http, $state, $rootScope, User, Restangular) { App.controller('Navigation', function($scope, $http, $state, $rootScope, User, Restangular) {
$rootScope.userInfo = User.userInfo(); $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. * User logout.
*/ */
@ -16,7 +51,10 @@ App.controller('Navigation', function($scope, $http, $state, $rootScope, User, R
}); });
$event.preventDefault(); $event.preventDefault();
}; };
/**
* Returns true if at least an asynchronous request is in progress.
*/
$scope.isLoading = function() { $scope.isLoading = function() {
return $http.pendingRequests.length > 0; return $http.pendingRequests.length > 0;
}; };

View File

@ -72,6 +72,11 @@
</ul> </ul>
<ul class="nav pull-right" ng-show="!userInfo.anonymous"> <ul class="nav pull-right" ng-show="!userInfo.anonymous">
<li ng-show="errorNumber > 0">
<a href="#/settings/log" ng-click="openLogs()" class="nav-text-error">
<span class="icon-warning-sign"></span> {{ errorNumber }} new error{{ errorNumber > 1 ? 's' : '' }}
</a>
</li>
<li ng-class="{active: $uiRoute}" ui-route="/settings.*"><a href="#/settings/account"><span class="icon-cog"></span><span class="hidden-phone"> Settings</span></a></li> <li ng-class="{active: $uiRoute}" ui-route="/settings.*"><a href="#/settings/account"><span class="icon-cog"></span><span class="hidden-phone"> Settings</span></a></li>
<li><a href="#" ng-click="logout($event)"><span class="icon-off"></span><span class="hidden-phone"> Logout</span></a></li> <li><a href="#" ng-click="logout($event)"><span class="icon-off"></span><span class="hidden-phone"> Logout</span></a></li>
</ul> </ul>

View File

@ -133,4 +133,8 @@ input[readonly].share-link {
ul > li { ul > li {
cursor: pointer; cursor: pointer;
} }
}
.nav-text-error {
color: #b94a48 !important;
} }