From bd07f69a238428849de32ec6c1e7492f6c232247 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 1 Mar 2016 20:44:14 +0100 Subject: Minor cleanups around the loadProblemData function --- js/codeq/problem_list.js | 20 +++++++++++--------- js/codeq/prolog.js | 7 +++---- js/codeq/python.js | 7 +++---- js/codeq/robot.js | 7 +++---- 4 files changed, 20 insertions(+), 21 deletions(-) (limited to 'js') diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js index 9c19852..268276f 100644 --- a/js/codeq/problem_list.js +++ b/js/codeq/problem_list.js @@ -384,7 +384,7 @@ along with this program. If not, see . */ }); }, - loadProblemData = function(ref, data){ + loadProblemData = function (ref, data) { var language = data.language; return codeq.wait( Q.all([ @@ -392,16 +392,18 @@ along with this program. If not, see . */ 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}; + if (userProblemData.code !== 0) { + throw new Error('Failed to obtain user problem data: ' + userProblemData.message); + } + if (!generalProblemData) { + throw new Error('General problem data is not defined.'); + } + return { + 'generalProblemData': generalProblemData, + 'solution': userProblemData.data.solution + }; }) ); - //while(!generalProblemData1){} - //return [generalProblemData1, userProblemDataSolution]; - //codeq.log.debug("after wait:"+a); }, currentLanguage; // the currently active language diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js index 18e3fdd..1be339f 100644 --- a/js/codeq/prolog.js +++ b/js/codeq/prolog.js @@ -33,16 +33,15 @@ along with this program. If not, see . */ navigationProlog.addClass("active"); navigationProlog.css('display', ''); - jqScreen.css('display', '');//we have to show the screen now so the code editor shows its initial values correctly + jqScreen.css('display', ''); // we have to show the screen now so the code editor shows its initial values correctly prologHandler = createPrologHandler(problemDef, commonDef, currentSolution); }; codeq.globalStateMachine.register('prolog', { 'jqScreen': jqScreen, 'enter': function (ref, data) { - codeq.loadProblemData(ref,data).then(function(problem){ - //codeq.log.debug("then:"+JSON.stringify(problem)); - enterFun(problem.generalProblemData,data.commonDef,problem.solution); + codeq.loadProblemData(ref, data).then(function (problem) { + enterFun(problem.generalProblemData, data.commonDef, problem.solution); }) .fail(function (reason) { codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); diff --git a/js/codeq/python.js b/js/codeq/python.js index 05821e1..9fc34c8 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -31,7 +31,7 @@ along with this program. If not, see . */ navigationPhython.addClass("active"); navigationPhython.css('display', ''); - jqScreen.css('display', '');//we have to show the screen now so the code editor shows its initial values correctly + jqScreen.css('display', ''); // we have to show the screen now so the code editor shows its initial values correctly pythonHandler = createPythonHandler(problemDef, commonDef, currentSolution); }; @@ -39,9 +39,8 @@ along with this program. If not, see . */ 'jqScreen': jqScreen, 'enter': function (ref, data) { - codeq.loadProblemData(ref,data).then(function(problem){ - //codeq.log.debug("then:"+JSON.stringify(problem)); - enterFun(problem.generalProblemData,data.commonDef,problem.solution); + codeq.loadProblemData(ref, data).then(function (problem) { + enterFun(problem.generalProblemData, data.commonDef, problem.solution); }) .fail(function (reason) { codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); diff --git a/js/codeq/robot.js b/js/codeq/robot.js index 70f7c5d..4222d0b 100644 --- a/js/codeq/robot.js +++ b/js/codeq/robot.js @@ -31,7 +31,7 @@ along with this program. If not, see . */ navigationRobot.addClass("active"); navigationRobot.css('display', ''); - jqScreen.css('display', '');//we have to show the screen now so the code editor shows its initial values correctly + jqScreen.css('display', ''); // we have to show the screen now so the code editor shows its initial values correctly robotHandler = createRobotHandler(problemDef, commonDef, currentSolution); }; @@ -39,9 +39,8 @@ along with this program. If not, see . */ 'jqScreen': jqScreen, 'enter': function (ref, data) { - codeq.loadProblemData(ref,data).then(function(problem){ - //codeq.log.debug("then:"+JSON.stringify(problem)); - enterFun(problem.generalProblemData,data.commonDef,problem.solution); + codeq.loadProblemData(ref, data).then(function (problem) { + enterFun(problem.generalProblemData, data.commonDef, problem.solution); }) .fail(function (reason) { codeq.log.error('Failed to obtain the problem definition: ' + reason, reason); -- cgit v1.2.1