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

majorité des messages OK

parent 5a9ba5f7
......@@ -12,6 +12,7 @@ Presque fait, il manque juste une harmonisation des noms... (getBy/FromID, setGe
** DONE Sécurité redirection user/admin/non loggé
CLOSED: [2018-08-20 lun. 18:16]
** TODO Proprifier le hack de questionController
* Court terme
......@@ -75,7 +76,7 @@ Au final je n'ai pas utilisé flex
** TODO Randomiser l'affichage des réponses
** TODO Vérifier les RESTRICT/CASCADE pour la bdd (dans le fichier)
* Long terme
......
var User = require('../models/user');
var Room = require('../models/room');
var Set = require('../models/set');
var SetController = require('./setController');
var Question = require('../models/question');
var config = require("./../configuration");
var async = require('async');
/*************************************************************/
/* Controlleurs GET pour les questions */
/* Fonctions render pour les questions */
/*************************************************************/
// Afficher la liste des questions
exports.question_list = function(req, res) {
async.parallel(
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) },
user: function (callback) {
callback(null, req.session.user);
},
questionList: function (callback) {
Question.listOwnedFromSetId(req.params.setId,function (e,b) {callback(e,b)});
},
set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.setId, callback);
},
title: function(callback) { callback(null, "Class Panic: Modification d'un set")}
},
function (err, results) {
console.log(results.questionList);
res.render('questions', results)
});
};
// Afficher le détails d'une question
// render de manage_question.ejs
exports.questionShow = function(req, res) {
renderManageQuestion = function(user, questionID, setID, msgs, res) {
async.parallel(
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) },
user: function (callback) {
callback(null, req.session.user);
callback(null, user);
},
newQuestion: function(callback) { callback(null, typeof questionID == "undefined")},
question: function (callback) {
Question.getOwnedByID(req.params.questionId,function (e,b) {callback(e,b)});
if(typeof questionID != "undefined")
Question.getOwnedByID(user, questionID, function (e,b) {callback(e,b)});
else
callback(null,
{
reponses : [{
reponse: "",
validity: false
}],
enonce: ""
})
},
title: function(callback) { callback(null, "Class Panic: Modification d'un set")},
set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.setId, callback);
Set.setOwnedGet(user, setID, function(a,b) {callback(a,b)});
}
},
function (err, results) {
console.log(results.questionList);
res.render('questioqzdn', results)
console.log(results);
res.render('manage_question', results)
});
};
/*************************************************************/
/* Controlleurs GET pour les questions */
/*************************************************************/
// Pour commencer à créer une question
exports.question_create_get = function(req, res) {
tmp = {};
Set.setOwnedGet(req.session.user, req.params.idSet, function(err, r) {
options = {
title: "ClassPanic : créer une nouvelle question",
user: req.session.user,
config: config,
newQuestion: true,
question: {
reponses : [{
reponse: "",
validity: false
}],
enonce: ""
},
set : r
};
res.render('manage_question', options);
});
renderManageQuestion(req.session.user, undefined, req.params.idSet, [], res);
};
// Pour commencer à modifier une question
exports.question_update_get = function(req, res) {
async.parallel(
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) },
user: function (callback) {
callback(null, req.session.user);
},
question: function (callback) {
Question.getOwnedByID(req.session.user, req.params.id,function (e,b) {callback(e,b)});
},
newQuestion: function (callback) { callback(null, false) },
title: function(callback) { callback(null, "Class Panic: Modification d'un set")},
set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.idSet, callback);
}
},
function (err, results) {
res.render('manage_question', results)
});
renderManageQuestion(req.session.user, req.params.id, req.params.idSet, [], res);
};
......@@ -113,19 +70,39 @@ exports.question_update_get = function(req, res) {
// Create
exports.question_create_post = function(req, res) {
Question.questionCreate(req.session.user, req.body, {id:req.params.idSet}, function(err, id) { res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ; });
Question.questionCreate(req.session.user, req.body, {id:req.params.idSet}, function(err, info) {
// res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ;
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible d'ajouter la question !"]);
else
SetController.set_manage_msgs(req, res, ["Question ajoutée !"]);
});
};
// Update
exports.question_update_post = function(req, res) {
Question.questionUpdate(req.session.user, req.params, req.body, function() {
res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
Question.questionUpdate(req.session.user, req.params, req.body, function(err, info) {
// res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible de mettre à jour la question !"]);
else
SetController.set_manage_msgs(req, res, ["Question mise à jour !"]);
});
};
// Delete
exports.question_delete_post = function(req, res) {
Question.questionDelete(req.session.user, req.params, function(err, id) { res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ; });
Question.questionDelete(req.session.user, req.params, function(err, id) {
console.log(err);
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible de supprimer la question (peut-être est-elle la question courante d'une room) !"]);
else
SetController.set_manage_msgs(req, res, ["Question supprimée !"]);
// res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
});
};
......@@ -121,14 +121,18 @@ exports.room_manage_all = function(req, res) {
exports.room_create_post = function(req, res) {
if(req.body.questionSet) {
Room.create(req.session.user, req.body, function (err) {
Room.create(req.session.user, req.body, function (err,r) {
// res.redirect(config.PATH+'/manage/room');
// console.log(req.body);
renderManageRooms(req.session.user, ["Room créée !"], res);
// console.log(req.body);
if(err)
renderManageRooms(req.session.user, ["Impossible de créer la room !"], res);
else
renderManageRooms(req.session.user, ["Room créée !"], res);
});
}
else {
res.redirect(config.PATH+'/manage/room');
renderManageRooms(req.session.user, ["Impossible de créer la room : merci de spécifier un set valide à associer"], res);
// res.redirect(config.PATH+'/manage/room');
}
};
......@@ -136,7 +140,10 @@ exports.room_create_post = function(req, res) {
exports.room_delete_post = function(req, res) {
Room.delete(req.session.user, req.params.id, function () {
renderManageRooms(req.session.user, ["Room supprimée"], res);
if(err)
renderManageRooms(req.session.user, ["Impossible de supprimer la room"], res);
else
renderManageRooms(req.session.user, ["Room supprimée"], res);
// res.redirect(config.PATH+"/manage/room");
});
};
......@@ -145,7 +152,10 @@ exports.room_delete_post = function(req, res) {
exports.room_update_post = function(req, res) {
Room.update(req.session.user, req.params, req.body, function (id) {
renderRoomManage(req.session.user, req.params.id, ["Room updaté"], res);
if(err)
renderRoomManage(req.session.user, req.params.id, ["Impossible de modifier la room"], res);
else
renderRoomManage(req.session.user, req.params.id, ["Room updaté"], res);
// res.redirect(config.PATH+'/manage/room/');
});
};
......@@ -47,7 +47,7 @@ renderManageSet = function(req, user, setID, msgs, res) {
callback(null, user);
},
questionList : function (callback) {
Question.listOwnedBySetID(user, setID, callback);
Question.listOwnedBySetID(user, setID, function(a,b) {callback(a,b)});
},
msgs: function(callback) { callback(null, msgs) },
set : function (callback) {
......@@ -68,12 +68,18 @@ renderManageSet = function(req, user, setID, msgs, res) {
exports.set_manage_all = function(req, res) {
renderManageSets(req.session.user, [], res);
};
exports.set_manage_all_msgs = function(req, res, msgs) {
renderManageSets(req.session.user, msgs, res);
};
// Afficher le détails d'un set
exports.set_manage = function(req, res) {
renderManageSet(req, req.session.user, req.params.id, [], res);
};
exports.set_manage_msgs = function(req, res, msgs) {
renderManageSet(req, req.session.user, req.params.id, msgs, res);
};
/*************************************************************/
/* Controlleurs POST pour modifier les sets */
......@@ -83,7 +89,10 @@ exports.set_manage = function(req, res) {
exports.set_create_post = function(req, res) {
Set.setCreate(req.session.user, req.body, function (err, set) {
renderManageSet(req, req.session.user, set.id, ["Set créé !"], res);
if(err)
renderManageSet(req, req.session.user, set.id, ["Impossible de créer le set !"], res);
else
renderManageSet(req, req.session.user, set.id, ["Set créé !"], res);
});
};
......@@ -91,7 +100,11 @@ exports.set_create_post = function(req, res) {
exports.set_delete_post = function(req, res) {
Set.setDelete(req.session.user, req.params, function (err, set) {
renderManageSets(req.session.user, ["Set supprimé"], res);
console.log(err);
if(err)
renderManageSets(req.session.user, ["Impossible de supprimer le set, sans doute est-il utilisé dans une room"], res);
else
renderManageSets(req.session.user, ["Set supprimé"], res);
});
};
......@@ -99,6 +112,9 @@ exports.set_delete_post = function(req, res) {
exports.set_update_post = function(req, res) {
Set.setUpdate(req.session.user, req.params, req.body, function (err, set) {
renderManageSets(req.session.user, ["Set mis à jour"], res);
if(err)
renderManageSets(req.session.user, ["Impossible de modifier le set"], res);
else
renderManageSets(req.session.user, ["Set mis à jour"], res);
});
};
......@@ -68,13 +68,17 @@ exports.getByName= function (room, callback) {
exports.create = function (user, newRoom, callback) {
Question.getFirstOfOwnedSet(user, newRoom.questionSet, function (err, question) {
if(question) {
bdd.query('INSERT INTO `rooms`(`name`, `id_currentQuestion`, `questionSet`, `ownerID`, `status`) VALUES (?, ?, ?, ?, "pending")', [newRoom.name, question.id, newRoom.questionSet, user.id], function(err, rows) {
callback(err, rows);
});
}
if(err)
callback(err, null)
else {
callback(err);
if(question) {
bdd.query('INSERT INTO `rooms`(`name`, `id_currentQuestion`, `questionSet`, `ownerID`, `status`) VALUES (?, ?, ?, ?, "pending")', [newRoom.name, question.id, newRoom.questionSet, user.id], function(err, rows) {
callback(err, rows);
});
}
else {
callback(err);
}
}
});
}
......
......@@ -33,7 +33,7 @@ blockquote:before, blockquote:after, q:before, q:after {
font-family: Impact, "Arial Black", Arial, Verdana, sans-serif;
}
/***************************************************/
html {
background:url("/images/blackboard-wallpaper3.jpg") no-repeat center fixed;
background-size:cover;
......@@ -41,7 +41,6 @@ html {
color:white;
}
h1, h2 {
color:white;
font-size:1.5em;
......@@ -100,6 +99,9 @@ h1 {
font-size: 7em;
}
.msg {
color: red;
}
a {
color:white;
......@@ -185,83 +187,14 @@ nav ul li {
padding-bottom: 20px;
}
/*select {
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
outline: 0;
box-shadow: none;
border: 0 !important;
background: black;
color:white;
background-image: none;
}
select,.select, select:active, .select:active, .select:focus, select:focus {
outline:none;
}
select:-moz-focusring {
// color: transparent;
text-shadow: 0 0 0 #000;
}
*/
/* Custom Select */
/*.select {
position: relative;
top:19px;
display: inline-block;
width: 20em;
height: 3em;
line-height: 3;
vertical-align: baseline;
background: black;
overflow: hidden;
border-radius: .25em;
margin-top:8px;
border: solid 1px white;
}
select {
width: 100%;
height: 100%;
margin: 0;
padding: 0 0 0 .5em;
color: white;
cursor: pointer;
}
select::-ms-expand {
display: none;
}*/
/* Arrow */
/*.select::after {
content: '\25BC';
position: absolute;
top: 0;
right: 0;
bottom: 0;
padding: 0 1em;
background: #34495e;
pointer-events: none;
}*/
/* Transition */
/*.select:hover::after {
color: #f39c12;
}
.select::after {
-webkit-transition: .25s all ease;
-o-transition: .25s all ease;
transition: .25s all ease;
}
*/
input[type=text] {
/* width: 100%;*/
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
background:black;
color:white;
color:white;
}
input {
height:3em;
......
<%- include('admin_header'); -%>
<h2> Modification de la question <%= question.id %></h2>
<h2> <%= newQuestion ? "Création" : "Modification" %> d'une question</h2>
<!-- Vous pouvez vous connecter &agrave; l'une des salles suivantes :-->
<form id="newQuestion" method="post" action="<%= config.PATH %>/manage/set/<%= set.id %>/question/<%= newQuestion ? "create" : (question.id+"/update") %>">
Énoncé :
......
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