From 85ad80a671e826f42464c7b014bd5caa1a2cad9b Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 26 Apr 2020 23:56:44 +0200 Subject: [PATCH] token-validator: update dashboard: include visualization for individual student --- token-validator/htdocs/dashboard.html | 86 ++++++++++++++++---- token-validator/htdocs/js/adlin-dashboard.js | 44 +++++++++- token-validator/htdocs/views/home.html | 21 +++-- token-validator/static-dev.go | 7 +- token-validator/static.go | 11 +-- 5 files changed, 130 insertions(+), 39 deletions(-) diff --git a/token-validator/htdocs/dashboard.html b/token-validator/htdocs/dashboard.html index 5172285..4689e0c 100644 --- a/token-validator/htdocs/dashboard.html +++ b/token-validator/htdocs/dashboard.html @@ -9,6 +9,14 @@ font-size: 13px; margin-top: 0.2vh; } + .dropdown a { + display: block; + color: black; + } + .dropdown a:hover { + background-color: #ccc; + text-decoration: none; + } .student { background-position: center; background-repeat: no-repeat; @@ -46,24 +54,70 @@ -
-
-
ADLIN TP {{tutoid+1}}
-
- {{ stats[ch].warning * 100 / stats.total | number:0 }} % -
+
+
+
+
+ {{ student.login }} +
+
+
+
{{ student.login }}
+

+ + 💻 + + +

+
+
+
TP {{tutoid+1}}
+ +
+

+
+
+
+
+
+
+
+
+ ADLIN TP {{tutoid+1}} + + + + + +
+
+ +
+
+ {{ stats[ch].warning * 100 / stats.total | number:0 }} % +
+
-
- -
- -
+
+ +
+ +
+
diff --git a/token-validator/htdocs/js/adlin-dashboard.js b/token-validator/htdocs/js/adlin-dashboard.js index db02f8e..74e8976 100644 --- a/token-validator/htdocs/js/adlin-dashboard.js +++ b/token-validator/htdocs/js/adlin-dashboard.js @@ -36,7 +36,7 @@ angular.module("AdLinApp", ["ngResource", "ngSanitize"]) return $resource("/api/progress") }) .factory("StudentProgression", function($resource) { - return $resource("/api/dashboard.json") + return $resource("/api/students/:studentId/progress", { studentId: '@id' }) }) .factory("Challenge", function($resource) { return $resource("/challenge/:challengeId", { challengeId: '@id' }) @@ -46,11 +46,18 @@ angular.module("AdLinApp") .run(function($rootScope, $location) { if (window.location.pathname.split("/").length >= 3) { $rootScope.tutoid = parseInt(window.location.pathname.split("/")[2], 10); + if (isNaN($rootScope.tutoid)) { + $rootScope.onestudent = window.location.pathname.split("/")[2]; + } } if (!$rootScope.tutoid || isNaN($rootScope.tutoid)) { $rootScope.tutoid = 1; } $rootScope.tutoid--; + $rootScope.show_dropdown = false; + $rootScope.toogleDropdown = function() { + $rootScope.show_dropdown = !$rootScope.show_dropdown; + } }) .controller("StudentsController", function($scope, $interval, Student) { $scope.students = Student.query(); @@ -103,19 +110,48 @@ angular.module("AdLinApp") refreshStd(); $interval(refreshStd, 9750); }) + .controller("StudentProgressionController", function($scope, $interval, $http, Student, StudentProgression) { + $scope.tuto_progress = tuto_progress; + var refreshStd = function() { + $scope.student = Student.get({studentId: $scope.onestudent}) + $scope.img = $scope.onestudent == "nemunaire" ? "mercie_d" : $scope.onestudent + $scope.mychallenges = StudentProgression.get({studentId: $scope.onestudent}) + $scope.mychallenges.$promise.then(function(mychallenges) { + angular.forEach(mychallenges, function(ch, chid) { + if (ch.time) { + mychallenges[chid].time = new Date(ch.time); + mychallenges[chid].recent = (Date.now() - mychallenges[chid].time)/1000; + } + }); + }) + $scope.student.$promise.then(function(student) { + $http.get("/api/students/" + $scope.student.id + "/ips").then(function(response) { + $scope.ips = response.data; + }); + }) + } + $scope.$watch("onestudent", function(onestudent) { + refreshStd(); + $interval(refreshStd, 15000); + }) + }) .controller("PingController", function($scope, $interval, $http) { $scope.PING = false; $scope.PING_time = ''; $scope.PING_ok = false; - var refreshPing = function() { + var refreshPing = function() { $http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) { $scope.PING_ok = response.data.State; $scope.PING_time = new Date(response.data.Date); $scope.PING = (Date.now() - $scope.PING_time)/1000; }); } - refreshPing(); - $interval(refreshPing, 15000); + $scope.$watch("student", function(student) { + student.$promise.then(function(std) { + refreshPing(); + $interval(refreshPing, 15000); + }) + }) }) .controller("SSHController", function($scope, $interval, $http) { $scope.SSH = false; diff --git a/token-validator/htdocs/views/home.html b/token-validator/htdocs/views/home.html index bb46cae..9a22146 100644 --- a/token-validator/htdocs/views/home.html +++ b/token-validator/htdocs/views/home.html @@ -11,13 +11,24 @@

- Qu'allons-nous faire aujourd'hui ? + Qu'allons-nous faire aujourd'hui ? Voir l'avancement...

-
- HTTP - HTTPS - DNS +
+
+ TP 2  + HTTP + HTTPS + DNS + Matrix +
+
+ TP 3  + HTTP + HTTPS + DNS + Matrix +
diff --git a/token-validator/static-dev.go b/token-validator/static-dev.go index cc748e6..d461ea3 100644 --- a/token-validator/static-dev.go +++ b/token-validator/static-dev.go @@ -8,7 +8,6 @@ import ( "os" "path" "path/filepath" - "strconv" "strings" "github.com/julienschmidt/httprouter" @@ -49,11 +48,7 @@ func init() { http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html")) }) Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - if _, err := strconv.ParseInt(string(ps.ByName("where")), 10, 64); err != nil { - http.NotFound(w, r) - } else { - http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html")) - } + http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html")) }) Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { r.URL.Path = strings.TrimPrefix(r.URL.Path, "/dashboard") diff --git a/token-validator/static.go b/token-validator/static.go index 6be3cbe..1ca9931 100644 --- a/token-validator/static.go +++ b/token-validator/static.go @@ -7,7 +7,6 @@ import ( "net/http" "path" "strings" - "strconv" "github.com/julienschmidt/httprouter" ) @@ -91,14 +90,10 @@ func init() { } }) Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - if _, err := strconv.ParseInt(string(ps.ByName("where")), 10, 64); err != nil { - http.NotFound(w, r) + if data, err := Asset("htdocs/dashboard.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) } else { - if data, err := Asset("htdocs/dashboard.html"); err != nil { - fmt.Fprintf(w, "{\"errmsg\":%q}", err) - } else { - w.Write(data) - } + w.Write(data) } }) Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {