From abfbafa6f65bb995a83f1ff86e86711d460f99ed Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 2 Nov 2019 15:24:01 -0600 Subject: [PATCH] Code to collect participant IDs --- devel/devel-server.py | 3 ++- theme/index.html | 7 ++++++- theme/moth.js | 34 +++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 438c0e8..635c22a 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -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") diff --git a/theme/index.html b/theme/index.html index 89bdf48..3a19276 100644 --- a/theme/index.html +++ b/theme/index.html @@ -13,8 +13,13 @@
- Team name: + Team ID:
+ Team name:
diff --git a/theme/moth.js b/theme/moth.js index f6f99ec..7a1987b 100644 --- a/theme/moth.js +++ b/theme/moth.js @@ -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)