mirror of https://github.com/dirtbags/moth.git
Code to collect participant IDs
This commit is contained in:
parent
4b05d31002
commit
abfbafa6f6
|
@ -224,8 +224,9 @@ sessionStorage.setItem("id", "devel-server")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
url = urllib.parse.urlparse(self.path)
|
||||||
for pattern, function in self.endpoints:
|
for pattern, function in self.endpoints:
|
||||||
result = parse.parse(pattern, self.path)
|
result = parse.parse(pattern, url.path)
|
||||||
if result:
|
if result:
|
||||||
self.req = result.named
|
self.req = result.named
|
||||||
seed = self.req.get("seed", "random")
|
seed = self.req.get("seed", "random")
|
||||||
|
|
|
@ -13,8 +13,13 @@
|
||||||
<div id="messages"></div>
|
<div id="messages"></div>
|
||||||
|
|
||||||
<form id="login">
|
<form id="login">
|
||||||
Team name: <input name="name">
|
<!--
|
||||||
|
<span id="pid">
|
||||||
|
Participant ID: <input name="pid"> (optional) <br>
|
||||||
|
</span>
|
||||||
|
-->
|
||||||
Team ID: <input name="id"> <br>
|
Team ID: <input name="id"> <br>
|
||||||
|
Team name: <input name="name"> <br>
|
||||||
<input type="submit" value="Sign In">
|
<input type="submit" value="Sign In">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -77,13 +77,15 @@ function renderPuzzles(obj) {
|
||||||
container.appendChild(puzzlesElement)
|
container.appendChild(puzzlesElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
function heartbeat(teamId) {
|
function heartbeat(teamId, participantId) {
|
||||||
|
let url = new URL("puzzles.json", window.location)
|
||||||
|
url.searchParams.set("id", teamId)
|
||||||
|
if (participantId) {
|
||||||
|
url.searchParams.set("pid", participantId)
|
||||||
|
}
|
||||||
let fd = new FormData()
|
let fd = new FormData()
|
||||||
fd.append("id", teamId)
|
fd.append("id", teamId)
|
||||||
fetch("puzzles.json", {
|
fetch(url)
|
||||||
method: "POST",
|
|
||||||
body: fd,
|
|
||||||
})
|
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
resp.json()
|
resp.json()
|
||||||
|
@ -100,22 +102,27 @@ function heartbeat(teamId) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPuzzles(teamId) {
|
function showPuzzles(teamId, participantId) {
|
||||||
let spinner = document.createElement("span")
|
let spinner = document.createElement("span")
|
||||||
spinner.classList.add("spinner")
|
spinner.classList.add("spinner")
|
||||||
|
|
||||||
sessionStorage.setItem("id", teamId)
|
sessionStorage.setItem("id", teamId)
|
||||||
|
if (participantId) {
|
||||||
|
sessionStorage.setItem("pid", participantId)
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("login").style.display = "none"
|
document.getElementById("login").style.display = "none"
|
||||||
document.getElementById("puzzles").appendChild(spinner)
|
document.getElementById("puzzles").appendChild(spinner)
|
||||||
heartbeat(teamId)
|
heartbeat(teamId, participantId)
|
||||||
setInterval(e => { heartbeat(teamId) }, 40000)
|
setInterval(e => { heartbeat(teamId) }, 40000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function login(e) {
|
function login(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let name = document.querySelector("[name=name]").value
|
let name = document.querySelector("[name=name]").value
|
||||||
let id = document.querySelector("[name=id]").value
|
let teamId = document.querySelector("[name=id]").value
|
||||||
|
let pide = document.querySelector("[name=pid]")
|
||||||
|
let participantId = pide?pide.value:""
|
||||||
|
|
||||||
fetch("register", {
|
fetch("register", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -127,10 +134,10 @@ function login(e) {
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
if (obj.status == "success") {
|
if (obj.status == "success") {
|
||||||
toast("Team registered")
|
toast("Team registered")
|
||||||
showPuzzles(id)
|
showPuzzles(teamId, participantId)
|
||||||
} else if (obj.data.short == "Already registered") {
|
} else if (obj.data.short == "Already registered") {
|
||||||
toast("Logged in with previously-registered team name")
|
toast("Logged in with previously-registered team name")
|
||||||
showPuzzles(id)
|
showPuzzles(teamId, participantId)
|
||||||
} else {
|
} else {
|
||||||
toast(obj.data.description)
|
toast(obj.data.description)
|
||||||
}
|
}
|
||||||
|
@ -152,9 +159,10 @@ function login(e) {
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// Already signed in?
|
// Already signed in?
|
||||||
let id = sessionStorage.getItem("id")
|
let teamId = sessionStorage.getItem("id")
|
||||||
if (id) {
|
let participantId = sessionStorage.getItem("pid")
|
||||||
showPuzzles(id)
|
if (teamId) {
|
||||||
|
showPuzzles(teamId, participantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("login").addEventListener("submit", login)
|
document.getElementById("login").addEventListener("submit", login)
|
||||||
|
|
Loading…
Reference in New Issue