From 78d7c8d75a5f55ab56dd018edc85ebce9aa033bb Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Fri, 7 Sep 2018 00:32:51 +0200 Subject: :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. --- src/public/js/scripts.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/public/js/scripts.js (limited to 'src/public/js/scripts.js') 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 = "
  • {{script_name}}

    {{badges}}

    {{buttons}}
  • "; + if (scriptList[i].loc === "local") { + HTMLElem = HTMLElem.replace("{{badges}}", ""); + HTMLElem = HTMLElem.replace("{{script_name}}", scriptList[i].name); + HTMLElem = HTMLElem.replace("{{buttons}}", + "play_arrow" + + "edit" + + "delete_forever" + ); + localScriptsHTML += HTMLElem; + } else if (scriptList[i].loc === "remote") { + HTMLElem = HTMLElem.replace("{{badges}}", "GitHub"); + 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); + +}; -- cgit v1.2.3