Skip to content

Commit

Permalink
fix bug (-1)
Browse files Browse the repository at this point in the history
- Disconnect all student if teacher disconnected
- Add session informations when teacher modify session status
- Modify Page end of quizz
  • Loading branch information
Tristan13R committed Jun 5, 2023
1 parent f019a8e commit cf3e0dd
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 36 deletions.
52 changes: 44 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ io.on('connection', async function (client) { // Client socket connected
sessionStatus = "SessionStatus";

client.emit('updateSessionStatus', getSession(false)); // send the session status to the teacher when he connects (in case he refreshed the page)
io.to('student').emit('sessionUpdated', getSession().sessionStatus);
io.to('student').emit('sessionUpdated', getSession().sessionStatus);

io.to('student').emit('informationSession', {
quizzTitle: getSession().quizzTitle,
numberOfRegisteredStudents: getNumberOfRegisteredStudent(),
teacherMail: getSession().teacher,
groupName: getSession().groupName,
});








client.emit('tempMessage',
{
status: 'success',
Expand Down Expand Up @@ -135,7 +150,7 @@ io.on('connection', async function (client) { // Client socket connected
questionNumber++;
callback(getQuestion());

io.to('boitier').emit('question number', getQuestion().currentQuestionNumber); // envoie numero de question boitier
io.to('boitier').emit('questionNumber', getQuestion().currentQuestionNumber); // envoie numero de question boitier
io.timeout(5000).to('student').emit('getStudentAnswer', { numberQuestion: getQuestion().currentQuestionNumber }, (err, responses) => {
if (err) {
io.to('teacher').emit('tempMessage',
Expand Down Expand Up @@ -177,6 +192,30 @@ io.on('connection', async function (client) { // Client socket connected

client.on('endOfQuizz', (callback) => {
questionNumber++;
io.to('boitier').emit('getStudentsAnswers', (err, responses) => {

console.log("resp getstudentsanswers", responses);
// responses.forEach(trame => {
// console.log("trame du boitier :", trame)


// quizzResults[questionNumber - 1].answers.push({
// 'studentMail': response.//id du boitier,
// 'studentAnswer': getAnswersAsString(response.answers, quizzQuestionsAndAnswers[1][questionNumber - 1][1]),
// 'result': checkAnswers(response.answers,
// quizzQuestionsAndAnswers[1][questionNumber - 1][1], // list of possible answers
// quizzQuestionsAndAnswers[1][questionNumber - 1][2] // list of good answers
// )
// });



// });

// traiter le tableau de ahmed avec toutes les réponses.
// push dans quizzResults
});

io.timeout(5000).to('student').emit('getStudentAnswer', { numberQuestion: quizzQuestionsAndAnswers[1][questionNumber - 1][3] }, (err, responses) => {
if (err) {
io.to('teacher').emit('tempMessage',
Expand Down Expand Up @@ -211,6 +250,7 @@ io.on('connection', async function (client) { // Client socket connected

sessionStatus = "DisplayResults";

// Vérifie si un elève ne s'est pas déconnecté en cours de QCM
listOfStudents.forEach((student) => {
let tempsMail = student.mail
let numero = 0;
Expand Down Expand Up @@ -278,10 +318,6 @@ io.on('connection', async function (client) { // Client socket connected
groupName: getSession().groupName,
});

// io.to('student').emit('updateStudentList', getSession());
// client.emit // send all data
// io.to student // only list of students

client.on('buttonValidateClicked', (value) => {
listOfStudents.forEach(student => {
if (student.mail == client.mail) {
Expand Down Expand Up @@ -331,9 +367,8 @@ io.on('connection', async function (client) { // Client socket connected
}
else if (client.handshake.query.status == 'boitier') {
client.join('boitier');
io.to('boitier').emit('questionNumber', {number : 5});

client.on('trameComplete', (trame) => {
})
}
else { // Unknown client
/* things to do when an unknown user connects */
Expand Down Expand Up @@ -383,6 +418,7 @@ function resetSession() {
questionNumber = 0;
quizzResults = [];
quizzTime = null;
socket.disconnect();
}

function checkAnswers(studentAnswers, possibleAnswers, correctAnswers) {
Expand Down
24 changes: 10 additions & 14 deletions src/scripts/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,14 @@ answerQuestion.hidden = true;

changeDivState('#test');

socket.on('teacherNotConnected', () => {
waitingRoom.innerHTML = "Le prof n'est pas connecté";
});

// Get information session when student registered
socket.on('informationSession', (data) => {
// document.querySelector('#nameOfQuizz').innerHTML = `Nom du quizz : ${data.quizzTitle}`;
document.querySelector('#nameOfTeacher').innerHTML = `Nom du professeur : ${data.teacherMail}`;
document.querySelector('#statusSessionWaitRoom').innerHTML = `Nom du quizz : ${data.quizzTitle}`;
document.querySelector('#numberOfStudentRegistered').innerHTML = `Nombre d'élèves enregistrés : ${data.numberOfRegisteredStudents}`;
document.querySelector('#nameOfGroup').innerHTML = `Nom du groupe : ${data.groupName}`;



});

socket.on('test', (dat) => {
console.log(dat);
});

socket.on('sessionStarted', () => {
changeDivState('#answerQuestion');
Expand Down Expand Up @@ -85,10 +75,10 @@ socket.on('sessionUpdated', (sessionStatus) => {
changeDivState('#answerQuestion');
}
});
// A modifier

// Page end of quizz
socket.on('endOfQuizzTeacher', () => {
changeDivState('#endOfTheQcm');
// messageEndQuizz.innerHTML = "fin";
timerReturnHome();

});
Expand All @@ -107,7 +97,6 @@ btnAnswers.forEach((button, index) => {

socket.on('connect', () => {
changeDivState('#formMail');

formulaireMail.addEventListener('submit', (e) => {
e.preventDefault();
let inputMail = document.querySelector('#mailAddress')
Expand Down Expand Up @@ -296,6 +285,13 @@ function returnHome() {
modal.style.display = "none";
}

function informationSession(data) {
document.querySelector('#nameOfTeacher').innerHTML = `Nom du professeur : ${data.teacherMail}`;
document.querySelector('#statusSessionWaitRoom').innerHTML = `Nom du quizz : ${data.quizzTitle}`;
document.querySelector('#numberOfStudentRegistered').innerHTML = `Nombre d'élèves enregistrés : ${data.numberOfRegisteredStudents}`;
document.querySelector('#nameOfGroup').innerHTML = `Nom du groupe : ${data.groupName}`;
}

function timerReturnHome() {
let monTimer = setTimeout(() => {
returnHome();
Expand Down
36 changes: 22 additions & 14 deletions student.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
<button type="button" class="btn btn-outline-danger w-100"
data-bs-toggle="modal"
data-bs-target="#ModalDeconnexion">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-right" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z"/>
<path fill-rule="evenodd" d="M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="16"
height="16" fill="currentColor"
class="bi bi-box-arrow-right" viewBox="0 0 16 16">
<path fill-rule="evenodd"
d="M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z" />
<path fill-rule="evenodd"
d="M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z" />
</svg>
<i class="bi bi-box-arrow-right"></i>
</button>
</li>
Expand Down Expand Up @@ -151,14 +155,14 @@ <h1 id="numberQuestion" class="text-center"></h1>


<div class="col d-flex justify-content-center">
<div class="d-flex align-items-start">
<button id="btnModify" type="button"
class="btn btn-danger">CORRIGER</button>
</div>
<div class="d-flex align-items-end">
<button id="btnValidate" type="button"
class="btn btn-success">Valider</button>
</div>
<div class="d-flex align-items-start">
<button id="btnModify" type="button"
class="btn btn-danger">CORRIGER</button>
</div>
<div class="d-flex align-items-end">
<button id="btnValidate" type="button"
class="btn btn-success">Valider</button>
</div>

</div>
</div>
Expand All @@ -167,7 +171,8 @@ <h1 id="numberQuestion" class="text-center"></h1>
<div class="part" id="waitTeacherConnect">
<p class="d-flex justify-content-center">
<button class="btn btn-primary" type="button" data-bs-toggle="collapse"
data-bs-target=".multi-collapse" aria-expanded="false">Voir status de la
data-bs-target=".multi-collapse" aria-expanded="false">Voir status de
la
session</button>
</p>
<div class="row">
Expand Down Expand Up @@ -236,7 +241,10 @@ <h5 class="card-header w-100 text-center">Informations de
</div>

<div class="part" id="endOfTheQcm">
<h3 id="End">page de fin de quizz</h3>
<div class="alert alert-info" role="alert">
<h4 id="End">Le QCM est terminé, vous allez être redirigé vers la page de
connexion</h4>
</div>
</div>
</div>
<script src="/bootstrap/js/bootstrap.bundle.min.js"></script>
Expand Down

0 comments on commit cf3e0dd

Please sign in to comment.