frontend: fix race condition in interface

This commit is contained in:
nemunaire 2018-11-28 06:40:01 +01:00
parent 3dcb233c3f
commit 3838f7645d

View file

@ -247,12 +247,12 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("SubmissionController", function($scope, $http, $rootScope, $timeout) {
$rootScope.sberr = "";
var waitMy = function() {
if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice]) {
$scope.$watch("my", function(my) {
if (!my || !my.exercices || !my.exercices[$rootScope.current_exercice]) {
$timeout.cancel($scope.cbs);
$scope.cbs = $timeout(waitMy, 420);
} else {
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) {
angular.forEach(my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) {
angular.forEach(mcq["choices"], function(choice,cid) {
this[cid] = {
label: choice,
@ -265,8 +265,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}, mcq["choices"]);
}, $scope.mcqs);
}
}
waitMy();
});
$scope.ssubmit = function() {
var resp = {"flags":{}}
@ -348,7 +347,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
if ($scope.my.exercices[$rootScope.current_exercice].tries != my.exercices[$rootScope.current_exercice].tries || $scope.my.exercices[$rootScope.current_exercice].solved_time != my.exercices[$rootScope.current_exercice].solved_time) {
$rootScope.refresh();
$scope.my = my;
waitMy();
} else {
$timeout.cancel($scope.cbd);
$scope.cbd = $timeout(checkDiff, 750);