manual submission redesign phase B

This commit is contained in:
Joren de Graaf
2026-10-06 19:44:24 +02:00
parent a2844e0dc1
commit 56733c93b9
20 changed files with 146 additions and 33 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
{% load i18n %}
<div class="manual-direction-panel{% if measuring %} manual-direction-panel--measuring{% endif %}" id="manual-direction-panel">
{% if measuring %}
<div class="manual-direction-panel__topline">
<strong class="manual-direction-panel__heading">{% trans "Capture direction" %}</strong>
<button class="manual-direction-panel__close" type="button" hx-get="{% url 'fireworks_detect:manual_direction_panel' %}" hx-target="#manual-direction-panel" hx-swap="outerHTML" aria-label="{% trans 'Close direction capture' %}">×</button>
</div>
<p class="manual-direction-panel__copy">{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}</p>
<div id="manual-direction-status" class="manual-direction-panel__status" aria-live="polite"></div>
<button id="manual-capture-direction" class="manual-direction-panel__button" type="button">{% trans "Start measuring direction" %}</button>
{% else %}
<strong class="manual-direction-panel__heading">{% trans "Direction" %} <span>({% trans "optional" %})</span></strong>
<p id="manual-direction-summary" class="manual-direction-panel__summary">{% trans "Not captured" %}</p>
<button class="manual-direction-panel__open" type="button" hx-get="{% url 'fireworks_detect:manual_direction_panel' %}?mode=measure" hx-target="#manual-direction-panel" hx-swap="outerHTML">{% trans "Capture direction" %}</button>
{% endif %}
</div>
@@ -13,16 +13,15 @@
<input id="manual-direction-accuracy" name="direction_accuracy_degrees" type="hidden">
<div class="manual-report__primary">
<div class="manual-report__quantity">
<label class="manual-report__label" for="manual-occurrences">{% trans "Number of occurrences" %}</label>
<input id="manual-occurrences" name="occurrences" type="number" min="1" max="1000" value="1" required inputmode="numeric">
<label class="manual-report__label" for="manual-occurrences">{% trans "How many times did you hear it?" %}</label>
<div class="manual-report__stepper">
<button id="manual-decrease" type="button" aria-label="{% trans 'Decrease occurrences' %}">−</button>
<input id="manual-occurrences" name="occurrences" type="number" min="1" max="1000" value="1" required inputmode="numeric">
<button id="manual-increase" type="button" aria-label="{% trans 'Increase occurrences' %}">+</button>
</div>
</div>
<div class="manual-direction-panel" id="manual-direction-panel" hidden>
<strong class="manual-direction-panel__heading">{% trans "Direction" %} <span>({% trans "optional" %})</span></strong>
<p class="manual-direction-panel__copy">{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}</p>
<button id="manual-capture-direction" class="manual-direction-panel__button" type="button">{% trans "Capture direction" %}</button>
<div id="manual-direction-status" class="manual-direction-panel__status" aria-live="polite"></div>
</div>
<button id="manual-submit" class="manual-report__submit" type="button">{% trans "I heard fireworks — send to Pending" %}</button>
{% include "fireworks_detect/includes/manual_direction_panel.html" %}
<button id="manual-submit" class="manual-report__submit" type="button"><span aria-hidden="true">🔥</span> {% trans "I heard fireworks" %}</button>
</div>
<section class="manual-report__supporting" aria-labelledby="manual-listening-title">
<h3 id="manual-listening-title">{% trans "Automatic detection" %}</h3>
+15 -2
View File
@@ -157,9 +157,12 @@ class ManualPendingEventTests(TestCase):
response = self.client.get(reverse("hello"))
self.assertContains(response, "Report fireworks now")
self.assertContains(response, "I heard fireworks — send to Pending")
self.assertContains(response, "I heard fireworks")
self.assertContains(response, "Capture direction")
self.assertContains(response, 'manual-direction-panel" hidden')
self.assertContains(response, 'id="manual-decrease"')
self.assertContains(response, 'id="manual-increase"')
self.assertContains(response, 'id="manual-direction-panel"')
self.assertContains(response, 'hx-get="/fireworks/manual-direction/?mode=measure"')
self.assertContains(response, 'id="manual-compass"')
self.assertContains(response, 'aria-label="Compass direction" hidden')
self.assertContains(response, "htmx.min.js")
@@ -169,6 +172,16 @@ class ManualPendingEventTests(TestCase):
self.assertContains(response, "Open map controls")
self.assertContains(response, "Classify a recording")
def test_direction_subsection_opens_and_closes_with_htmx_fragments(self):
url = reverse("fireworks_detect:manual_direction_panel")
measuring = self.client.get(url, {"mode": "measure"}, HTTP_HX_REQUEST="true")
self.assertContains(measuring, 'id="manual-capture-direction"')
self.assertContains(measuring, 'hx-target="#manual-direction-panel"')
closed = self.client.get(url, HTTP_HX_REQUEST="true")
self.assertContains(closed, 'id="manual-direction-summary"')
self.assertNotContains(closed, 'id="manual-capture-direction"')
def test_old_route_preserves_the_previous_landing_page(self):
response = self.client.get(reverse("old_home"))
+2
View File
@@ -10,6 +10,7 @@ from .views import (
fireworks_map_view,
fireworks_view,
pending_audio,
manual_direction_panel,
submit_manual_pending_event,
submit_pending_event,
sensor_heartbeat,
@@ -27,6 +28,7 @@ urlpatterns = [
path("heartbeat/", sensor_heartbeat, name="sensor_heartbeat"),
path("submit-pending/", submit_pending_event, name="submit_pending"),
path("submit-manual-pending/", submit_manual_pending_event, name="submit_manual_pending"),
path("manual-direction/", manual_direction_panel, name="manual_direction_panel"),
path("events/", events_view, name="events"),
path("events/list/", events_list, name="events_list"),
path("admin-audio/pending/<int:event_id>/", pending_audio, name="pending_audio"),
+9
View File
@@ -363,6 +363,15 @@ def _manual_direction(request):
accuracy = None
return heading, accuracy
@require_http_methods(["GET"])
@never_cache
def manual_direction_panel(request):
return render(request, "fireworks_detect/includes/manual_direction_panel.html", {
"measuring": request.GET.get("mode") == "measure",
})
@require_http_methods(["POST"])
@never_cache
def submit_manual_pending_event(request):
+47 -18
View File
@@ -3,20 +3,19 @@
const manualForm = document.querySelector("#manual-report-form");
const manualSubmit = document.querySelector("#manual-submit");
const occurrences = document.querySelector("#manual-occurrences");
const decrease = document.querySelector("#manual-decrease");
const increase = document.querySelector("#manual-increase");
const manualStatus = document.querySelector("#manual-submission");
const latitude = document.querySelector("#manual-latitude");
const longitude = document.querySelector("#manual-longitude");
const directionDegrees = document.querySelector("#manual-direction-degrees");
const directionAccuracy = document.querySelector("#manual-direction-accuracy");
const captureDirectionButton = document.querySelector("#manual-capture-direction");
const directionStatus = document.querySelector("#manual-direction-status");
const directionPanel = document.querySelector("#manual-direction-panel");
const captureDirectionButton = () => document.querySelector("#manual-capture-direction");
const directionStatus = () => document.querySelector("#manual-direction-status");
const compass = document.querySelector("#manual-compass");
const compassRose = document.querySelector("#manual-compass-rose");
const compassHeading = document.querySelector("#manual-compass-heading");
const isMobileDevice = /Android|iPhone|iPad|iPod|IEMobile|Opera Mini/.test(navigator.userAgent)
|| (navigator.userAgent.includes("Macintosh") && navigator.maxTouchPoints > 1);
if (isMobileDevice) directionPanel.hidden = false;
let orientationListener;
let compassUnavailableTimeout;
let compassRotation = null;
@@ -26,6 +25,17 @@
const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)];
const displayDegrees = (value) => Number(value.toFixed(1)).toString();
const setCount = (value) => {
const count = Number.parseInt(value, 10);
occurrences.value = String(Math.min(1000, Math.max(1, Number.isFinite(count) ? count : 1)));
decrease.disabled = occurrences.value === "1";
increase.disabled = occurrences.value === "1000";
};
setCount(occurrences.value);
decrease.addEventListener("click", () => setCount(Number(occurrences.value) - 1));
increase.addEventListener("click", () => setCount(Number(occurrences.value) + 1));
occurrences.addEventListener("change", () => setCount(occurrences.value));
const stopCompassReading = () => {
if (orientationListener) window.removeEventListener("deviceorientation", orientationListener);
window.clearTimeout(compassUnavailableTimeout);
@@ -56,13 +66,16 @@
const showCapturedDirection = (heading, accuracy) => {
const accuracyText = accuracy === null ? (t.accuracyUnavailable || "Accuracy unavailable") : (t.accuracy || "Accuracy") + ": ±" + displayDegrees(accuracy) + "°";
directionStatus.innerHTML = "<strong>" + displayDegrees(heading) + "° · " + cardinalDirection(heading) + "</strong><br>" + accuracyText;
captureDirectionButton.textContent = (t.stopCapture || "Stop direction capture");
const status = directionStatus();
if (status) status.innerHTML = "<strong>" + cardinalDirection(heading) + " · " + displayDegrees(heading) + "°</strong><br>" + accuracyText;
const button = captureDirectionButton();
if (button) button.textContent = (t.stopCapture || "Stop measuring direction");
};
const listenForCompassReading = () => {
if (!directionStatus()) return;
stopCompassReading();
directionStatus.textContent = (t.pointPhone || "Point the top of your phone toward the sound — direction will update live.");
directionStatus().textContent = (t.pointPhone || "Point the top of your phone toward the sound — direction will update live.");
orientationListener = (event) => {
const isWebKitCompass = "webkitCompassHeading" in event;
const heading = isUsableNumber(event.webkitCompassHeading)
@@ -84,34 +97,36 @@
window.addEventListener("deviceorientation", orientationListener);
compassUnavailableTimeout = window.setTimeout(() => {
stopCompassReading();
captureDirectionButton.textContent = (t.captureDirection || "Capture direction");
directionStatus.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
const button = captureDirectionButton();
const status = directionStatus();
if (button) button.textContent = (t.captureDirection || "Start measuring direction");
if (status) status.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
}, 15000);
};
const captureDirection = async () => {
if (orientationListener) {
stopCompassReading();
captureDirectionButton.textContent = (t.captureAgain || "Capture again");
captureDirectionButton().textContent = (t.captureAgain || "Measure again");
return;
}
if (!window.isSecureContext) {
directionStatus.textContent = (t.secureCompass || "Compass capture requires a secure HTTPS connection.");
directionStatus().textContent = (t.secureCompass || "Compass capture requires a secure HTTPS connection.");
return;
}
if (typeof window.DeviceOrientationEvent === "undefined") {
directionStatus.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
directionStatus().textContent = (t.compassUnavailable || "Compass unavailable on this device.");
return;
}
if (typeof DeviceOrientationEvent.requestPermission === "function") {
directionStatus.textContent = (t.compassPermission || "Requesting compass permission…");
directionStatus().textContent = (t.compassPermission || "Requesting compass permission…");
try {
if (await DeviceOrientationEvent.requestPermission(true) !== "granted") {
directionStatus.textContent = (t.compassDenied || "Compass permission denied.");
if (directionStatus()) directionStatus().textContent = (t.compassDenied || "Compass permission denied.");
return;
}
} catch (error) {
directionStatus.textContent = (t.compassDenied || "Compass permission denied.");
if (directionStatus()) directionStatus().textContent = (t.compassDenied || "Compass permission denied.");
return;
}
}
@@ -119,6 +134,7 @@
};
const submitManualReport = async () => {
setCount(occurrences.value);
stopCompassReading();
manualSubmit.disabled = true;
if (burstListener?.active) {
@@ -148,8 +164,21 @@
}
};
captureDirectionButton.addEventListener("click", captureDirection);
manualForm.addEventListener("click", (event) => {
if (event.target.closest("#manual-capture-direction")) captureDirection();
if (event.target.closest(".manual-direction-panel__close")) stopCompassReading();
});
document.body.addEventListener("htmx:afterSwap", (event) => {
if (event.detail.target?.id !== "manual-direction-panel") return;
const summary = document.querySelector("#manual-direction-summary");
if (summary && directionDegrees.value !== "") {
const heading = Number(directionDegrees.value);
summary.textContent = `${cardinalDirection(heading)} · ${displayDegrees(heading)}°`;
}
});
manualSubmit.addEventListener("click", () => {
if (manualSubmit.disabled) return;
manualSubmit.disabled = true;
if (!navigator.geolocation) {
submitManualReport();
return;
@@ -16,18 +16,48 @@
}
.manual-report__quantity #manual-occurrences {
margin-bottom: 0;
width: 100%;
min-width: 0;
min-height: 3.75rem;
margin: 0;
padding: 0;
border: 0;
color: #f5f0ff;
font-size: clamp(2.25rem, 8vw, 3.5rem);
font-weight: 850;
text-align: center;
background: transparent;
appearance: textfield;
-moz-appearance: textfield;
}
.manual-report__quantity #manual-occurrences::-webkit-inner-spin-button,
.manual-report__quantity #manual-occurrences::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.manual-report__stepper { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem; align-items: center; gap: .5rem; }
.manual-report__stepper button { width: 3.5rem; min-height: 3.5rem; border: 1px solid #6d54ac; border-radius: 50%; color: #f5f0ff; font: inherit; font-size: 2rem; background: #302553; cursor: pointer; }
.manual-report__stepper button:disabled { opacity: .4; cursor: default; }
.manual-report__primary .manual-direction-panel {
width: 100%;
margin: 0;
border-radius: 1rem;
background: #1a1739;
}
.manual-direction-panel__topline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.manual-direction-panel__summary { margin: .35rem 0 .8rem; color: #f5f0ff; font-weight: 700; }
.manual-direction-panel__open, .manual-direction-panel__close { min-height: 2.75rem; border: 1px solid #8d77d2; border-radius: .7rem; color: #e8dcff; font: inherit; font-weight: 750; background: #302553; cursor: pointer; }
.manual-direction-panel__open { padding: .5rem .85rem; }
.manual-direction-panel__close { min-width: 2.75rem; font-size: 1.4rem; }
.manual-report__primary .manual-report__submit {
width: 100%;
min-height: 4.5rem;
}
.manual-report button:focus-visible, .manual-report input:focus-visible { outline: 3px solid #c9b4ff; outline-offset: 3px; }
.manual-report__supporting {
max-width: 36rem;
margin-top: 1.5rem;
@@ -50,6 +80,12 @@
background: #fff8fb;
}
:root[data-theme="light"] .manual-report__quantity #manual-occurrences { color: #321d42; }
:root[data-theme="light"] .manual-report__stepper button,
:root[data-theme="light"] .manual-direction-panel__open,
:root[data-theme="light"] .manual-direction-panel__close { color: #321d42; border-color: #b68bb5; background: #ead2eb; }
:root[data-theme="light"] .manual-direction-panel__summary { color: #321d42; }
:root[data-theme="light"] .manual-report__supporting {
border-color: #d9b4d8;
}
+1
View File
@@ -7,6 +7,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide
<form id="manual-report-form" action="/submit">
<input id="manual-latitude"><input id="manual-longitude">
<input id="manual-direction-degrees"><input id="manual-direction-accuracy">
<button id="manual-decrease" type="button"></button><input id="manual-occurrences" value="1"><button id="manual-increase" type="button"></button>
<div id="manual-direction-panel" hidden><button id="manual-capture-direction" type="button"></button><div id="manual-direction-status"></div></div>
<button id="manual-submit" type="button"></button>
<button id="burst-start" type="button"></button><div id="burst-panel"></div><strong id="burst-heading"></strong>
@@ -0,0 +1 @@
/* empty css */import"./fireworks-home.js-BqdOneRR.js";import"./map.js-BLPiBo7S.js";import"../../../manual-report-D-WkDeVJ.js";import"../../../theme-DXAi27ON.js";
@@ -0,0 +1 @@
/* empty css */import"./fireworks-home.js-BqdOneRR.js";import"./map.js-BLPiBo7S.js";import"../../../manual-report-zABrlhpW.js";import"../../../theme-DXAi27ON.js";
@@ -0,0 +1 @@
import"../../../manual-report-D-WkDeVJ.js";import"../../../theme-DXAi27ON.js";
@@ -0,0 +1 @@
import"../../../manual-report-zABrlhpW.js";import"../../../theme-DXAi27ON.js";
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
.burst-listener{width:min(100%,36rem);margin-top:1rem}.burst-listener__button,.burst-listener__actions button{min-height:2.75rem;padding:.65rem 1rem;border:1px solid #ffd18c;border-radius:.7rem;color:#fff2df;font:inherit;font-weight:750;background:#39243a;cursor:pointer}.burst-listener__panel{margin-top:.8rem;padding:1rem;border:1px solid #aa7294;border-radius:.8rem;background:#1b1730;color:#fff2df}.burst-listener__panel canvas{display:block;width:100%;height:90px;margin:.8rem 0;background:#171225;border-radius:.4rem}.burst-listener__panel p{margin:.5rem 0 1rem;color:#efc9dc}.burst-listener__panel audio{width:100%;margin-bottom:1rem}.burst-listener__actions{display:flex;flex-wrap:wrap;gap:.5rem}.burst-listener [hidden]{display:none!important}.burst-listener [role=alert]{color:#ffd18c}.manual-compass{display:grid;justify-items:center;width:7rem;margin:.6rem 0 0 auto;color:#fff3d7;font-size:.78rem;font-weight:850;font-variant-numeric:tabular-nums}.manual-compass[hidden]{display:none}.manual-compass__dial{position:relative;width:5.75rem;aspect-ratio:1;border:2px solid #f2d7a8;border-radius:50%;background:radial-gradient(circle,#342441 0,#342441 28%,#211a32 75%);box-shadow:0 .35rem 1rem #09061566,inset 0 0 0 .25rem #ffffff12}.manual-compass__rose{position:absolute;top:0;right:0;bottom:0;left:0;transition:transform .12s ease-out}.manual-compass__rose span{position:absolute;line-height:1}.manual-compass__north{top:.38rem;left:50%;color:#ff9e78;transform:translate(-50%)}.manual-compass__east{right:.47rem;top:50%;transform:translateY(-50%)}.manual-compass__south{bottom:.38rem;left:50%;transform:translate(-50%)}.manual-compass__west{left:.47rem;top:50%;transform:translateY(-50%)}.manual-compass__pointer{position:absolute;top:-.55rem;left:50%;width:0;height:0;border-right:.37rem solid transparent;border-bottom:.65rem solid #ffbd62;border-left:.37rem solid transparent;transform:translate(-50%);filter:drop-shadow(0 .1rem .15rem #160d1b)}.manual-compass__center{position:absolute;top:50%;left:50%;width:.5rem;aspect-ratio:1;border-radius:50%;background:#ffbd62;transform:translate(-50%,-50%)}.manual-compass__heading{margin-top:.5rem;white-space:nowrap}:root[data-theme=light] .manual-compass{color:#43243d}:root[data-theme=light] .manual-compass__dial{border-color:#996a9b;background:radial-gradient(circle,#f8ebf8 0,#f8ebf8 28%,#e8d7e9 75%)}:root[data-theme=light] .manual-compass__east,:root[data-theme=light] .manual-compass__south,:root[data-theme=light] .manual-compass__west{color:#43243d}@media(prefers-reduced-motion:reduce){.manual-compass__rose{transition:none}}.manual-report__header{max-width:42rem}.manual-report__primary{display:grid;gap:1rem;max-width:36rem}.manual-report__quantity{padding:1rem;border:1px solid #584891;border-radius:1rem;background:#151932}.manual-report__quantity #manual-occurrences{margin-bottom:0}.manual-report__primary .manual-direction-panel{width:100%;margin:0}.manual-report__primary .manual-report__submit{width:100%}.manual-report__supporting{max-width:36rem;margin-top:1.5rem;padding-top:1.25rem;border-top:1px solid #584891}.manual-report__supporting h3{margin:0;color:#d8cffd;font-size:1rem}.manual-report__supporting .burst-listener{width:100%}:root[data-theme=light] .manual-report__quantity{border-color:#d9b4d8;background:#fff8fb}:root[data-theme=light] .manual-report__supporting{border-color:#d9b4d8}:root[data-theme=light] .manual-report__supporting h3{color:#492846}
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -12,10 +12,10 @@ window.BOOMCAST_I18N = {
uploadFailed: "{% trans 'Upload failed. Check your connection and try again.' as value %}{{ value|escapejs }}",
accuracyUnavailable: "{% trans 'Accuracy unavailable' as value %}{{ value|escapejs }}",
accuracy: "{% trans 'Accuracy' as value %}{{ value|escapejs }}",
stopCapture: "{% trans 'Stop direction capture' as value %}{{ value|escapejs }}",
stopCapture: "{% trans 'Stop measuring direction' as value %}{{ value|escapejs }}",
pointPhone: "{% trans 'Point the top of your phone toward the sound — direction will update live.' as value %}{{ value|escapejs }}",
captureDirection: "{% trans 'Capture direction' as value %}{{ value|escapejs }}",
captureAgain: "{% trans 'Capture again' as value %}{{ value|escapejs }}",
captureDirection: "{% trans 'Start measuring direction' as value %}{{ value|escapejs }}",
captureAgain: "{% trans 'Measure again' as value %}{{ value|escapejs }}",
compassUnavailable: "{% trans 'Compass unavailable on this device.' as value %}{{ value|escapejs }}",
secureCompass: "{% trans 'Compass capture requires a secure HTTPS connection.' as value %}{{ value|escapejs }}",
compassPermission: "{% trans 'Requesting compass permission…' as value %}{{ value|escapejs }}",