admin: add confirmation message box on error and some success

This commit is contained in:
nemunaire 2017-11-10 20:38:31 +01:00 committed by Pierre-Olivier Mercier
parent 1458c71cfa
commit df5c9532cd
3 changed files with 53 additions and 9 deletions

View file

@ -45,6 +45,9 @@ const indextpl = `<!DOCTYPE html>
</nav> </nav>
<div class="container"> <div class="container">
<div class="row" ng-controller="DIWEBoxController">
<div ng-repeat="box in boxes" class="alert alert-{{"{{ box.kind }}"}}" ng-cloak><strong ng-if="box.title">{{"{{ box.title }}"}}</strong> {{"{{ box.msg }}"}}</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-12" ng-view></div> <div class="col-sm-12" ng-view></div>
</div> </div>

View file

@ -43,6 +43,9 @@
</nav> </nav>
<div class="container"> <div class="container">
<div class="row" ng-controller="DIWEBoxController">
<div ng-repeat="box in boxes" class="alert alert-{{ box.kind }}" ng-cloak><strong ng-if="box.title">{{ box.title }}</strong> {{ box.msg }}</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-12" ng-view></div> <div class="col-sm-12" ng-view></div>
</div> </div>

View file

@ -260,18 +260,50 @@ angular.module("FICApp")
$scope.v = Version.get(); $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.config = Settings.get();
$scope.duration = 240; $scope.duration = 240;
$scope.saveSettings = function() { $scope.saveSettings = function(msg) {
if (msg === undefined) { msg = 'New settings saved!'; }
this.config.$update(function() { 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() { $scope.regenerate = function() {
this.config.generation = (new Date()).toISOString(); this.config.generation = (new Date()).toISOString();
$scope.saveSettings(); $scope.saveSettings("Regeneration in progress...");
} }
$scope.launchChallenge = function() { $scope.launchChallenge = function() {
var ts = Date.now() - Date.now() % 60000; var ts = Date.now() - Date.now() % 60000;
@ -283,7 +315,10 @@ angular.module("FICApp")
$scope.reset = function(type) { $scope.reset = function(type) {
if (confirm("Êtes-vous sûr ?")) { if (confirm("Êtes-vous sûr ?")) {
$http.post("/api/reset", {"type": type}).success(function(time) { $http.post("/api/reset", {"type": type}).success(function(time) {
$rootScope.newBox('success', type + 'reseted');
$location.url("/"); $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.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteFile = function() { $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.team = Team.get({ teamId: $routeParams.teamId });
$scope.fields = ["name", "color"]; $scope.fields = ["name", "color"];
@ -564,8 +599,9 @@ angular.module("FICApp")
transformResponse: null transformResponse: null
}).then(function(response) { }).then(function(response) {
$scope.hasCertificate = true; $scope.hasCertificate = true;
$rootScope.newBox('success', 'Team certificate successfully generated!');
}, function(response) { }, function(response) {
console.log(response.data); $rootScope.newBox('danger', 'An error occurs when generating certiticate:', response.data);
}); });
} }
$scope.revokeCertificate = function() { $scope.revokeCertificate = function() {
@ -579,7 +615,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.hasCertificate = false; $scope.hasCertificate = false;
}, function(response) { }, 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() { $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() { $scope.showStats = function() {
$location.url("/teams/" + $scope.team.id + "/stats"); $location.url("/teams/" + $scope.team.id + "/stats");