diff --git a/View/src/JS/Admin.js b/View/src/JS/Admin.js index 166d0bc7..339857eb 100644 --- a/View/src/JS/Admin.js +++ b/View/src/JS/Admin.js @@ -7,3 +7,104 @@ element.classList.remove("nav-button"); element.classList.add("currentText"); } + +function run() { + var terminal =""; + const runner = new BrythonRunner({ + stdout: { + write(content) { + terminal += content; + }, + flush() {}, + }, + stderr: { + write(content) { + terminal += content; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal += "\n"; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + var code = getElementById("solution").value; + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); +} + +function run_init() { + if (terminal != "") { + terminal = ""; + } + run(); +} + +//Function that execute given code and return the result in a given element by id + +function exec(code, id) { + var terminal = ""; + const runner = new BrythonRunner({ + stdout: { + write(content) { + if (id == "code") { + retourCode = content; + } + if (id == "solution") { + retourSolution = content; + } + }, + flush() {}, + }, + stderr: { + write(content) { + if (id == "solution") { + retourSolution = "ERROR"; + } + terminal += content; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal += "\n"; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); +} + +/** + * It checks if the code in the editor as the same result as the solution. + */ +function check() { + if (retourSolution == "ERROR") { + alert("Il semblerait qu'il y a une erreur de python dans le code" + "Le terminal affiche : " + terminal); + } else if (retourSolution == retourCode) { + alert("Aucune erreur détectée"); + } else { + alert("Il semblerait que le solution ne soit pas la bonne " + "Le terminal affiche : " + terminal); + } +} + +async function submit(){ + var test = document.getElementById("test").value; + exec("print ('True')", "code"); + exec(test, "solution"); + var result = document.getElementById("result"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); +} \ No newline at end of file diff --git a/View/src/pages/Admin/ModifEnigmeSolo.php b/View/src/pages/Admin/ModifEnigmeSolo.php index 32ac767b..aa41c081 100644 --- a/View/src/pages/Admin/ModifEnigmeSolo.php +++ b/View/src/pages/Admin/ModifEnigmeSolo.php @@ -79,6 +79,15 @@ + + + Se rendre à l'énigme + +
+
+