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..8d777cc 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"); @@ -168,7 +172,7 @@ function load_section() { i--; } } - Object.keys(data[year]).forEach((el) => { + Object.keys(data[year - 1]).forEach((el) => { const option = document.createElement("option"); option.value = el; option.text = el; @@ -187,7 +191,7 @@ function load_major() { i--; } } - data[year][section].forEach((el) => { + data[year - 1][section].forEach((el) => { const option = document.createElement("option"); option.value = el; option.text = el;