158 lines
4.7 KiB
HTML
158 lines
4.7 KiB
HTML
{% 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">Bestätigen</button>
|
|
</form>
|
|
|
|
<div class="result invisible" id="result">
|
|
<fieldset>
|
|
<legend id="result_title"></legend>
|
|
<div id="result_content"></div>
|
|
</fieldset>
|
|
<button onclick="loadNext();">Weiter</button>
|
|
</div>
|
|
|
|
|
|
<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 rating_div = document.getElementById("rating");
|
|
rating_div.style = "";
|
|
|
|
const result_div = document.getElementById("result");
|
|
result_div.classList.add("invisible");
|
|
|
|
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);
|
|
|
|
const rating_div = document.getElementById("rating");
|
|
rating_div.style = "display: none;";
|
|
|
|
const result_div = document.getElementById("result");
|
|
result_div.classList.remove("invisible");
|
|
|
|
const result_title = document.getElementById("result_title");
|
|
const result_content = document.getElementById("result_content");
|
|
|
|
const data = await res.json();
|
|
console.log(data);
|
|
if (data.solution.truth !== false) {
|
|
if (data.solution.truth === data.solution.choice) {
|
|
result_div.classList.add("right");
|
|
result_title.innerHTML = "Richtig";
|
|
result_content.innerHTML = "Du hast richtig gehört!";
|
|
console.log("Richtig [debug]");
|
|
} else {
|
|
result_title.innerHTML = "Falsch";
|
|
result_content.innerHTML = "Du hast falsch gehört!";
|
|
result_div.classList.add("wrong");
|
|
console.log("Falsch [debug]");
|
|
}
|
|
} else {
|
|
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 %} |