summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/codeq/problem_list.js38
-rw-r--r--js/codeq/prolog.js48
-rw-r--r--js/codeq/python.js60
-rw-r--r--js/codeq/robot.js56
4 files changed, 173 insertions, 29 deletions
diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js
index e3ce255..645a58a 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 23d8cc7..b772685 100644
--- a/js/codeq/prolog.js
+++ b/js/codeq/prolog.js
@@ -80,12 +80,45 @@ 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', {
'jqScreen': jqScreen,
+ //'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);
- 'enter': function (problemDef, commonDef, currentSolution) {
- $('#navigation-problem_list').css('display', '');
+ history.back();//TODO test
+ })
+ .done();
+ /*$('#navigation-problem_list').css('display', '');
$("#navigation-prolog").addClass("active");
$('#navigation-prolog').css('display', '');
@@ -93,16 +126,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
@@ -116,8 +147,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 b1f46f5..0fb7d2b 100644
--- a/js/codeq/python.js
+++ b/js/codeq/python.js
@@ -86,21 +86,60 @@ 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', {
'jqScreen': jqScreen,
- '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
@@ -112,7 +151,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
@@ -126,8 +165,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 32c3b35..ee6eda6 100644
--- a/js/codeq/robot.js
+++ b/js/codeq/robot.js
@@ -80,12 +80,53 @@ 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', {
'jqScreen': jqScreen,
- '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', '');
@@ -93,9 +134,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
@@ -107,7 +146,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
@@ -121,8 +160,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');
}
});