From 62a58407779d2ff403664403f9423dfb248bab8f Mon Sep 17 00:00:00 2001 From: jendib Date: Thu, 22 Aug 2013 17:41:47 +0200 Subject: [PATCH] Alert in navigation bar if there is a new error in logs --- docs-parent/TODO | 1 - .../docs/rest/resource/AppResource.java | 1 + .../webapp/app/docs/controller/Navigation.js | 42 ++++++++++++++++++- docs-web/src/main/webapp/index.html | 5 +++ docs-web/src/main/webapp/style/main.less | 4 ++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/docs-parent/TODO b/docs-parent/TODO index 76fc1aa3..06560279 100644 --- a/docs-parent/TODO +++ b/docs-parent/TODO @@ -1,2 +1 @@ -- Check regulary for > INFO logs (client) - Show number of files on documents list (client/server) \ No newline at end of file diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java index 2a624e01..ead2c4cb 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/AppResource.java @@ -110,6 +110,7 @@ public class AppResource extends BaseResource { throw new ForbiddenClientException(); } checkBaseFunction(BaseFunction.ADMIN); + // TODO Change level by minLevel (returns all logs above) // Get the memory appender Logger logger = Logger.getRootLogger(); diff --git a/docs-web/src/main/webapp/app/docs/controller/Navigation.js b/docs-web/src/main/webapp/app/docs/controller/Navigation.js index 8d11ae00..a6319db4 100644 --- a/docs-web/src/main/webapp/app/docs/controller/Navigation.js +++ b/docs-web/src/main/webapp/app/docs/controller/Navigation.js @@ -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; }; diff --git a/docs-web/src/main/webapp/index.html b/docs-web/src/main/webapp/index.html index 62d22af6..5c5bc624 100644 --- a/docs-web/src/main/webapp/index.html +++ b/docs-web/src/main/webapp/index.html @@ -72,6 +72,11 @@ diff --git a/docs-web/src/main/webapp/style/main.less b/docs-web/src/main/webapp/style/main.less index b7299d7d..11ed3548 100644 --- a/docs-web/src/main/webapp/style/main.less +++ b/docs-web/src/main/webapp/style/main.less @@ -133,4 +133,8 @@ input[readonly].share-link { ul > li { cursor: pointer; } +} + +.nav-text-error { + color: #b94a48 !important; } \ No newline at end of file