From 39d0ce0fdb7ee6198da7d5b2b91045f2c4f02b47 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 9 Nov 2016 23:12:34 +0800 Subject: webui: Allow to toggle and delete the logging messages --- fg21sim/webui/static/js/console.js | 46 ++++++++++++++++++++++++++++++++++++ fg21sim/webui/static/js/websocket.js | 18 ++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'fg21sim/webui/static/js') diff --git a/fg21sim/webui/static/js/console.js b/fg21sim/webui/static/js/console.js index f9e75dc..86ea90c 100644 --- a/fg21sim/webui/static/js/console.js +++ b/fg21sim/webui/static/js/console.js @@ -81,6 +81,52 @@ var appendLogMessage = function (msg) { }; +/** + * Toggle the display of the logging messages at the given level. + * + * NOTE: + * Use a data attribute to keep the current toggle state to be more robust. + * + * @param {String} level - Which level of logging messages to be toggled? + * Valid: debug, info, warning, error, critical + */ +var toggleLogMessages = function (level) { + var valid_levels = ["debug", "info", "warning", "error", "critical"]; + if (! level) { + console.error("toggleLogMessages: level not specified"); + } else if ($.inArray(level.toLowerCase(), valid_levels) == -1) { + console.error("toggleLogMessages: invalid level:", level); + } else { + level = level.toLowerCase(); + var logbox = $("#log-messages"); + var status = null; + if (typeof logbox.data(level) === "undefined") { + // No stored display status, assuming true: show + status = true; + logbox.data(level, status); + } else { + // Use the stored display status + status = logbox.data(level); + } + // Toggle the display status + status = !status; + logbox.find("p.log-" + level).toggle(); + // Save the new display status + logbox.data(level, status); + console.log("Toggled", level, "logging messages:", + status ? "show" : "hide"); + } +}; + + +/** + * Delete all the logging messages + */ +var deleteLogMessages = function () { + $("#log-messages").empty(); + console.warn("Deleted all logging messages!"); +}; + /** * Get the task status from the server * diff --git a/fg21sim/webui/static/js/websocket.js b/fg21sim/webui/static/js/websocket.js index 8f726b8..cff66b2 100644 --- a/fg21sim/webui/static/js/websocket.js +++ b/fg21sim/webui/static/js/websocket.js @@ -234,6 +234,24 @@ $(document).ready(function () { getServerTaskStatus(g_ws); }); + /* Logging messages controls */ + $("#log-toggle-debug").on("click", function () { + toggleLogMessages("debug"); + }); + $("#log-toggle-info").on("click", function () { + toggleLogMessages("info"); + }); + $("#log-toggle-warning").on("click", function () { + toggleLogMessages("warning"); + }); + $("#log-toggle-error").on("click", function () { + toggleLogMessages("error"); + toggleLogMessages("critical"); + }); + $("#log-delete").on("click", function () { + deleteLogMessages(); + }); + } else { // WebSocket NOT supported console.error("Oops, WebSocket is NOT supported!"); -- cgit v1.2.2