frontend: keep answers on screen after submission (lost on refresh)

This commit is contained in:
nemunaire 2018-12-02 01:24:38 +01:00
commit 7b0e8195ff
2 changed files with 18 additions and 16 deletions

View file

@ -206,23 +206,31 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
refreshMyInterval = $interval(refreshMy, Math.floor(Math.random() * 24000) + 24000);
$http.get("/my.json").then(function(response) {
if (response.data.team_id == 0) {
angular.forEach(response.data.exercices, function(exercice, eid) {
$rootScope.recvMy(response.data);
}, function(response) {
if (!$scope.my && response.status == 404) {
$location.url("/register");
}
});
}
$rootScope.recvMy = function(data) {
if (data.team_id == 0) {
angular.forEach(data.exercices, function(exercice, eid) {
angular.forEach(exercice.hints, function(hint, hid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].hints[hid] && $scope.my.exercices[eid].hints[hid].hidden !== undefined)
response.data.exercices[eid].hints[hid].hidden = $scope.my.exercices[eid].hints[hid].hidden;
data.exercices[eid].hints[hid].hidden = $scope.my.exercices[eid].hints[hid].hidden;
else
response.data.exercices[eid].hints[hid].hidden = true;
data.exercices[eid].hints[hid].hidden = true;
});
});
}
angular.forEach(response.data.exercices, function(exercice, eid) {
angular.forEach(data.exercices, function(exercice, eid) {
angular.forEach(exercice.flags, function(flag, fid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].value !== undefined)
response.data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value;
data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value;
});
});
angular.forEach(response.data.exercices, function(exercice, eid) {
angular.forEach(data.exercices, function(exercice, eid) {
angular.forEach(exercice.mcqs, function(mcq, mid) {
angular.forEach(mcq.choices, function(choice, cid) {
this[cid] = {
@ -243,14 +251,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}, mcq.choices);
});
});
$rootScope.recvMy(response.data);
}, function(response) {
if (!$scope.my && response.status == 404) {
$location.url("/register");
}
});
}
$rootScope.recvMy = function(data) {
$scope.my = data;
angular.forEach($scope.my.exercices, function(exercice, eid) {
exercice.solved = exercice.solved_rank > 0;