diff options
Diffstat (limited to 'app/assets/javascripts/snippets.es6')
-rw-r--r-- | app/assets/javascripts/snippets.es6 | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/assets/javascripts/snippets.es6 b/app/assets/javascripts/snippets.es6 new file mode 100644 index 0000000..d3c3be1 --- /dev/null +++ b/app/assets/javascripts/snippets.es6 @@ -0,0 +1,53 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. + +const codeField = document.querySelector("#code-field"); +if (codeField !== null) { + const origTextarea = codeField.querySelector("textarea[name=\"snippet[code]\"]"); + const codeMirror = CodeMirror.fromTextArea(origTextarea, { + mode: "ruby", + lineNumbers: true, + }); + codeMirror.on("change", cm => cm.save()); +} + +const agg = (elm, n) => { + if (!n) n = 0; + n++; + setTimeout(() => { + $.ajax({ + type: "GET", + url: "/results/" + elm.getAttribute("data-id"), + dataType: "text", + success: (text, st) => { + console.log(text); + elm.outerHTML = text; + if (n < 3) agg(elm, n); + } + }); + }, 1000); +}; + +const refresher = () => { + const runnings = document.querySelectorAll(".result-item[data-status=running]"); + for (var i = 0, len = runnings.length; i < len; i++) { + agg(runnings[i]); + } +}; +refresher(); + +const notrans = document.querySelectorAll(".result-item[data-status=notran]"); +const snippet_id = document.querySelector("#snippet-id").innerHTML; +for (var i = 0, len = notrans.length; i < len; i++) { + const elm = notrans[i]; + $.ajax({ + type: "POST", + url: "/results/run", + dataType: "text", + data: { compiler_id: elm.getAttribute("data-compiler-id"), snippet_id: snippet_id }, + success: (text, st) => { + console.log(text); + elm.outerHTML = text; + } + }); +} |