frontend: polish public version checks

This commit is contained in:
nemunaire 2019-01-25 07:26:52 +01:00
parent 85d326db6b
commit db22c4af1b
3 changed files with 38 additions and 9 deletions

View file

@ -19,12 +19,21 @@ function treatFlagKey(flag) {
}
if (flag.found == null && flag.soluce !== undefined) {
if (check === undefined) check = true;
if (flag.value && flag.soluce) {
if (flag.ignore_case)
flag.value = flag.value.toLowerCase();
if (flag.validator_regexp) {
var re = new RegExp(flag.validator_regexp, flag.ignore_case?'ui':'u');
var match = re.exec(flag.value);
match.shift();
flag.value = match.join("+");
}
if (flag.value && flag.soluce == b2sum(flag.value))
flag.found = new Date();
check &= flag.found;
if (flag.soluce == b2sum(flag.value))
flag.found = new Date();
}
}
return flag.found !== undefined && flag.found !== false;
}
angular.module("FICApp", ["ngRoute", "ngSanitize"])
@ -329,7 +338,11 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
angular.forEach(data.exercices, function(exercice, eid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].submitted)
data.exercices[eid].timeouted = true;
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].solved !== undefined)
data.exercices[eid].solved = $scope.my.exercices[eid].solved;
angular.forEach(exercice.flags, function(flag, fid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].found !== undefined)
data.exercices[eid].flags[fid].found = $scope.my.exercices[eid].flags[fid].found;
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].value !== undefined)
data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value;
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].values !== undefined)
@ -337,6 +350,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
else
data.exercices[eid].flags[fid].values = [""];
});
angular.forEach(exercice.mcqs, function(mcq, mid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].mcqs && $scope.my.exercices[eid].mcqs[mid] && $scope.my.exercices[eid].mcqs[mid].solved !== undefined)
data.exercices[eid].mcqs[mid].solved = $scope.my.exercices[eid].mcqs[mid].solved;
});
});
angular.forEach(data.exercices, function(exercice, eid) {
angular.forEach(exercice.mcqs, function(mcq, mid) {
@ -474,18 +491,23 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
{
resp["flags"] = {};
angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
treatFlagKey(flag);
if (flag.found == null && flag.soluce === undefined) {
resp["flags"][kid] = flag.value;
if (check === undefined) check = true;
check &= treatFlagKey(flag) || flag.found;
if (flag.soluce === undefined) {
check = undefined;
if (flag.found == null) {
resp["flags"][kid] = flag.value;
}
}
});
}
if ($scope.my.exercices[$rootScope.current_exercice].mcqs && Object.keys($scope.my.exercices[$rootScope.current_exercice].mcqs).length)
{
var soluce = "";
resp["mcqs"] = {};
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq) {
var soluce = "";
if (mcq.solved == null) {
angular.forEach(mcq.choices, function(choice, cid) {
if (mcq.soluce !== undefined) {