Shell: Refactor usage of methods and const
This commit is contained in:
@ -1,11 +1,11 @@
|
|||||||
$(document).on('turbolinks:load', function () {
|
$(document).on('turbolinks:load', function () {
|
||||||
var ENTER_KEY_CODE = 13;
|
const ENTER_KEY_CODE = 13;
|
||||||
|
|
||||||
var clearOutput = function () {
|
const clearOutput = function () {
|
||||||
$('#output').html('');
|
$('#output').html('');
|
||||||
};
|
};
|
||||||
|
|
||||||
var executeCommand = function (command) {
|
const executeCommand = function (command) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
data: {
|
data: {
|
||||||
command: command
|
command: command
|
||||||
@ -15,9 +15,9 @@ $(document).on('turbolinks:load', function () {
|
|||||||
}).done(handleResponse);
|
}).done(handleResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleKeyPress = function (event) {
|
const handleKeyPress = function (event) {
|
||||||
if (event.which === ENTER_KEY_CODE) {
|
if (event.which === ENTER_KEY_CODE) {
|
||||||
var command = $(this).val();
|
const command = $(this).val();
|
||||||
if (command === 'clear') {
|
if (command === 'clear') {
|
||||||
clearOutput();
|
clearOutput();
|
||||||
} else {
|
} else {
|
||||||
@ -28,7 +28,7 @@ $(document).on('turbolinks:load', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleResponse = function (response) {
|
const handleResponse = function (response) {
|
||||||
if (response.status === 'timeout') {
|
if (response.status === 'timeout') {
|
||||||
printTimeout(response);
|
printTimeout(response);
|
||||||
} else {
|
} else {
|
||||||
@ -36,45 +36,51 @@ $(document).on('turbolinks:load', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var printCommand = function (command) {
|
const printCommand = function (command) {
|
||||||
$('#output').append('<p><em>' + command + '</em></p>');
|
const em = $('<em>');
|
||||||
|
em.text(command);
|
||||||
|
const p = $('<p>');
|
||||||
|
p.append(em)
|
||||||
|
$('#output').append(p);
|
||||||
};
|
};
|
||||||
|
|
||||||
var printOutput = function (output) {
|
const printOutput = function (output) {
|
||||||
if (output) {
|
if (output) {
|
||||||
if (output.stdout) {
|
if (output.stdout) {
|
||||||
var element = $('<p>');
|
const element = $('<p>');
|
||||||
element.addClass('text-success');
|
element.addClass('text-success');
|
||||||
element.html(output.stdout);
|
element.text(output.stdout);
|
||||||
$('#output').append(element);
|
$('#output').append(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output.stderr) {
|
if (output.stderr) {
|
||||||
var element = $('<p>');
|
const element = $('<p>');
|
||||||
element.addClass('text-warning');
|
element.addClass('text-warning');
|
||||||
element.html(output.stderr);
|
element.text(output.stderr);
|
||||||
$('#output').append(element);
|
$('#output').append(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output.stdout && !output.stderr) {
|
if (!output.stdout && !output.stderr) {
|
||||||
var element = $('<p>');
|
const element = $('<p>');
|
||||||
element.addClass('text-muted');
|
element.addClass('text-muted');
|
||||||
element.html($('#output').data('message-no-output'));
|
const output = $('#output');
|
||||||
$('#output').append(element);
|
element.text(output.data('message-no-output'));
|
||||||
|
output.append(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var printTimeout = function (output) {
|
const printTimeout = function (output) {
|
||||||
var element = $.append('<p>');
|
const element = $.append('<p>');
|
||||||
element.addClass('text-danger');
|
element.addClass('text-danger');
|
||||||
element.html($('#shell').data('message-timeout'));
|
element.text($('#shell').data('message-timeout'));
|
||||||
$('#output').append(element);
|
$('#output').append(element);
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($('#shell').isPresent()) {
|
if ($('#shell').isPresent()) {
|
||||||
$('#command').focus();
|
const command = $('#command')
|
||||||
$('#command').on('keypress', handleKeyPress);
|
command.focus();
|
||||||
|
command.on('keypress', handleKeyPress);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
Reference in New Issue
Block a user