Compare commits
No commits in common. "7a31ac4ba08ba601cd60894d90a4e87d66423e89" and "99a81ba6a00b8656a400ae56d7a18a7c401fd31d" have entirely different histories.
7a31ac4ba0
...
99a81ba6a0
@ -68,15 +68,7 @@ function load_classes(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_teacher_table(id, teacher) {
|
function make_teacher_table(id, teacher) {
|
||||||
make_table(`/api/professore?id=${id}&professore=${teacher}`);
|
fetch(`/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)
|
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
@ -99,19 +91,61 @@ function make_table(url) {
|
|||||||
"Venerdì",
|
"Venerdì",
|
||||||
"Sabato",
|
"Sabato",
|
||||||
];
|
];
|
||||||
let thead = document.createElement("thead");
|
week.forEach((weekday) => {
|
||||||
let tr = document.createElement("tr");
|
let tr = document.createElement("tr");
|
||||||
let th = document.createElement("th");
|
let th = document.createElement("th");
|
||||||
th.scope = "col";
|
th.scope = "row";
|
||||||
tr.appendChild(th);
|
th.textContent = weekday;
|
||||||
for (let i = 0; i < columns; i++) {
|
|
||||||
let th = document.createElement("th");
|
|
||||||
th.scope = "col";
|
|
||||||
th.textContent = i + 1;
|
|
||||||
tr.appendChild(th);
|
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++;
|
||||||
}
|
}
|
||||||
thead.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
table.appendChild(thead);
|
}
|
||||||
|
});
|
||||||
|
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--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) => {
|
week.forEach((weekday) => {
|
||||||
let tr = document.createElement("tr");
|
let tr = document.createElement("tr");
|
||||||
let th = document.createElement("th");
|
let th = document.createElement("th");
|
||||||
@ -122,7 +156,7 @@ function make_table(url) {
|
|||||||
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.replace(/ (?=[a-z])/g, "");
|
td.textContent = student_class;
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
inserted++;
|
inserted++;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user