Sending command 'client_kill' on stop button click now.
Killing a container only if command client_kill was send. Moved propmpt to prompt.js
This commit is contained in:
@ -11,7 +11,8 @@ $(function() {
|
||||
CodeOceanEditorFlowr,
|
||||
CodeOceanEditorSubmissions,
|
||||
CodeOceanEditorTurtle,
|
||||
CodeOceanEditorWebsocket
|
||||
CodeOceanEditorWebsocket,
|
||||
CodeOceanEditorPrompt
|
||||
);
|
||||
|
||||
if ($('#editor').isPresent() && CodeOceanEditor) {
|
||||
|
@ -28,7 +28,6 @@ var CodeOceanEditor = {
|
||||
output_mode_is_streaming: true,
|
||||
|
||||
numMessages: 0,
|
||||
prompt: '#prompt',
|
||||
lastCopyText: null,
|
||||
|
||||
autosaveTimer: null,
|
||||
|
@ -111,82 +111,27 @@ CodeOceanEditorEvaluation = {
|
||||
stopCode: function (event) {
|
||||
event.preventDefault();
|
||||
if (this.isActiveFileStoppable()) {
|
||||
this.killWebsocketAndContainer();
|
||||
this.websocket.send(JSON.stringify({'cmd': 'client_kill'}));
|
||||
this.killWebsocket();
|
||||
this.cleanUpUI();
|
||||
}
|
||||
},
|
||||
|
||||
stopCodeServerSendEvent: function (event) {
|
||||
var jqxhr = this.ajax({
|
||||
data: {
|
||||
container_id: $('#stop').data('container').id
|
||||
},
|
||||
url: $('#stop').data('url')
|
||||
});
|
||||
jqxhr.always(function () {
|
||||
this.hideSpinner();
|
||||
this.running = false;
|
||||
this.toggleButtonStates();
|
||||
}.bind(this));
|
||||
jqxhr.fail(ajaxError);
|
||||
},
|
||||
|
||||
killWebsocketAndContainer: function () {
|
||||
if (this.websocket.getReadyState() != WebSocket.OPEN) {
|
||||
killWebsocket: function () {
|
||||
if (this.websocket != null && this.websocket.getReadyState() != WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.websocket.send(JSON.stringify({cmd: 'exit'}));
|
||||
this.websocket.killWebSocket();
|
||||
|
||||
this.hideSpinner();
|
||||
this.running = false;
|
||||
},
|
||||
|
||||
cleanUpUI: function() {
|
||||
this.hideSpinner();
|
||||
this.toggleButtonStates();
|
||||
this.hidePrompt();
|
||||
},
|
||||
|
||||
//TODO: Move Prompt Part in own component
|
||||
showPrompt: function(msg) {
|
||||
var label = $('#prompt .input-group-addon');
|
||||
var prompt = $(this.prompt);
|
||||
label.text(msg.data || label.data('prompt'));
|
||||
if (prompt.isPresent() && prompt.hasClass('hidden')) {
|
||||
prompt.removeClass('hidden');
|
||||
}
|
||||
$('#prompt input').focus();
|
||||
},
|
||||
|
||||
hidePrompt: function() {
|
||||
var prompt = $(this.prompt);
|
||||
if (prompt.isPresent() && !prompt.hasClass('hidden')) {
|
||||
prompt.addClass('hidden');
|
||||
}
|
||||
},
|
||||
|
||||
initPrompt: function() {
|
||||
if ($('#run').isPresent()) {
|
||||
$('#run').bind('click', this.hidePrompt.bind(this));
|
||||
}
|
||||
if ($('#prompt').isPresent()) {
|
||||
$('#prompt').on('keypress', this.handlePromptKeyPress.bind(this));
|
||||
$('#prompt-submit').on('click', this.submitPromptInput.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
submitPromptInput: function() {
|
||||
var input = $('#prompt-input');
|
||||
var message = input.val();
|
||||
this.websocket.send(JSON.stringify({cmd: 'result', 'data': message}));
|
||||
this.websocket.flush();
|
||||
input.val('');
|
||||
this.hidePrompt();
|
||||
},
|
||||
|
||||
handlePromptKeyPress: function(evt) {
|
||||
if (evt.which === this.ENTER_KEY_CODE) {
|
||||
this.submitPromptInput();
|
||||
}
|
||||
},
|
||||
|
||||
renderWebsocketOutput: function(msg){
|
||||
var element = this.findOrCreateRenderElement(0);
|
||||
element.append(msg.data);
|
||||
|
@ -39,10 +39,11 @@ CodeOceanEditorWebsocket = {
|
||||
},
|
||||
|
||||
handleExitCommand: function() {
|
||||
this.killWebsocketAndContainer();
|
||||
this.killWebsocket();
|
||||
this.handleQaApiOutput();
|
||||
this.handleStderrOutputForFlowr();
|
||||
this.augmentStacktraceInOutput();
|
||||
this.cleanUpTurtle();
|
||||
this.cleanUpUI();
|
||||
}
|
||||
};
|
45
app/assets/javascripts/editor/prompt.js
Normal file
45
app/assets/javascripts/editor/prompt.js
Normal file
@ -0,0 +1,45 @@
|
||||
CodeOceanEditorPrompt = {
|
||||
prompt: '#prompt',
|
||||
|
||||
showPrompt: function(msg) {
|
||||
var label = $('#prompt .input-group-addon');
|
||||
var prompt = $(this.prompt);
|
||||
label.text(msg.data || label.data('prompt'));
|
||||
if (prompt.isPresent() && prompt.hasClass('hidden')) {
|
||||
prompt.removeClass('hidden');
|
||||
}
|
||||
$('#prompt input').focus();
|
||||
},
|
||||
|
||||
hidePrompt: function() {
|
||||
var prompt = $(this.prompt);
|
||||
if (prompt.isPresent() && !prompt.hasClass('hidden')) {
|
||||
prompt.addClass('hidden');
|
||||
}
|
||||
},
|
||||
|
||||
initPrompt: function() {
|
||||
if ($('#run').isPresent()) {
|
||||
$('#run').bind('click', this.hidePrompt.bind(this));
|
||||
}
|
||||
if ($('#prompt').isPresent()) {
|
||||
$('#prompt').on('keypress', this.handlePromptKeyPress.bind(this));
|
||||
$('#prompt-submit').on('click', this.submitPromptInput.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
submitPromptInput: function() {
|
||||
var input = $('#prompt-input');
|
||||
var message = input.val();
|
||||
this.websocket.send(JSON.stringify({cmd: 'result', 'data': message}));
|
||||
this.websocket.flush();
|
||||
input.val('');
|
||||
this.hidePrompt();
|
||||
},
|
||||
|
||||
handlePromptKeyPress: function(evt) {
|
||||
if (evt.which === this.ENTER_KEY_CODE) {
|
||||
this.submitPromptInput();
|
||||
}
|
||||
}
|
||||
};
|
@ -139,12 +139,12 @@ class SubmissionsController < ApplicationController
|
||||
tubesock.onmessage do |data|
|
||||
Rails.logger.info(Time.now.getutc.to_s + ": Client sending: " + data)
|
||||
# Check whether the client send a JSON command and kill container
|
||||
# if the command is 'exit', send it to docker otherwise.
|
||||
# if the command is 'client_exit', send it to docker otherwise.
|
||||
begin
|
||||
parsed = JSON.parse(data)
|
||||
if parsed['cmd'] == 'exit'
|
||||
if parsed['cmd'] == 'client_kill'
|
||||
Rails.logger.debug("Client exited container.")
|
||||
@docker_client.exit_container(result[:container])
|
||||
@docker_client.kill_container(result[:container])
|
||||
else
|
||||
socket.send data
|
||||
Rails.logger.debug('Sent the received client data to docker:' + data)
|
||||
|
Reference in New Issue
Block a user