dashboard: improve: scale, flex, ...

This commit is contained in:
nemunaire 2020-02-27 15:29:41 +01:00
parent 7865373ffc
commit 7bac1ead6b
2 changed files with 104 additions and 81 deletions

View file

@ -5,62 +5,64 @@
<title>AdLin - Tableau d'avancement</title> <title>AdLin - Tableau d'avancement</title>
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet"> <link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
<style> <style>
.login { body {
overflow-x: hidden; font-size: 13px;
text-overflow: ellipsis; margin-top: 0.2vh;
max-width: 84%;
display: inline-block;
vertical-align: middle;
white-space: nowrap;
word-wrap: normal;
} }
.card-body { .student {
background-color: rgba(255,255,255,0.4);
padding: .3rem;
}
.card-img-top {
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: cover; background-size: cover;
height: 8.5rem; height: calc(100vh / 5 - 0.3vh);
margin-bottom: -60px; margin-left: 0.2%;
margin-bottom: 0.2vh;
width: calc(100vw / 12 - 0.22vw);
} }
.card-title { .student-title {
margin-bottom: 0; width: calc(2 * (100vw / 12 - 0.22vw) + 0.2vw);
font-size: 15px;
} }
.student { .student h5 {
margin-left: 0.3%; font-size: 16px;
width: 16.3%; }
.student h5 span {
font-size: 10px;
}
.student div, .student h5 {
background-color: rgba(255,255,255,0.35);
padding: 0.2vh 0.2vw;
transition: background-color .5s;
}
.student:hover h5, .student-title h5 {
background-color: rgba(255,255,255,0.7);
}
.login {
max-width: 122px;
}
.badge {
padding: .15em .35em;
} }
</style> </style>
<base href="/"> <base href="/">
</head> </head>
<body> <body>
<div ng-controller="StudentsController" ng-cloak> <div ng-controller="StudentsProgressionController" class="d-flex flex-wrap" ng-cloak>
<div class="card float-left mt-1 student" ng-controller="ProgressStatsController"> <div class="card student student-title d-flex flex-column justify-content-around" style="background-image: url('https://srs.epita.fr/assets/images/logo-srs.png');">
<div class="card-img-top" style="background-image: url('https://srs.epita.fr/assets/images/logo-srs.png')"></div> <h5 class="text-center" title="SRS" ng-cloak>ADLIN TP {{tutoid+1}}</h5>
<div class="card-body"> <div class="d-flex flex-wrap justify-content-around" style="padding: 0">
<h5 class="card-title"> <span class="badge" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-success': stats[ch].success > 0 || (tutoid == 0 && stats[ch].warning > 0), 'badge-warning': tutoid != 0 && stats[ch].success == 0 && stats[ch].warning > 0, 'badge-danger': !stats[ch] || (stats[ch].success == 0 && stats[ch].warning == 0)}" title="{{ t.title }}: {{ stats[ch].success }} - {{ stats[ch].warning }}/{{ stats.total }}" ng-cloak>{{ stats[ch].warning * 100 / stats.total | number:0 }} %</span>
<span class="login" title="SRS" ng-cloak>ADLIN TP {{tutoid+1}}</span>
</h5>
<div>
<span class="badge ml-1" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-success': stats[ch].success > 0, 'badge-warning': stats[ch].success == 0 && stats[ch].warning > 0, 'badge-danger': !stats[ch] || (stats[ch].success == 0 && stats[ch].warning == 0)}" title="{{ t.title }}: {{ stats[ch].success }} - {{ stats[ch].warning }}/{{ stats.total }}" ng-cloak>{{ stats[ch].warning * 100 / stats.total | number:0 }} %</span>
</div>
</div> </div>
</div> </div>
<div class="card float-left mt-1 student" ng-repeat="student in students"> <div class="card student d-flex flex-column justify-content-between" ng-repeat="(login, mychallenges) in students" style="background-image: url('https://photos.cri.epita.fr/square/{{ mychallenges.img | lowercase }}')">
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/{{ student.login | lowercase }}')" ng-if="student.login != 'nemunaire'"></div> <h5 class="login text-truncate" title="{{ login }}">
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/mercie_d')" ng-if="student.login == 'nemunaire'" ng-cloak></div> <span class="badge" ng-class="{'badge-success': mychallenges['ping'] && mychallenges['ping'].recent < 120, 'badge-info': mychallenges['ping'] && mychallenges['ping'].recent >= 120 && mychallenges['ping'].recent < 300, 'badge-warning': mychallenges['ping'] && mychallenges['ping'].recent >= 300 && mychallenges['ping'].recent < 900, 'badge-danger': mychallenges['ping'] && mychallenges['ping'].recent >= 900, 'badge-dark': !mychallenges['ping']}" title="{{ mychallenges['ping'].time }}">
<div class="card-body"> &#x1f4bb;
<h5 class="card-title" ng-controller="PingController"> </span>
<span class="login" title="{{ student.login }}">{{ student.login }}</span> {{ login }}
<span class="badge float-right" ng-class="{'badge-success': PING && PING < 120, 'badge-info': PING >= 120 && PING < 300, 'badge-warning': PING >= 300 && PING < 900, 'badge-danger': PING >= 900, 'badge-dark': !PING}" title="{{ PING_time }}"> </h5>
&#x1f4bb; <div class="d-flex flex-wrap justify-content-around" style="padding: 0">
</span> <span class="badge" style="margin-left: .07rem" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-warning': mychallenges[ch] && mychallenges[ch].recent && (tutoid != 0 && mychallenges[ch].recent > 300), 'badge-info': mychallenges[ch] && mychallenges[ch].recent && mychallenges[ch].recent <= 300 && mychallenges[ch].recent >= 120, 'badge-success': mychallenges[ch] && mychallenges[ch].recent && (tutoid == 0 || mychallenges[ch].recent < 120), 'badge-danger': !mychallenges[ch]}" title="{{ t.title }} @ {{ mychallenges[ch].time | date: 'medium' }} {{ mychallenges[ch].recent }}" ng-bind="t.label"></span>
</h5>
<div ng-controller="ProgressionController">
<span class="badge ml-1" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-warning': mychallenges[ch] && mychallenges[ch].recent && mychallenges[ch].recent > 300, 'badge-info': mychallenges[ch] && mychallenges[ch].recent && mychallenges[ch].recent <= 300 && mychallenges[ch].recent >= 120, 'badge-success': mychallenges[ch] && mychallenges[ch].recent && mychallenges[ch].recent < 120, 'badge-danger': !mychallenges[ch]}" title="{{ t.title }} @ {{ mychallenges[ch].time | date: 'medium' }} {{ mychallenges[ch].recent }}" ng-bind="t.label"></span>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,13 +1,14 @@
var tuto_progress = [ var tuto_progress = [
{ {
1: { title: "Is alive?", label: "T1"}, 1: { title: "Is alive?", label: "t1"},
2: { title: "DMZ reached", label: "T2"}, 2: { title: "DMZ reached", label: "t2"},
3: { title: "HTTPS on + time", label: "T3"}, 3: { title: "HTTPS on + time", label: "t3"},
4: { title: "DNS ok", label: "T4"}, 4: { title: "DNS ok", label: "t4"},
5: { title: "On Internet", label: "T5"}, 5: { title: "On Internet", label: "t5"},
6: { title: "Bonus ICMP", label: "B1"}, 6: { title: "Bonus caché", label: "B?"},
7: { title: "Bonus disk", label: "B2"}, 7: { title: "Bonus ICMP", label: "B1"},
8: { title: "Uploaded SSH key", label: "SSH"}, 8: { title: "Bonus disk", label: "B2"},
9: { title: "Uploaded SSH key", label: "C"},
}, },
{ {
100: { title: "HTTP", label: "HTTP"}, 100: { title: "HTTP", label: "HTTP"},
@ -27,13 +28,16 @@ angular.module("AdLinApp", ["ngResource", "ngSanitize"])
.factory("Progression", function($resource) { .factory("Progression", function($resource) {
return $resource("/api/progress") return $resource("/api/progress")
}) })
.factory("StudentProgression", function($resource) {
return $resource("/api/dashboard.json")
})
.factory("Challenge", function($resource) { .factory("Challenge", function($resource) {
return $resource("/challenge/:challengeId", { challengeId: '@id' }) return $resource("/challenge/:challengeId", { challengeId: '@id' })
}); });
angular.module("AdLinApp") angular.module("AdLinApp")
.run(function($rootScope, $location) { .run(function($rootScope, $location) {
$rootScope.tutoid = 1; $rootScope.tutoid = 0;
}) })
.controller("StudentsController", function($scope, $interval, Student) { .controller("StudentsController", function($scope, $interval, Student) {
$scope.students = Student.query(); $scope.students = Student.query();
@ -42,12 +46,58 @@ angular.module("AdLinApp")
} }
$interval(refreshStd, 1600000); $interval(refreshStd, 1600000);
}) })
.controller("StudentsProgressionController", function($scope, $interval, Progression) {
$scope.tuto_progress = tuto_progress;
$scope.stats = {};
$scope.students = {};
var refreshStd = function() {
var students = Progression.get();
students.$promise.then(function(response) {
var recent = new Date(Date.now() - 120000);
var tmpstats = {total:0};
angular.forEach(tuto_progress, function(tuto) {
angular.forEach(tuto, function(ch, chid) {
tmpstats[chid] = {"success":0, "warning":0};
});
});
angular.forEach(response, function(challenges, login) {
if (login[0] == "$") return;
tmpstats.total++;
angular.forEach(challenges, function(ch, chid) {
if (ch.time) {
challenges[chid].time = new Date(ch.time);
challenges[chid].recent = (Date.now() - ch.time)/1000;
if (recent < challenges[chid].time)
tmpstats[chid].success++;
}
if (tmpstats[chid] !== undefined)
tmpstats[chid].warning++;
});
if (login == "nemunaire")
challenges["img"] = "mercie_d"
else
challenges["img"] = login
$scope.students[login] = challenges;
});
$scope.stats = tmpstats;
})
}
refreshStd();
$interval(refreshStd, 9750);
})
.controller("PingController", function($scope, $interval, $http) { .controller("PingController", function($scope, $interval, $http) {
$scope.PING = false; $scope.PING = false;
$scope.PING_time = ''; $scope.PING_time = '';
$scope.PING_ok = false;
var refreshPing = function() { var refreshPing = function() {
$http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) { $http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) {
$scope.PING_time = new Date(response.data); $scope.PING_ok = response.data.State;
$scope.PING_time = new Date(response.data.Date);
$scope.PING = (Date.now() - $scope.PING_time)/1000; $scope.PING = (Date.now() - $scope.PING_time)/1000;
}); });
} }
@ -64,35 +114,6 @@ angular.module("AdLinApp")
refreshSSH(); refreshSSH();
$interval(refreshSSH, 15500); $interval(refreshSSH, 15500);
}) })
.controller("ProgressStatsController", function($scope, $interval, $http) {
$scope.tuto_progress = tuto_progress;
$scope.stats = {};
var refreshChal = function() {
var recent = new Date(Date.now() - 120000);
var tmpstats = {total:0};
angular.forEach(tuto_progress, function(tuto) {
angular.forEach(tuto, function(ch, chid) {
tmpstats[chid] = {"success":0, "warning":0};
});
});
$http.get("/api/progress/").then(function(response) {
angular.forEach(response.data, function(challenges, login) {
tmpstats.total++;
angular.forEach(challenges, function(ch, chid) {
tmpstats[chid].warning++;
if (ch.time) {
challenges[chid].time = new Date(ch.time);
if (recent < challenges[chid].time)
tmpstats[chid].success++;
}
});
});
$scope.stats = tmpstats;
});
}
refreshChal();
$interval(refreshChal, 14750);
})
.controller("ProgressionController", function($scope, $interval, $http) { .controller("ProgressionController", function($scope, $interval, $http) {
$scope.tuto_progress = tuto_progress; $scope.tuto_progress = tuto_progress;
$scope.mychallenges = {}; $scope.mychallenges = {};