diff --git a/admin/index.go b/admin/index.go index 7e1270f2..c2231010 100644 --- a/admin/index.go +++ b/admin/index.go @@ -45,6 +45,9 @@ const indextpl = `
+
+
{{"{{ box.title }}"}} {{"{{ box.msg }}"}}
+
diff --git a/admin/static/index.html b/admin/static/index.html index 631dd44a..2e5f9fed 100644 --- a/admin/static/index.html +++ b/admin/static/index.html @@ -43,6 +43,9 @@
+
+
{{ box.title }} {{ box.msg }}
+
diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 0d7b3e9a..d0d74aae 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -260,18 +260,50 @@ angular.module("FICApp") $scope.v = Version.get(); }) - .controller("SettingsController", function($scope, Settings, $location, $http) { + .controller("DIWEBoxController", function($scope, $rootScope, $interval, $timeout) { + function updBox() { + while ($rootScope._newBoxes.length > 0) { + var b = $rootScope._newBoxes.shift(); + $scope.boxes.unshift(b); + var id = $scope.boxes.length - 1; + $timeout(function() { $scope.boxes.pop(id); }, b.timeout); + } + } + + $rootScope._newBoxes = new Array(); + $rootScope.newBox = function(kind, title, msg, tmout) { + if (kind === undefined) { kind = 'default'; } + if (msg === undefined) { msg = ''; } + if (tmout === undefined) { tmout = 5000; } + + $rootScope._newBoxes.push({ + 'kind': kind, + 'title': title, + 'msg': msg, + 'timeout': tmout, + }) + }; + $scope.boxes = new Array(); + + updBox(); + $interval(updBox, 750); + }) + + .controller("SettingsController", function($scope, $rootScope, Settings, $location, $http) { $scope.config = Settings.get(); $scope.duration = 240; - $scope.saveSettings = function() { + $scope.saveSettings = function(msg) { + if (msg === undefined) { msg = 'New settings saved!'; } this.config.$update(function() { - $location.url("/"); + $rootScope.newBox('success', msg); + }, function(response) { + $rootScope.newBox('danger', 'An error occurs when saving settings:', response.data); }); } $scope.regenerate = function() { this.config.generation = (new Date()).toISOString(); - $scope.saveSettings(); + $scope.saveSettings("Regeneration in progress..."); } $scope.launchChallenge = function() { var ts = Date.now() - Date.now() % 60000; @@ -283,7 +315,10 @@ angular.module("FICApp") $scope.reset = function(type) { if (confirm("Êtes-vous sûr ?")) { $http.post("/api/reset", {"type": type}).success(function(time) { + $rootScope.newBox('success', type + 'reseted'); $location.url("/"); + }).error(function(repsonse) { + $rootScope.newBox('danger', 'An error occurs when reseting ' + type + ':', response.data); }); } }; @@ -459,7 +494,7 @@ angular.module("FICApp") } }) - .controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams, $location) { + .controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams) { $scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId }); $scope.deleteFile = function() { @@ -542,7 +577,7 @@ angular.module("FICApp") } } }) - .controller("TeamController", function($scope, $location, Team, TeamMember, $routeParams, $http) { + .controller("TeamController", function($scope, $rootScope, $location, Team, TeamMember, $routeParams, $http) { $scope.team = Team.get({ teamId: $routeParams.teamId }); $scope.fields = ["name", "color"]; @@ -564,8 +599,9 @@ angular.module("FICApp") transformResponse: null }).then(function(response) { $scope.hasCertificate = true; + $rootScope.newBox('success', 'Team certificate successfully generated!'); }, function(response) { - console.log(response.data); + $rootScope.newBox('danger', 'An error occurs when generating certiticate:', response.data); }); } $scope.revokeCertificate = function() { @@ -579,7 +615,7 @@ angular.module("FICApp") }).then(function(response) { $scope.hasCertificate = false; }, function(response) { - console.log(response.data); + $rootScope.newBox('danger', 'An error occurs when revoking the certiticate:', response.data); }); } @@ -593,7 +629,9 @@ angular.module("FICApp") } } $scope.deleteTeam = function() { - this.team.$remove(function() { $location.url("/teams/");}); + backName = this.team.name; + this.team.$remove(function() { $rootScope.newBox('success', 'Team ' + backName + ' successfully removed.'); $location.url("/teams/"); }, + function(response) { console.log($rootScope.newBox); $rootScope.newBox('danger', 'An error occurs during suppression of the team:', response.data); }); } $scope.showStats = function() { $location.url("/teams/" + $scope.team.id + "/stats");