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>
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
<style>
.login {
overflow-x: hidden;
text-overflow: ellipsis;
max-width: 84%;
display: inline-block;
vertical-align: middle;
white-space: nowrap;
word-wrap: normal;
body {
font-size: 13px;
margin-top: 0.2vh;
}
.card-body {
background-color: rgba(255,255,255,0.4);
padding: .3rem;
}
.card-img-top {
.student {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 8.5rem;
margin-bottom: -60px;
height: calc(100vh / 5 - 0.3vh);
margin-left: 0.2%;
margin-bottom: 0.2vh;
width: calc(100vw / 12 - 0.22vw);
}
.card-title {
margin-bottom: 0;
.student-title {
width: calc(2 * (100vw / 12 - 0.22vw) + 0.2vw);
font-size: 15px;
}
.student {
margin-left: 0.3%;
width: 16.3%;
.student h5 {
font-size: 16px;
}
.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>
<base href="/">
</head>
<body>
<div ng-controller="StudentsController" ng-cloak>
<div class="card float-left mt-1 student" ng-controller="ProgressStatsController">
<div class="card-img-top" style="background-image: url('https://srs.epita.fr/assets/images/logo-srs.png')"></div>
<div class="card-body">
<h5 class="card-title">
<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 ng-controller="StudentsProgressionController" class="d-flex flex-wrap" ng-cloak>
<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');">
<h5 class="text-center" title="SRS" ng-cloak>ADLIN TP {{tutoid+1}}</h5>
<div class="d-flex flex-wrap justify-content-around" style="padding: 0">
<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>
</div>
</div>
<div class="card float-left mt-1 student" ng-repeat="student in students">
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/{{ student.login | lowercase }}')" ng-if="student.login != 'nemunaire'"></div>
<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>
<div class="card-body">
<h5 class="card-title" ng-controller="PingController">
<span class="login" title="{{ student.login }}">{{ student.login }}</span>
<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 }}">
&#x1f4bb;
</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 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 }}')">
<h5 class="login text-truncate" title="{{ login }}">
<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 }}">
&#x1f4bb;
</span>
{{ login }}
</h5>
<div class="d-flex flex-wrap justify-content-around" style="padding: 0">
<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>
</div>
</div>
</div>

View File

@ -1,13 +1,14 @@
var tuto_progress = [
{
1: { title: "Is alive?", label: "T1"},
2: { title: "DMZ reached", label: "T2"},
3: { title: "HTTPS on + time", label: "T3"},
4: { title: "DNS ok", label: "T4"},
5: { title: "On Internet", label: "T5"},
6: { title: "Bonus ICMP", label: "B1"},
7: { title: "Bonus disk", label: "B2"},
8: { title: "Uploaded SSH key", label: "SSH"},
1: { title: "Is alive?", label: "t1"},
2: { title: "DMZ reached", label: "t2"},
3: { title: "HTTPS on + time", label: "t3"},
4: { title: "DNS ok", label: "t4"},
5: { title: "On Internet", label: "t5"},
6: { title: "Bonus caché", label: "B?"},
7: { title: "Bonus ICMP", label: "B1"},
8: { title: "Bonus disk", label: "B2"},
9: { title: "Uploaded SSH key", label: "C"},
},
{
100: { title: "HTTP", label: "HTTP"},
@ -27,13 +28,16 @@ angular.module("AdLinApp", ["ngResource", "ngSanitize"])
.factory("Progression", function($resource) {
return $resource("/api/progress")
})
.factory("StudentProgression", function($resource) {
return $resource("/api/dashboard.json")
})
.factory("Challenge", function($resource) {
return $resource("/challenge/:challengeId", { challengeId: '@id' })
});
angular.module("AdLinApp")
.run(function($rootScope, $location) {
$rootScope.tutoid = 1;
$rootScope.tutoid = 0;
})
.controller("StudentsController", function($scope, $interval, Student) {
$scope.students = Student.query();
@ -42,12 +46,58 @@ angular.module("AdLinApp")
}
$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) {
$scope.PING = false;
$scope.PING_time = '';
$scope.PING_ok = false;
var refreshPing = function() {
$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;
});
}
@ -64,35 +114,6 @@ angular.module("AdLinApp")
refreshSSH();
$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) {
$scope.tuto_progress = tuto_progress;
$scope.mychallenges = {};