diff options
author | jakobst1n <jakob.stendahl@outlook.com> | 2018-09-07 00:32:51 +0200 |
---|---|---|
committer | jakobst1n <jakob.stendahl@outlook.com> | 2018-09-07 00:32:51 +0200 |
commit | 78d7c8d75a5f55ab56dd018edc85ebce9aa033bb (patch) | |
tree | 2ad9da977667b79236cfdd827d0446a5bf9fea18 /src/public/js/index.js | |
download | Luxcena-Neo-78d7c8d75a5f55ab56dd018edc85ebce9aa033bb.tar.gz Luxcena-Neo-78d7c8d75a5f55ab56dd018edc85ebce9aa033bb.zip |
:construction: Add pre-v1 project
Because of some stupid mistakes with the repo, I decided to delete the
git history. Create a new, fresh repo, and move all the code there.
Since all this is pre-v1, everything is in a testing-phase anyways. So i
do not think we are going to feel the need for any history. The old repo
is renamed to Luxcena-Neo-Old, and will be there until i convince
myself i won't need the history.
Diffstat (limited to 'src/public/js/index.js')
-rw-r--r-- | src/public/js/index.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/public/js/index.js b/src/public/js/index.js new file mode 100644 index 0000000..5b67de2 --- /dev/null +++ b/src/public/js/index.js @@ -0,0 +1,68 @@ +let socket = io(); + +module.exports = () => { + M.AutoInit(); + setupSocket(); + + setInterval(() => { + socket.emit("GetGeneralInfo"); + }, 500); + + socket.emit("GetLog", {filter: "success error event", entryN: 10}); +}; + +function setupSocket() { + + socket.on("lastLogEntries", (entries) => { + let list = ""; + entries.forEach((entry) => { + list += "<tr><td>" + prettifyType(entry.type) + "</td><td>" + entry.time + "</td><td>" + entry.details + "</td></tr>"; + }); + + document.getElementById("log-table-body").innerHTML = list; + M.AutoInit(); + }); + + socket.on("newLogEntry", (entry) => { + // Start with parsing the new entry, no reason to select the DOM-element and stuff, if we are filtering out the entry anyway. + let type = entry.type; + if ( (type.toUpperCase() !== "SUCCESS") && (type.toUpperCase() !== "ERROR") && (type.toUpperCase() !== "EVENT") && (type.toUpperCase() !== "INFO")) { + return; + } + + let logTable = document.getElementById("log-table-body"); + + let LTable = logTable.rows.length; + logTable.deleteRow(LTable - 1); // Since length outputs a 1-based number + + let newEntry = logTable.insertRow(0); + newEntry.insertCell(0).innerHTML = prettifyType(entry.type); + newEntry.insertCell(1).innerHTML = entry.time; + newEntry.insertCell(2).innerHTML = entry.details; + M.AutoInit(); + newEntry.className = "newLogEntry"; + }); + + socket.on("generalInfo", (info) => { + if (info["scriptIsExited"]) { + document.getElementById("currentScript").innerHTML = info["currentScript"] + " (exited)"; + } else { + document.getElementById("currentScript").innerHTML = info["currentScript"]; + } + document.getElementById("uptime").innerHTML = info["uptime"] + " seconds"; + }); + +} + +function prettifyType(type) { + let prettyTable = { + "DEBUG": `<span class="tooltipped" data-position="top" data-tooltip="Debug-log">đ¸</span>`, + "INFO": `<span class="tooltipped" data-position="top" data-tooltip="Just some information">âšī¸</span>`, + "WARNING": `<span class="tooltipped" data-position="top" data-tooltip="A warning">â ī¸</span>`, + "EVENT": `<span class="tooltipped" data-position="top" data-tooltip="Event">âĄī¸</span>`, + "SUCCESS": `<span class="tooltipped" data-position="top" data-tooltip="Something exited successfully">â
</span>`, + "ERROR": `<span class="tooltipped" data-position="top" data-tooltip="Error">đ´</span>`, + "PYTHON": `<span class="tooltipped" data-position="top" data-tooltip="Output from user-script">đ</span>` + }; + return prettyTable[type]; +} |