manual submission redesign phase G

This commit is contained in:
Joren de Graaf
2026-10-06 20:04:21 +02:00
parent d112028eb1
commit c0c0bd7db8
11 changed files with 206 additions and 15 deletions
Binary file not shown.
@@ -11,7 +11,7 @@
<p class="manual-submission__summary">
{{ pending.created_at|date:"H:i" }} ·
{% blocktrans count count=pending.occurrences %}{{ count }} occurrence{% plural %}{{ count }} occurrences{% endblocktrans %}
{% if pending.direction_degrees is not None %} · {{ pending.direction_cardinal }} {{ pending.direction_degrees|floatformat:0 }}°{% endif %}
{% if direction_label %} · {{ direction_label }} {{ pending.direction_degrees|floatformat:0 }}°{% endif %}
</p>
{% endif %}
</div>
+14 -1
View File
@@ -185,6 +185,19 @@ class ManualPendingEventTests(TestCase):
self.assertContains(closed, 'id="manual-direction-summary"')
self.assertNotContains(closed, 'id="manual-capture-direction"')
def test_dutch_report_labels_and_direction_are_translated(self):
self.client.cookies["django_language"] = "nl"
page = self.client.get(reverse("hello"))
self.assertContains(page, "Hoe vaak hoorde je het?")
self.assertContains(page, "Ik hoorde vuurwerk")
self.assertContains(page, "Start luisteren")
response = self.client.post(reverse("fireworks_detect:submit_manual_pending"), {
"occurrences": "1", "direction_degrees": "192",
})
self.assertContains(response, "Melding ontvangen!")
self.assertContains(response, "Zuid 192°")
def test_old_route_preserves_the_previous_landing_page(self):
response = self.client.get(reverse("old_home"))
@@ -294,7 +307,7 @@ class ManualPendingEventTests(TestCase):
})
self.assertContains(response, "2 occurrences")
self.assertContains(response, "SW 237°")
self.assertContains(response, "Southwest 237°")
self.assertEqual(response.status_code, 200)
pending = PendingEvent.objects.get()
+8 -1
View File
@@ -415,7 +415,14 @@ def submit_manual_pending_event(request):
direction_accuracy_degrees=direction_accuracy_degrees,
direction_source="device_compass" if direction_degrees is not None else "",
)
return render(request, "fireworks_detect/manual_pending_submission.html", {"pending": pending})
direction_names = {
"N": _("North"), "NE": _("Northeast"), "E": _("East"), "SE": _("Southeast"),
"S": _("South"), "SW": _("Southwest"), "W": _("West"), "NW": _("Northwest"),
}
return render(request, "fireworks_detect/manual_pending_submission.html", {
"pending": pending,
"direction_label": direction_names.get(pending.direction_cardinal) if direction_degrees is not None else "",
})
@never_cache
def events_list(request):
+7 -6
View File
@@ -1,4 +1,5 @@
const form = document.querySelector("#manual-report-form");
const t = window.BOOMCAST_I18N || {};
export function createBurstListener() {
if (!form) return null;
@@ -47,12 +48,12 @@ export function createBurstListener() {
state = next;
if (container) container.dataset.state = next;
if (section) section.dataset.state = next;
if (stateLabel) stateLabel.textContent = next === "listening" ? "Listening for the next bang" : next === "tail" ? "Sound detected" : next === "captured" ? "Sound captured" : "Not listening";
if (stateLabel) stateLabel.textContent = next === "listening" ? (t.listeningNextBang || "Listening for the next bang") : next === "tail" ? (t.soundDetected || "Sound detected") : next === "captured" ? (t.soundCaptured || "Sound captured") : (t.notListening || "Not listening");
start.hidden = next !== "off";
panel.hidden = next === "off";
resume.hidden = discard.hidden = next !== "captured";
heading.textContent = next === "captured" ? "Sound captured" : next === "tail" ? "Sound detected — finishing clip…" : "Listening for the next sound…";
detail.textContent = next === "listening" ? "Keeping the most recent ~10 seconds" : next === "captured" ? "Preview the clip or send your report." : "";
heading.textContent = next === "captured" ? (t.soundCaptured || "Sound captured") : next === "tail" ? (t.soundDetectedFinishing || "Sound detected — finishing clip…") : (t.listeningNextSound || "Listening for the next sound…");
detail.textContent = next === "listening" ? (t.keepingRecentAudio || "Keeping the most recent ~10 seconds") : next === "captured" ? (t.previewClipOrSend || "Preview the clip or send your report.") : "";
}
function wav(samples, rate) {
@@ -81,7 +82,7 @@ export function createBurstListener() {
start.disabled = true;
if (container) container.dataset.state = "starting";
if (section) section.dataset.state = "starting";
if (stateLabel) stateLabel.textContent = "Starting microphone…";
if (stateLabel) stateLabel.textContent = t.startingMicrophone || "Starting microphone…";
try {
if (!navigator.mediaDevices?.getUserMedia || !window.AudioWorkletNode) throw new Error("Microphone listening is unavailable in this browser or connection.");
stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 }, video: false });
@@ -122,8 +123,8 @@ export function createBurstListener() {
await end();
if (container) container.dataset.state = "error";
if (section) section.dataset.state = "error";
if (stateLabel) stateLabel.textContent = "Microphone unavailable";
error.textContent = cause.name === "NotAllowedError" ? "Microphone permission was denied. Manual reporting is still available." : (cause.message || "Microphone capture failed.");
if (stateLabel) stateLabel.textContent = t.microphoneUnavailable || "Microphone unavailable";
error.textContent = cause.name === "NotAllowedError" ? (t.microphoneDenied || "Microphone permission was denied. Manual reporting is still available.") : (t.microphoneFailed || "Microphone capture failed.");
error.hidden = false;
} finally {
start.disabled = false;
+4 -1
View File
@@ -25,7 +25,10 @@
const burstListener = createBurstListener();
const isUsableNumber = (value) => Number.isFinite(value);
const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)];
const cardinalDirection = (heading) => [
t.north || "North", t.northeast || "Northeast", t.east || "East", t.southeast || "Southeast",
t.south || "South", t.southwest || "Southwest", t.west || "West", t.northwest || "Northwest",
][Math.floor(((heading + 22.5) % 360) / 45)];
const displayDegrees = (value) => Number(value.toFixed(1)).toString();
const updateReportTime = () => {
if (!reportTime) return;
+35 -3
View File
@@ -16,7 +16,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide
<button id="burst-stop" type="button"></button><p id="burst-error"></p>
</form>
<div id="manual-submission"></div>
<div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div>
<div id="manual-compass-home"><div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div></div>
</body></html>`, { url: "https://example.test/" });
const { window } = dom;
Object.defineProperty(window, "isSecureContext", { value: true });
@@ -24,8 +24,10 @@ test("compass stays hidden until permission and a heading, then rotates and hide
class MockOrientation {}
MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; });
window.DeviceOrientationEvent = MockOrientation;
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation })) {
let submissions = 0;
window.htmx = { ajax: () => { submissions++; } };
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent", "htmx", "DOMParser"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation, htmx: window.htmx, DOMParser: window.DOMParser })) {
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
}
try {
@@ -51,6 +53,36 @@ test("compass stays hidden until permission and a heading, then rotates and hide
assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1");
button.click();
assert.equal(compass.hidden, true);
window.document.querySelector("#manual-increase").click();
assert.equal(window.document.querySelector("#manual-occurrences").value, "2");
window.document.querySelector("#manual-decrease").click();
assert.equal(window.document.querySelector("#manual-occurrences").value, "1");
window.document.querySelector("#manual-direction-panel").outerHTML = '<div id="manual-direction-panel"><p class="manual-direction-panel__copy"></p><button id="manual-capture-direction"></button><div id="manual-direction-status"></div></div>';
const opened = window.document.querySelector("#manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: opened } }));
assert.equal(compass.parentElement.id, "manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:beforeSwap", { detail: { target: opened } }));
assert.equal(compass.parentElement.id, "manual-compass-home");
opened.outerHTML = '<div id="manual-direction-panel"><p id="manual-direction-summary">Not captured</p></div>';
const closed = window.document.querySelector("#manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: closed } }));
assert.equal(window.document.querySelector("#manual-direction-summary").textContent, "North · 1°");
const submit = window.document.querySelector("#manual-submit");
const form = window.document.querySelector("#manual-report-form");
submit.click();
submit.click();
assert.equal(submissions, 1);
assert.equal(submit.disabled, true);
window.document.querySelector("#manual-submission").outerHTML = '<div id="manual-submission" data-result="success">Received</div>';
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 200 } } }));
assert.equal(submit.disabled, false);
submit.click();
assert.equal(submissions, 2);
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 400, responseText: '<div id="manual-submission" data-result="error">Try again</div>' } } }));
assert.equal(window.document.querySelector("#manual-submission").dataset.result, "error");
assert.equal(submit.disabled, false);
} finally {
for (const [key, descriptor] of Object.entries(previous)) {
if (descriptor === undefined) delete globalThis[key];
Binary file not shown.
+114
View File
@@ -1286,3 +1286,117 @@ msgstr "De server verwerkt momenteel alleen audio-opnamen. Kies een audiobestand
msgid "Local checking was unavailable. BoomCast will use normal server processing."
msgstr "Lokale controle was niet beschikbaar. BoomCast gebruikt de normale verwerking op de server."
msgid "Quick report"
msgstr "Snelle melding"
msgid "Did you hear a bang? Report what you heard in a few taps."
msgstr "Heb je een knal gehoord? Meld in een paar tikken wat je hoorde."
msgid "Now"
msgstr "Nu"
msgid "How many times did you hear it?"
msgstr "Hoe vaak hoorde je het?"
msgid "Decrease occurrences"
msgstr "Aantal verlagen"
msgid "Increase occurrences"
msgstr "Aantal verhogen"
msgid "I heard fireworks"
msgstr "Ik hoorde vuurwerk"
msgid "Automatic detection"
msgstr "Automatische detectie"
msgid "Not listening"
msgstr "Luistert niet"
msgid "Start listening"
msgstr "Start luisteren"
msgid "Close direction capture"
msgstr "Richtingmeting sluiten"
msgid "Start measuring direction"
msgstr "Richting meten"
msgid "Not captured"
msgstr "Niet vastgelegd"
msgid "Report received!"
msgstr "Melding ontvangen!"
msgid "Thank you. Your report helps map fireworks nearby."
msgstr "Bedankt voor je bijdrage. Je melding helpt om vuurwerk in de buurt in kaart te brengen."
msgid "Stop measuring direction"
msgstr "Stop richting meten"
msgid "Measure again"
msgstr "Opnieuw meten"
msgid "Sending…"
msgstr "Versturen…"
msgid "Could not send the report. Please try again."
msgstr "De melding kon niet worden verzonden. Probeer het opnieuw."
msgid "North"
msgstr "Noord"
msgid "Northeast"
msgstr "Noordoost"
msgid "East"
msgstr "Oost"
msgid "Southeast"
msgstr "Zuidoost"
msgid "South"
msgstr "Zuid"
msgid "Southwest"
msgstr "Zuidwest"
msgid "West"
msgstr "West"
msgid "Northwest"
msgstr "Noordwest"
msgid "Listening for the next bang"
msgstr "Luistert naar de volgende knal"
msgid "Sound detected"
msgstr "Geluid gedetecteerd"
msgid "Sound captured"
msgstr "Geluid vastgelegd"
msgid "Sound detected — finishing clip…"
msgstr "Geluid gedetecteerd — opname afronden…"
msgid "Listening for the next sound…"
msgstr "Luistert naar het volgende geluid…"
msgid "Keeping the most recent ~10 seconds"
msgstr "Bewaart de laatste ~10 seconden"
msgid "Preview the clip or send your report."
msgstr "Luister de opname terug of dien je melding in."
msgid "Starting microphone…"
msgstr "Microfoon starten…"
msgid "Microphone unavailable"
msgstr "Microfoon niet beschikbaar"
msgid "Microphone permission was denied. Manual reporting is still available."
msgstr "Toegang tot de microfoon is geweigerd. Je kunt nog steeds handmatig melden."
msgid "Microphone capture failed."
msgstr "Opnemen met de microfoon is mislukt."
+2 -1
View File
@@ -7,7 +7,8 @@
<title>{% trans "Settings · Sound Signal" %}</title>
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js"></script>
{% vite_asset "frontend/src/entries/settings.js" %}
{% include "js_translations.html" %}</head>
{% include "js_translations.html" %}
</head>
<body>
<main class="settings-shell">
{% include "fireworks_detect/includes/navigation.html" %}
+20
View File
@@ -23,6 +23,26 @@ window.BOOMCAST_I18N = {
requestingLocation: "{% trans 'Requesting your optional location…' as value %}{{ value|escapejs }}",
sendingReport: "{% trans 'Sending…' as value %}{{ value|escapejs }}",
reportFailed: "{% trans 'Could not send the report. Please try again.' as value %}{{ value|escapejs }}",
north: "{% trans 'North' as value %}{{ value|escapejs }}",
northeast: "{% trans 'Northeast' as value %}{{ value|escapejs }}",
east: "{% trans 'East' as value %}{{ value|escapejs }}",
southeast: "{% trans 'Southeast' as value %}{{ value|escapejs }}",
south: "{% trans 'South' as value %}{{ value|escapejs }}",
southwest: "{% trans 'Southwest' as value %}{{ value|escapejs }}",
west: "{% trans 'West' as value %}{{ value|escapejs }}",
northwest: "{% trans 'Northwest' as value %}{{ value|escapejs }}",
listeningNextBang: "{% trans 'Listening for the next bang' as value %}{{ value|escapejs }}",
soundDetected: "{% trans 'Sound detected' as value %}{{ value|escapejs }}",
soundCaptured: "{% trans 'Sound captured' as value %}{{ value|escapejs }}",
notListening: "{% trans 'Not listening' as value %}{{ value|escapejs }}",
soundDetectedFinishing: "{% trans 'Sound detected — finishing clip…' as value %}{{ value|escapejs }}",
listeningNextSound: "{% trans 'Listening for the next sound…' as value %}{{ value|escapejs }}",
keepingRecentAudio: "{% trans 'Keeping the most recent ~10 seconds' as value %}{{ value|escapejs }}",
previewClipOrSend: "{% trans 'Preview the clip or send your report.' as value %}{{ value|escapejs }}",
startingMicrophone: "{% trans 'Starting microphone…' as value %}{{ value|escapejs }}",
microphoneUnavailable: "{% trans 'Microphone unavailable' as value %}{{ value|escapejs }}",
microphoneDenied: "{% trans 'Microphone permission was denied. Manual reporting is still available.' as value %}{{ value|escapejs }}",
microphoneFailed: "{% trans 'Microphone capture failed.' as value %}{{ value|escapejs }}",
mapCompass: "{% trans 'Map compass: north is up' as value %}{{ value|escapejs }}",
reports: "{% trans 'reports' as value %}{{ value|escapejs }}",
occurrences: "{% trans 'occurrences' as value %}{{ value|escapejs }}",