Commit e39308ad authored by Paul-Elliot Anglès d'Auriac's avatar Paul-Elliot Anglès d'Auriac
Browse files

ajout de questions custom terminé

parent 6edb4b4c
......@@ -80,7 +80,7 @@ Au final je n'ai pas utilisé flex
** TODO voir pour le problème de timers.enroll deprecated (express-session-mysql est bloqué sur mysql v2.15, on peut manuellement l'upgrader en v2.16)
** TODO Randomiser l'affichage des réponses
Fait (mais commenté) modulo le fait que ça se passe du coté client...
** DONE faire les routes GET de delete, update, etc...
CLOSED: [2018-09-12 mer. 22:26]
** DONE Refaire l'interface d'ajout d'une question
......@@ -92,6 +92,8 @@ Au final je n'ai pas utilisé flex
** TODO style css pour souligner dans quelle page nous sommes dans le menu
** TODO mettre configuration.js en configuration.js.example et mettre à jour le README en accord avec cela
* BUGs
** DONE Lors d'une reconnexion, on recrée un nouvelle réponse au lieu d'updater la précédente...
......
......@@ -53,7 +53,7 @@ module.exports = function (server, sessionMiddleware) {
}
function broadcastRoomQuestion(room, callback) {
console.log("room", room);
// console.log("room", room);
game.questionFromRoomID(room.id, function (err, question) {
// question.reponses.sort(function() { return 0.5 - Math.random() });
io.of("/student").to(room.id).emit("newQuestion", question);
......@@ -125,7 +125,7 @@ module.exports = function (server, sessionMiddleware) {
/******************************************/
socket.on('sendQuestionPlease', function () {
console.log(socket.room);
// console.log(socket.room);
sendRoomQuestion(socket,function() {});
});
......@@ -134,6 +134,7 @@ module.exports = function (server, sessionMiddleware) {
/******************************************/
socket.on('chosenAnswer', function (answer) {
// console.log(answer);
game.registerAnswer(socket.request.session.user, socket.room, answer, function () {
sendOwnedStats(socket.room)
});
......@@ -229,6 +230,15 @@ module.exports = function (server, sessionMiddleware) {
//TO BE IMPLEMENTED
});
/******************************************/
/* Un admin me demande la question */
/******************************************/
socket.on('sendQuestionPlease', function () {
// console.log(socket.room);
sendRoomOwnedQuestion(socket.request.session.user, socket, function() {});
});
/******************************************/
/* On souhaite passer à la question suivante */
/******************************************/
......@@ -248,9 +258,11 @@ module.exports = function (server, sessionMiddleware) {
/******************************************/
socket.on('customQuestion', function (customQuestion) {
console.log(customQuestion);
// console.log(customQuestion);
delete(customQuestion.id);
game.setQuestion(socket.room.id, customQuestion, function () {
broadcastRoomQuestion(socket.room, function(err, res) { console.log("broadcast done");})
broadcastRoomQuestion(socket.room, function(err, res) {});
sendOwnedStats(socket.room);
});
});
......@@ -258,12 +270,12 @@ module.exports = function (server, sessionMiddleware) {
/* On souhaite revenir aux questions du set*/
/******************************************/
socket.on('backToSet', function () {
console.log("backToSet");
/* socket.on('backToSet', function () {
// console.log("backToSet");
game.backToSet(socket.room.id, function(err, res) {
broadcastRoomQuestion(socket.room, function(err,res) {console.log("broadcast done");})
broadcastRoomQuestion(socket.room, function(err,res) {})
});
});
});*/
}
}
});
......
......@@ -130,7 +130,7 @@ exports.enterRoom = function (user, room, callback) {
exports.setQuestion = function(roomID, question, callback) {
exports.flushOldPlayers(roomID, function(err) {
query = "UPDATE rooms SET question = ? "+(question.id ? (", id_currentQuestion = " + question.id) : "") +" WHERE id = ?";
query = "UPDATE rooms SET status = \"pending\", question = ? "+(question.id ? (", id_currentQuestion = " + question.id) : "") +" WHERE id = ?";
// console.log(query);
bdd.query(query, [JSON.stringify(question), roomID], function(err, res) { callback(err, res);});
});
......
//var socketAdmin = io.connect('http://192.168.0.12:3000/admin');
//var socketAdmin = io.connect('http://localhost:3000/admin');
var socketAdmin = io.connect(server+'/admin');
var isAdmin = true;
/*********************************************************************/
/* Actions à effectuer à toute connection */
......@@ -19,12 +20,19 @@ function changeQuestionPlease() {
socketAdmin.emit("changeQuestionPlease");
}
/*********************************************************************/
/* pour redemander d'envoyer la question */
/*********************************************************************/
function sendOwnedQuestionPlease() {
socket.emit("sendQuestionPlease");
}
/*********************************************************************/
/* lorsque l'on veut reveler les resultats */
/*********************************************************************/
function revealResults() {
console.log("rev");
socketAdmin.emit("revealResults");
}
......@@ -41,7 +49,7 @@ function gotoQuestion(i) {
/*********************************************************************/
socketAdmin.on('newStats', function (newStats) {
console.log(newStats);
// console.log(newStats);
ul = document.createElement("ul")
ul.innerHTML = '<li style="font-family: Impact, \'Arial Black\', Arial, Verdana, sans-serif;"> Ce qu\'en disent les élèves : </li>';
......@@ -62,26 +70,27 @@ socketAdmin.on('newStats', function (newStats) {
/*********************************************************************/
socketAdmin.on('newQuestion', function (reponse) {
console.log("fromAdminnewQuestion", reponse);
// console.log("fromAdminnewQuestion", reponse);
if(temp=document.querySelector("li.inactiveQuestion")) {
if(reponse.id)
temp.classList.remove("inactiveQuestion")
}
if(temp=document.querySelector("li.currentQuestion")) {
temp.classList.remove("currentQuestion");
console.log("reponse is", reponse);
// console.log("reponse is", reponse);
if(!reponse.id)
temp.classList.add("inactiveQuestion")
}
if(reponse.id) {
document.querySelector("#customQuestion").innerHTML = "Créer sa propre question temporaire";
document.querySelector("#customQuestion").onclick = customQuestion;
document.querySelector("li#q"+reponse.id).classList.add("currentQuestion");
}
document.querySelector("#customQuestion").innerHTML = "Créer sa propre question temporaire";
document.querySelector("#customQuestion").onclick = customQuestion;
/* }
else {
document.querySelector("#customQuestion").innerHTML = "Revenir à la question du set";
document.querySelector("#customQuestion").onclick = backToSetQuestion;
}
}*/
document.querySelector("#question").contentEditable = false;
});
......@@ -93,8 +102,8 @@ backToSetQuestion = function (event) {
document.querySelector("#customQuestion").innerHTML = "Créer sa propre question temporaire";
document.querySelector("#customQuestion").onclick = customQuestion;
// document.querySelector("#question").contentEditable = false;
// sendQuestionPlease();
socketAdmin.emit("backToSet");
sendOwnedQuestionPlease();
// socketAdmin.emit("backToSet");
}
addReponse = function (event) {
......@@ -106,7 +115,6 @@ addReponse = function (event) {
}
removeReponse = function (elem) {
// console.log(event);
elem.parentNode.remove();
}
......@@ -122,14 +130,14 @@ sendReponse = function() {
});
newQuestion.enonce = document.querySelector("#question").textContent;
console.log(newQuestion);
// console.log(newQuestion);
// backToSetQuestion();
socketAdmin.emit("customQuestion", newQuestion);
}
chooseAsCorrect = function (elem) {
console.log(elem);
// console.log(elem);
if(temp=document.querySelector(".juste"))
temp.classList.remove("juste");
elem.parentNode.classList.add("juste");
......
......@@ -16,7 +16,7 @@ socket.on('connect', () => {
/*********************************************************************/
socket.on('newQuestion', function (reponse) {
console.log(reponse);
// console.log(reponse);
document.querySelector("#question").textContent=reponse.enonce;
wrapper = document.querySelector("#wrapperAnswer");
while (wrapper.firstChild) {
......@@ -27,9 +27,10 @@ socket.on('newQuestion', function (reponse) {
elem.classList.add("reponse");
elem.classList.add("notSelected");
elem.id = "r"+index;
elem.addEventListener("click", function (ev) {
chooseAnswer(index);
});
if(typeof isAdmin == "undefined")
elem.addEventListener("click", function (ev) {
chooseAnswer(index);
});
elem.textContent = rep.reponse;
wrapper.appendChild(elem);
});
......@@ -40,7 +41,7 @@ socket.on('newQuestion', function (reponse) {
/*********************************************************************/
socket.on('correction', function (correction) {
console.log(correction);
// console.log(correction);
document.querySelectorAll(".reponse").forEach(function (elem) {elem.style.boxShadow="0 0 8px 10px red"});
// document.querySelector("#rep"+correction.correct).style.boxShadow="0 0 8px 15px green";
document.querySelector("#r"+correction.correctAnswer).style.boxShadow="0 0 8px 15px green";
......@@ -51,7 +52,7 @@ socket.on('correction', function (correction) {
if(v.answer!=-1) {
// console.log("#rep"+v.answer);
document.querySelector("#r"+v.answer).style.background =
"linear-gradient(to right, rgba(0,0,0,0.5) "+((0.+v.count)/total*100.-5)+"%,#F5F5DC "+((0.+v.count)/total*100.)+"%)";
"linear-gradient(to right, rgba(0,0,0,0.5) "+((0.+v.count)/total*100./*-5*/)+"%,#F5F5DC "+((0.+v.count)/total*100.)+"%)";
}
});
});
......@@ -79,12 +80,9 @@ function chooseAnswer(i) {
reponses.forEach(function (rep) {
rep.classList.replace('selected', 'notSelected');
});
console.log('a');
if(i>-1) {
console.log('a');
a = document.querySelector("#r"+i);
a.classList.replace("notSelected", "selected");
}
console.log("socket emit chosen answer", i);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment