Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/show register on dom #43

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions registri.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il problema è che il container per i registri esisteva già:
riga 72: <div class="Registro flex-grow-1"></div>

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- @format -->

<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -89,8 +88,12 @@ <h3 class="Edita">edita</h3>
</div>
</main>
</div>
</div>
</div>

<!-- Aggiunta della sezione per mostrare i registri -->
<div id="registro-container" class="RegistroContainer">
<!-- Qui verranno aggiunti dinamicamente i registri -->
</div>
</section>

<div class="container-fluid">
<div class="row">
Expand Down
98 changes: 68 additions & 30 deletions script.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Va bene, ma va lasciata la parte della CRUD degli studenti che utilizza il localstorage

Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
/** @format */

// Array di registri e studenti
const registers = [];
const students = [];

// ultimo id per gli elementi di Registers
let lastRegId = "0";
let lastRegId = '0';
// ultimo id per gli elementi di Students
let lastStudId = "0";
let lastStudId = '0';
// ultimo id per gli le attendances dentro ogni Register (univoco)
let lastAttId = "0";
let lastAttId = '0';

// Funzione per rimuovere whitespace prima & dopo la stringa e per farne il Title Case
const normalizeName = (string_) => {
const normalizeName = string_ => {
string_ = string_.trim();
string_ = string_.charAt(0).toUpperCase() + string_.substr(1).toLowerCase();
return string_;
}
};

// Funzione per ottenere la lista dei registri
const getRegisterList = () => {
return registers;
};

// Funzione per ottenere uno specifico registro
const getRegister = (id) => {
const getRegister = id => {
for (let i = 0; i < registers.length; i++) {
//fixare questo e metterlo come non strict comparison?
if (registers[i].id === id) { return registers[i] };
if (registers[i].id === id) {
return registers[i];
}
}
return null;
}
};

// Funzione per creare un registro
const createRegister = ({ name, students, votes, attendances }) => {
Expand All @@ -43,20 +46,21 @@ const createRegister = ({ name, students, votes, attendances }) => {
name: name,
students: [],
votes: [],
attendances: []
attendances: [],
};

sampleRegister.students.push(...students);
sampleRegister.votes.push(...votes);
sampleRegister.attendances.push(...attendances);



registers.push(sampleRegister);

// Chiamata alla funzione per mostrare il registro nel DOM
showRegisterInDOM(sampleRegister);
};

// Funzione per eliminare un registro
const deleteRegister = (id) => {
const deleteRegister = id => {
for (let i = 0; i < registers.length; i++) {
if (registers[i].id == id) {
console.log(`register ${registers[i].id} deleted.`);
Expand All @@ -65,11 +69,10 @@ const deleteRegister = (id) => {
}
}
console.log(`id ${id} not found in registers`);
}
};

// Funzione per aggiornare un registro
const updateRegister = ({ id, name, students, votes, attendances }) => {

const register = getRegister(id);
if (register === null) {
console.log(`no register with id: ${id} found.`);
Expand All @@ -84,7 +87,44 @@ const updateRegister = ({ id, name, students, votes, attendances }) => {
register.attendances = attendances || register.attendances;

console.log(`updated register with id ${id} : ${register}`);
}
};

// Funzione per mostrare un registro nel DOM
const showRegisterInDOM = register => {
// Ottieni il riferimento all'elemento del DOM in cui vuoi mostrare il registro
const containerElement = document.getElementById('registro-container');

// Assicurati che l'elemento esista prima di procedere
if (!containerElement) {
console.error('Elemento del DOM non trovato.');
return;
}

// Crea un elemento div per rappresentare il registro
const registerElement = document.createElement('div');
registerElement.className = 'registro'; // Aggiungi eventuali classi CSS necessarie

// Aggiungi il contenuto del registro all'elemento
registerElement.innerHTML = `
<h2>${register.name}</h2>
<p>Numero di studenti: ${register.students.length}</p>
<!-- Aggiungi altri dettagli del registro secondo le tue esigenze -->
`;

// Aggiungi l'elemento del registro al contenitore nel DOM
containerElement.appendChild(registerElement);
};

// Funzione per aggiungere un registro al DOM
const addRegisterToDOM = registerId => {
const register = getRegister(registerId);

if (register) {
showRegisterInDOM(register);
} else {
console.error(`Registro con ID ${registerId} non trovato.`);
}
};

// Controllare se l'arrivo non deve superare un certo valore
// che sarebbe l'orario di uscita?
Expand All @@ -98,12 +138,12 @@ const createAttendance = ({ registerId, date, argument, attendants }) => {
date: new Date(date), //"yyyy-MM-ddTh:m:s" This is standardized and will work reliably
id: '' + lastAttId,
argument: argument,
attendants: [] //array<{nome, arrivo, uscita}>
attendants: [], //array<{nome, arrivo, uscita}>
};

Attendance.attendants.push(...attendants);
getRegister(registerId).attendances.push(Attendance);
}
};

const deleteAttendance = ({ registerId, attendanceId }) => {
const lessons = getRegister(registerId).attendances;
Expand All @@ -115,7 +155,7 @@ const deleteAttendance = ({ registerId, attendanceId }) => {
}
}
console.log(`lesson with id: ${attendanceId} not found.`);
}
};

// Funzione per creare uno studente
const createStudent = ({ name, lastName, email, lectures }) => {
Expand All @@ -130,12 +170,11 @@ const createStudent = ({ name, lastName, email, lectures }) => {
name: name,
lastName: lastName,
email: email,
lectures: []
}
lectures: [],
};

sampleStudent.lectures.push(...lectures);


students.push(sampleStudent);
};

Expand All @@ -155,10 +194,10 @@ const connectStudentToRegister = (studentId, classId) => {

register.students.push(student);
console.log(`student assigned to ${register.name} successfully.`);
}
};

// Funzione per eliminare uno studente
const deleteStudent = (id) => {
const deleteStudent = id => {
for (let i = 0; i < students.length; i++) {
if (students[i].id == id) {
console.log(`student ${students[i].id} deleted.`);
Expand All @@ -177,7 +216,7 @@ const updateStudent = ({ id, name, lastName, email, lectures }) => {
lastName = normalizeName(lastName);

if (student_ == undefined) {
console.log(`id ${id} not found in students`);;
console.log(`id ${id} not found in students`);
return;
}

Expand All @@ -197,17 +236,16 @@ const getStudentList = () => {
};

// Funzione per ottenere uno specifico studente
const getStudent = (id) => {
const getStudent = id => {
for (let i = 0; i < students.length; i++) {
if (students[i].id == id) {
console.log(`student with id ${id} found in students.`);
return students[i]
};
return students[i];
}
}
console.log(`id ${id} not found in students`);
return null;
}

};

// // Export delle funzioni
// module.exports = {
Expand Down