From 99a81ba6a00b8656a400ae56d7a18a7c401fd31d Mon Sep 17 00:00:00 2001 From: Mariano Riefolo Date: Thu, 5 Sep 2024 14:47:29 +0200 Subject: [PATCH] feat(frontend): fill table rows with empty cells --- static/index.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/static/index.js b/static/index.js index 8d777cc..707d192 100644 --- a/static/index.js +++ b/static/index.js @@ -71,6 +71,16 @@ function make_teacher_table(id, teacher) { fetch(`/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 = [ @@ -88,11 +98,18 @@ function make_teacher_table(id, teacher) { 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); } }); @@ -109,6 +126,16 @@ 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 = [ @@ -126,11 +153,18 @@ function make_student_table(id, student_class) { th.textContent = weekday; tr.appendChild(th); if (data[weekday] != null) { + let inserted = 0; data[weekday].forEach((student_class) => { let td = document.createElement("td"); td.textContent = student_class; tr.appendChild(td); + inserted++; }); + while (inserted < columns) { + let td = document.createElement("td"); + tr.appendChild(td); + inserted++; + } tbody.appendChild(tr); } });