Compare commits

...

3 Commits

View File

@ -68,62 +68,15 @@ function load_classes(id) {
} }
function make_teacher_table(id, teacher) { function make_teacher_table(id, teacher) {
fetch(`/api/professore?id=${id}&professore=${teacher}`) make_table(`/api/professore?id=${id}&professore=${teacher}`);
.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--;
}
}
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");
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) { function make_student_table(id, student_class) {
fetch(`/api/classe?id=${id}&classe=${student_class}`) make_table(`/api/classe?id=${id}&classe=${student_class}`);
}
function make_table(url) {
fetch(url)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
for (let key in data) { for (let key in data) {
@ -146,6 +99,19 @@ function make_student_table(id, student_class) {
"Venerdì", "Venerdì",
"Sabato", "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++) {
let th = document.createElement("th");
th.scope = "col";
th.textContent = i + 1;
tr.appendChild(th);
}
thead.appendChild(tr);
table.appendChild(thead);
week.forEach((weekday) => { week.forEach((weekday) => {
let tr = document.createElement("tr"); let tr = document.createElement("tr");
let th = document.createElement("th"); let th = document.createElement("th");
@ -156,7 +122,7 @@ function make_student_table(id, student_class) {
let inserted = 0; let inserted = 0;
data[weekday].forEach((student_class) => { data[weekday].forEach((student_class) => {
let td = document.createElement("td"); let td = document.createElement("td");
td.textContent = student_class; td.textContent = student_class.replace(/ (?=[a-z])/g, "");
tr.appendChild(td); tr.appendChild(td);
inserted++; inserted++;
}); });