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"}, }, { 100: { title: "HTTP", label: "HTTP"}, 101: { title: "HTTPS", label: "HTTPS"}, 102: { title: "DNS", label: "DNS"}, 103: { title: "Matrix", label: "Matrix"}, }, ]; angular.module("AdLinApp", ["ngResource", "ngSanitize"]) .factory("Student", function($resource) { return $resource("/api/students/:studentId", { studentId: '@id' }, { 'update': {method: 'PUT'}, }) }) .factory("Progression", function($resource) { return $resource("/api/progress") }) .factory("Challenge", function($resource) { return $resource("/challenge/:challengeId", { challengeId: '@id' }) }); angular.module("AdLinApp") .run(function($rootScope, $location) { $rootScope.tutoid = 1; }) .controller("StudentsController", function($scope, $interval, Student) { $scope.students = Student.query(); var refreshStd = function() { $scope.students = Student.query(); } $interval(refreshStd, 1600000); }) .controller("PingController", function($scope, $interval, $http) { $scope.PING = false; $scope.PING_time = ''; var refreshPing = function() { $http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) { $scope.PING_time = new Date(response.data); $scope.PING = (Date.now() - $scope.PING_time)/1000; }); } refreshPing(); $interval(refreshPing, 15000); }) .controller("SSHController", function($scope, $interval, $http) { $scope.SSH = false; var refreshSSH = function() { $http.get("/api/students/" + $scope.student.id + "/hassshkeys").then(function(response) { $scope.SSH = response.data }); } 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 = {}; var refreshChal = function() { $http.get("/api/students/" + $scope.student.id + "/progress").then(function(response) { angular.forEach(response.data, function(ch, chid) { if (ch.time) { response.data[chid].time = new Date(ch.time); response.data[chid].recent = (Date.now() - response.data[chid].time)/1000; } }); $scope.mychallenges = response.data }); } refreshChal(); $interval(refreshChal, 15750); })