154 lines
4.6 KiB
HTML
154 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<header>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
|
|
<script>
|
|
let session = Number(
|
|
Date.
|
|
now().
|
|
toString().
|
|
split("").
|
|
reverse().
|
|
join("")
|
|
).toString(36)
|
|
console.log("session", session)
|
|
</script>
|
|
</header>
|
|
<body>
|
|
<!--{{USER}}-->
|
|
<form id="flash" action="">
|
|
<h1 name="status"></h1>
|
|
<input type="text" name="idq" readonly=true value="" style="display: none;">
|
|
<div name="question"></div>
|
|
<div name="clues"></div>
|
|
<div name="solution"></div>
|
|
<input type="button" value="clue">
|
|
<input type="text" name="answer">
|
|
<input type="button" value="pass" onclick="passQuestion(this.parentElement)">
|
|
<input type="button" value="fail" onclick="failQuestion(this.parentElement)">
|
|
<input type="button" value="skip" onclick="skipQuestion(this.parentElement)">
|
|
</form>
|
|
</body>
|
|
<footer>
|
|
<script>
|
|
let knowledgebase = {{ASSIGNMENTS_JSON}}
|
|
knowledgebase = Object.
|
|
keys(knowledgebase).
|
|
map((key) => [
|
|
[key, knowledgebase[key]]
|
|
])
|
|
console.log(0, knowledgebase)
|
|
|
|
function passQuestion(form) {
|
|
if (!form.children.answer.retake) {
|
|
pushAnswer(form.children.idq.value, form.children.answer.value, true)
|
|
}
|
|
nextQuestion(form)
|
|
}
|
|
|
|
function failQuestion(form) {
|
|
if (!form.children.answer.retake) {
|
|
pushAnswer(form.children.idq.value, form.children.answer.value, false)
|
|
}
|
|
queueRedoQuestion(form)
|
|
nextQuestion(form)
|
|
}
|
|
|
|
function skipQuestion(form) {
|
|
queueRedoQuestion(form)
|
|
nextQuestion(form)
|
|
}
|
|
|
|
function queueRedoQuestion(form) {
|
|
knowledgebase.push([[
|
|
form.children.idq.value,
|
|
{
|
|
Q: form.children.question.value,
|
|
Clues: form.children.clues.value,
|
|
Solution: form.children.solution.value,
|
|
Retake: true,
|
|
},
|
|
]])
|
|
}
|
|
|
|
function pushAnswer(idq, answer, passed) {
|
|
http("post", `/api/questions/${idq}/answers`, noopcallback,
|
|
JSON.stringify(
|
|
{
|
|
"answer": answer,
|
|
"passed": new Boolean(passed),
|
|
}
|
|
),
|
|
)
|
|
}
|
|
|
|
function nextQuestion(form) {
|
|
form.children.answer.value = ""
|
|
let todo = knowledgebase.shift()
|
|
if (!todo) {
|
|
todo = [0]
|
|
}
|
|
todo = todo[0]
|
|
if (! todo) {
|
|
todo = ["", {Q: "ALL DONE"}]
|
|
}
|
|
|
|
form.children.status.innerHTML = knowledgebase.length.toString()
|
|
|
|
form.children.idq.value = todo[0]
|
|
|
|
if (todo[1].Q.startsWith("img:")) {
|
|
form.children.question.innerHTML = `<img src="static/${todo[1].Q.slice(4, 1000)}"/>`
|
|
} else {
|
|
form.children.question.innerHTML = `<h3>${todo[1].Q}</h3>`
|
|
}
|
|
form.children.question.value = todo[1].Q
|
|
|
|
let clues = ""
|
|
for (var i in todo[1].Clues) {
|
|
clues += `<details><summary>clue #${i}</summary>`
|
|
if (todo[1].Clues[i].startsWith("img:")) {
|
|
clues += `<img src="static/${todo[1].Clues[i].slice(4, 1000)}"/>`
|
|
} else {
|
|
clues += todo[1].Clues[i]
|
|
}
|
|
clues += `</details>`
|
|
}
|
|
form.children.clues.innerHTML = clues
|
|
form.children.clues.value = todo[1].Clues
|
|
|
|
let solution = ""
|
|
for (var i in todo[1].Solution) {
|
|
solution += `<br>${todo[1].Solution[i]}`
|
|
}
|
|
if (solution) {
|
|
solution = `<details><summary>solution</summary>${solution}</details>`
|
|
}
|
|
form.children.solution.innerHTML = solution
|
|
form.children.solution.value = todo[1].Solution
|
|
|
|
form.children.answer.retake = todo[1].Retake
|
|
}
|
|
|
|
function noopcallback(responseBody, responseStatus) {
|
|
console.log(responseStatus, responseBody)
|
|
}
|
|
function http(method, remote, callback, body) {
|
|
var xmlhttp = new XMLHttpRequest();
|
|
xmlhttp.onreadystatechange = function() {
|
|
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
|
callback(xmlhttp.responseText, xmlhttp.status)
|
|
}
|
|
};
|
|
xmlhttp.open(method, remote, true);
|
|
if (typeof body == "undefined") {
|
|
body = null
|
|
}
|
|
xmlhttp.send(body);
|
|
}
|
|
|
|
nextQuestion(document.getElementById("flash"))
|
|
</script>
|
|
</footer>
|
|
</html>
|