Added command history into client
This commit is contained in:
parent
36f950f2c3
commit
13d374ec32
@ -11,6 +11,7 @@ var persistenceManager = new WebConsolePersistenceManager();
|
|||||||
var connectionManager = new WebConsoleManager();
|
var connectionManager = new WebConsoleManager();
|
||||||
var autoPasswordCompleted = false; //When true, saved password was used. If a 401 is received, then saved password is not correct
|
var autoPasswordCompleted = false; //When true, saved password was used. If a 401 is received, then saved password is not correct
|
||||||
var statusCommandsInterval = -1;
|
var statusCommandsInterval = -1;
|
||||||
|
var commandHistoryIndex = -1; //Saves current command history index. -1 when not browsing history.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare and show server to user
|
* Prepare and show server to user
|
||||||
@ -26,6 +27,7 @@ function openServer(serverName){
|
|||||||
|
|
||||||
//New server, new variables:
|
//New server, new variables:
|
||||||
autoPasswordCompleted = false;
|
autoPasswordCompleted = false;
|
||||||
|
commandHistoryIndex = -1; //Reset command history index
|
||||||
|
|
||||||
//Create or retrieve connection
|
//Create or retrieve connection
|
||||||
connectionManager.loadConnection(serverName);
|
connectionManager.loadConnection(serverName);
|
||||||
@ -206,6 +208,9 @@ function backToHomepage(){
|
|||||||
//Stop gathering info from server
|
//Stop gathering info from server
|
||||||
clearInterval(statusCommandsInterval);
|
clearInterval(statusCommandsInterval);
|
||||||
statusCommandsInterval = -1;
|
statusCommandsInterval = -1;
|
||||||
|
|
||||||
|
//Reset command history index
|
||||||
|
commandHistoryIndex = -1;
|
||||||
|
|
||||||
//Clear all server indicators
|
//Clear all server indicators
|
||||||
writePlayerInfo(0, 0);
|
writePlayerInfo(0, 0);
|
||||||
|
@ -11,6 +11,7 @@ class WebConsoleConnector {
|
|||||||
this.serverURI = serverURI;
|
this.serverURI = serverURI;
|
||||||
this.subscribers = []; //List of functions called when a new message arrive
|
this.subscribers = []; //List of functions called when a new message arrive
|
||||||
this.messages = []; //All messages retrieved since connection start
|
this.messages = []; //All messages retrieved since connection start
|
||||||
|
this.commands = []; //EXEC Commands sent by user to this server
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,13 +88,14 @@ $('#passwordModal').on('hidden.bs.modal', function (e) {
|
|||||||
$("#sendCommandButton").click(function() {
|
$("#sendCommandButton").click(function() {
|
||||||
connectionManager.sendConsoleCmd($("#commandInput").val());
|
connectionManager.sendConsoleCmd($("#commandInput").val());
|
||||||
$("#commandInput").val('');
|
$("#commandInput").val('');
|
||||||
|
commandHistoryIndex = -1; //Reset command history index
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter key on command input
|
* Enter or arrow up key on command input
|
||||||
*/
|
*/
|
||||||
$("#commandInput").on('keypress', function (e) {
|
$("#commandInput").on('keydown', function (e) {
|
||||||
if(e.which === 13){
|
if(e.which === 13){ //Detect enter key
|
||||||
//Disable textbox to prevent multiple submit
|
//Disable textbox to prevent multiple submit
|
||||||
$(this).attr("disabled", "disabled");
|
$(this).attr("disabled", "disabled");
|
||||||
|
|
||||||
@ -106,6 +107,21 @@ $("#commandInput").on('keypress', function (e) {
|
|||||||
|
|
||||||
//Focus again
|
//Focus again
|
||||||
$(this).focus();
|
$(this).focus();
|
||||||
|
}else if(e.which === 38){ //Detect arrow up key
|
||||||
|
//Replace with older command
|
||||||
|
if(commandHistoryIndex == -1){
|
||||||
|
//If not browsing history, start by latest command sent
|
||||||
|
commandHistoryIndex = connectionManager.activeConnection.commands.length;
|
||||||
|
}
|
||||||
|
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex - 1]);
|
||||||
|
commandHistoryIndex = commandHistoryIndex - 1;
|
||||||
|
}else if(e.which === 40){ //Detect arrow down key
|
||||||
|
//Replace with newer command
|
||||||
|
if(commandHistoryIndex !== -1){
|
||||||
|
//If not browsing history, do nothing
|
||||||
|
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex + 1]);
|
||||||
|
commandHistoryIndex = commandHistoryIndex + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class WebConsoleManager {
|
|||||||
*/
|
*/
|
||||||
sendConsoleCmd(cmd){
|
sendConsoleCmd(cmd){
|
||||||
this.activeConnection.sendToServer("EXEC " + cmd);
|
this.activeConnection.sendToServer("EXEC " + cmd);
|
||||||
|
this.activeConnection.commands.push(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ public class WSServer extends WebSocketServer {
|
|||||||
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
|
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
|
||||||
LoginManager.getInstance().logOut(conn.getRemoteSocketAddress());
|
LoginManager.getInstance().logOut(conn.getRemoteSocketAddress());
|
||||||
Bukkit.getLogger()
|
Bukkit.getLogger()
|
||||||
.info("[WebConsole] Closed WS connection " + conn.getRemoteSocketAddress() + ". Reason: " + reason);
|
.info("[WebConsole] Closed WS connection " + conn.getRemoteSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user