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

This commit is contained in:
nemunaire 2018-12-02 01:24:38 +01:00
parent 87b41ab3cc
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;

View file

@ -86,6 +86,7 @@
<form ng-submit="ssubmit()">
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
<label for="sol_{{ kid }}">{{ key.label }}&nbsp;:</label>
<span ng-if="key.found && key.value" ng-bind="key.value"></span>
<input type="text" class="form-control" id="sol_{{ kid }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && !key.choices">
<select class="custom-select" id="sol_{{ kid }}" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && key.choices" ng-options="l as v for (l, v) in key.choices"></select>
<small class="form-text text-muted" ng-if="!key.found && key.help.length > 0" ng-bind="key.help"></small>
@ -94,10 +95,11 @@
<div class="form-check" ng-repeat="(k,mcq) in my.exercices[current_exercice].mcqs">
<p ng-if="mcq.title">{{ mcq.title }} <span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="mcq.solved" title="QCM réussi à {{ mcq.solved | date:'mediumTime'}}"></span></p>
<div class="custom-control custom-checkbox" ng-repeat="(cid,choice) in mcq.choices" ng-if="!mcq.solved">
<div class="custom-control custom-checkbox" ng-repeat="(cid,choice) in mcq.choices" ng-if="!mcq.solved || mcq.justify">
<input class="custom-control-input" type="checkbox" id="mcq_{{k}}_{{cid}}" name="mcq_{{k}}_{{cid}}" ng-model="choice.value" ng-disabled="choice.disabled">
<label class="custom-control-label" for="mcq_{{k}}_{{cid}}" ng-bind="choice.label"></label>
<input type="text" class="form-control" autocomplete="off" placeholder="Flag correspondant" name="sol_{{ cid }}" ng-model="choice.justify" ng-if="choice.value && mcq.justify && !choice.solved">
<span ng-if="choice.value && mcq.justify && choice.solved" ng-bind="choice.justify"></span>
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="choice.solved" title="Flag trouvé !"></span>
</div>
<hr>