diff --git a/tunictracker/tracker/static/tracker/assets/test.js b/tunictracker/tracker/static/tracker/assets/refresh.js similarity index 59% rename from tunictracker/tracker/static/tracker/assets/test.js rename to tunictracker/tracker/static/tracker/assets/refresh.js index 5a4b8ce..b9dccdf 100644 --- a/tunictracker/tracker/static/tracker/assets/test.js +++ b/tunictracker/tracker/static/tracker/assets/refresh.js @@ -2,6 +2,7 @@ window.onload = () => { let overview = { checks: document.getElementById("overview_checks"), entrances: document.getElementById("overview_entrances"), + summary: document.getElementById("summary"), }; let current_scene = { name: document.getElementById("current_scene_text"), @@ -21,14 +22,26 @@ window.onload = () => { let mapped_line_elem = document .getElementById("current_scene_entrances_mapped") .firstElementChild.cloneNode(true); - + let summary_element = document + .getElementById("summary") + .firstElementChild.cloneNode(true); + summary_element.classList.forEach((class_name) => { + if (class_name == "bg-green-900") { + summary_element.classList.remove(class_name); + } else if (class_name == "bg-yellow-900") { + summary_element.classList.remove(class_name); + } else if (class_name == "bg-blue-900") { + summary_element.classList.remove(class_name); + } + }); const refresh_interval = setInterval( refresh_elements, - 300, + 500, overview, current_scene, line_elem, - mapped_line_elem + mapped_line_elem, + summary_element ); }; @@ -36,7 +49,8 @@ async function refresh_elements( overview, current_scene, line_elem, - mapped_line_elem + mapped_line_elem, + summary_element ) { fetch("http://localhost:8000/spoiler") .then((response) => response.json()) @@ -62,6 +76,7 @@ async function refresh_elements( response_object.Scenes[current_scene_name].Checks; const current_scene_entrances_list = response_object.Scenes[current_scene_name].Entrances; + const all_scenes = response_object.Scenes; overview.checks.textContent = `Checks: ${overview_checks_undiscovered}/${overview_checks_total}`; overview.entrances.textContent = `Entrances: ${overview_entrances_undiscovered}/${overview_entrances_total}`; current_scene.name.textContent = current_scene_name; @@ -70,6 +85,7 @@ async function refresh_elements( current_scene.checks.list.innerHTML = ""; current_scene.entrances.list.innerHTML = ""; current_scene.entrances.mapped.innerHTML = ""; + overview.summary.innerHTML = ""; Object.keys(current_scene_checks_list).forEach((check) => { if (!current_scene_checks_list[check]) { line_elem.textContent = `❌ ${check}`; @@ -87,6 +103,74 @@ async function refresh_elements( ); } }); + let scene_div = document.createElement("div"); + let checks_div = document.createElement("div"); + let entrances_div = document.createElement("div"); + let scene_checks_undiscovered = 0; + let scene_checks_total = 0; + let scene_entrances_undiscovered = 0; + let scene_entrances_total = 0; + Object.keys(all_scenes).forEach((scene) => { + summary_element.innerHTML = ""; + scene_div.textContent = scene; + scene_checks_undiscovered = + all_scenes[scene]["Totals"]["Checks"]["Undiscovered"]; + scene_checks_total = all_scenes[scene]["Totals"]["Checks"]["Total"]; + scene_entrances_undiscovered = + all_scenes[scene]["Totals"]["Entrances"]["Undiscovered"]; + scene_entrances_total = + all_scenes[scene]["Totals"]["Entrances"]["Total"]; + if (scene_entrances_total <= 0) { + return; + } + if (scene == current_scene.name.textContent) { + return; + } + checks_div.textContent = `Checks: ${scene_checks_undiscovered}/${scene_checks_total}`; + entrances_div.textContent = `Entrances: ${scene_entrances_undiscovered}/${scene_entrances_total}`; + if (scene_checks_undiscovered > 0 && scene_entrances_undiscovered > 0) { + if (scene_entrances_undiscovered == scene_entrances_total) { + summary_element.classList.add("bg-red-900"); + summary_element.classList.remove( + "bg-green-900", + "bg-yellow-900", + "bg-blue-900" + ); + } else { + summary_element.classList.add("bg-green-900"); + summary_element.classList.remove( + "bg-blue-900", + "bg-yellow-900", + "bg-red-900" + ); + } + } else if (scene_checks_undiscovered > 0) { + summary_element.classList.add("bg-yellow-900"); + summary_element.classList.remove( + "bg-blue-900", + "bg-green-900", + "bg-red-900" + ); + } else if (scene_entrances_undiscovered > 0) { + summary_element.classList.add("bg-blue-900"); + summary_element.classList.remove( + "bg-green-900", + "bg-yellow-900", + "bg-red-900" + ); + } else { + summary_element.classList.remove( + "bg-green-900", + "bg-yellow-900", + "bg-blue-900", + "bg-red-900" + ); + } + summary_element.appendChild(scene_div.cloneNode(true)); + summary_element.appendChild(checks_div.cloneNode(true)); + summary_element.appendChild(entrances_div.cloneNode(true)); + overview.summary.appendChild(summary_element.cloneNode(true)); + }); }) .catch((err) => { console.log(err); diff --git a/tunictracker/tracker/templates/index.html b/tunictracker/tracker/templates/index.html index 8925add..ee64ed6 100644 --- a/tunictracker/tracker/templates/index.html +++ b/tunictracker/tracker/templates/index.html @@ -9,7 +9,7 @@ {% load static tailwind_tags %} {% tailwind_css %} {% load static %} - +
{% block content %} diff --git a/tunictracker/tracker/templates/tracker/index.html b/tunictracker/tracker/templates/tracker/index.html index 63446a8..0eadb77 100644 --- a/tunictracker/tracker/templates/tracker/index.html +++ b/tunictracker/tracker/templates/tracker/index.html @@ -20,10 +20,23 @@