2024-09-11 17:45:03 +00:00
|
|
|
function load_pdfs() {
|
2024-09-03 14:36:44 +00:00
|
|
|
fetch("/api/pdf")
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
let i = 0;
|
2024-09-11 17:45:03 +00:00
|
|
|
if (data === undefined || data.length === 0) {
|
2024-09-07 12:26:34 +00:00
|
|
|
show_error(null, "Nessun orario trovato");
|
|
|
|
return;
|
|
|
|
}
|
2024-09-11 17:45:03 +00:00
|
|
|
data.forEach((el) => {
|
|
|
|
const select = document.getElementById("pdf");
|
2024-09-03 14:36:44 +00:00
|
|
|
const option = document.createElement("option");
|
|
|
|
option.value = i;
|
2024-09-11 17:45:03 +00:00
|
|
|
option.text = el;
|
2024-09-03 14:36:44 +00:00
|
|
|
select.appendChild(option);
|
|
|
|
i++;
|
|
|
|
});
|
2024-09-11 17:45:03 +00:00
|
|
|
document.getElementById("pdf-label").removeAttribute("aria-busy");
|
2024-09-04 12:25:52 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-09-07 12:26:34 +00:00
|
|
|
show_error(error);
|
2024-09-03 14:36:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_teachers(id) {
|
|
|
|
fetch(`/api/professori?id=${id}`)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
2024-09-03 14:42:59 +00:00
|
|
|
sessionStorage.setItem("teachers", JSON.stringify(data));
|
2024-09-03 14:36:44 +00:00
|
|
|
let i = 0;
|
2024-09-04 12:01:18 +00:00
|
|
|
const list = document.getElementById("teachers");
|
|
|
|
list.innerHTML = "";
|
2024-09-03 14:36:44 +00:00
|
|
|
data.forEach((el) => {
|
|
|
|
const option = document.createElement("option");
|
|
|
|
option.value = el;
|
2024-09-12 10:41:41 +00:00
|
|
|
option.text = el;
|
2024-09-04 12:01:18 +00:00
|
|
|
list.appendChild(option);
|
2024-09-03 14:36:44 +00:00
|
|
|
i++;
|
|
|
|
});
|
2024-09-04 12:48:55 +00:00
|
|
|
document.getElementById("teacher-label").removeAttribute("aria-busy");
|
2024-09-04 12:25:52 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-09-07 12:26:34 +00:00
|
|
|
show_error(error);
|
2024-09-03 14:36:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_classes(id) {
|
|
|
|
fetch(`/api/classi?id=${id}`)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
2024-09-04 12:01:18 +00:00
|
|
|
const select = document.getElementById("year");
|
|
|
|
for (let i = 0; i < select.children.length; i++) {
|
|
|
|
if (!select.children[i].hasAttribute("disabled")) {
|
|
|
|
select.removeChild(select.children[i]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2024-09-03 14:36:44 +00:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
const option = document.createElement("option");
|
2024-09-04 15:11:24 +00:00
|
|
|
option.value = i + 1;
|
2024-09-03 14:36:44 +00:00
|
|
|
option.text = i + 1;
|
|
|
|
select.appendChild(option);
|
|
|
|
}
|
|
|
|
sessionStorage.setItem("classes", JSON.stringify(data));
|
2024-09-04 12:48:55 +00:00
|
|
|
document.getElementById("class-label").removeAttribute("aria-busy");
|
2024-09-04 12:25:52 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-09-07 12:26:34 +00:00
|
|
|
show_error(error);
|
2024-09-03 14:36:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_teacher_table(id, teacher) {
|
2024-09-05 13:01:04 +00:00
|
|
|
make_table(`/api/professore?id=${id}&professore=${teacher}`);
|
2024-09-03 14:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function make_student_table(id, student_class) {
|
2024-09-05 13:01:04 +00:00
|
|
|
make_table(`/api/classe?id=${id}&classe=${student_class}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_table(url) {
|
|
|
|
fetch(url)
|
2024-09-03 14:36:44 +00:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
2024-09-05 12:47:29 +00:00
|
|
|
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),
|
|
|
|
);
|
2024-09-03 14:36:44 +00:00
|
|
|
let table = document.getElementById("table");
|
|
|
|
let tbody = document.createElement("tbody");
|
|
|
|
let week = [
|
|
|
|
"Lunedì",
|
|
|
|
"Martedì",
|
|
|
|
"Mercoledì",
|
|
|
|
"Giovedì",
|
|
|
|
"Venerdì",
|
|
|
|
"Sabato",
|
|
|
|
];
|
2024-09-05 13:26:59 +00:00
|
|
|
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);
|
2024-09-03 14:36:44 +00:00
|
|
|
week.forEach((weekday) => {
|
|
|
|
let tr = document.createElement("tr");
|
|
|
|
let th = document.createElement("th");
|
|
|
|
th.scope = "row";
|
|
|
|
th.textContent = weekday;
|
|
|
|
tr.appendChild(th);
|
2024-09-04 15:11:24 +00:00
|
|
|
if (data[weekday] != null) {
|
2024-09-05 12:47:29 +00:00
|
|
|
let inserted = 0;
|
2024-09-04 15:11:24 +00:00
|
|
|
data[weekday].forEach((student_class) => {
|
|
|
|
let td = document.createElement("td");
|
2024-09-05 13:30:38 +00:00
|
|
|
td.textContent = student_class.replace(/ (?=[a-z])/g, "");
|
2024-09-04 15:11:24 +00:00
|
|
|
tr.appendChild(td);
|
2024-09-05 12:47:29 +00:00
|
|
|
inserted++;
|
2024-09-04 15:11:24 +00:00
|
|
|
});
|
2024-09-05 12:47:29 +00:00
|
|
|
while (inserted < columns) {
|
|
|
|
let td = document.createElement("td");
|
|
|
|
tr.appendChild(td);
|
|
|
|
inserted++;
|
|
|
|
}
|
2024-09-04 15:11:24 +00:00
|
|
|
tbody.appendChild(tr);
|
|
|
|
}
|
2024-09-03 14:36:44 +00:00
|
|
|
});
|
|
|
|
table.appendChild(tbody);
|
2024-09-04 12:48:55 +00:00
|
|
|
document.getElementById("table").removeAttribute("aria-busy");
|
2024-09-04 12:25:52 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-09-07 12:26:34 +00:00
|
|
|
show_error(error);
|
2024-09-03 14:36:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_pdf() {
|
2024-09-11 17:45:03 +00:00
|
|
|
Cookies.set("id", document.getElementById("pdf").value);
|
2024-09-07 11:45:10 +00:00
|
|
|
reset_forms();
|
|
|
|
document.getElementById("type").value = "none";
|
|
|
|
document.getElementById("form-teacher").setAttribute("hidden", "");
|
|
|
|
document.getElementById("form-classes").setAttribute("hidden", "");
|
2024-09-03 14:36:44 +00:00
|
|
|
document.getElementById("form-type").removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
|
2024-09-07 11:45:10 +00:00
|
|
|
function reset_forms() {
|
|
|
|
document.getElementById("year").value = "none";
|
|
|
|
document.getElementById("section").value = "none";
|
|
|
|
document.getElementById("major").value = "none";
|
|
|
|
document.getElementById("teacher").value = "";
|
|
|
|
}
|
|
|
|
|
2024-09-03 14:36:44 +00:00
|
|
|
function select_type() {
|
2024-09-11 17:45:03 +00:00
|
|
|
let id = document.getElementById("pdf").value;
|
2024-09-03 14:36:44 +00:00
|
|
|
let value = document.getElementById("type").value;
|
2024-09-07 11:45:10 +00:00
|
|
|
reset_forms();
|
2024-09-03 14:36:44 +00:00
|
|
|
if (value === "teacher") {
|
|
|
|
load_teachers(id);
|
|
|
|
document.getElementById("form-teacher").removeAttribute("hidden");
|
|
|
|
document.getElementById("form-classes").setAttribute("hidden", "");
|
|
|
|
} else if (value === "student") {
|
|
|
|
load_classes(id);
|
|
|
|
document.getElementById("form-classes").removeAttribute("hidden");
|
|
|
|
document.getElementById("form-teacher").setAttribute("hidden", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_section() {
|
|
|
|
let data = JSON.parse(sessionStorage.getItem("classes"));
|
|
|
|
let year = document.getElementById("year").value;
|
2024-09-04 12:01:18 +00:00
|
|
|
const select = document.getElementById("section");
|
|
|
|
for (let i = 0; i < select.children.length; i++) {
|
|
|
|
if (!select.children[i].hasAttribute("disabled")) {
|
|
|
|
select.removeChild(select.children[i]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2024-09-04 15:11:24 +00:00
|
|
|
Object.keys(data[year - 1]).forEach((el) => {
|
2024-09-03 14:36:44 +00:00
|
|
|
const option = document.createElement("option");
|
|
|
|
option.value = el;
|
|
|
|
option.text = el;
|
|
|
|
select.appendChild(option);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_major() {
|
|
|
|
let data = JSON.parse(sessionStorage.getItem("classes"));
|
|
|
|
let year = document.getElementById("year").value;
|
|
|
|
let section = document.getElementById("section").value;
|
2024-09-04 12:01:18 +00:00
|
|
|
let select = document.getElementById("major");
|
|
|
|
for (let i = 0; i < select.children.length; i++) {
|
|
|
|
if (!select.children[i].hasAttribute("disabled")) {
|
|
|
|
select.removeChild(select.children[i]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2024-09-04 15:11:24 +00:00
|
|
|
data[year - 1][section].forEach((el) => {
|
2024-09-03 14:36:44 +00:00
|
|
|
const option = document.createElement("option");
|
|
|
|
option.value = el;
|
|
|
|
option.text = el;
|
|
|
|
select.appendChild(option);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_teacher() {
|
2024-09-12 10:41:41 +00:00
|
|
|
let teacher = document.getElementById("teachers").value;
|
2024-09-03 14:42:59 +00:00
|
|
|
let teachers = JSON.parse(sessionStorage.getItem("teachers"));
|
|
|
|
if (!teachers.includes(teacher)) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-09-03 14:36:44 +00:00
|
|
|
Cookies.set("type", "teacher");
|
2024-09-03 14:42:59 +00:00
|
|
|
Cookies.set("teacher", teacher);
|
2024-09-03 14:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function select_class() {
|
|
|
|
Cookies.set("type", "student");
|
|
|
|
let student_class = document.getElementById("year").value;
|
|
|
|
student_class += document.getElementById("section").value;
|
|
|
|
student_class += document.getElementById("major").value;
|
|
|
|
Cookies.set("class", student_class);
|
|
|
|
}
|
|
|
|
|
2024-09-03 15:17:04 +00:00
|
|
|
function delete_cookies() {
|
|
|
|
Cookies.remove("id");
|
|
|
|
Cookies.remove("type");
|
|
|
|
Cookies.remove("teacher");
|
|
|
|
Cookies.remove("class");
|
|
|
|
}
|
|
|
|
|
2024-09-07 12:26:34 +00:00
|
|
|
function show_error(e, message) {
|
|
|
|
let default_error = "Errore nel caricamento dei dati, riprova più tardi";
|
|
|
|
console.error(e ?? default_error);
|
|
|
|
document.getElementById("error").textContent = message ?? default_error;
|
|
|
|
document.getElementById("error-dialog").setAttribute("open", "");
|
|
|
|
}
|
|
|
|
|
2024-09-12 10:41:41 +00:00
|
|
|
function filter_teachers() {
|
|
|
|
let input = document.getElementById("teacher");
|
|
|
|
let filter = input.value.toUpperCase();
|
|
|
|
let select = document.getElementById("teachers");
|
|
|
|
let option = select.getElementsByTagName("option");
|
|
|
|
let found_first = false;
|
|
|
|
for (let i = 0; i < option.length; i++) {
|
|
|
|
let txtValue = option[i].textContent;
|
|
|
|
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
|
|
|
option[i].style.display = "";
|
|
|
|
if (!found_first) {
|
|
|
|
select.selectedIndex = i;
|
|
|
|
found_first = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
option[i].style.display = "none";
|
|
|
|
if (option[i].hasAttribute("selected")) {
|
|
|
|
option[i].removeAttribute("selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-03 14:36:44 +00:00
|
|
|
if (Cookies.get("id") && Cookies.get("type")) {
|
|
|
|
if (Cookies.get("type") === "teacher" && Cookies.get("teacher")) {
|
|
|
|
make_teacher_table(Cookies.get("id"), Cookies.get("teacher"));
|
2024-09-03 15:17:04 +00:00
|
|
|
document.getElementById("dashboard").removeAttribute("hidden");
|
2024-09-03 14:36:44 +00:00
|
|
|
} else if (Cookies.get("type") === "student" && Cookies.get("class")) {
|
|
|
|
make_student_table(Cookies.get("id"), Cookies.get("class"));
|
2024-09-03 15:17:04 +00:00
|
|
|
document.getElementById("dashboard").removeAttribute("hidden");
|
2024-09-03 14:36:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById("forms").removeAttribute("hidden");
|
2024-09-11 17:45:03 +00:00
|
|
|
load_pdfs();
|
2024-09-03 14:36:44 +00:00
|
|
|
}
|