diff --git a/public/assets/branding/favicon/site.webmanifest b/public/assets/branding/favicon/site.webmanifest
index e41d420..cd761eb 100644
--- a/public/assets/branding/favicon/site.webmanifest
+++ b/public/assets/branding/favicon/site.webmanifest
@@ -1,14 +1,14 @@
{
- "name": "",
- "short_name": "",
+ "name": "checq.me",
+ "short_name": "checq.me",
"icons": [
{
- "src": "/android-chrome-192x192.png",
+ "src": "./android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
- "src": "/android-chrome-512x512.png",
+ "src": "./android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
diff --git a/public/js/ajax_dashboard.js b/public/js/ajax_dashboard.js
deleted file mode 100644
index f5ca08b..0000000
--- a/public/js/ajax_dashboard.js
+++ /dev/null
@@ -1,23 +0,0 @@
-n1 = document.getElementById('nav-1');
-n2 = document.getElementById('nav-2');
-n3 = document.getElementById('nav-3');
-n4 = document.getElementById('nav-4');
-n5 = document.getElementById('nav-5');
-
-function assignEvents(nav_n, svg_n, name) {
- if (!nav_n.classList.contains('active')) {
- nav_n.addEventListener('mouseenter', () => {
- document.getElementById(`${svg_n}`).src = `assets/icons/nav/${name}_sel.svg`
- })
-
- nav_n.addEventListener('mouseleave', () => {
- document.getElementById(`${svg_n}`).src = `assets/icons/nav/${name}.svg`;
- })
- }
-}
-
-assignEvents(n1, 'svg1','dashboard');
-assignEvents(n2, 'svg2', 'classroom');
-assignEvents(n3, 'svg3', 'schedule');
-assignEvents(n4, 'svg4', 'profile');
-assignEvents(n5, 'svg5', 'manager');
diff --git a/public/js/views.js b/public/js/views.js
index e0ac365..1c717d6 100644
--- a/public/js/views.js
+++ b/public/js/views.js
@@ -1,5 +1,4 @@
-//EJS Compiled Views - This file was automatically generated on Sun Nov 22 2020 12:59:16 GMT+0100 (Central European Standard Time)
-
+//EJS Compiled Views - This file was automatically generated on Mon Nov 23 2020 19:57:14 GMT+0100 (Central European Standard Time)
ejs.views_include = function(locals) {
return function(path, d) {
return ejs["views_"+path.replace(/\//g,"_")]({...d,...locals}, null, ejs.views_include(locals));
@@ -790,7 +789,7 @@ function encode_char(c) {
};
;
var __line = 1
- , __lines = "\n\n\n\n
\n <%- include(\"../../partials/navigation\", {active: 'manager'}) %>\n
\n Classroom Manager
\n \n \n \n \n \n \n \n \n \n \n
\n\n\n\n\n\n\n\n"
+ , __lines = "\n\n\n\n\n <%- include(\"../../partials/navigation\", {active: 'manager'}) %>\n
\n Classroom Manager
\n \n \n \n \n \n \n \n \n \n \n \n \n
\n\n\n\n\n\n\n\n"
, __filename = undefined;
try {
var __output = "";
@@ -799,8 +798,8 @@ try {
; __append("\n\n\n\n\n ")
; __line = 7
; __append( include("../../partials/navigation", {active: 'manager'}) )
- ; __append("\n
\n Classroom Manager
\n \n \n \n \n \n \n \n \n \n \n
\n\n\n\n\n\n\n\n")
- ; __line = 30
+ ; __append("\n \n Classroom Manager
\n \n \n \n \n \n \n \n \n \n \n \n \n\n\n\n\n\n\n\n\n")
+ ; __line = 32
}
return __output;
} catch (e) {
diff --git a/routes/classroom.js b/routes/classroom.js
index bf2a480..43a7e1a 100644
--- a/routes/classroom.js
+++ b/routes/classroom.js
@@ -18,9 +18,17 @@ const { response } = require("express");
module.exports = router;
-// if PROFESSOR/TA = Get all the classrooms where the current user is the professor
-// if STUDENT = returns all classes in which the student is enrolled
+// COMMON ROUTES
+
+/**
+ * If PROFESSOR/TA -> Get all the classrooms where the current user is the professor/ta,
+ * if STUDENT -> returns all classes in which the student is enrolled.
+ * @name get/classroom
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/", ensureAuthenticated, (req, res) => {
if (req.user.role == 1 || req.user.role == 0) {
Classroom.find({ lecturer: req.user })
@@ -55,11 +63,16 @@ router.get("/", ensureAuthenticated, (req, res) => {
}
});
-/*
-PROFESSOR ROUTES
-*/
-//Post a new classroom
+// PROFESSOR ROUTES
+
+/**
+ * Route creating a new classroom.
+ * @name post/classroom/new
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.post("/new", ensureAuthenticated, ensureProfessor, (req, res) => {
console.log(req.body);
if (!req.body.name || !req.body.description) {
@@ -86,72 +99,84 @@ router.post("/new", ensureAuthenticated, ensureProfessor, (req, res) => {
})
});
+/**
+ * Route serving a classroom given its id.
+ * @name get/classroom/:id
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/:id", ensureAuthenticated, ensureProfessor, (req, res) => {
Classroom.find({ _id: req.params.id })
- .populate("teaching_assistants")
- .populate("mastery_checks")
- .populate("lecturer")
- .populate("partecipants")
- .then((result) => {
- //
- res.json(result);
- })
- .catch((err) => {
- console.log(err);
- res.json({});
- });
-
+ .populate("teaching_assistants")
+ .populate("mastery_checks")
+ .populate("lecturer")
+ .populate("partecipants")
+ .then((result) => {
+ //
+ res.json(result);
+ })
+ .catch((err) => {
+ console.log(err);
+ res.json({});
+ });
})
-//create a new invite link
-//TODO: if token for class already exists return the existing one.
-router.get(
- "/invite/:classroom_id",
- ensureAuthenticated,
- ensureProfessor,
- (req, res) => {
- TokenClassroom.findOne({_classroomId: req.params.classroom_id}).then(c_t => {
- if(c_t){
- res.json(`http://${req.headers.host}/classroom/join/${c_t.token}`)
- } else {
- Classroom.findById(req.params.classroom_id).then((c) => {
- // console.log(c.lecturer.toString() == req.user._id.toString());
- if (c && c.lecturer.toString() == req.user._id.toString()) {
- let token = new TokenClassroom({
- _classroomId: c._id,
- token: crypto.randomBytes(20).toString("hex"),
+/**
+ * Route serving the classroom's token given its id.
+ * @name get/classroom/invite/:classroom_id
+ * @todo If token for class already exists return the existing one.
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
+router.get( "/invite/:classroom_id", ensureAuthenticated, ensureProfessor, (req, res) => {
+ TokenClassroom.findOne({_classroomId: req.params.classroom_id}).then(c_t => {
+ if(c_t){
+ res.json(`http://${req.headers.host}/classroom/join/${c_t.token}`)
+ } else {
+ Classroom.findById(req.params.classroom_id).then((c) => {
+ // console.log(c.lecturer.toString() == req.user._id.toString());
+ if (c && c.lecturer.toString() == req.user._id.toString()) {
+ let token = new TokenClassroom({
+ _classroomId: c._id,
+ token: crypto.randomBytes(20).toString("hex"),
+ });
+ token
+ .save()
+ .then(() => {
+ res.json(
+ `http://${req.headers.host}/classroom/join/${token.token}`
+ );
+ })
+ .catch((err) => {
+ console.log(err);
+ res.status(400).end();
});
- token
- .save()
- .then(() => {
- res.json(
- `http://${req.headers.host}/classroom/join/${token.token}`
- );
- })
- .catch((err) => {
- console.log(err);
- res.status(400).end();
- });
- } else {
- res.status(400).end();
- }
- });
- }
- })
- }
-);
+ } else {
+ res.status(400).end();
+ }
+ });
+ }
+ })
+});
+
-/*
-STUDENT ROUTES
-*/
+// STUDENT ROUTES
-//this link will be given to the new students, once clicked it will automatically join the classroom
-//this route CANNOT be used as an API to interact with the database from ajax.
+/**
+ * Check if the invite link is valid, in which case the class that the link is referred to will
+ * be added to the student's classrooms list. This route CANNOT be used as an API to interact
+ * with the database from ajax.
+ * @name get/classroom/join/:token
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/join/:token", ensureAuthenticated, ensureStudent, (req, res) => {
// console.log("here")
TokenClassroom.findOne({ token: req.params.token })
.then((t) => {
-
let p1 = Classroom.findById(t._classroomId);
let p2 = User.findById(req.user._id);
@@ -189,7 +214,10 @@ router.get("/join/:token", ensureAuthenticated, ensureStudent, (req, res) => {
});
-// Random color chooser
+/**
+ * Random color generator for the newly created classroom
+ * @returns {string} - random color hex string
+ */
function randomColor() {
let colors = ['e53935', 'd81b60', '8e24aa', '5e35b1', '3949ab',
'1e88e5', '039be5', '00acc1', '00897b', '43a047',
diff --git a/routes/classrooms.js b/routes/classrooms.js
index 5b7e1e2..f35ca88 100644
--- a/routes/classrooms.js
+++ b/routes/classrooms.js
@@ -18,52 +18,47 @@ const { response } = require("express");
module.exports = router;
+/**
+ * Route serving the user's list of classrooms.
+ * @name get/classrooms
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/", ensureAuthenticated, (req, res) => {
- if (req.user.role == 1 || req.user.role == 0) {
- Classroom.find({ lecturer: req.user })
- .populate("topics")
- .then((result) => {
- res.json({ classrooms: result, user: req.user });
- })
- .catch((err) => {
- console.log(err);
- res.json({});
- });
- } else if (req.user.role == 2) {
- User.findOne({ _id: req.user._id })
- .select({
- _id: 1,
- role: 1,
- classrooms: 1,
- })
- .then((user) => {
- if (user) {
- Classroom.find({ _id: { $in: user.classrooms } })
- .select({
- teaching_assistants: 1,
- lecturer: 1,
- name: 1,
- _id: 1,
- color: 1,
- description: 1
- })
- .populate({
- path: "teaching_assistants",
- select: ["email", "name", "surname"],
- })
- .populate({
- path: "lecturer",
- select: ["email", "name", "surname"],
- })
- .then((re) => {
- let Model = {
- user: user,
- classrooms: re
- }
+ User.findOne({ _id: req.user._id })
+ .select({
+ _id: 1,
+ role: 1,
+ classrooms: 1,
+ })
+ .then((user) => {
+ if (user) {
+ Classroom.find({ _id: { $in: user.classrooms } })
+ .select({
+ teaching_assistants: 1,
+ lecturer: 1,
+ name: 1,
+ _id: 1,
+ color: 1,
+ description: 1
+ })
+ .populate({
+ path: "teaching_assistants",
+ select: ["email", "name", "surname"],
+ })
+ .populate({
+ path: "lecturer",
+ select: ["email", "name", "surname"],
+ })
+ .then((re) => {
+ let Model = {
+ user: user,
+ classrooms: re
+ }
- res.render('classroom', { model: Model });
- });
- }
- });
- }
+ res.render('classroom', { model: Model });
+ });
+ }
+ });
})
diff --git a/routes/dashboard.js b/routes/dashboard.js
index 1b2b1ca..963c8e1 100644
--- a/routes/dashboard.js
+++ b/routes/dashboard.js
@@ -6,9 +6,15 @@ const Classroom = require("../models/Classroom");
module.exports = router;
-// Dashboard
+/**
+ * Route serving the dashboard.
+ * @name get/dashboard
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get('/', ensureAuthenticated, (req, res) => {
- Classroom.find({ _id: { $in: req.user.classrooms }})
+ Classroom.find({ _id: { $in: req.user.classrooms } })
.then((classrooms) => {
let Model = {
user: req.user,
diff --git a/routes/user.js b/routes/user.js
index 15f1b21..290579a 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -13,10 +13,24 @@ const Token = require("../models/Token");
module.exports = router;
+/**
+ * Route serving the signup page.
+ * @name get/user/signup
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/signup", (req, res) => {
res.render("signup", {});
});
+/**
+ * Route serving the login page.
+ * @name get/user/login
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.get("/login", (req, res) => {
if (req.isUnauthenticated()) {
res.render("login", {});
@@ -25,6 +39,13 @@ router.get("/login", (req, res) => {
}
});
+/**
+ * Route serving the POST request for signup
+ * @name post/user/signup
+ * @function
+ * @param {string} path - Express path
+ * @param {callback} middleware - Express middleware.
+ */
router.post("/signup", (req, res) => {
const { name, surname, email, password, conf_password } = req.body;
let errors = [];
diff --git a/views/profile/profile.ejs b/views/profile/profile.ejs
index 1eaefc7..9ddda5a 100644
--- a/views/profile/profile.ejs
+++ b/views/profile/profile.ejs
@@ -2,23 +2,22 @@
checq.me - Profile
-
+
<%- include("../partials/navigation", { active: "profile" }) %>
-
-
-
My Profile
-
<%= user.name %> <%= user.surname %>
-
Email: <%= user.email %>
-
-
-
-
+
+
My Profile
+
<%= user.name %> <%= user.surname %>
+
Email: <%= user.email %>
+
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file