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,
|
CodeOceanEditorFlowr,
|
||||||
CodeOceanEditorSubmissions,
|
CodeOceanEditorSubmissions,
|
||||||
CodeOceanEditorTurtle,
|
CodeOceanEditorTurtle,
|
||||||
CodeOceanEditorWebsocket
|
CodeOceanEditorWebsocket,
|
||||||
|
CodeOceanEditorPrompt
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($('#editor').isPresent() && CodeOceanEditor) {
|
if ($('#editor').isPresent() && CodeOceanEditor) {
|
||||||
|
@ -28,7 +28,6 @@ var CodeOceanEditor = {
|
|||||||
output_mode_is_streaming: true,
|
output_mode_is_streaming: true,
|
||||||
|
|
||||||
numMessages: 0,
|
numMessages: 0,
|
||||||
prompt: '#prompt',
|
|
||||||
lastCopyText: null,
|
lastCopyText: null,
|
||||||
|
|
||||||
autosaveTimer: null,
|
autosaveTimer: null,
|
||||||
|
@ -111,82 +111,27 @@ CodeOceanEditorEvaluation = {
|
|||||||
stopCode: function (event) {
|
stopCode: function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (this.isActiveFileStoppable()) {
|
if (this.isActiveFileStoppable()) {
|
||||||
this.killWebsocketAndContainer();
|
this.websocket.send(JSON.stringify({'cmd': 'client_kill'}));
|
||||||
|
this.killWebsocket();
|
||||||
|
this.cleanUpUI();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
stopCodeServerSendEvent: function (event) {
|
killWebsocket: function () {
|
||||||
var jqxhr = this.ajax({
|
if (this.websocket != null && this.websocket.getReadyState() != WebSocket.OPEN) {
|
||||||
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) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify({cmd: 'exit'}));
|
|
||||||
this.websocket.killWebSocket();
|
this.websocket.killWebSocket();
|
||||||
|
|
||||||
this.hideSpinner();
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
cleanUpUI: function() {
|
||||||
|
this.hideSpinner();
|
||||||
this.toggleButtonStates();
|
this.toggleButtonStates();
|
||||||
this.hidePrompt();
|
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){
|
renderWebsocketOutput: function(msg){
|
||||||
var element = this.findOrCreateRenderElement(0);
|
var element = this.findOrCreateRenderElement(0);
|
||||||
element.append(msg.data);
|
element.append(msg.data);
|
||||||
|
@ -39,10 +39,11 @@ CodeOceanEditorWebsocket = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleExitCommand: function() {
|
handleExitCommand: function() {
|
||||||
this.killWebsocketAndContainer();
|
this.killWebsocket();
|
||||||
this.handleQaApiOutput();
|
this.handleQaApiOutput();
|
||||||
this.handleStderrOutputForFlowr();
|
this.handleStderrOutputForFlowr();
|
||||||
this.augmentStacktraceInOutput();
|
this.augmentStacktraceInOutput();
|
||||||
this.cleanUpTurtle();
|
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|
|
tubesock.onmessage do |data|
|
||||||
Rails.logger.info(Time.now.getutc.to_s + ": Client sending: " + data)
|
Rails.logger.info(Time.now.getutc.to_s + ": Client sending: " + data)
|
||||||
# Check whether the client send a JSON command and kill container
|
# 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
|
begin
|
||||||
parsed = JSON.parse(data)
|
parsed = JSON.parse(data)
|
||||||
if parsed['cmd'] == 'exit'
|
if parsed['cmd'] == 'client_kill'
|
||||||
Rails.logger.debug("Client exited container.")
|
Rails.logger.debug("Client exited container.")
|
||||||
@docker_client.exit_container(result[:container])
|
@docker_client.kill_container(result[:container])
|
||||||
else
|
else
|
||||||
socket.send data
|
socket.send data
|
||||||
Rails.logger.debug('Sent the received client data to docker:' + data)
|
Rails.logger.debug('Sent the received client data to docker:' + data)
|
||||||
|
Reference in New Issue
Block a user