feat(frontend): fill table rows with empty cells
This commit is contained in:
parent
98e1d31e13
commit
99a81ba6a0
@ -71,6 +71,16 @@ function make_teacher_table(id, teacher) {
|
|||||||
fetch(`/api/professore?id=${id}&professore=${teacher}`)
|
fetch(`/api/professore?id=${id}&professore=${teacher}`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.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 table = document.getElementById("table");
|
||||||
let tbody = document.createElement("tbody");
|
let tbody = document.createElement("tbody");
|
||||||
let week = [
|
let week = [
|
||||||
@ -88,11 +98,18 @@ function make_teacher_table(id, teacher) {
|
|||||||
th.textContent = weekday;
|
th.textContent = weekday;
|
||||||
tr.appendChild(th);
|
tr.appendChild(th);
|
||||||
if (data[weekday] != null) {
|
if (data[weekday] != null) {
|
||||||
|
let inserted = 0;
|
||||||
data[weekday].forEach((teacher_class) => {
|
data[weekday].forEach((teacher_class) => {
|
||||||
let td = document.createElement("td");
|
let td = document.createElement("td");
|
||||||
td.textContent = teacher_class;
|
td.textContent = teacher_class;
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
|
inserted++;
|
||||||
});
|
});
|
||||||
|
while (inserted < columns) {
|
||||||
|
let td = document.createElement("td");
|
||||||
|
tr.appendChild(td);
|
||||||
|
inserted++;
|
||||||
|
}
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -109,6 +126,16 @@ function make_student_table(id, student_class) {
|
|||||||
fetch(`/api/classe?id=${id}&classe=${student_class}`)
|
fetch(`/api/classe?id=${id}&classe=${student_class}`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.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 table = document.getElementById("table");
|
||||||
let tbody = document.createElement("tbody");
|
let tbody = document.createElement("tbody");
|
||||||
let week = [
|
let week = [
|
||||||
@ -126,11 +153,18 @@ function make_student_table(id, student_class) {
|
|||||||
th.textContent = weekday;
|
th.textContent = weekday;
|
||||||
tr.appendChild(th);
|
tr.appendChild(th);
|
||||||
if (data[weekday] != null) {
|
if (data[weekday] != null) {
|
||||||
|
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;
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
|
inserted++;
|
||||||
});
|
});
|
||||||
|
while (inserted < columns) {
|
||||||
|
let td = document.createElement("td");
|
||||||
|
tr.appendChild(td);
|
||||||
|
inserted++;
|
||||||
|
}
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user