Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Jan 16, 2025
1 parent 307222d commit 820893a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/meshdb/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:'rtl,ltr,auto' }}">
<head>
<script>const PANEL_URL = "/admin/panel/";</script>
<script src="{% static 'admin/iframe_check.js' %}"></script>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
Expand Down
10 changes: 0 additions & 10 deletions src/meshdb/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'meshwe

{% block userlinks %}
{{ block.super }}
<!--This will let people "show" the map by offering to navigate them to /admin/panel if they have found themselves at /admin-->
<!--
<a href="#" class="hidden" style="margin-left: 5px; vertical-align: middle; border: none;" id="navigate_to_panel_view">
<img src="{% static '/admin/map/img/map.png' %}" height="16px" title="Show Map">
</a>
-->
<!--Script to quietly update the panel view link-->
<!--
<script src="{% static '/admin/panel_view_nav.js' %}"></script>
-->
{% endblock %}

{% block footer %}
Expand Down
10 changes: 7 additions & 3 deletions src/meshdb/templates/admin/iframed.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
<!DOCTYPE html>
<html>
<head>
<script>
const MAP_BASE_URL = "{% get_env_var 'ADMIN_MAP_BASE_URL' %}";
const PANEL_URL = "/admin/panel/";
</script>
<!--We don't want people navigating to this URL, so we're gonna redirect them
if they find themselves here-->
<script src="{% static 'admin/panel_url_check.js' %}"></script>
<!--Script that powers this iframed view and communicates between the admin panel
and the map-->
<script src="{% static '/admin/map.js' %}" defer></script>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
{% block dark-mode-vars %}
Expand All @@ -28,8 +35,6 @@
{% if LANGUAGE_BIDI %}<link rel="stylesheet" href="{% static "admin/css/responsive_rtl.css" %}">{% endif %}
{% endblock %}
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE">{% endblock %}

<script>let MAP_BASE_URL = "{% get_env_var 'ADMIN_MAP_BASE_URL' %}";</script>
<link rel="stylesheet" href="{% static '/admin/iframed.css'%}"/>
</head>
<body>
Expand Down Expand Up @@ -72,6 +77,5 @@
<iframe src="{% get_env_var 'ADMIN_MAP_BASE_URL' %}" id="map_panel"></iframe>
</div>
</div>
<script src="{% static '/admin/map.js' %}"></script>
</body>
</html>
1 change: 0 additions & 1 deletion src/meshweb/static/admin/iframe_check.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const PANEL_URL = "/admin/panel/";

async function checkIframed() {
// Check if we're in an iframe
Expand Down
4 changes: 2 additions & 2 deletions src/meshweb/static/admin/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand Down
7 changes: 4 additions & 3 deletions src/meshweb/static/admin/panel_url_check.js
Original file line number Diff line number Diff line change
@@ -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/"));
}
}

Expand Down
18 changes: 0 additions & 18 deletions src/meshweb/static/admin/panel_view_nav.js

This file was deleted.

0 comments on commit 820893a

Please sign in to comment.