summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq')
-rw-r--r--js/codeq/prolog.js41
-rw-r--r--js/codeq/python.js63
2 files changed, 55 insertions, 49 deletions
diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js
index d01cc54..66ab970 100644
--- a/js/codeq/prolog.js
+++ b/js/codeq/prolog.js
@@ -259,7 +259,10 @@
editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true }),
activityHandler = makeActivityHandler(editor, problem.id),
terminal = makePrologTerminalHandler(jqTerminal, editor, problem.id, activityHandler),
- hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan);
+ hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan),
+ commError = function (error) {
+ alert(error);
+ };
editor.setValue(info.solution);
$('#title').text(problem.slug);
@@ -293,17 +296,15 @@
'program': editor.getDoc().getValue(),
'problem_id': problem.id
})
- .then(
- function hintSuccess(data) {
- if (data.code === 0)
- hinter.handle(data.hints);
- else
- terminal.append(data.message + '\n', 'error');
- },
- function hintFailed (error) {
- terminal.append(error + '\n', 'error');
+ .then(function (data) {
+ if (data.code === 0) {
+ hinter.handle(data.hints);
+ }
+ else {
+ terminal.append(data.message + '\n', 'error');
}
- )
+ })
+ .fail(commError)
.fin(function () {
terminal.inputEnable();
terminal.append('?- ', 'output');
@@ -319,17 +320,15 @@
'program': editor.getDoc().getValue(),
'problem_id': problem.id
})
- .then(
- function testSuccess(data) {
- if (data.code === 0)
- hinter.handle(data.hints);
- else
- terminal.append(data.message + '\n', 'error');
- },
- function testFailed (error) {
- terminal.append(error + '\n', 'error');
+ .then(function (data) {
+ if (data.code === 0) {
+ hinter.handle(data.hints);
}
- )
+ else {
+ terminal.append(data.message + '\n', 'error');
+ }
+ })
+ .fail(commError)
.fin(function () {
terminal.inputEnable();
terminal.append('?- ', 'output');
diff --git a/js/codeq/python.js b/js/codeq/python.js
index 37fdccd..b745a20 100644
--- a/js/codeq/python.js
+++ b/js/codeq/python.js
@@ -220,7 +220,10 @@
editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true, mode: 'python' }),
activityHandler = makeActivityHandler(editor, problem.id),
terminal = makePythonTerminalHandler(jqTerminal, editor, problem.id, activityHandler),
- hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan);
+ hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan),
+ commError = function (error) {
+ alert(error);
+ };
editor.setValue(info.solution);
$('#title').text(problem.slug);
@@ -251,17 +254,17 @@
'language': 'python',
'program': editor.getDoc().getValue(),
'problem_id': problem.id
- }).then(
- function hintSuccess(data) {
- if (data.code === 0)
- hinter.handle(data.hints);
- else
- terminal.append('error: ' + data.message);
- },
- function hintFailed (error) {
- terminal.append('exception: ' + error);
+ })
+ .then(function (data) {
+ if (data.code === 0) {
+ hinter.handle(data.hints);
+ }
+ else {
+ terminal.append('error: ' + data.message);
}
- ).done();
+ })
+ .fail(commError)
+ .done();
});
jqBtnTest.on('click', function () {
var doc = editor.getDoc();
@@ -269,31 +272,35 @@
'language': 'python',
'program': editor.getDoc().getValue(),
'problem_id': problem.id
- }).then(
- function testSuccess(data) {
- if (data.code === 0)
- hinter.handle(data.hints);
- else
- terminal.append('error: ' + data.message);
- },
- function testFailed (error) {
- terminal.append('exception: ' + error);
+ })
+ .then(function (data) {
+ if (data.code === 0) {
+ hinter.handle(data.hints);
+ }
+ else {
+ terminal.append('error: ' + data.message);
}
- ).done();
+ })
+ .fail(commError)
+ .done();
});
jqBtnRun.on('click', function () {
var program = editor.getDoc().getValue();
- // TODO error handling
- codeq.comms.sendPythonStop({});
- codeq.comms.sendPythonExec({
- 'program': program
- });
+ codeq.comms.sendPythonStop({})
+ .then(function () {
+ codeq.comms.sendPythonExec({
+ 'program': program
+ });
+ })
+ .fail(commError)
+ .done();
// focus the terminal
jqTerminal.click();
});
jqBtnStop.on('click', function () {
- // TODO error handling
- codeq.comms.sendPythonStop({});
+ codeq.comms.sendPythonStop({})
+ .fail(commError)
+ .done();
});
// TODO first line of interpreter output is buffered without this, why?