Check for output prior printing

This commit is contained in:
Sebastian Serth
2020-03-06 15:35:02 +01:00
parent 207cf1084b
commit 2a8aabcf60

View File

@ -1,11 +1,11 @@
$(document).on('turbolinks:load', function() {
$(document).on('turbolinks:load', function () {
var ENTER_KEY_CODE = 13;
var clearOutput = function() {
var clearOutput = function () {
$('#output').html('');
};
var executeCommand = function(command) {
var executeCommand = function (command) {
$.ajax({
data: {
command: command
@ -15,7 +15,7 @@ $(document).on('turbolinks:load', function() {
}).done(handleResponse);
};
var handleKeyPress = function(event) {
var handleKeyPress = function (event) {
if (event.which === ENTER_KEY_CODE) {
var command = $(this).val();
if (command === 'clear') {
@ -28,7 +28,7 @@ $(document).on('turbolinks:load', function() {
}
};
var handleResponse = function(response) {
var handleResponse = function (response) {
if (response.status === 'ok') {
printOutput(response);
} else if (response.status === 'timeout') {
@ -36,11 +36,12 @@ $(document).on('turbolinks:load', function() {
}
};
var printCommand = function(command) {
var printCommand = function (command) {
$('#output').append('<p><em>' + command + '</em></p>');
};
var printOutput = function(output) {
var printOutput = function (output) {
if (output) {
var element = $('<p>');
if (output.stderr) {
element.addClass('text-warning');
@ -53,9 +54,10 @@ $(document).on('turbolinks:load', function() {
element.html($('#output').data('message-no-output'));
}
$('#output').append(element);
}
};
var printTimeout = function(output) {
var printTimeout = function (output) {
var element = $.append('<p>');
element.addClass('text-danger');
element.html($('#shell').data('message-timeout'));
@ -66,4 +68,5 @@ $(document).on('turbolinks:load', function() {
$('#command').focus();
$('#command').on('keypress', handleKeyPress);
}
});
})
;