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

routes, nav et controller

parent 40c65c2f
......@@ -80,6 +80,9 @@ renderCourseManage = function (user, course, msgs, req, res) {
msgs : function(callback) {
callback(null, msgs);
},
roomList : function(callback) {
Room.listOfCourse(course.id, callback);
},
subscription: function(callback) {
callback(null, req.subscription);
},
......@@ -113,7 +116,7 @@ renderManageCourses = function(user, msgs, req, res) {
callback(null, msgs);
},
courseOwnedList : function (callback) {
Course.ownedList(user, callback);
Course.subscribedCourses(user, callback);
}
/* setOwnedList : function (callback) {
Set.setOwnedList(user, callback);
......
......@@ -14,7 +14,7 @@ var async = require('async');
// render de manage_question.ejs
renderManageQuestion = function(user, course, question, set, msgs, res) {
renderManageQuestion = function(user, course, question, set, msgs, req, res) {
async.parallel(
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
......@@ -40,6 +40,9 @@ renderManageQuestion = function(user, course, question, set, msgs, res) {
course : function(callback) {
callback(null, course)
},
subscription: function(callback) {
callback(null, req.subscription);
},
title: function(callback) { callback(null, "Class Panic: Modification d'un set")},
set: function (callback) {
callback(null, set)
......@@ -58,13 +61,13 @@ renderManageQuestion = function(user, course, question, set, msgs, res) {
// Pour commencer à créer une question
exports.question_create_get = function(req, res) {
renderManageQuestion(req.session.user, req.course, undefined, req.set, req.msgs, res);
renderManageQuestion(req.session.user, req.course, undefined, req.set, req.msgs, req, res);
};
// Pour commencer à modifier une question
exports.question_update_get = function(req, res) {
renderManageQuestion(req.session.user, req.course, req.question, req.set, req.msgs, res);
renderManageQuestion(req.session.user, req.course, req.question, req.set, req.msgs, req, res);
};
......
......@@ -30,7 +30,7 @@ exports.getOwnedByID = function(user, courseID, callback) {
// By ID
exports.subscribedCourses = function (user, callback) {
query = "SELECT * FROM courses INNER JOIN subscription ON courseID = `courses`.`id` INNER JOIN users ON `courses`.`ownerID` = `users`.`id` WHERE userID = ?";
query = "SELECT * FROM courses WHERE id IN (SELECT courseID FROM subscription WHERE userID = ?)";
bdd.query(query, [user.id], function(err, rows) {
// console.log(rows);
callback(err, rows);
......@@ -38,7 +38,7 @@ exports.subscribedCourses = function (user, callback) {
}
exports.subscribedAsTDMan = function (user, callback) {
query = "SELECT * FROM courses INNER JOIN subscription ON courseID = `courses`.`id` INNER JOIN users ON `courses`.`ownerID` = `users`.`id` WHERE isTDMan = 1 AND userID = ?";
query = "SELECT * FROM courses WHERE id IN (SELECT courseID FROM subscription WHERE isTDMan = 1 AND userID = ?)";
bdd.query(query, [user.id], function(err, rows) {
// console.log(rows);
callback(err, rows);
......
......@@ -44,6 +44,11 @@ html {
h1 {
border-bottom: aliceblue 1px solid;
}
h1 div {
font-size:0.15em;
margin:10px;
}
h1, h2 {
/* color:white;*/
font-size:1.5em;
......
......@@ -51,10 +51,10 @@ router.use('/:courseID/', function (req, res, next) {
req.subscription = subscription;
req.course = course;
console.log(subscription)
if(req.subscription.isTDMan)
// if(req.subscription.isTDMan)
next();
else
res.redirect(config.PATH);
// else
// res.redirect(config.PATH);
}
else
res.redirect(config.PATH);
......
......@@ -39,31 +39,28 @@ router.use(function (req, res, next) {
/*************************************************************/
// GET request for showing room list.
router.get('/room', room_controller.room_list);
//router.get('/room', room_controller.room_list);
// GET request for showing subscribed courses list.
router.get('/course', course_controller.courses_list);
//router.get('/course', course_controller.courses_list);
// GET request for subscribing to a courses.
//router.get('/subscribe', course_controller.courses_subscribe);
// GET request for showing a course.
router.get('/course/:idCourse', course_controller.course);
//router.get('/course/:idCourse', course_controller.course);
// POST request for showing room list.
router.post('/room', room_controller.room_list);
//router.post('/room', room_controller.room_list);
// GET request for entering a room.
router.use('/course/:idCourse/room/:id', (req, res, next) => {
});
router.get('/course/:idCourse/room/:id', game_controller.room_enter);
//router.get('/course/:idCourse/room/:id', game_controller.room_enter);
......@@ -71,10 +68,10 @@ router.get('/course/:idCourse/room/:id', game_controller.room_enter);
router.post('/course/:idCourse/admin/:id', game_controller.room_admin);
//router.post('/course/:idCourse/admin/:id', game_controller.room_admin);
router.use("/manage/course", courseRouter);
router.use("/course", courseRouter);
// GET request for admining a room.
router.get('/course/:idCourse/admin/:id', game_controller.room_admin);
......
......@@ -7,22 +7,24 @@
</head>
<body>
<div id="main_wrapper">
<h1>Class Panic</h1>
<h1>Big Sister <div> Ta grande soeur t'aide à faire tes devoirs</div></h1>
<nav>
<ul>
<a href="<%= config.PATH %>/"><li <%= active == "etudiant" ? "class=selected" : "" %>>Travailler</li></a>
<a href="<%= config.PATH %>/manage/course"><li <%= active == "courses" ? "class=selected" : "" %>>Gérer mes cours</li></a>
<a href="<%= config.PATH %>/course"><li <%= active == "courses" ? "class=selected" : "" %>>Mes cours</li></a>
<a href="<%= config.PATH %>/"><li <%= active == "etudiant" ? "class=selected" : "" %>>Mon compte</li></a>
<a id="leave" href="<%= config.PATH %>/logout"><li>Se d&eacute;connecter</li></a>
</nav>
<% if(typeof course != "undefined") { %>
<nav>
<ul>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>"><li <%= active == "course" ? "class=selected" : "" %>><%= course.name %></li></a>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/room"><li <%= active == "rooms" ? "class=selected" : "" %>>Salles</li></a>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/set"><li <%= active == "sets" ? "class=selected" : "" %>>Sets</li></a>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/subscription"><li <%= active == "subscription" ? "class=selected" : "" %>>Inscriptions</li></a>
<a href="<%= config.PATH %>/course/<%= course.id %>"><li <%= active == "course" ? "class=selected" : "" %>><%= course.name %></li></a>
<% if(subscription.isTDMan) { %>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/stats"><li <%= active == "stats" ? "class=selected" : "" %>>Statistiques</li></a>
<a href="<%= config.PATH %>/course/<%= course.id %>/room"><li <%= active == "rooms" ? "class=selected" : "" %>>Salles</li></a>
<a href="<%= config.PATH %>/course/<%= course.id %>/set"><li <%= active == "sets" ? "class=selected" : "" %>>Sets</li></a>
<% } %>
<a href="<%= config.PATH %>/course/<%= course.id %>/subscription"><li <%= active == "subscription" ? "class=selected" : "" %>>Inscriptions</li></a>
<% if(subscription.isTDMan) { %>
<a href="<%= config.PATH %>/course/<%= course.id %>/stats"><li <%= active == "stats" ? "class=selected" : "" %>>Statistiques</li></a>
<% } %>
</nav>
<% } %>
......
<%- include('student_header', {active:"salles"}); -%>
<%- include('admin_header', {active:"salles"}); -%>
<h2>Se connecter à une scéance de question :</h2>
<ul class="room">
......
<%- include('student_header', {active:"salles"}); -%>
<%- include('admin_header', {active:"salles"}); -%>
<h2>Mes cours :</h2>
<ul class="room">
......
<%- include('student_header', {active:"salles"}); -%>
<%- include('admin_header', {active:"salles"}); -%>
<h2>Se connecter à une salle</h2>
<ul class="room">
......
......@@ -2,7 +2,7 @@
<h2>Votre cours <%= course.name %> :</h2>
<% if(course.ownerID == user.id) { %>
<form action="<%= config.PATH %>/manage/course/<%=course.id%>/update" method="post">
<form action="<%= config.PATH %>/course/<%=course.id%>/update" method="post">
Name : <input name="name" style="margin:10px;" value="<%= course.name %>"> <br>
Description : <textarea name="commentaire" rows="10" style="display:block;width:90%; margin:20px" ><%= course.commentaire %></textarea>
<input type="submit" value="Modifier">
......@@ -11,13 +11,33 @@
Name : <%= course.name %> <br>
Description : <div><%= course.commentaire %></div>
<% } %>
<h2>Travailler</h2>
<ul class="room">
<% roomList.forEach(function(room) { %>
<a class="room" href="<%= config.PATH %>/course/<%= course.id %>/<%= subscription.isTDMan ? "control" : "play"%>/<%= room.id %>">
<li class="room">
<span class="froom"><%= room.name %></span>
<ul>
<li>Nombre de participants : <%= //room.number %></li>
<li>Administrateur: <%=room.owner %></li>
</ul>
<div>
Rejoindre
</div>
</li>
</a>
<% });%>
</ul>
<% if(course.ownerID == user.id) { %>
<h2>Ou le supprimer</h2>
<form onsubmit="return confirm('Etes-vous sure de vouloir supprimer le cours <%=course.name%> ?');" action="<%= config.PATH %>/manage/course/<%=course.id%>/delete" method="post">
<form onsubmit="return confirm('Etes-vous sure de vouloir supprimer le cours <%=course.name%> ?');" action="<%= config.PATH %>/course/<%=course.id%>/delete" method="post">
Irréversible : <input type="submit" value="Supprimer le cours <%= course.name%>">
</form>
<% } %>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/manage/course"> Retourner à la liste des cours </a>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/course"> Retourner à la liste des cours </a>
<%- include('admin_footer'); -%>
......@@ -4,7 +4,7 @@
<!-- Vous pouvez vous connecter &agrave; l'une des salles suivantes :-->
<ul class="room">
<% courseOwnedList.forEach(function(cours) { %>
<a class="room" href="<%= config.PATH %>/manage/course/<%= cours.id %>">
<a class="room" href="<%= config.PATH %>/course/<%= cours.id %>">
<li class="room">
<span class="froom"><%= cours.name %></span>
<ul>
......@@ -13,22 +13,24 @@
</ul>
<div>
<ul>
<!-- <a class="room" href="<%= config.PATH %>/manage/room/<%= //room.id %>"><li> Modifier </li></a> -->
<!-- <a class="room" href="<%= config.PATH %>/room/<%= //room.id %>"><li> Modifier </li></a> -->
<!-- <a class="room" href="<%= config.PATH %>/admin/<%= //room.id %>"><li> Détails du cours </li></a> -->
</ul>
</div>
</li>
</a>
<% });%>
<a class="room" onclick="document.querySelector('#win').classList.toggle('shown');window.scrollTo(0,0)">
<li style="cursor:pointer; text-align:center;" class="room">
<span class="froom">+</span>
</li>
</a>
<% if(user.isAdmin) { %>
<a class="room" onclick="document.querySelector('#win').classList.toggle('shown');window.scrollTo(0,0)">
<li style="cursor:pointer; text-align:center;" class="room">
<span class="froom">+</span>
</li>
</a>
<% } %>
<!-- <li class="room">
<span class="froom">Créer un nouveau cours</span>
<div>
<form id="formNewRoom" action="<%= config.PATH %>/manage/course/create" method="post">
<form id="formNewRoom" action="<%= config.PATH %>/course/create" method="post">
<input placeholder="Nom du cours" name="name"> -->
<!-- <select name="questionSet">
<% //setOwnedList.forEach( function (set) { %>
......@@ -43,20 +45,22 @@
</li> -->
</ul>
<div class="window" id="win">
<h2> Créer un nouveau cours</h2>
<form action="<%= config.PATH %>/manage/course/create" method="post">
<p>
<input type='text' name="name" placeholder='Nom du nouveau cours'>
</p>
<p>
<textarea name="commentaire" placeholder="Une description du cours" style="width:80%;height:90px";></textarea>
</p>
<p>
<input type='submit' value='Créer le cours'>
<input type='button' onclick="document.querySelector('#win').classList.toggle('shown')" value='Supprimer la fenetre'>
</p>
</form>
</div>
<% if(user.isAdmin) { %>
<div class="window" id="win">
<h2> Créer un nouveau cours</h2>
<form action="<%= config.PATH %>/course/create" method="post">
<p>
<input type='text' name="name" placeholder='Nom du nouveau cours'>
</p>
<p>
<textarea name="commentaire" placeholder="Une description du cours" style="width:80%;height:90px";></textarea>
</p>
<p>
<input type='submit' value='Créer le cours'>
<input type='button' onclick="document.querySelector('#win').classList.toggle('shown')" value='Supprimer la fenetre'>
</p>
</form>
</div>
<% } %>
<%- include('admin_footer'); -%>
......@@ -8,7 +8,7 @@
<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/course/<%= course.id %>/set/<%= set.id %>/question/<%= newQuestion ? "create" : (question.id+"/update") %>">
<form id="newQuestion" method="post" action="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>/question/<%= newQuestion ? "create" : (question.id+"/update") %>">
<ul class="room" id="listeQue">
<li class="room">
<span class="froom">Énoncé :</span>
......@@ -44,12 +44,12 @@ Utiliser $...$ pour mettre des maths.
</form>
<% if (!newQuestion) { %>
<div style="margin:20px";> Vous pouvez aussi supprimer définitivement cette question :
<form onsubmit='return confirm("Etes-vous sure de vouloir supprimer la question \"<%= question.enonce%>\" ?");' id="delete" method="post" action="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%= set.id %>/question/<%= question.id %>/delete">
<form onsubmit='return confirm("Etes-vous sure de vouloir supprimer la question \"<%= question.enonce%>\" ?");' id="delete" method="post" action="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>/question/<%= question.id %>/delete">
<input type="submit" value="Supprimer cette question"">
</form>
</div>
<% } %>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%= set.id %>/">Revenir au set "<%= set.name %>"</a>
<a href="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>/">Revenir au set "<%= set.name %>"</a>
<script>
function toggleText(elem) {
elem.classList.toggle("texted");
......
......@@ -2,7 +2,7 @@
<h2>Modifier votre salle <%= room.name %></h2>
<form action="<%= config.PATH %>/manage/course/<%= course.id %>/room/<%=room.id%>/update" method="post">
<form action="<%= config.PATH %>/course/<%= course.id %>/room/<%=room.id%>/update" method="post">
Name : <input name="name" value="<%= room.name %>"> <br>
Acutellement avec le set :
<select name="questionSet">
......@@ -17,10 +17,10 @@
<h2>Ou la supprimer</h2>
<form onsubmit="return confirm('Etes-vous sure de vouloir supprimer la salle <%=room.name%> ?');" action="<%= config.PATH %>/manage/course/<%= room.courseID %>/room/<%=room.id%>/delete" method="post">
<form onsubmit="return confirm('Etes-vous sure de vouloir supprimer la salle <%=room.name%> ?');" action="<%= config.PATH %>/course/<%= room.courseID %>/room/<%=room.id%>/delete" method="post">
Irréversible : <input type="submit" value="Supprimer la salle <%= room.name%>">
</form>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/manage/course/<%= room.courseID %>"> Retourner à la liste des rooms </a>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/course/<%= room.courseID %>"> Retourner à la liste des rooms </a>
<%- include('admin_footer'); -%>
......@@ -3,7 +3,7 @@
<h2>Vos salle(s) de classe :</h2>
<ul class="room">
<% roomOwnedList.forEach(function(room) { %>
<a class="room" href="<%= config.PATH %>/manage/course/<%= course.id %>/room/<%= room.id %>">
<a class="room" href="<%= config.PATH %>/course/<%= course.id %>/room/<%= room.id %>">
<li class="room">
<span class="froom"><%= room.name %></span>
<ul>
......@@ -30,7 +30,7 @@
<% if(subscription.canRoomCreate) {%>
<div class="window" id="win">
<h2> Créer une salle de classe</h2>
<form action="<%= config.PATH %>/manage/course/<%= course.id %>/room/create" method="post">
<form action="<%= config.PATH %>/course/<%= course.id %>/room/create" method="post">
<p>
<input type='text' name="name" placeholder='Nom de la salle'>
</p>
......
<%- include('admin_header', {active:"sets"}); -%>
<h2> Renommer ou supprimer "<%= set.name%>"</h2>
<form action="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%=set.id%>/update" method="post">
<form action="<%= config.PATH %>/course/<%= course.id %>/set/<%=set.id%>/update" method="post">
Name : <input name="name" value="<%= set.name %>"> <br>
<input type="submit" value="Modifier">
</form>
<h2>Ou la supprimer</h2>
<form onsubmit='return confirm("Etes-vous sure de vouloir supprimer le set \"<%=set.name%>\" ?");' action="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%=set.id%>/delete" method="post">
<form onsubmit='return confirm("Etes-vous sure de vouloir supprimer le set \"<%=set.name%>\" ?");' action="<%= config.PATH %>/course/<%= course.id %>/set/<%=set.id%>/delete" method="post">
Irréversible : <input type="submit" value='Supprimer le set "<%= set.name%>"'>
</form>
......@@ -18,7 +18,7 @@
<ul class="room sortable-list">
<% questionList.forEach(function(q) { %>
<li class="question" id="q<%= q.id %>">
<a class="room" href="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%= set.id %>/question/<%= q.id %>">
<a class="room" href="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>/question/<%= q.id %>">
<span class="froom"><%= q.enonce %></span>
<div>
Modifier
......@@ -28,7 +28,7 @@
<% });%>
</ul>
<ul>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%= set.id %>/question/create">
<a href="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>/question/create">
<li class="room">
<span class="froom">Créer une nouvelle question</span>
<!-- <div>
......@@ -38,7 +38,7 @@
</a>
</ul>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/manage/course/<%= course.id %>/set"> Retourner à la liste des sets </a>
<a style="display:block; margin:40px;" href="<%= config.PATH %>/course/<%= course.id %>/set"> Retourner à la liste des sets </a>
<script src="/javascripts/Sortable.js">
</script>
<script src="/socket.io/socket.io.js"></script>
......
......@@ -5,7 +5,7 @@
<% if(subscription.isTDMan) { %>
<ul class="room">
<% setOwnedList.forEach(function(set) { %>
<a class="room" href="<%= config.PATH %>/manage/course/<%= course.id %>/set/<%= set.id %>">
<a class="room" href="<%= config.PATH %>/course/<%= course.id %>/set/<%= set.id %>">
<li class="room">
<span class="froom"><%= set.name %></span>
<!-- <ul>
......@@ -32,7 +32,7 @@
<% if(subscription.canSetCreate) { %>
<div class="window" id="win">
<h2> Créer un nouveau cours</h2>
<form action="<%= config.PATH %>/manage/course/<%= course.id %>/set/create" method="post" id="formNewSet">
<form action="<%= config.PATH %>/course/<%= course.id %>/set/create" method="post" id="formNewSet">
<p>
<input type='text' name="name" placeholder='Nom du nouveau set'>
</p>
......
......@@ -96,6 +96,6 @@
</script>
<% } %>
<a href="<%= config.PATH %>/manage/course/<%= course.id %>/">Retourner au cours</a>
<a href="<%= config.PATH %>/course/<%= course.id %>/">Retourner au cours</a>
<%- include('admin_footer'); -%>
......@@ -46,7 +46,7 @@
</div>
<div id="wrapperAnswer">
</div>
<div id="leave"><a href="<%= config.PATH %>/manage/course/<%= room.courseID %>">Quitter la salle</a></div>
<div id="leave"><a href="<%= config.PATH %>/course/<%= room.courseID %>">Quitter la salle</a></div>
</div>
<div id="controlPanel">
<div class="controlPanel" id="reveal">Réveler</div>
......
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