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 | |
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')
-rw-r--r-- | src/public/js/general.js | 10 | ||||
-rw-r--r-- | src/public/js/index.js | 68 | ||||
-rw-r--r-- | src/public/js/logviewer.js | 64 | ||||
-rw-r--r-- | src/public/js/neo_ide.js | 4 | ||||
-rw-r--r-- | src/public/js/scripts.js | 71 |
5 files changed, 217 insertions, 0 deletions
diff --git a/src/public/js/general.js b/src/public/js/general.js new file mode 100644 index 0000000..b0b04d2 --- /dev/null +++ b/src/public/js/general.js @@ -0,0 +1,10 @@ +let sidenav = require("../components/sidenav"); + +module.exports = () => { + const pageName = document.getElementsByTagName("body")[0].id; + if (pageName == "neo_ide") { return; } + + document.getElementById("sidenav").innerHTML = sidenav; + + M.AutoInit(); +}; 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]; +} diff --git a/src/public/js/logviewer.js b/src/public/js/logviewer.js new file mode 100644 index 0000000..d376196 --- /dev/null +++ b/src/public/js/logviewer.js @@ -0,0 +1,64 @@ +let socket = io(); + +module.exports = () => { + M.AutoInit(); + + socket.emit("GetLog", {filter: "success error event debug python info warning", entryN: 1000}); + socket.on("lastLogEntries", (entries) => { + M.toast({html: "Loading log-files..."}); + console.log("Log-entries received: " + entries.length); + let HTMLBasicTable = ""; + let HTMLAdvancedTable = ""; + let HTMLScriptTable = ""; + let HTMLRAWTable = ""; + + entries.forEach((entry) => { + let strHTML = "<tr><td>" + prettifyType(entry.type) + "</td><td>" + entry.time + "</td><td>" + entry.details + "</td></tr>"; + + if (entry.type === "SUCCESS") { HTMLBasicTable += strHTML; } + if (entry.type === "ERROR") { HTMLBasicTable += strHTML; } + if (entry.type === "EVENT") { HTMLBasicTable += strHTML; } + if (entry.type === "PYTHON") { HTMLScriptTable += strHTML; } + if (entry.type !== "PYTHON") { HTMLAdvancedTable += strHTML; } + + //HTMLRAWTable += entry.join(" "); + }); + + document.getElementById("log-table-basic").innerHTML = HTMLBasicTable; + document.getElementById("log-table-script").innerHTML = HTMLScriptTable; + document.getElementById("log-table-advanced").innerHTML = HTMLAdvancedTable; + //document.getElementById("log-table-raw").innerHTML = HTMLRAWTable; + + }); + + socket.on("newLogEntry", (entry) => { + if (entry.type === "SUCCESS") { appendEntryToTable("log-table-basic", entry); } + if (entry.type === "ERROR") { appendEntryToTable("log-table-basic", entry); } + if (entry.type === "EVENT") { appendEntryToTable("log-table-basic", entry); } + if (entry.type === "PYTHON") { appendEntryToTable("log-table-script", entry); } + if (entry.type !== "PYTHON") { appendEntryToTable("log-table-advanced", entry); } + }); + +}; + +function appendEntryToTable(tableName, entry) { + let newEntry = document.getElementById(tableName).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"; +} + +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]; +}
\ No newline at end of file diff --git a/src/public/js/neo_ide.js b/src/public/js/neo_ide.js new file mode 100644 index 0000000..6108be4 --- /dev/null +++ b/src/public/js/neo_ide.js @@ -0,0 +1,4 @@ +module.exports = () => { + + +};
\ No newline at end of file diff --git a/src/public/js/scripts.js b/src/public/js/scripts.js new file mode 100644 index 0000000..ccad3cf --- /dev/null +++ b/src/public/js/scripts.js @@ -0,0 +1,71 @@ +module.exports = () => { + let socket = io(); + socket.emit("GetScripts", {}); + + socket.on("updatedScriptList", (scriptList) => { + let localScriptsHTML = ""; + let remoteScriptsHTML = ""; + + for (let i = 0; i < scriptList.length; i++) { + if (scriptList[i].loc !== "local") { continue; } + let HTMLElem = "<li><div class=\"col s12 m4\"><div class=\"card blue darken-1\"><div class=\"card-content white-text\"><p class=\"card-title\">{{script_name}}</p><p>{{badges}}</p></div><div class=\"card-action white\">{{buttons}}</div></div></div></li>"; + if (scriptList[i].loc === "local") { + HTMLElem = HTMLElem.replace("{{badges}}", ""); + HTMLElem = HTMLElem.replace("{{script_name}}", scriptList[i].name); + HTMLElem = HTMLElem.replace("{{buttons}}", + "<a class=\"selectScript\" data-path=" + scriptList[i].path + "><i class=\"material-icons\">play_arrow</i></a>" + + "<a class=\"editScript\" data-path=" + scriptList[i].path + "><i class=\"material-icons\">edit</i></a>" + + "<a class=\"deleteScript\" data-path=" + scriptList[i].path + "><i class=\"material-icons\">delete_forever</i></a>" + ); + localScriptsHTML += HTMLElem; + } else if (scriptList[i].loc === "remote") { + HTMLElem = HTMLElem.replace("{{badges}}", "<span class=\"badge yellow darken-1 white-text\">GitHub</span>"); + HTMLElem = HTMLElem.replace("{{script_name}}", scriptList[i].name); + remoteScriptsHTML += HTMLElem; + } + } + + document.getElementById("local-scripts").innerHTML = localScriptsHTML; + document.getElementById("remote-scripts").innerHTML = remoteScriptsHTML; + + }); + + /* + The delays here with settimeout, is set to a second deliberately, because, rather than making a whole checking-thing. + We just wait a second, and assume, that if it worked, the change should show now. Else, check the logViewer. + */ + function clickHandler(event) { + let element = event.target.parentElement; + + if (element.className === "selectScript") { + M.toast({html: "Now selecting script: " + element.dataset.path}); + socket.emit("SelectScript", {"scriptPath": element.dataset.path}); + + } else if (element.className === "editScript") { + window.location.href = ( + "http://" + window.location.hostname + ":" + window.location.port + + "/neo_ide?scriptName=" + btoa(element.dataset.path) + ); + + } else if (element.className === "deleteScript") { + if (confirm("Do you really want to delete this script?\n" + element.dataset.path + "\n\nYou can not undo this action, and the script will be lost forever...")) { + M.toast({html: "Trying to create script. If no change after a second. Check the logViewer."}); + socket.emit("DeleteScript", {"scriptPath": element.dataset.path}); + setTimeout(() => {socket.emit("GetScripts", {})}, 1000); + } + + } else if (element.id === "createEmptyScript") { + var scriptName = prompt("Please enter the name of the new script:"); + if (scriptName != null || scriptName != "") { + M.toast({html: "Trying to create script. If no change after a second. Check the logViewer."}); + socket.emit("CreateEmptyScript", {"scriptName": scriptName}); + setTimeout(() => {socket.emit("GetScripts", {})}, 1000); + } + + } + + } + + addEventListener("click", clickHandler, false); + +}; |