feat: test and save results
This commit is contained in:
1 parent
92807e857a
commit
255699a25c
12 files changed
+797
-3
No files matched your search
@@ -1,4 +1,118 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style/player.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style/test.css') }}">
|
||||
|
||||
<h2 id="title"></h2>
|
||||
|
||||
<div class="ab-player" id="player">
|
||||
<p class="status" role="status"></p>
|
||||
|
||||
<div class="track is-active">
|
||||
<button type="button" class="track-label" aria-pressed="true" aria-label="Version A hören">A</button>
|
||||
<canvas aria-hidden="true"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="track">
|
||||
<button type="button" class="track-label" aria-pressed="false" aria-label="Version B hören">B</button>
|
||||
<canvas aria-hidden="true"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="transport">
|
||||
<button type="button" class="play" aria-label="Abspielen" disabled>
|
||||
<svg class="icon-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4.5v15l13-7.5z"/></svg>
|
||||
<svg class="icon-pause" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>
|
||||
</button>
|
||||
<span class="time">0:00 / 0:00</span>
|
||||
<button type="button" class="toggle" disabled>A/B wechseln</button>
|
||||
<p class="hint">Leertaste startet und pausiert. [A] wechselt auf A, [B] auf B. [T] wechselt zwischen A und B.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form class="rating" id="rating">
|
||||
<fieldset>
|
||||
<legend>Welche Version hat die bessere Qualität?</legend>
|
||||
<div class="choices">
|
||||
<label class="choice">
|
||||
<input type="radio" name="choice" value="a" required>
|
||||
<span>A</span>
|
||||
</label>
|
||||
<label class="choice">
|
||||
<input type="radio" name="choice" value="b">
|
||||
<span>B</span>
|
||||
</label>
|
||||
<label class="choice choice-none">
|
||||
<input type="radio" name="choice" value="non">
|
||||
<span>Kein Unterschied</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<button type="submit">Weiter</button>
|
||||
</form>
|
||||
|
||||
|
||||
<script src="{{ url_for('static', filename='player.js') }}"></script>
|
||||
<script>
|
||||
const player = new ABPlayer(document.getElementById("player"));
|
||||
const form = document.getElementById("rating");
|
||||
|
||||
async function loadNext() {
|
||||
const res = await fetch("{{ url_for('main.api_getRandomSong') }}");
|
||||
|
||||
if (res.status === 401) {
|
||||
location.href = "{{ url_for('main.index') }}";
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.finished) {
|
||||
player.reset();
|
||||
document.getElementById("title").textContent = "Fertig, danke!";
|
||||
document.getElementById("player").hidden = true;
|
||||
form.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById("title").textContent = "Test " + data.number + ": " + data.song_name;
|
||||
try {
|
||||
await player.load(data.a, data.b);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const choice = new FormData(form).get("choice");
|
||||
const submit = form.querySelector("button[type=submit]");
|
||||
|
||||
submit.disabled = true;
|
||||
player.pause();
|
||||
|
||||
try {
|
||||
const res = await fetch("{{ url_for('main.api_rate') }}", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ choice }),
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
location.href = "{{ url_for('main.index') }}";
|
||||
return;
|
||||
}
|
||||
if (!res.ok) throw new Error("HTTP " + res.status);
|
||||
|
||||
form.reset();
|
||||
await loadNext();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
player.setStatus("Die Bewertung konnte nicht gespeichert werden. Bitte versuche es erneut.");
|
||||
} finally {
|
||||
submit.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
loadNext();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user