Compare commits

..

No commits in common. "7a31ac4ba08ba601cd60894d90a4e87d66423e89" and "99a81ba6a00b8656a400ae56d7a18a7c401fd31d" have entirely different histories.

View File

@ -68,15 +68,7 @@ function load_classes(id) {
}
function make_teacher_table(id, teacher) {
make_table(`/api/professore?id=${id}&professore=${teacher}`);
}
function make_student_table(id, student_class) {
make_table(`/api/classe?id=${id}&classe=${student_class}`);
}
function make_table(url) {
fetch(url)
fetch(`/api/professore?id=${id}&professore=${teacher}`)
.then((response) => response.json())
.then((data) => {
for (let key in data) {
@ -99,19 +91,61 @@ function make_table(url) {
"Venerdì",
"Sabato",
];
let thead = document.createElement("thead");
let tr = document.createElement("tr");
let th = document.createElement("th");
th.scope = "col";
tr.appendChild(th);
for (let i = 0; i < columns; i++) {
week.forEach((weekday) => {
let tr = document.createElement("tr");
let th = document.createElement("th");
th.scope = "col";
th.textContent = i + 1;
th.scope = "row";
th.textContent = weekday;
tr.appendChild(th);
if (data[weekday] != null) {
let inserted = 0;
data[weekday].forEach((teacher_class) => {
let td = document.createElement("td");
td.textContent = teacher_class;
tr.appendChild(td);
inserted++;
});
while (inserted < columns) {
let td = document.createElement("td");
tr.appendChild(td);
inserted++;
}
tbody.appendChild(tr);
}
});
table.appendChild(tbody);
document.getElementById("table").removeAttribute("aria-busy");
})
.catch((error) => {
alert("Errore nel caricamento dei dati, riprova più tardi.");
console.error("Error:", error);
});
}
function make_student_table(id, student_class) {
fetch(`/api/classe?id=${id}&classe=${student_class}`)
.then((response) => response.json())
.then((data) => {
for (let key in data) {
let i = data[key].length - 1;
while (i >= 0 && data[key][i] === "") {
data[key].pop();
i--;
}
}
thead.appendChild(tr);
table.appendChild(thead);
const columns = Math.max(
...Object.values(data).map((vettore) => vettore.length),
);
let table = document.getElementById("table");
let tbody = document.createElement("tbody");
let week = [
"Lunedì",
"Martedì",
"Mercoledì",
"Giovedì",
"Venerdì",
"Sabato",
];
week.forEach((weekday) => {
let tr = document.createElement("tr");
let th = document.createElement("th");
@ -122,7 +156,7 @@ function make_table(url) {
let inserted = 0;
data[weekday].forEach((student_class) => {
let td = document.createElement("td");
td.textContent = student_class.replace(/ (?=[a-z])/g, "");
td.textContent = student_class;
tr.appendChild(td);
inserted++;
});