From 820893a8de556922fd23dc2b803fe3c573e50ee1 Mon Sep 17 00:00:00 2001 From: Willard Nilges Date: Wed, 15 Jan 2025 19:56:00 -0500 Subject: [PATCH] Refactor --- src/meshdb/templates/admin/base.html | 1 + src/meshdb/templates/admin/base_site.html | 10 ---------- src/meshdb/templates/admin/iframed.html | 10 +++++++--- src/meshweb/static/admin/iframe_check.js | 1 - src/meshweb/static/admin/map.js | 4 ++-- src/meshweb/static/admin/panel_url_check.js | 7 ++++--- src/meshweb/static/admin/panel_view_nav.js | 18 ------------------ 7 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 src/meshweb/static/admin/panel_view_nav.js diff --git a/src/meshdb/templates/admin/base.html b/src/meshdb/templates/admin/base.html index 196b3070..2f3421de 100644 --- a/src/meshdb/templates/admin/base.html +++ b/src/meshdb/templates/admin/base.html @@ -2,6 +2,7 @@ {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} + {% block title %}{% endblock %} diff --git a/src/meshdb/templates/admin/base_site.html b/src/meshdb/templates/admin/base_site.html index 803fbc8d..8e49dbfe 100644 --- a/src/meshdb/templates/admin/base_site.html +++ b/src/meshdb/templates/admin/base_site.html @@ -17,16 +17,6 @@

- - - {% endblock %} {% block footer %} diff --git a/src/meshdb/templates/admin/iframed.html b/src/meshdb/templates/admin/iframed.html index fc790609..e38c5104 100644 --- a/src/meshdb/templates/admin/iframed.html +++ b/src/meshdb/templates/admin/iframed.html @@ -5,9 +5,16 @@ + + + {% block title %}{% endblock %} {% block dark-mode-vars %} @@ -28,8 +35,6 @@ {% if LANGUAGE_BIDI %}{% endif %} {% endblock %} {% block blockbots %}{% endblock %} - - @@ -72,6 +77,5 @@ - diff --git a/src/meshweb/static/admin/iframe_check.js b/src/meshweb/static/admin/iframe_check.js index 64f327a5..127597d4 100644 --- a/src/meshweb/static/admin/iframe_check.js +++ b/src/meshweb/static/admin/iframe_check.js @@ -1,4 +1,3 @@ -const PANEL_URL = "/admin/panel/"; async function checkIframed() { // Check if we're in an iframe diff --git a/src/meshweb/static/admin/map.js b/src/meshweb/static/admin/map.js index 482f2b35..bcfaa6fe 100644 --- a/src/meshweb/static/admin/map.js +++ b/src/meshweb/static/admin/map.js @@ -279,7 +279,7 @@ async function adminPanelRestoreLastVisited() { console.log(`Entry Path: ${entryPath}`); const entrypointRegex = /^(\/?admin\/?)$/; if (!entryPath.match(entrypointRegex)) { - const newEntryPath = entryPath.replace("admin/panel", "admin"); + const newEntryPath = entryPath.replace(PANEL_URL, "admin"); document.getElementById("admin_panel_iframe").src = newEntryPath; localStorage.setItem(MESHDB_LAST_PAGE_VISITED, newEntryPath); return; @@ -292,7 +292,7 @@ async function adminPanelRestoreLastVisited() { // If the URL doesn't contain "panel," then something broke, and the safest // thing is to just default back home - if (!lastVisitedUrl.startsWith("/admin/panel/")) { + if (!lastVisitedUrl.startsWith(ADMIN_PANEL_HOME)) { localStorage.setItem(MESHDB_LAST_PAGE_VISITED, ADMIN_PANEL_HOME); lastVisitedUrl = ADMIN_PANEL_HOME; console.error("MESHDB_LAST_PAGE_VISITED was somehow corrupted. It's probably @willard's fault."); diff --git a/src/meshweb/static/admin/panel_url_check.js b/src/meshweb/static/admin/panel_url_check.js index 0ca9f376..a3e2a598 100644 --- a/src/meshweb/static/admin/panel_url_check.js +++ b/src/meshweb/static/admin/panel_url_check.js @@ -1,9 +1,10 @@ -// Used to check if a user has accessed /admin/panel directly, and adjusts the +// Used to check if a user has accessed the PANEL_URL directly, and adjusts the // URL for them +// This file is meant to be loaded from iframe.html where that variable is defined function checkForPanelURL() { - if (entryPath.contains("/admin/panel/")) { + if (entryPath.contains(PANEL_URL)) { const entryPath = new URL(window.location.href).pathname; - window.history.pushState("MeshDB Admin Panel", "", entryPath.replace("/admin/panel/", "/admin/")); + window.history.pushState("MeshDB Admin Panel", "", entryPath.replace(PANEL_URL, "/admin/")); } } diff --git a/src/meshweb/static/admin/panel_view_nav.js b/src/meshweb/static/admin/panel_view_nav.js deleted file mode 100644 index be2e506d..00000000 --- a/src/meshweb/static/admin/panel_view_nav.js +++ /dev/null @@ -1,18 +0,0 @@ -function checkIframed() { - // Check if we're in an iframe - const inIframe = window.self !== window.top; - - // If not, show button - if (!inIframe) { - const panelViewButton = document.getElementById("navigate_to_panel_view"); - panelViewButton.classList.toggle("hidden"); - - let panelURL = window.location.href; - console.log(panelURL); - panelURL = panelURL.replace("/admin", "/admin/panel"); - console.log(panelURL); - panelViewButton.href = panelURL; - } -} - -checkIframed();