Fixed turtle.

This commit is contained in:
Alexander Kastius
2016-08-12 14:42:35 +02:00
parent fbb1cfb67b
commit 0ca52a9b8f
5 changed files with 22 additions and 45 deletions

View File

@ -31,9 +31,7 @@ var CodeOceanEditor = {
runmode: this.NONE, runmode: this.NONE,
websocket: null, websocket: null,
turtlescreen: null,
numMessages: 0, numMessages: 0,
turtlecanvas: $('#turtlecanvas'),
prompt: $('#prompt'), prompt: $('#prompt'),
commands: ['input', 'write', 'turtle', 'turtlebatch', 'render', 'exit', 'timeout', 'status'], commands: ['input', 'write', 'turtle', 'turtlebatch', 'render', 'exit', 'timeout', 'status'],
streams: ['stdin', 'stdout', 'stderr'], streams: ['stdin', 'stdout', 'stderr'],
@ -191,7 +189,7 @@ var CodeOceanEditor = {
resetSaveTimer: function () { resetSaveTimer: function () {
clearTimeout(this.autosaveTimer); clearTimeout(this.autosaveTimer);
this.autosaveTimer = setTimeout(this.autosave, this.AUTOSAVE_INTERVAL); this.autosaveTimer = setTimeout(this.autosave.bind(this), this.AUTOSAVE_INTERVAL);
}, },
autosave: function () { autosave: function () {
@ -478,18 +476,6 @@ var CodeOceanEditor = {
}; };
}, },
closeEventSource: function (event) {
event.target.close();
this.hideSpinner();
this.running = false;
this.toggleButtonStates();
if (event.type === 'error' || JSON.parse(event.data).code !== 200) {
this.ajaxError();
this.showTab(0);
}
},
showRequestedTab: function() { showRequestedTab: function() {
if(this.REMEMBER_TAB){ if(this.REMEMBER_TAB){
var regexp = /tab=(\d+)/; var regexp = /tab=(\d+)/;

View File

@ -2,10 +2,7 @@ CodeOceanEditorEvaluation = {
chunkBuffer: [{streamedResponse: true}], chunkBuffer: [{streamedResponse: true}],
evaluateCode: function (url, onmessageFunction) { evaluateCode: function (url, onmessageFunction) {
this.initWebsocketConnection(url, onmessageFunction); this.initWebsocketConnection(url, onmessageFunction);;
// TODO only init turtle when required
this.initTurtle();
}, },
handleScoringResponse: function (websocket_event) { handleScoringResponse: function (websocket_event) {
@ -120,7 +117,7 @@ CodeOceanEditorEvaluation = {
stopCode: function (event) { stopCode: function (event) {
event.preventDefault(); event.preventDefault();
if ($('#stop').is(':visible')) { if (this.isActiveFileStoppable()) {
if (this.runmode == this.WEBSOCKET) { if (this.runmode == this.WEBSOCKET) {
this.killWebsocketAndContainer(); this.killWebsocketAndContainer();
} else if (this.runmode == this.SERVER_SEND_EVENT) { } else if (this.runmode == this.SERVER_SEND_EVENT) {
@ -159,22 +156,6 @@ CodeOceanEditorEvaluation = {
this.hidePrompt(); this.hidePrompt();
}, },
// todo set this from websocket command, required to e.g. stop container
storeContainerInformation: function (event) {
var container_information = JSON.parse(event.data);
$('#stop').data('container', container_information);
if (_.size(container_information.port_bindings) > 0) {
$.flash.info({
icon: ['fa', 'fa-exchange'],
text: _.map(container_information.port_bindings, function (key, value) {
var url = window.location.protocol + '//' + window.location.hostname + ':' + key;
return $('#run').data('message-network').replace('%{port}', value).replace(/%{address}/g, url);
}).join('\n')
});
}
},
//TODO: Move Prompt Part in own component //TODO: Move Prompt Part in own component
showPrompt: function(msg) { showPrompt: function(msg) {
var label = $('#prompt .input-group-addon'); var label = $('#prompt .input-group-addon');

View File

@ -83,9 +83,4 @@ CodeOceanEditorFlowr = {
} }
this.QaApiOutputBuffer = {'stdout': '', 'stderr': ''}; this.QaApiOutputBuffer = {'stdout': '', 'stderr': ''};
}, },
handleStreamedResponseForCodePilot: function (event) {
this.qa_api.executeCommand('syncOutput', [this.chunkBuffer]);
this.chunkBuffer = [{streamedResponse: true}];
}
}; };

View File

@ -1,11 +1,20 @@
CodeOceanEditorTurtle = { CodeOceanEditorTurtle = {
turtlecanvas: null,
turtlescreen: null,
resetTurtle: true,
initTurtle: function () { initTurtle: function () {
this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas); if (this.resetTurtle) {
if ($('#run').isPresent()) { this.resetTurtle = false;
$('#run').bind('click', this.hideCanvas); this.turtlecanvas = $('#turtlecanvas');
this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas);
} }
}, },
cleanUpTurtle: function() {
this.resetTurtle = true;
},
handleTurtleCommand: function (msg) { handleTurtleCommand: function (msg) {
if (msg.action in this.turtlescreen) { if (msg.action in this.turtlescreen) {
var result = this.turtlescreen[msg.action].apply(this.turtlescreen, msg.args); var result = this.turtlescreen[msg.action].apply(this.turtlescreen, msg.args);
@ -29,6 +38,7 @@ CodeOceanEditorTurtle = {
// initialize two-column layout // initialize two-column layout
$('#output-col1').addClass('col-lg-7 col-md-7 two-column'); $('#output-col1').addClass('col-lg-7 col-md-7 two-column');
this.turtlecanvas.removeClass('hidden'); this.turtlecanvas.removeClass('hidden');
//this.turtlecanvas.parent().parent().removeClass('hidden');
} }
}, },
@ -40,6 +50,8 @@ CodeOceanEditorTurtle = {
output.removeClass('col-lg-7 col-md-7 two-column'); output.removeClass('col-lg-7 col-md-7 two-column');
} }
this.turtlecanvas.addClass('hidden'); this.turtlecanvas.addClass('hidden');
//this.turtlecanvas.parent().parent().addClass('hidden');
} }
}, }
}; };

View File

@ -34,10 +34,12 @@ CodeOceanEditorWebsocket = {
this.printWebsocketOutput(msg); this.printWebsocketOutput(msg);
break; break;
case 'turtle': case 'turtle':
this.initTurtle();
this.showCanvas(); this.showCanvas();
this.handleTurtleCommand(msg); this.handleTurtleCommand(msg);
break; break;
case 'turtlebatch': case 'turtlebatch':
this.initTurtle();
this.showCanvas(); this.showCanvas();
this.handleTurtlebatchCommand(msg); this.handleTurtlebatchCommand(msg);
break; break;
@ -49,6 +51,7 @@ CodeOceanEditorWebsocket = {
this.handleQaApiOutput(); this.handleQaApiOutput();
this.handleStderrOutputForFlowr(); this.handleStderrOutputForFlowr();
this.augmentStacktraceInOutput(); this.augmentStacktraceInOutput();
this.cleanUpTurtle();
break; break;
case 'timeout': case 'timeout':
// just show the timeout message here. Another exit command is sent by the rails backend when the socket to the docker container closes. // just show the timeout message here. Another exit command is sent by the rails backend when the socket to the docker container closes.