fix: adjust class year, filter out unexpected weekdays and ignore useless CSV rows

This commit is contained in:
Mariano Riefolo 2024-09-04 17:11:24 +02:00
parent 4524d84ab9
commit 98e1d31e13
2 changed files with 20 additions and 21 deletions

View File

@ -171,12 +171,7 @@ pub async fn get_class(Query(params): Query<FilterByClassQuery>) -> impl IntoRes
for record in rdr.records() { for record in rdr.records() {
let record = match record { let record = match record {
Ok(x) => x, Ok(x) => x,
Err(_) => { Err(_) => continue,
return (
StatusCode::UNPROCESSABLE_ENTITY,
Json(json!({ "errore": "Formato non supportato"})),
)
}
}; };
for (i, cell) in record.iter().enumerate() { for (i, cell) in record.iter().enumerate() {
if cell == params.classe { if cell == params.classe {

View File

@ -54,7 +54,7 @@ function load_classes(id) {
} }
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const option = document.createElement("option"); const option = document.createElement("option");
option.value = i; option.value = i + 1;
option.text = i + 1; option.text = i + 1;
select.appendChild(option); select.appendChild(option);
} }
@ -87,12 +87,14 @@ function make_teacher_table(id, teacher) {
th.scope = "row"; th.scope = "row";
th.textContent = weekday; th.textContent = weekday;
tr.appendChild(th); tr.appendChild(th);
data[weekday].forEach((teacher_class) => { if (data[weekday] != null) {
let td = document.createElement("td"); data[weekday].forEach((teacher_class) => {
td.textContent = teacher_class; let td = document.createElement("td");
tr.appendChild(td); td.textContent = teacher_class;
}); tr.appendChild(td);
tbody.appendChild(tr); });
tbody.appendChild(tr);
}
}); });
table.appendChild(tbody); table.appendChild(tbody);
document.getElementById("table").removeAttribute("aria-busy"); document.getElementById("table").removeAttribute("aria-busy");
@ -123,12 +125,14 @@ function make_student_table(id, student_class) {
th.scope = "row"; th.scope = "row";
th.textContent = weekday; th.textContent = weekday;
tr.appendChild(th); tr.appendChild(th);
data[weekday].forEach((student_class) => { if (data[weekday] != null) {
let td = document.createElement("td"); data[weekday].forEach((student_class) => {
td.textContent = student_class; let td = document.createElement("td");
tr.appendChild(td); td.textContent = student_class;
}); tr.appendChild(td);
tbody.appendChild(tr); });
tbody.appendChild(tr);
}
}); });
table.appendChild(tbody); table.appendChild(tbody);
document.getElementById("table").removeAttribute("aria-busy"); document.getElementById("table").removeAttribute("aria-busy");
@ -168,7 +172,7 @@ function load_section() {
i--; i--;
} }
} }
Object.keys(data[year]).forEach((el) => { Object.keys(data[year - 1]).forEach((el) => {
const option = document.createElement("option"); const option = document.createElement("option");
option.value = el; option.value = el;
option.text = el; option.text = el;
@ -187,7 +191,7 @@ function load_major() {
i--; i--;
} }
} }
data[year][section].forEach((el) => { data[year - 1][section].forEach((el) => {
const option = document.createElement("option"); const option = document.createElement("option");
option.value = el; option.value = el;
option.text = el; option.text = el;