diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-09 23:12:34 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-09 23:12:34 +0800 |
commit | 39d0ce0fdb7ee6198da7d5b2b91045f2c4f02b47 (patch) | |
tree | 884686e12582838a41c25d58f55b64e8097d0243 /fg21sim/webui/static | |
parent | 33fa91fccdf81bcaa0ad42e897d7d6d95c44985f (diff) | |
download | fg21sim-39d0ce0fdb7ee6198da7d5b2b91045f2c4f02b47.tar.bz2 |
webui: Allow to toggle and delete the logging messages
Diffstat (limited to 'fg21sim/webui/static')
-rw-r--r-- | fg21sim/webui/static/js/console.js | 46 | ||||
-rw-r--r-- | fg21sim/webui/static/js/websocket.js | 18 |
2 files changed, 64 insertions, 0 deletions
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 @@ -82,6 +82,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 * * @param {Object} ws - The opened WebSocket object through which to send 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!"); |