Add bulk import
All checks were successful
continuous-integration/drone/push Build is passing

Also make pressing return submit the manual number
This commit is contained in:
Julius 2022-06-23 17:09:28 +02:00
parent 1258bfe3a1
commit 9ca961d706
Signed by: j00lz
GPG key ID: AF241B0AA237BBA2

View file

@ -25,14 +25,19 @@
<div class="columns">
<div class="column col-md-12 col-6">
<h2>Handmatig Toevoegen</h2>
<p><label for="student_number">Leerlingnummer:</label></p>
<input type="text" id="student_number" name="student_number" placeholder="Leerlingnummer">
<button class="btn btn-primary" id="add_student">"Scan"</button>
<form id="student_number_wrapper">
<p><label for="student_number">Leerlingnummer:</label></p>
<input type="text" id="student_number" name="student_number" placeholder="Leerlingnummer">
<button class="btn btn-primary" id="add_student">"Scan"</button>
</form>
</div>
<div class="column col-md-12 col-6">
<h2>Extra opties</h2>
<p><a href="/party/{{id}}/lijst">Bekijk een tabel in je browser</a></p>
<p><a href="/party/{{id}}/export">Exporteer als CSV</a></p>
<p><label for="file-selector">Importeer CSV:</label><input type="file" id="file-selector"
accept=".csv" /></p>
<p><button id="file-selector-button">Importeer</button> <span id="import-result"></span></p>
</div>
</div>
</div>
@ -120,11 +125,19 @@
return data;
}).then(set_state);
}
function return_handler(e) {
e.preventDefault();
let code = document.getElementById("student_number").value;
console.log(code);
scan_ticket(code);
}
function button_click_handler() {
let code = document.getElementById("student_number").value;
scan_ticket(code);
}
document.getElementById("add_student").addEventListener("click", button_click_handler);
document.getElementById("student_number_wrapper").addEventListener("submit", return_handler);
document.getElementById("start_scan_btn").addEventListener('click', start_scanning);
const videoElement = document.querySelector("video");
@ -216,5 +229,29 @@
})
}
function upload_csv() {
let file = document.getElementById("file-selector").files[0];
if (file) {
const reader = new FileReader();
let num = 0;
reader.onload = (evt) => {
let result = evt.target.result;
for (let line of result.split("\n")) {
for (let llnr of line.split(",")) {
if (llnr.length === 6 && !isNaN(llnr)) {
scan_ticket(llnr);
num += 1;
}
}
}
document.getElementById("import-result").innerHTML = `${num} leerlingen geïmporteerd!`
}
reader.readAsText(file);
}
}
document.getElementById("file-selector-button").addEventListener("click", upload_csv);
</script>
{% endblock %}