From 9fdd2d4161d0546182af3c58427ab1549816c86f Mon Sep 17 00:00:00 2001 From: Mariano Riefolo Date: Wed, 4 Sep 2024 17:11:24 +0200 Subject: [PATCH] fix: adjust class year, filter out unexpected weekdays and ignore useless CSV rows --- src/api/mod.rs | 7 +------ static/index.js | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index f0d9233..f3c447c 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -171,12 +171,7 @@ pub async fn get_class(Query(params): Query) -> impl IntoRes for record in rdr.records() { let record = match record { Ok(x) => x, - Err(_) => { - return ( - StatusCode::UNPROCESSABLE_ENTITY, - Json(json!({ "errore": "Formato non supportato"})), - ) - } + Err(_) => continue, }; for (i, cell) in record.iter().enumerate() { if cell == params.classe { diff --git a/static/index.js b/static/index.js index 01faee5..15bdd6c 100644 --- a/static/index.js +++ b/static/index.js @@ -54,7 +54,7 @@ function load_classes(id) { } for (let i = 0; i < data.length; i++) { const option = document.createElement("option"); - option.value = i; + option.value = i + 1; option.text = i + 1; select.appendChild(option); } @@ -87,12 +87,14 @@ function make_teacher_table(id, teacher) { th.scope = "row"; th.textContent = weekday; tr.appendChild(th); - data[weekday].forEach((teacher_class) => { - let td = document.createElement("td"); - td.textContent = teacher_class; - tr.appendChild(td); - }); - tbody.appendChild(tr); + if (data[weekday] == null) { + data[weekday].forEach((teacher_class) => { + let td = document.createElement("td"); + td.textContent = teacher_class; + tr.appendChild(td); + }); + tbody.appendChild(tr); + } }); table.appendChild(tbody); document.getElementById("table").removeAttribute("aria-busy"); @@ -123,12 +125,14 @@ function make_student_table(id, student_class) { th.scope = "row"; th.textContent = weekday; tr.appendChild(th); - data[weekday].forEach((student_class) => { - let td = document.createElement("td"); - td.textContent = student_class; - tr.appendChild(td); - }); - tbody.appendChild(tr); + if (data[weekday] != null) { + data[weekday].forEach((student_class) => { + let td = document.createElement("td"); + td.textContent = student_class; + tr.appendChild(td); + }); + tbody.appendChild(tr); + } }); table.appendChild(tbody); document.getElementById("table").removeAttribute("aria-busy");