From 1709713bff2fb6a05e0c3bdf52c3b565150353df Mon Sep 17 00:00:00 2001 From: Asger Geel Weirsoee Date: Sat, 28 Feb 2026 02:40:07 +0100 Subject: [PATCH] =?UTF-8?q?UI:=20l=C3=A5s=20kategori-valg=20udenfor=20lobb?= =?UTF-8?q?y-fasen=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lobby/templates/lobby/host_screen.html | 3 ++- lobby/tests.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lobby/templates/lobby/host_screen.html b/lobby/templates/lobby/host_screen.html index 5f0d17a..f5672f1 100644 --- a/lobby/templates/lobby/host_screen.html +++ b/lobby/templates/lobby/host_screen.html @@ -9,6 +9,7 @@

Kræver mindst 3 spillere i lobbyen.

Spillere i session: ukendt

+

Kategori er kun redigérbar i lobby-fasen.

Fase: ukendt (opdatér session-status).

@@ -32,7 +33,7 @@ function restoreHostContext(){try{var raw=localStorage.getItem("wppHostContext") function phaseLabel(status){if(status==="lobby"){return"Lobby";}if(status==="lie"){return"Løgn";}if(status==="guess"){return"Gæt";}if(status==="reveal"){return"Reveal";}if(status==="finished"){return"Afsluttet";}return"Ukendt";} function updatePhaseStatus(){var el=document.getElementById("phaseStatus");if(!el){return;}if(!currentSessionStatus){el.textContent="Fase: ukendt (opdatér session-status).";return;}el.textContent="Fase: "+phaseLabel(currentSessionStatus)+" ("+currentSessionStatus+")";} function syncStartRoundGuard(data){var btn=document.getElementById("startRoundBtn");var hint=document.getElementById("startRoundHint");var status=document.getElementById("playerCountStatus");if(!btn||!hint||!status){return;}var count=(data&&data.session&&typeof data.session.players_count==="number")?data.session.players_count:null;var phase=currentSessionStatus||"";if(phase&&phase!=="lobby"){btn.disabled=true;status.textContent=count===null?"Spillere i session: ukendt":"Spillere i session: "+count;hint.textContent="Start runde er kun tilladt i lobby-fasen.";return;}if(count===null){btn.disabled=true;status.textContent="Spillere i session: ukendt";hint.textContent="Opdatér session-status for at validere min. 3 spillere.";return;}status.textContent="Spillere i session: "+count;if(count<3){btn.disabled=true;hint.textContent="Mangler spillere: kræver mindst 3 for at starte runde.";return;}btn.disabled=false;hint.textContent="Klar: nok spillere til at starte runde.";} -function updateHostActionState(){var hasCode=!!code();var hasRound=!!rq();var phase=currentSessionStatus||"";var showQuestionBtn=document.getElementById("showQuestionBtn");var mixAnswersBtn=document.getElementById("mixAnswersBtn");var calcScoresBtn=document.getElementById("calcScoresBtn");var showScoreboardBtn=document.getElementById("showScoreboardBtn");var nextRoundBtn=document.getElementById("nextRoundBtn");var finishGameBtn=document.getElementById("finishGameBtn");var hint=document.getElementById("hostActionHint");if(showQuestionBtn){showQuestionBtn.disabled=!hasCode||phase!=="lie";}if(showScoreboardBtn){showScoreboardBtn.disabled=!hasCode||phase!=="reveal";}if(nextRoundBtn){nextRoundBtn.disabled=!hasCode||phase!=="reveal";}if(finishGameBtn){finishGameBtn.disabled=!hasCode||phase!=="reveal";}if(mixAnswersBtn){mixAnswersBtn.disabled=!hasCode||!hasRound||(phase!=="lie"&&phase!=="guess");}if(calcScoresBtn){calcScoresBtn.disabled=!hasCode||!hasRound||phase!=="guess";}if(!hint){return;}if(!hasCode){hint.textContent="Angiv sessionkode for at aktivere host-actions.";return;}if(!phase){hint.textContent="Opdatér session-status for fasebaserede host-actions.";return;}if(phase==="finished"){hint.textContent="Spillet er afsluttet: gameplay-actions er låst.";return;}if((phase==="lie"||phase==="guess")&&!hasRound){hint.textContent="Round question id mangler: mix/beregn score er låst.";return;}hint.textContent="Host-actions er klar for fase: "+phaseLabel(phase)+".";} +function updateHostActionState(){var hasCode=!!code();var hasRound=!!rq();var phase=currentSessionStatus||"";var showQuestionBtn=document.getElementById("showQuestionBtn");var mixAnswersBtn=document.getElementById("mixAnswersBtn");var calcScoresBtn=document.getElementById("calcScoresBtn");var showScoreboardBtn=document.getElementById("showScoreboardBtn");var nextRoundBtn=document.getElementById("nextRoundBtn");var finishGameBtn=document.getElementById("finishGameBtn");var categorySelect=document.getElementById("category");var categoryGuardHint=document.getElementById("categoryGuardHint");var hint=document.getElementById("hostActionHint");if(showQuestionBtn){showQuestionBtn.disabled=!hasCode||phase!=="lie";}if(showScoreboardBtn){showScoreboardBtn.disabled=!hasCode||phase!=="reveal";}if(nextRoundBtn){nextRoundBtn.disabled=!hasCode||phase!=="reveal";}if(finishGameBtn){finishGameBtn.disabled=!hasCode||phase!=="reveal";}if(mixAnswersBtn){mixAnswersBtn.disabled=!hasCode||!hasRound||(phase!=="lie"&&phase!=="guess");}if(calcScoresBtn){calcScoresBtn.disabled=!hasCode||!hasRound||phase!=="guess";}if(categorySelect){categorySelect.disabled=!hasCode||phase!=="lobby";}if(categoryGuardHint){if(!hasCode){categoryGuardHint.textContent="Angiv sessionkode for at låse kategori til lobby-fasen.";}else if(phase==="lobby"){categoryGuardHint.textContent="Kategori kan vælges i lobby-fasen.";}else if(!phase){categoryGuardHint.textContent="Opdatér session-status for at validere kategori-lås.";}else{categoryGuardHint.textContent="Kategori er låst udenfor lobby-fasen.";}}if(!hint){return;}if(!hasCode){hint.textContent="Angiv sessionkode for at aktivere host-actions.";return;}if(!phase){hint.textContent="Opdatér session-status for fasebaserede host-actions.";return;}if(phase==="finished"){hint.textContent="Spillet er afsluttet: gameplay-actions er låst.";return;}if((phase==="lie"||phase==="guess")&&!hasRound){hint.textContent="Round question id mangler: mix/beregn score er låst.";return;}hint.textContent="Host-actions er klar for fase: "+phaseLabel(phase)+".";} async function api(path,method,payload){var o={method:method||"GET",headers:{"Accept":"application/json"}};if(payload!==null){o.headers["Content-Type"]="application/json";o.headers["X-CSRFToken"]=csrf();o.body=JSON.stringify(payload);}var r=await fetch(path,o);var d=await r.json().catch(function(){return {};});document.getElementById("out").textContent=JSON.stringify({status:r.status,data:d},null,2);if(d.session&&d.session.code){document.getElementById("code").value=d.session.code;}if(d.session&&d.session.status){currentSessionStatus=d.session.status;}if(d.round_question&&d.round_question.id){document.getElementById("roundQuestionId").value=d.round_question.id;}updatePhaseStatus();syncStartRoundGuard(d);updateHostActionState();saveHostContext();return d;} function createSession(){return api("/lobby/sessions/create","POST",{});} function sessionDetail(){return api("/lobby/sessions/"+code(),"GET",null);} diff --git a/lobby/tests.py b/lobby/tests.py index 34c7d59..7408f85 100644 --- a/lobby/tests.py +++ b/lobby/tests.py @@ -778,12 +778,15 @@ class UiScreenTests(TestCase): self.assertContains(response, "id=\"showQuestionBtn\"") self.assertContains(response, "id=\"mixAnswersBtn\"") self.assertContains(response, "id=\"hostActionHint\"") + self.assertContains(response, "id=\"categoryGuardHint\"") self.assertContains(response, "id=\"phaseStatus\"") self.assertContains(response, "updateHostActionState") self.assertContains(response, "phaseLabel") self.assertContains(response, "Opdatér session-status for fasebaserede host-actions.") self.assertContains(response, "Angiv sessionkode for at aktivere host-actions.") + self.assertContains(response, "Kategori er kun redigérbar i lobby-fasen.") + self.assertContains(response, "categorySelect.disabled=!hasCode||phase!==\"lobby\"") def test_player_screen_is_public(self): response = self.client.get(reverse("lobby:player_screen"))