Check for output prior printing
This commit is contained in:
@ -1,69 +1,72 @@
|
|||||||
$(document).on('turbolinks:load', function() {
|
$(document).on('turbolinks:load', function () {
|
||||||
var ENTER_KEY_CODE = 13;
|
var ENTER_KEY_CODE = 13;
|
||||||
|
|
||||||
var clearOutput = function() {
|
var clearOutput = function () {
|
||||||
$('#output').html('');
|
$('#output').html('');
|
||||||
};
|
};
|
||||||
|
|
||||||
var executeCommand = function(command) {
|
var executeCommand = function (command) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
data: {
|
data: {
|
||||||
command: command
|
command: command
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: $('#shell').data('url')
|
url: $('#shell').data('url')
|
||||||
}).done(handleResponse);
|
}).done(handleResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleKeyPress = function(event) {
|
var handleKeyPress = function (event) {
|
||||||
if (event.which === ENTER_KEY_CODE) {
|
if (event.which === ENTER_KEY_CODE) {
|
||||||
var command = $(this).val();
|
var command = $(this).val();
|
||||||
if (command === 'clear') {
|
if (command === 'clear') {
|
||||||
clearOutput();
|
clearOutput();
|
||||||
} else {
|
} else {
|
||||||
printCommand(command);
|
printCommand(command);
|
||||||
executeCommand(command);
|
executeCommand(command);
|
||||||
}
|
}
|
||||||
$(this).val('');
|
$(this).val('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var handleResponse = function (response) {
|
||||||
|
if (response.status === 'ok') {
|
||||||
|
printOutput(response);
|
||||||
|
} else if (response.status === 'timeout') {
|
||||||
|
printTimeout(response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var printCommand = function (command) {
|
||||||
|
$('#output').append('<p><em>' + command + '</em></p>');
|
||||||
|
};
|
||||||
|
|
||||||
|
var printOutput = function (output) {
|
||||||
|
if (output) {
|
||||||
|
var element = $('<p>');
|
||||||
|
if (output.stderr) {
|
||||||
|
element.addClass('text-warning');
|
||||||
|
element.html(output.stderr);
|
||||||
|
} else if (output.stdout) {
|
||||||
|
element.addClass('text-success');
|
||||||
|
element.html(output.stdout);
|
||||||
|
} else {
|
||||||
|
element.addClass('text-muted');
|
||||||
|
element.html($('#output').data('message-no-output'));
|
||||||
|
}
|
||||||
|
$('#output').append(element);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var printTimeout = function (output) {
|
||||||
|
var element = $.append('<p>');
|
||||||
|
element.addClass('text-danger');
|
||||||
|
element.html($('#shell').data('message-timeout'));
|
||||||
|
$('#output').append(element);
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($('#shell').isPresent()) {
|
||||||
|
$('#command').focus();
|
||||||
|
$('#command').on('keypress', handleKeyPress);
|
||||||
}
|
}
|
||||||
};
|
})
|
||||||
|
;
|
||||||
var handleResponse = function(response) {
|
|
||||||
if (response.status === 'ok') {
|
|
||||||
printOutput(response);
|
|
||||||
} else if (response.status === 'timeout') {
|
|
||||||
printTimeout(response);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var printCommand = function(command) {
|
|
||||||
$('#output').append('<p><em>' + command + '</em></p>');
|
|
||||||
};
|
|
||||||
|
|
||||||
var printOutput = function(output) {
|
|
||||||
var element = $('<p>');
|
|
||||||
if (output.stderr) {
|
|
||||||
element.addClass('text-warning');
|
|
||||||
element.html(output.stderr);
|
|
||||||
} else if (output.stdout) {
|
|
||||||
element.addClass('text-success');
|
|
||||||
element.html(output.stdout);
|
|
||||||
} else {
|
|
||||||
element.addClass('text-muted');
|
|
||||||
element.html($('#output').data('message-no-output'));
|
|
||||||
}
|
|
||||||
$('#output').append(element);
|
|
||||||
};
|
|
||||||
|
|
||||||
var printTimeout = function(output) {
|
|
||||||
var element = $.append('<p>');
|
|
||||||
element.addClass('text-danger');
|
|
||||||
element.html($('#shell').data('message-timeout'));
|
|
||||||
$('#output').append(element);
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($('#shell').isPresent()) {
|
|
||||||
$('#command').focus();
|
|
||||||
$('#command').on('keypress', handleKeyPress);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
Reference in New Issue
Block a user