frontend: keep answers on screen after submission (lost on refresh)
This commit is contained in:
parent
87b41ab3cc
commit
7b0e8195ff
2 changed files with 18 additions and 16 deletions
|
@ -206,23 +206,31 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
refreshMyInterval = $interval(refreshMy, Math.floor(Math.random() * 24000) + 24000);
|
refreshMyInterval = $interval(refreshMy, Math.floor(Math.random() * 24000) + 24000);
|
||||||
|
|
||||||
$http.get("/my.json").then(function(response) {
|
$http.get("/my.json").then(function(response) {
|
||||||
if (response.data.team_id == 0) {
|
$rootScope.recvMy(response.data);
|
||||||
angular.forEach(response.data.exercices, function(exercice, eid) {
|
}, 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) {
|
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)
|
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
|
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) {
|
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)
|
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(exercice.mcqs, function(mcq, mid) {
|
||||||
angular.forEach(mcq.choices, function(choice, cid) {
|
angular.forEach(mcq.choices, function(choice, cid) {
|
||||||
this[cid] = {
|
this[cid] = {
|
||||||
|
@ -243,14 +251,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
}, mcq.choices);
|
}, mcq.choices);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$rootScope.recvMy(response.data);
|
|
||||||
}, function(response) {
|
|
||||||
if (!$scope.my && response.status == 404) {
|
|
||||||
$location.url("/register");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$rootScope.recvMy = function(data) {
|
|
||||||
$scope.my = data;
|
$scope.my = data;
|
||||||
angular.forEach($scope.my.exercices, function(exercice, eid) {
|
angular.forEach($scope.my.exercices, function(exercice, eid) {
|
||||||
exercice.solved = exercice.solved_rank > 0;
|
exercice.solved = exercice.solved_rank > 0;
|
||||||
|
|
|
@ -86,6 +86,7 @@
|
||||||
<form ng-submit="ssubmit()">
|
<form ng-submit="ssubmit()">
|
||||||
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
|
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
|
||||||
<label for="sol_{{ kid }}">{{ key.label }} :</label>
|
<label for="sol_{{ kid }}">{{ key.label }} :</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">
|
<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>
|
<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>
|
<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">
|
<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>
|
<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">
|
<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>
|
<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">
|
<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>
|
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="choice.solved" title="Flag trouvé !"></span>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
Reference in a new issue