Code to collect participant IDs

This commit is contained in:
Neale Pickett 2019-11-02 15:24:01 -06:00
parent 4b05d31002
commit abfbafa6f6
3 changed files with 29 additions and 15 deletions

View File

@ -224,8 +224,9 @@ sessionStorage.setItem("id", "devel-server")
},
)
url = urllib.parse.urlparse(self.path)
for pattern, function in self.endpoints:
result = parse.parse(pattern, self.path)
result = parse.parse(pattern, url.path)
if result:
self.req = result.named
seed = self.req.get("seed", "random")

View File

@ -13,8 +13,13 @@
<div id="messages"></div>
<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 name: <input name="name"> <br>
<input type="submit" value="Sign In">
</form>

View File

@ -77,13 +77,15 @@ function renderPuzzles(obj) {
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()
fd.append("id", teamId)
fetch("puzzles.json", {
method: "POST",
body: fd,
})
fetch(url)
.then(resp => {
if (resp.ok) {
resp.json()
@ -100,22 +102,27 @@ function heartbeat(teamId) {
})
}
function showPuzzles(teamId) {
function showPuzzles(teamId, participantId) {
let spinner = document.createElement("span")
spinner.classList.add("spinner")
sessionStorage.setItem("id", teamId)
if (participantId) {
sessionStorage.setItem("pid", participantId)
}
document.getElementById("login").style.display = "none"
document.getElementById("puzzles").appendChild(spinner)
heartbeat(teamId)
heartbeat(teamId, participantId)
setInterval(e => { heartbeat(teamId) }, 40000)
}
function login(e) {
e.preventDefault()
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", {
method: "POST",
@ -127,10 +134,10 @@ function login(e) {
.then(obj => {
if (obj.status == "success") {
toast("Team registered")
showPuzzles(id)
showPuzzles(teamId, participantId)
} else if (obj.data.short == "Already registered") {
toast("Logged in with previously-registered team name")
showPuzzles(id)
showPuzzles(teamId, participantId)
} else {
toast(obj.data.description)
}
@ -152,9 +159,10 @@ function login(e) {
function init() {
// Already signed in?
let id = sessionStorage.getItem("id")
if (id) {
showPuzzles(id)
let teamId = sessionStorage.getItem("id")
let participantId = sessionStorage.getItem("pid")
if (teamId) {
showPuzzles(teamId, participantId)
}
document.getElementById("login").addEventListener("submit", login)