diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index 825b1f88..eb5562c0 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -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+)/; diff --git a/app/assets/javascripts/editor/evaluation.js.erb b/app/assets/javascripts/editor/evaluation.js.erb index 8d877a77..a062e4e5 100644 --- a/app/assets/javascripts/editor/evaluation.js.erb +++ b/app/assets/javascripts/editor/evaluation.js.erb @@ -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'); diff --git a/app/assets/javascripts/editor/flowr.js.erb b/app/assets/javascripts/editor/flowr.js.erb index 57cc742b..6440a0b5 100644 --- a/app/assets/javascripts/editor/flowr.js.erb +++ b/app/assets/javascripts/editor/flowr.js.erb @@ -83,9 +83,4 @@ CodeOceanEditorFlowr = { } this.QaApiOutputBuffer = {'stdout': '', 'stderr': ''}; }, - - handleStreamedResponseForCodePilot: function (event) { - this.qa_api.executeCommand('syncOutput', [this.chunkBuffer]); - this.chunkBuffer = [{streamedResponse: true}]; - } }; \ No newline at end of file diff --git a/app/assets/javascripts/editor/turtle.js.erb b/app/assets/javascripts/editor/turtle.js.erb index a6c06ed7..87e5bdc8 100644 --- a/app/assets/javascripts/editor/turtle.js.erb +++ b/app/assets/javascripts/editor/turtle.js.erb @@ -1,11 +1,20 @@ CodeOceanEditorTurtle = { + turtlecanvas: null, + turtlescreen: null, + resetTurtle: true, + initTurtle: function () { - this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas); - if ($('#run').isPresent()) { - $('#run').bind('click', this.hideCanvas); + if (this.resetTurtle) { + this.resetTurtle = false; + this.turtlecanvas = $('#turtlecanvas'); + this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas); } }, + 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'); } - }, + } + }; \ No newline at end of file diff --git a/app/assets/javascripts/editor/websocket.js.erb b/app/assets/javascripts/editor/websocket.js.erb index ee6928d7..f9d5466a 100644 --- a/app/assets/javascripts/editor/websocket.js.erb +++ b/app/assets/javascripts/editor/websocket.js.erb @@ -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.