From 3838f7645dbc4320b1c36e99db714aa7870d4026 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 28 Nov 2018 06:40:01 +0100 Subject: [PATCH] frontend: fix race condition in interface --- frontend/static/js/challenge.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index c7e20c30..79d7b3d9 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -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);