summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Zorko <robertz@gurucue.com>2015-12-16 14:05:18 +0100
committerRobert Zorko <robertz@gurucue.com>2015-12-16 14:05:18 +0100
commitca3aa94da7798bba4fed6ae467d8fa94324a832e (patch)
tree5b339da7fba0f2c95b093828908ac944e3c899cb
parent2d4b5b535c2a3df875a0a3c97cdd25ed67275b29 (diff)
moved loading of problem data into the 'enter' of the python, robot and prolog states
-rw-r--r--js/codeq/problem_list.js38
-rw-r--r--js/codeq/prolog.js49
-rw-r--r--js/codeq/python.js60
-rw-r--r--js/codeq/robot.js56
4 files changed, 174 insertions, 29 deletions
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 <http://www.gnu.org/licenses/>. */
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 <http://www.gnu.org/licenses/>. */
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 <http://www.gnu.org/licenses/>. */
});
},
+ 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
// ================================================================================
diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js
index 7f74aaf..0bbf547 100644
--- a/js/codeq/prolog.js
+++ b/js/codeq/prolog.js
@@ -80,10 +80,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
}
}
};
+
+ var enterFun = function(problemDef, commonDef, currentSolution){
+ $('#navigation-problem_list').css('display', '');
+ var navigationProlog = $("#navigation-prolog");
+ 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
+ prologHandler = createPrologHandler(problemDef, commonDef, currentSolution);
+ subScreens = codeq.makeStateMachine(substates);
+ subScreens.transition(jqDescription.data(stateNameTag));
+
+ jqAllButtons.on(transitionEventName, function (event) {
+ subScreens.transition('info'); // set focus on the hints quadrant
+ event.stopPropagation(); // don't allow the event to go on and trigger further transition
+ });
+ jqAllQuadrants.on(transitionEventName, function () {
+ subScreens.transition($(this).data(stateNameTag));
+ });
+ };
+
var prologHandler; //created when we enter the prolog state and destroyed once we leave it
codeq.globalStateMachine.register('prolog', {
- 'enter': function (problemDef, commonDef, currentSolution) {
- $('#navigation-problem_list').css('display', '');
+ //'enter': function (problemDef, commonDef, currentSolution) {
+ 'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
+
+ codeq.loadProblemData(ref,data).then(function(problem){
+ //codeq.log.debug("then:"+JSON.stringify(problem));
+ enterFun(problem.generalProblemData,data.commonDef,problem.solution);
+ })
+ .fail(function (reason) {
+ codeq.log.error('Failed to obtain the problem definition: ' + reason, reason);
+ alert('Failed to obtain the problem definition: ' + reason);
+
+ history.back();//TODO test
+ })
+ .done();
+ /*$('#navigation-problem_list').css('display', '');
$("#navigation-prolog").addClass("active");
$('#navigation-prolog').css('display', '');
@@ -91,16 +125,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
prologHandler = createPrologHandler(problemDef, commonDef, currentSolution);
subScreens = codeq.makeStateMachine(substates);
subScreens.transition(jqDescription.data(stateNameTag));
-/* Q.delay(100).then(function(){
- jqAllQuadrants.addClass('transition');//for smooth animations - need to be delayed, because otherwise we get some weird "animations" while the page is loading
- }).done();*/
+
jqAllButtons.on(transitionEventName, function (event) {
subScreens.transition('info'); // set focus on the hints quadrant
event.stopPropagation(); // don't allow the event to go on and trigger further transition
});
jqAllQuadrants.on(transitionEventName, function () {
subScreens.transition($(this).data(stateNameTag));
- });
+ });*/
},
'exit': function () {
jqAllButtons.off(); // unregister all event handlers
@@ -114,8 +146,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqScreen.addClass('block1');
$('#navigation-problem_list').css('display', 'none');
- $("#navigation-prolog").removeClass("active");
- $('#navigation-prolog').css('display', 'none');
+ var navigationProlog = $("#navigation-prolog");
+ navigationProlog.removeClass("active");
+ navigationProlog.css('display', 'none');
}
});
diff --git a/js/codeq/python.js b/js/codeq/python.js
index 4033a63..472d700 100644
--- a/js/codeq/python.js
+++ b/js/codeq/python.js
@@ -86,19 +86,58 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
}
};
var pythonHandler; //created when we enter the python state and destroyed once we leave it
+
+ var enterFun = function(problemDef, commonDef, currentSolution){
+ $('#navigation-problem_list').css('display', '');
+ var navigationPhython = $("#navigation-python");
+ 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
+ pythonHandler = createPythonHandler(problemDef, commonDef, currentSolution);
+ subScreens = codeq.makeStateMachine(substates);
+ subScreens.transition(jqDescription.data(stateNameTag));
+
+ jqInfoButtons.on(transitionEventName, function (event) {
+ subScreens.transition('info'); // set focus on the hints quadrant
+ event.stopPropagation(); // don't allow the event to go on and trigger further transition
+ });
+ jqBtnRun.on(transitionEventName, function (event) {
+ subScreens.transition('console'); // set focus on the hints quadrant
+ event.stopPropagation(); // don't allow the event to go on and trigger further transition
+ });
+
+ jqAllQuadrants.on(transitionEventName, function () {
+ subScreens.transition($(this).data(stateNameTag));
+ });
+ };
+
codeq.globalStateMachine.register('python', {
- 'enter': function (problemDef, commonDef, currentSolution) {
- $('#navigation-problem_list').css('display', '');
- $("#navigation-python").addClass("active");
- $('#navigation-python').css('display', '');
+ 'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
+
+ codeq.loadProblemData(ref,data).then(function(problem){
+ //codeq.log.debug("then:"+JSON.stringify(problem));
+ enterFun(problem.generalProblemData,data.commonDef,problem.solution);
+ })
+ .fail(function (reason) {
+ codeq.log.error('Failed to obtain the problem definition: ' + reason, reason);
+ alert('Failed to obtain the problem definition: ' + reason);
+
+ history.back();//TODO test
+ })
+ .done();
+
+
+ /*$('#navigation-problem_list').css('display', '');
+ var navigationPhython = $("#navigation-python");
+ 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
pythonHandler = createPythonHandler(problemDef, commonDef, currentSolution);
subScreens = codeq.makeStateMachine(substates);
subScreens.transition(jqDescription.data(stateNameTag));
-/* Q.delay(100).then(function(){
- jqAllQuadrants.addClass('transition');//for smooth animations - need to be delayed, because otherwise we get some weird "animations" while the page is loading
- }).done();*/
+
jqInfoButtons.on(transitionEventName, function (event) {
subScreens.transition('info'); // set focus on the hints quadrant
event.stopPropagation(); // don't allow the event to go on and trigger further transition
@@ -110,7 +149,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqAllQuadrants.on(transitionEventName, function () {
subScreens.transition($(this).data(stateNameTag));
- });
+ });*/
},
'exit': function () {
jqAllButtons.off(); // unregister all event handlers
@@ -124,8 +163,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqScreen.addClass('block1');
$('#navigation-problem_list').css('display', 'none');
- $("#navigation-python").removeClass("active");
- $('#navigation-python').css('display', 'none');
+ var navigationPhython = $("#navigation-python");
+ navigationPhython.removeClass("active");
+ navigationPhython.css('display', 'none');
}
});
diff --git a/js/codeq/robot.js b/js/codeq/robot.js
index 0dca6f3..ffccc62 100644
--- a/js/codeq/robot.js
+++ b/js/codeq/robot.js
@@ -80,10 +80,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
}
}
};
+
+ var enterFun = function(problemDef, commonDef, currentSolution){
+ $('#navigation-problem_list').css('display', '');
+ var navigationRobot = $("#navigation-robot");
+ 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
+ robotHandler = createRobotHandler(problemDef, commonDef, currentSolution);
+ subScreens = codeq.makeStateMachine(substates);
+ subScreens.transition(jqDescription.data(stateNameTag));
+
+ jqInfoButtons.on(transitionEventName, function (event) {
+ subScreens.transition('info'); // set focus on the hints quadrant
+ event.stopPropagation(); // don't allow the event to go on and trigger further transition
+ });
+ jqBtnRun.on(transitionEventName, function (event) {
+ subScreens.transition('console'); // set focus on the hints quadrant
+ event.stopPropagation(); // don't allow the event to go on and trigger further transition
+ });
+
+ jqAllQuadrants.on(transitionEventName, function () {
+ subScreens.transition($(this).data(stateNameTag));
+ });
+ };
+
var robotHandler; //created when we enter the robot state and destroyed once we leave it
codeq.globalStateMachine.register('robot', {
- 'enter': function (problemDef, commonDef, currentSolution) {
- $('#navigation-problem_list').css('display', '');
+ //'enter': function (problemDef, commonDef, currentSolution) {
+ 'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
+
+ codeq.loadProblemData(ref,data).then(function(problem){
+ //codeq.log.debug("then:"+JSON.stringify(problem));
+ enterFun(problem.generalProblemData,data.commonDef,problem.solution);
+ })
+ .fail(function (reason) {
+ codeq.log.error('Failed to obtain the problem definition: ' + reason, reason);
+ alert('Failed to obtain the problem definition: ' + reason);
+
+ history.back();//TODO test
+ })
+ .done();
+
+
+ /*$('#navigation-problem_list').css('display', '');
$("#navigation-robot").addClass("active");
$('#navigation-robot').css('display', '');
@@ -91,9 +132,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
robotHandler = createRobotHandler(problemDef, commonDef, currentSolution);
subScreens = codeq.makeStateMachine(substates);
subScreens.transition(jqDescription.data(stateNameTag));
-/* Q.delay(100).then(function(){
- jqAllQuadrants.addClass('transition');//for smooth animations - need to be delayed, because otherwise we get some weird "animations" while the page is loading
- }).done();*/
+
jqInfoButtons.on(transitionEventName, function (event) {
subScreens.transition('info'); // set focus on the hints quadrant
event.stopPropagation(); // don't allow the event to go on and trigger further transition
@@ -105,7 +144,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqAllQuadrants.on(transitionEventName, function () {
subScreens.transition($(this).data(stateNameTag));
- });
+ });*/
},
'exit': function () {
jqAllButtons.off(); // unregister all event handlers
@@ -119,8 +158,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqScreen.addClass('block1');
$('#navigation-problem_list').css('display', 'none');
- $("#navigation-robot").removeClass("active");
- $('#navigation-robot').css('display', 'none');
+ var navigationRobot = $("#navigation-robot");
+ navigationRobot.removeClass("active");
+ navigationRobot.css('display', 'none');
}
});