From ca3aa94da7798bba4fed6ae467d8fa94324a832e Mon Sep 17 00:00:00 2001 From: Robert Zorko Date: Wed, 16 Dec 2015 14:05:18 +0100 Subject: moved loading of problem data into the 'enter' of the python, robot and prolog states --- js/codeq/problem_list.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'js/codeq/problem_list.js') diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js index 8c3808e..4e81927 100644 --- a/js/codeq/problem_list.js +++ b/js/codeq/problem_list.js @@ -274,8 +274,8 @@ along with this program. If not, see . */ if (!ref) { codeq.log.error('Clicked on a problem link having erroneous index: ' + index); return; - } - codeq.wait( + }//TODO + /*codeq.wait( Q.all([ codeq.comms.getCurrentSolution(ref.id), // the current user's solution to the selected problem getProblemData(language, ref.g, ref.p) // the (cached) result of processProblemData() @@ -290,7 +290,17 @@ along with this program. If not, see . */ codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); alert('Failed to obtain the problem definition: ' + reason); }) - .done(); + .done();*/ + /*loadProblemData(ref,data).then(function(tmp){ + codeq.log.debug("then:"+JSON.stringify(tmp)); + return tmp; + }) + .fail(function (reason) { + codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); + alert('Failed to obtain the problem definition: ' + reason); + }) + .done(codeq.log.debug("done"));*/ + codeq.globalStateMachine.transition(language,ref,data); }); }, @@ -365,8 +375,30 @@ along with this program. If not, see . */ }); }, + loadProblemData = function(ref, data){ + var language = data.language; + return codeq.wait( + Q.all([ + codeq.comms.getCurrentSolution(ref.id), // the current user's solution to the selected problem + getProblemData(language, ref.g, ref.p) // the (cached) result of processProblemData() + ]) + .spread(function (userProblemData, generalProblemData) { + //codeq.log.debug("spread"); + if (userProblemData.code !== 0) throw new Error('Failed to obtain user problem data, code: ' + userProblemData.code + ', message: ' + userProblemData.message); + if (!generalProblemData) throw new Error('General problem data is not defined'); + //codeq.globalStateMachine.transition(language, generalProblemData, data.commonDef, userProblemData.data.solution); + return {"generalProblemData":generalProblemData,"solution":userProblemData.data.solution}; + }) + ); + //while(!generalProblemData1){} + //return [generalProblemData1, userProblemDataSolution]; + //codeq.log.debug("after wait:"+a); + }, + currentLanguage; // the currently active language + codeq.loadProblemData = loadProblemData; + // ================================================================================ // Initialization, invoked from the boot sequence // ================================================================================ -- cgit v1.2.1