Skip to content

Commit

Permalink
add new screen to manage logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpennors committed Feb 28, 2020
1 parent b013c9c commit 6f34263
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 3 deletions.
5 changes: 5 additions & 0 deletions public/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ app.run(function($rootScope, PortailAuth) {
controller : 'loginCtrl',
controllerAs : 'login'
})
.when('/gestion/logs',{
templateUrl : 'app/components/logs/logs.html',
controller : 'logsCtrl',
controllerAs : 'logs'
})
.when('/logout',{
templateUrl : 'app/components/logout/logout.html',
controller : 'logoutCtrl',
Expand Down
64 changes: 64 additions & 0 deletions public/app/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,70 @@ app.controller('logoutCtrl', function($scope, PortailAuth) {

'use strict';


angular.module('bobbyApp')
.controller('logsCtrl', function ($scope, serviceAjax, $location, $rootScope) {
this.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];

if(!$rootScope.isAdmin()){
$location.path('/error/403');
}

$scope.error = false;

$scope.dates = {
currentDate : new Date(),
selectedDate : new Date(),
}

// Chargement des bugs
var loadLogs = function(selectedDate){
$scope.loading = true;
const day = ("0" + (selectedDate.getDate())).slice(-2);
const month_number = ("0" + (selectedDate.getMonth() + 1)).slice(-2)
const year = selectedDate.getFullYear();
const date = year + "-" + month_number + "-" + day;
serviceAjax.post('logs', {date : date}).then(function(res){
$scope.logs = res.data;
$scope.loading = false;
})
}
loadLogs($scope.dates.selectedDate);


/* Listener sur la date sélectionnée */
$scope.$watch("dates.selectedDate", function(){
if ($scope.dates.selectedDate) {
loadLogs($scope.dates.selectedDate);
}
});

$scope.logLevel = "error";

$scope.isActive = function(logLevel){
return logLevel == $scope.logLevel;
}

$scope.changeLogLevel = function(logLevel){
$scope.logLevel = logLevel;
}

$scope.showLog = function(log){
if ($scope.logLevel == "all") {
return true;
}
return log.level == $scope.logLevel;
}

});


'use strict';

/**
* @ngdoc function
* @name bobbyApp.controller:MainCtrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<table class="table table-hover col-md-12">
<div class="panel-heading">
<div class="row">
<div class="col-md-4 col-sm-12">
<h3>Gestion des catégories</h3>
<div class="col-md-5 col-sm-12">
<h3 class="underline-purple">Gestion des catégories</h3>
</div>
<div class="form-group col-md-5 offset-md-1 col-sm-8">
<div class="form-group col-md-4 offset-md-1 col-sm-8">
<input ng-model="categorieSearch" type="text" class="form-control search-list" placeholder="Rechercher une catégorie...">
</div>
<div class="col-md-1 offset-md-1 col-sm-2 offset-sm-2">
Expand Down
74 changes: 74 additions & 0 deletions public/app/components/logs/logs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<in-wrapper>
<br><br>
<div class = "row">
<div class="col-md-10 offset-md-1 margin20">

<div class="panel-heading">
<div class="row">
<div class="col-sm-12">
<h3 class="underline-purple">Gestion des logs</h3>
</div>
</div>
<div class="row" style="margin-bottom: 10px; margin-top: 20px;">
<label class="form-label col-md-3 col-sm-6" style="margin: 0; padding: 5px; margin-left: 10px;">Date sélectionnée</label>
<input class="form-control col-md-3 col-sm-5" type="date" style="margin: 0px; padding: 5px;" name="selectedDate" max="{{dates.currentDate | date:'yyyy-MM-dd'}}" ng-model="dates.selectedDate" required>
</div>
</div>
<div class="row" ng-if="error">
<div class="col-md-8 offset-md-2 col-sm-10 offset-sm-1 alert alert-danger" role="alert">
Une erreur est survenue.<br>
</div>
</div>
<div class="card text-center">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-link pointer" ng-click="changeLogLevel('info')" ng-class="{ active : isActive('info')}">Info</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('warning')" ng-class="{ active : isActive('warning')}">Warning</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('error')" ng-class="{ active : isActive('error')}">Erreur</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('all')" ng-class="{ active : isActive('all')}">Tous</a>
</li>
</ul>
</div>
<div class="card-body">
<table class="table table-hover col-md-12" ng-if="!loading">
<thead>
<tr>
<th>
Type
</th>
<th>
Description
</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="log in logs | toArray:false | orderBy:'date':reverse" ng-if="showLog(log)">
<td>
<span ng-if="log.level == 'warning'" class="badge badge-warning">{{log.level}}</span>
<span ng-if="log.level == 'error'" class="badge badge-danger">{{log.level}}</span>
<span ng-if="log.level == 'info'" class="badge badge-info">{{log.level}}</span>
</td>
<td>
<span>{{ log.description }}</span>
</td>
<td>
<span>{{ log.created_at.toString().replace(' ', 'T') | date : "dd/MM/yyyy HH:mm" }}</span>
</td>
</tr>
</tbody>
</table>
<div ng-if="loading">
<p><i class="fa fa-spinner fa-pulse fa-fw"></i></p>
</div>
</div>
</div>
</div>
</in-wrapper>
1 change: 1 addition & 0 deletions public/app/directives/inWrapper/in_wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<a class="dropdown-item pointer" href="#!/gestion/items">Matériels</a>
<a class="dropdown-item pointer" href="#!/gestion/bookings">Réservations</a>
<a class="dropdown-item pointer" href="#!/gestion/bugs">Bugs</a>
<a class="dropdown-item pointer" href="#!/gestion/logs">Logs</a>
</div>
</li>

Expand Down
5 changes: 5 additions & 0 deletions resources/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ app.run(function($rootScope, PortailAuth) {
controller : 'loginCtrl',
controllerAs : 'login'
})
.when('/gestion/logs',{
templateUrl : 'app/components/logs/logs.html',
controller : 'logsCtrl',
controllerAs : 'logs'
})
.when('/logout',{
templateUrl : 'app/components/logout/logout.html',
controller : 'logoutCtrl',
Expand Down
74 changes: 74 additions & 0 deletions resources/app/components/logs/logs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<in-wrapper>
<br><br>
<div class = "row">
<div class="col-md-10 offset-md-1 margin20">

<div class="panel-heading">
<div class="row">
<div class="col-sm-12">
<h3 class="underline-purple">Gestion des logs</h3>
</div>
</div>
<div class="row" style="margin-bottom: 10px; margin-top: 20px;">
<label class="form-label col-md-3 col-sm-6" style="margin: 0; padding: 5px; margin-left: 10px;">Date sélectionnée</label>
<input class="form-control col-md-3 col-sm-5" type="date" style="margin: 0px; padding: 5px;" name="selectedDate" max="{{dates.currentDate | date:'yyyy-MM-dd'}}" ng-model="dates.selectedDate" required>
</div>
</div>
<div class="row" ng-if="error">
<div class="col-md-8 offset-md-2 col-sm-10 offset-sm-1 alert alert-danger" role="alert">
Une erreur est survenue.<br>
</div>
</div>
<div class="card text-center">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-link pointer" ng-click="changeLogLevel('info')" ng-class="{ active : isActive('info')}">Info</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('warning')" ng-class="{ active : isActive('warning')}">Warning</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('error')" ng-class="{ active : isActive('error')}">Erreur</a>
</li>
<li class="nav-item pointer">
<a class="nav-link" ng-click="changeLogLevel('all')" ng-class="{ active : isActive('all')}">Tous</a>
</li>
</ul>
</div>
<div class="card-body">
<table class="table table-hover col-md-12" ng-if="!loading">
<thead>
<tr>
<th>
Type
</th>
<th>
Description
</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="log in logs | toArray:false | orderBy:'date':reverse" ng-if="showLog(log)">
<td>
<span ng-if="log.level == 'warning'" class="badge badge-warning">{{log.level}}</span>
<span ng-if="log.level == 'error'" class="badge badge-danger">{{log.level}}</span>
<span ng-if="log.level == 'info'" class="badge badge-info">{{log.level}}</span>
</td>
<td>
<span>{{ log.description }}</span>
</td>
<td>
<span>{{ log.created_at.toString().replace(' ', 'T') | date : "dd/MM/yyyy HH:mm" }}</span>
</td>
</tr>
</tbody>
</table>
<div ng-if="loading">
<p><i class="fa fa-spinner fa-pulse fa-fw"></i></p>
</div>
</div>
</div>
</div>
</in-wrapper>
63 changes: 63 additions & 0 deletions resources/app/components/logs/logsControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';


angular.module('bobbyApp')
.controller('logsCtrl', function ($scope, serviceAjax, $location, $rootScope) {
this.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];

if(!$rootScope.isAdmin()){
$location.path('/error/403');
}

$scope.error = false;

$scope.dates = {
currentDate : new Date(),
selectedDate : new Date(),
}

// Chargement des bugs
var loadLogs = function(selectedDate){
$scope.loading = true;
const day = ("0" + (selectedDate.getDate())).slice(-2);
const month_number = ("0" + (selectedDate.getMonth() + 1)).slice(-2)
const year = selectedDate.getFullYear();
const date = year + "-" + month_number + "-" + day;
serviceAjax.post('logs', {date : date}).then(function(res){
$scope.logs = res.data;
$scope.loading = false;
})
}
loadLogs($scope.dates.selectedDate);


/* Listener sur la date sélectionnée */
$scope.$watch("dates.selectedDate", function(){
if ($scope.dates.selectedDate) {
loadLogs($scope.dates.selectedDate);
}
});

$scope.logLevel = "error";

$scope.isActive = function(logLevel){
return logLevel == $scope.logLevel;
}

$scope.changeLogLevel = function(logLevel){
$scope.logLevel = logLevel;
}

$scope.showLog = function(log){
if ($scope.logLevel == "all") {
return true;
}
return log.level == $scope.logLevel;
}

});

1 change: 1 addition & 0 deletions resources/app/directives/inWrapper/in_wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<a class="dropdown-item pointer" href="#!/gestion/items">Matériels</a>
<a class="dropdown-item pointer" href="#!/gestion/bookings">Réservations</a>
<a class="dropdown-item pointer" href="#!/gestion/bugs">Bugs</a>
<a class="dropdown-item pointer" href="#!/gestion/logs">Logs</a>
</div>
</li>

Expand Down

0 comments on commit 6f34263

Please sign in to comment.