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,
websocket: null,
turtlescreen: null,
numMessages: 0,
turtlecanvas: $('#turtlecanvas'),
prompt: $('#prompt'),
commands: ['input', 'write', 'turtle', 'turtlebatch', 'render', 'exit', 'timeout', 'status'],
streams: ['stdin', 'stdout', 'stderr'],
@ -191,7 +189,7 @@ var CodeOceanEditor = {
resetSaveTimer: function () {
clearTimeout(this.autosaveTimer);
this.autosaveTimer = setTimeout(this.autosave, this.AUTOSAVE_INTERVAL);
this.autosaveTimer = setTimeout(this.autosave.bind(this), this.AUTOSAVE_INTERVAL);
},
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() {
if(this.REMEMBER_TAB){
var regexp = /tab=(\d+)/;

View File

@ -2,10 +2,7 @@ CodeOceanEditorEvaluation = {
chunkBuffer: [{streamedResponse: true}],
evaluateCode: function (url, onmessageFunction) {
this.initWebsocketConnection(url, onmessageFunction);
// TODO only init turtle when required
this.initTurtle();
this.initWebsocketConnection(url, onmessageFunction);;
},
handleScoringResponse: function (websocket_event) {
@ -120,7 +117,7 @@ CodeOceanEditorEvaluation = {
stopCode: function (event) {
event.preventDefault();
if ($('#stop').is(':visible')) {
if (this.isActiveFileStoppable()) {
if (this.runmode == this.WEBSOCKET) {
this.killWebsocketAndContainer();
} else if (this.runmode == this.SERVER_SEND_EVENT) {
@ -159,22 +156,6 @@ CodeOceanEditorEvaluation = {
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
showPrompt: function(msg) {
var label = $('#prompt .input-group-addon');

View File

@ -83,9 +83,4 @@ CodeOceanEditorFlowr = {
}
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 = {
turtlecanvas: null,
turtlescreen: null,
resetTurtle: true,
initTurtle: function () {
if (this.resetTurtle) {
this.resetTurtle = false;
this.turtlecanvas = $('#turtlecanvas');
this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas);
if ($('#run').isPresent()) {
$('#run').bind('click', this.hideCanvas);
}
},
cleanUpTurtle: function() {
this.resetTurtle = true;
},
handleTurtleCommand: function (msg) {
if (msg.action in this.turtlescreen) {
var result = this.turtlescreen[msg.action].apply(this.turtlescreen, msg.args);
@ -29,6 +38,7 @@ CodeOceanEditorTurtle = {
// initialize two-column layout
$('#output-col1').addClass('col-lg-7 col-md-7 two-column');
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');
}
this.turtlecanvas.addClass('hidden');
//this.turtlecanvas.parent().parent().addClass('hidden');
}
},
}
};

View File

@ -34,10 +34,12 @@ CodeOceanEditorWebsocket = {
this.printWebsocketOutput(msg);
break;
case 'turtle':
this.initTurtle();
this.showCanvas();
this.handleTurtleCommand(msg);
break;
case 'turtlebatch':
this.initTurtle();
this.showCanvas();
this.handleTurtlebatchCommand(msg);
break;
@ -49,6 +51,7 @@ CodeOceanEditorWebsocket = {
this.handleQaApiOutput();
this.handleStderrOutputForFlowr();
this.augmentStacktraceInOutput();
this.cleanUpTurtle();
break;
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.