Improved time prefix
This commit is contained in:
parent
a5335b1e6e
commit
2643999e8d
@ -257,6 +257,10 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
<!-- WebConsole JS Objects -->
|
||||
<script src="scripts/object/Setting.js?v=1.5.4"></script>
|
||||
<script src="scripts/object/WSServer.js?v=1.5.4"></script>
|
||||
|
||||
<!-- WebConsole JS Scripts -->
|
||||
<script src="scripts/WebConsoleLanguage.js?v=1.5.4"></script>
|
||||
<script src="scripts/WebConsoleConnector.js?v=1.5.4"></script>
|
||||
|
@ -52,7 +52,7 @@ function onWebSocketsMessage(message){
|
||||
switch (message.status) {
|
||||
case 10:
|
||||
//Console Output
|
||||
writeToWebConsole(message.message);
|
||||
writeToWebConsole(message.message, message.time);
|
||||
break;
|
||||
case 200:
|
||||
//Processed
|
||||
@ -106,7 +106,7 @@ function onWebSocketsMessage(message){
|
||||
/**
|
||||
* Write to console
|
||||
*/
|
||||
function writeToWebConsole(msg){
|
||||
function writeToWebConsole(msg, time){
|
||||
var isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 == $("#consoleTextArea").height();
|
||||
|
||||
//Write to div, replacing < to < (to avoid XSS) and replacing new line to br.
|
||||
@ -159,8 +159,15 @@ function writeToWebConsole(msg){
|
||||
msg = msg.replace(/§r/g, "</span>"); //&r
|
||||
|
||||
//Append datetime if enabled
|
||||
if(persistenceManager.getSetting("dateTimePrefix"))
|
||||
msg = "[" + new Date().toLocaleTimeString() + "] " + msg;
|
||||
if(persistenceManager.getSetting("dateTimePrefix")){
|
||||
if(typeof time !== 'undefined' && time !== null) //if time is present and not null
|
||||
msg = "[" + time + "] " + msg;
|
||||
else if(typeof time !== 'undefined' && time === null) //if time is present and null
|
||||
; //no time (is already printed)
|
||||
else
|
||||
msg = "[" + new Date().toLocaleTimeString() + "] " + msg;
|
||||
}
|
||||
|
||||
|
||||
$("#consoleTextArea").append(msg + "<br>");
|
||||
|
||||
|
@ -173,22 +173,4 @@ class WebConsolePersistenceManager{
|
||||
return JSON.parse(window.localStorage.WebConsole).settings[name];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WSServer{
|
||||
constructor(serverName, serverURI){
|
||||
this.serverName = serverName;
|
||||
this.serverURI = serverURI;
|
||||
}
|
||||
|
||||
setPassword(pwd){
|
||||
this.serverPassword = pwd;
|
||||
}
|
||||
}
|
||||
|
||||
class Setting{
|
||||
constructor(name, defaultValue){
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
6
client/scripts/object/Setting.js
Normal file
6
client/scripts/object/Setting.js
Normal file
@ -0,0 +1,6 @@
|
||||
class Setting{
|
||||
constructor(name, defaultValue){
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
10
client/scripts/object/WSServer.js
Normal file
10
client/scripts/object/WSServer.js
Normal file
@ -0,0 +1,10 @@
|
||||
class WSServer{
|
||||
constructor(serverName, serverURI){
|
||||
this.serverName = serverName;
|
||||
this.serverURI = serverURI;
|
||||
}
|
||||
|
||||
setPassword(pwd){
|
||||
this.serverPassword = pwd;
|
||||
}
|
||||
}
|
@ -7,4 +7,8 @@ public class DateTimeUtils {
|
||||
public static String getDateAsString() {
|
||||
return new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date());
|
||||
}
|
||||
|
||||
public static String getTimeAsString() {
|
||||
return new SimpleDateFormat("HH:mm:ss").format(new Date());
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
|
||||
import es.mesacarlos.webconsole.WebConsole;
|
||||
import es.mesacarlos.webconsole.util.DateTimeUtils;
|
||||
import es.mesacarlos.webconsole.util.Internationalization;
|
||||
import es.mesacarlos.webconsole.util.LoginManager;
|
||||
import es.mesacarlos.webconsole.websocket.command.WSCommandFactory;
|
||||
@ -97,7 +98,7 @@ public class WSServer extends WebSocketServer {
|
||||
Collection<WebSocket> connections = getConnections();
|
||||
for (WebSocket connection : connections) {
|
||||
if (LoginManager.getInstance().isLoggedIn(connection.getRemoteSocketAddress()))
|
||||
sendToClient(connection, new ConsoleOutput(line));
|
||||
sendToClient(connection, new ConsoleOutput(line, DateTimeUtils.getTimeAsString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class ReadLogFileCommand implements WSCommand{
|
||||
}
|
||||
|
||||
for(String line : lines)
|
||||
wsServer.sendToClient(conn, new ConsoleOutput(line));
|
||||
wsServer.sendToClient(conn, new ConsoleOutput(line, null));
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,11 @@ import com.google.gson.JsonObject;
|
||||
|
||||
public class ConsoleOutput implements JSONOutput{
|
||||
private String message;
|
||||
private String time;
|
||||
|
||||
public ConsoleOutput(String message) {
|
||||
public ConsoleOutput(String message, String time) {
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -18,12 +20,17 @@ public class ConsoleOutput implements JSONOutput{
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Console Output");
|
||||
object.addProperty("time", getTime());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user