aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkumar <kumar.damani@mail.utoronto.ca>2016-07-23 04:13:04 +0000
committerkumar <kumar.damani@mail.utoronto.ca>2016-07-23 04:13:04 +0000
commitf658b2367b9ea33703f3b4174688a96e682d86c8 (patch)
tree4d537a30f864625d00fb055f1672bb549456e9dd
parent9ab4094797e82798eab40b32e7c71b52bb847b8f (diff)
parenteefeb25d3fabf377c09dd6c7282f0992eb1afea1 (diff)
pull
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
-rw-r--r--app.js2
-rw-r--r--assets/css/style.css8
-rw-r--r--assets/js/script.js45
-rw-r--r--node_simple.js22
-rw-r--r--routes/admin.js49
-rw-r--r--routes/index.js21
-rw-r--r--routes/user.js8
-rw-r--r--views/admin.hbs284
-rw-r--r--views/signup.hbs2
-rw-r--r--views/user_profile_alt.hbs97
10 files changed, 359 insertions, 179 deletions
diff --git a/app.js b/app.js
index 7421fcf..4f398a9 100644
--- a/app.js
+++ b/app.js
@@ -54,6 +54,8 @@ app.use(express.static(__dirname));
app.use(function(req, res, next) {
res.locals.login = req.isAuthenticated(); // global variable
res.locals.session = req.session;
+ res.locals.user = req.user;
+ console.log(res.locals.user);
next();
});
diff --git a/assets/css/style.css b/assets/css/style.css
index eba03be..7b1538c 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -451,3 +451,11 @@ section.exam-info em {
background: #80cca0;
padding: 5px;
}
+/** Admin C-Panel **/
+.cpnl-details{
+ text-align: left;
+}
+
+.cpnl-container{
+ padding: 4%;
+} \ No newline at end of file
diff --git a/assets/js/script.js b/assets/js/script.js
index e752f0c..59fb358 100644
--- a/assets/js/script.js
+++ b/assets/js/script.js
@@ -49,6 +49,51 @@ function main(){
}
});
+ // ********* Admin Panel Scripts *********** //
+ var adminOptions = [
+ $("#cpnl-addExam"),
+ $("#cpnl-addCourse"),
+ $("#cpnl-removeExam"),
+ $("#cpnl-removeCourse"),
+ $("#cpnl-removeUser")];
+
+ function hideCpnlPages(){
+ adminOptions.forEach(function(item){
+ item.hide();
+ });
+ }
+
+ hideCpnlPages();
+
+ // Show General page
+ adminOptions[0].show();
+ $('.cpnl-page').bind('click', function(e){
+
+ e.preventDefault();
+ hideCpnlPages();
+
+ /* Each case will need to be changed to call a handler for fetching data
+ * from server*/
+ switch($(this).text()) {
+ case "Add Exam":
+ $("#cpnl-addExam").show();
+ break;
+ case "Add Course":
+ $("#cpnl-addCourse").show();
+ break;
+ case "Remove Exam":
+ $("#cpnl-removeExam").show();
+ break;
+ case "Remove Course":
+ $("#cpnl-removeCourse").show();
+ break;
+ case "Remove User":
+ $("#cpnl-removeUser").show();
+ break;
+ default:
+ console.log("Error: User page not found");
+ }
+ });
// --- nav scripts ---
diff --git a/node_simple.js b/node_simple.js
index 99079d5..16c84ed 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -196,7 +196,7 @@ exports.add_user = function (fields, callbackUser) {
};
// find out if this user already exists by checking their email
- exports.find_user( fields[0] ,callbackUser, function (result, callbackUser) {
+ exports.find_user( fields[0] ,callbackUser, function (result, callbackUser) {
if (result == false) {
// find out if the user_name is taken
@@ -685,7 +685,7 @@ exports.find_exam = function (fields, serverCallback, callback) {
* Params: course_code - an string of format "CSC309"
* title - the course description
* */
-exports.add_course = function (course_code, title) {
+exports.add_course = function (course_code, title, serverCallback) {
var courseData = {
course_code: course_code,
@@ -695,6 +695,7 @@ exports.add_course = function (course_code, title) {
exports.find_course(course_code, function (result) {
if (result == true){
+ serverCallback(false, "Course already exists");
console.log("course already exists");
}
else if (result == false) { // add it
@@ -707,7 +708,8 @@ exports.add_course = function (course_code, title) {
courses.insert(courseData, function(err) {
if (err) throw err;
else {
- console.log("couse added");
+ console.log("course added");
+ serverCallback(true, "Course added successfully.");
db.close(function (err) { // close the connection when done
if (err) throw err;
});
@@ -742,8 +744,8 @@ exports.find_course = function (course_code, callback) {
{ course_code: course_code }
).toArray(function (err, docs) {
if (err) throw err;
-
- if (docs.length == 0) { // if this course doesnt exist.... add it
+ // if this course doesnt exist.... add it (via add_course call)
+ if (docs.length == 0) {
callback(false);
}
else { // course was found
@@ -766,7 +768,7 @@ exports.find_course = function (course_code, callback) {
* Params: fields - an array of format ["course_code", year, "term", "type"]
*
* */
-exports.remove_exam = function (fields) {
+exports.remove_exam = function (fields, serverCallback) {
var course_code = fields[0];
var year = fields[1];
@@ -791,10 +793,14 @@ exports.remove_exam = function (fields) {
if (err) throw err;
else {
if (docs.deletedCount == 1) {
- console.log("exam was removed");
+ serverCallback(true, "Exam was removed successfully");
+ db.close();
+ //console.log("exam was removed");
}
else if (docs.deletedCount == 0) {
- console.log("No such exam was found");
+ serverCallback(false, "No such exam was found");
+ db.close();
+ //console.log("No such exam was found");
}
}
}
diff --git a/routes/admin.js b/routes/admin.js
index c5cbcb4..35b208b 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -1,3 +1,4 @@
+var dbFile = require("../node_simple.js");
var express = require('express');
var router = express.Router();
var csrf = require('csurf'); // Cross-Site Request Forgery prevention
@@ -11,7 +12,7 @@ router.get('/', function(req,res){
});
/* Adds exam from front-end */
-router.post('/update/exam', function(req,res){
+router.post('/add/exam', function(req,res){
var course_code = req.body.course_code,
year = req.body.year,
type = req.body.type,
@@ -26,8 +27,8 @@ router.post('/update/exam', function(req,res){
var fields = [
course_code, // String
year, // Int
- type, // String; Needs to be added to database code
term, // String
+ type, // String
instructors, // Array of strings
page_count, // Int
questions_count, // Int
@@ -42,11 +43,11 @@ router.post('/update/exam', function(req,res){
}
console.log(statusMessage);
});
- res.redirect('/');
+ res.redirect('/admin');
});
/* Adds course from front-end */
-router.post('/update/course', function(req,res){
+router.post('/add/course', function(req,res){
var course_code = req.body.course_code,
title = req.body.title;
@@ -58,8 +59,46 @@ router.post('/update/course', function(req,res){
}
console.log("Status message: " + statusMessage)
});
- res.redirect('/');
+ res.redirect('/admin');
});
+router.post('/remove/exam', function(req,res){
+ var course_code = req.body.course_code,
+ year = req.body.year,
+ term = req.body.term,
+ type = req.body.type,
+ campus = req.body.campus;
+
+ var fields = [course_code, year, term, type];
+ console.log(fields);
+ dbFile.remove_exam(fields,
+ function(examRemoved, statusMessage){
+ if(examRemoved){
+ console.log("Success.");
+ } else {
+ console.log("Failed.");
+ }
+ console.log(statusMessage);
+ });
+
+ res.redirect('/admin');
+});
+
+
+
+/* Takes an input string delimited by commas, will split by comma and trim white
+ * spaces. Consider callback.
+ */
+function parseStringArray(input){
+ var list = input.split(',');
+ var parsedList = [];
+ list.forEach(function(word){
+ if (word != ""){
+ parsedList.push(word.trim());
+ }
+ });
+ return parsedList;
+}
+
module.exports = router;
diff --git a/routes/index.js b/routes/index.js
index 30189da..ac8e9a8 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -19,11 +19,11 @@ router.get('/user_solutions', function(req, res, next) {
res.render('user_solutions');
});
-/* Render/GET questions page */
+/* Render/GET questions page
router.get('/questions', function(req, res, next) {
res.render('questions');
});
-
+*/
//EXAMPLE EXPECTED DATA GIVEN BELOW:
/*[ {courseCode: 'CSC240',
@@ -86,8 +86,9 @@ router.get('/search', function(req, res, next) {
router.get('/questions/:exam_id', function (req,res) {
console.log(req.params.exam_id);
dbFile.get_exam_info_by_ID(req.params.exam_id, function (questions) {
- res.render('questions', {query: questions});
console.log(questions);
+ res.render('questions', {query: questions});
+
});
});
@@ -144,18 +145,4 @@ function toProperCase(string) {
return string.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
-/* Takes an input string delimited by commas, will split by comma and trim white
- * spaces. Consider callback.
- */
-function parseStringArray(input){
- var list = input.split(',');
- var parsedList = [];
- list.forEach(function(word){
- if (word != ""){
- parsedList.push(word.trim());
- }
- });
- return parsedList;
-}
-
module.exports = router; \ No newline at end of file
diff --git a/routes/user.js b/routes/user.js
index 840930a..014a7d2 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -49,10 +49,11 @@ router.post('/signup', loggedOut, function(req, res, next) {
req.check('password', "Password should be between 6 and 12 characters.")
.notEmpty().withMessage('Password required').isLength({min: 6, max: 12});
req.check('password', "The confirmation password doesn't match.").equals(req.body.confirmPassword);
+
+ // phone number optional
if (req.body.phone_num){
req.check('phone_num', 'Please enter a valid phone number').isMobilePhone('en-CA');
}
- // password has to be at least 4 characters long
var errors = req.validationErrors();
if (errors) {
@@ -68,14 +69,11 @@ router.post('/signup', loggedOut, function(req, res, next) {
})(req, res);
}
- //res.redirect('/signup');
-
});
router.post('/signin', loggedOut, function(req, res, next) {
req.check('usrname', 'Username field is empty.').notEmpty();
req.check('password', "Password field is empty.").notEmpty();
- // password has to be at least 4 characters long
var errors = req.validationErrors();
if (errors) {
@@ -89,9 +87,9 @@ router.post('/signin', loggedOut, function(req, res, next) {
failureRedirect: '/user/signin',
failureFlash: true
})(req, res);
-
}
+
});
module.exports = router;
diff --git a/views/admin.hbs b/views/admin.hbs
index da33f41..36a3210 100644
--- a/views/admin.hbs
+++ b/views/admin.hbs
@@ -1,102 +1,206 @@
<main id="solutions-main">
-<div class="row signup">
- <div class="col-md-3 col-md-offset-1 admin-form">
- <h4>Add Exam</h4>
- <form action="/admin/update/exam" method="post">
- <div class="form-group">
- Course Code: <input type="text"
- class="form-control"
- placeholder="course code"
- name="course_code">
- </div>
- <div class="form-group">
- Year of Exam:
- <input type="text"
- class="form-control"
- placeholder="year"
- name="year">
- </div>
- <div class="form-group">
- Term: <input type="text"
- class="form-control"
- placeholder="term"
- name="term">
- </div>
- <div class="form-group">
- Type of test:
- <input type="radio" name="type" value="Midterm"> Midterm
- <input type="radio" name="type" value="Final"> Final
- </div>
- <div class="form-group">
- List all instructors separated by comma:
- <input type="text"
- class="form-control"
- placeholder="instructor1,instructor2,.."
- name="instructors">
- </div>
- <div class="form-group">
- Page Count:
- <input type="text"
- class="form-control"
- placeholder="page count"
- name="page_count">
- </div>
- <div class="form-group">
- Questions count:
- <input type="text"
- class="form-control"
- placeholder="questions count"
- name="questions_count">
+<div class="container">
+<div class="row">
+<!-- Admin control Panel --->
+<div class="col-xs-12 col-sm-12 col-md-8 col-md-offset-2 col-xs-offset-0 col-sm-offset-0 toppad cpnl-details">
+
+ <!-- Admin Control Panel Menu -->
+ <nav class="navbar navbar-custom">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <button type="button" class="navbar-toggle"
+ data-toggle="collapse" data-target="#profile-nav">
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </button>
</div>
- <div class="form-group">
- Questions Seperated by Comma
- <input type="text"
- class="form-control"
- placeholder="q1,q2,q3,.."
- name="questions_list">
+ <div class="collapse navbar-collapse" id="profile-nav">
+ <ul class="nav navbar-nav " >
+ <li><a href="#" class="cpnl-page">Add Exam</a></li>
+ <li><a href="#" class="cpnl-page">Add Course</a></li>
+ <li><a href="#" class="cpnl-page">Remove Exam</a></li>
+ <li><a href="#" class="cpnl-page">Remove Course</a></li>
+ <li><a href="#" class="cpnl-page">Remove User</a></li>
+ </ul>
</div>
+ </div>
+ </nav>
- <div class="form-group">
- Upload Date:
- <input type="text"
- class="form-control"
- placeholder="yyyy-mm-dd"
- name="upload_date">
- </div>
- <div class="form-group">
- Your username:
- <input type="text"
- class="form-control"
- placeholder="uploader"
- name="uploaded_by">
+ <!-- Admin Control Panel Pages -->
+ <div class="rounded">
+ <div class="panel panel-info rounded">
+ <div class="panel-heading">
+ <h3 class="panel-title">Admin Panel</h3>
</div>
+ <div class="panel-body">
- <input type="hidden" name="_csrf" value="{{ csrfToken }}">
- <button type="submit" class="btn btn-primary">Submit</button>
- </form>
- </div>
+ <!--- Add Exam --->
+ <div class="row cpnl-container" id="cpnl-addExam">
+ <h4>Add Exam</h4>
+ <form action="/admin/add/exam" method="post">
+ <div class="form-group">
+ Course Code: <input type="text"
+ class="form-control"
+ placeholder="course code"
+ name="course_code">
+ </div>
+ <div class="form-group">
+ Year of Exam:
+ <input type="text"
+ class="form-control"
+ placeholder="year"
+ name="year">
+ </div>
+ <div class="form-group">
+ Term:
+ <input type="radio" name="term" value="Fall"> Fall
+ <input type="radio" name="term" value="Winter"> Winter
+ <input type="radio" name="term" value="Summer"> Summer
+ </div>
+ <div class="form-group">
+ Type of test:
+ <input type="radio" name="type" value="Midterm"> Midterm
+ <input type="radio" name="type" value="Final"> Final
+ </div>
+ <div class="form-group">
+ List all instructors separated by comma:
+ <input type="text"
+ class="form-control"
+ placeholder="instructor1,instructor2,.."
+ name="instructors">
+ </div>
+ <div class="form-group">
+ Page Count:
+ <input type="text"
+ class="form-control"
+ placeholder="page count"
+ name="page_count">
+ </div>
+ <div class="form-group">
+ Questions count:
+ <input type="text"
+ class="form-control"
+ placeholder="questions count"
+ name="questions_count">
+ </div>
+ <div class="form-group">
+ Questions Seperated by Comma
+ <input type="text"
+ class="form-control"
+ placeholder="q1,q2,q3,.."
+ name="questions_list">
+ </div>
- <div class="col-md-3 admin-form">
- <h4>Add Course</h4>
- <form action="/admin/update/course" method="post">
- <div class="form-group">
- Course Code: <input type="text"
- class="form-control"
- placeholder="e.g. CSC240"
- name="course_code">
- </div>
- <div class="form-group">
- Title: <input type="text"
- class="form-control"
- placeholder="e.g. Theory of Computation"
- name="title">
- </div>
- <input type="hidden" name="_csrf" value="{{ csrfToken }}">
- <button type="submit" class="btn btn-primary">Submit</button>
- </form>
+ <div class="form-group">
+ Upload Date:
+ <input type="text"
+ class="form-control"
+ placeholder="yyyy-mm-dd"
+ name="upload_date">
+ </div>
+ <div class="form-group">
+ Your username:
+ <input type="text"
+ class="form-control"
+ placeholder="uploader"
+ name="uploaded_by">
+ </div>
- </div>
+ <input type="hidden" name="_csrf" value="{{ csrfToken }}">
+ <button type="submit" class="btn btn-primary">Submit</button>
+ </form>
+ </div>
+
+ <!--- Add Course --->
+ <div class="row cpnl-container" id="cpnl-addCourse">
+ <h4>Add Course</h4>
+ <form action="/admin/add/course" method="post">
+ <div class="form-group">
+ Course Code: <input type="text"
+ class="form-control"
+ placeholder="e.g. CSC240"
+ name="course_code">
+ </div>
+ <div class="form-group">
+ Title: <input type="text"
+ class="form-control"
+ placeholder="e.g. Theory of Computation"
+ name="title">
+ </div>
+ <input type="hidden" name="_csrf" value="{{ csrfToken }}">
+ <button type="submit" class="btn btn-primary">Submit</button>
+ </form>
+ </div>
+
+ <!--- Remove Exam --->
+ <div class="row cpnl-container" id="cpnl-removeExam">
+ <h4>Remove Exam</h4>
+ <form action="/admin/remove/exam" method="post">
+ <div class="form-group">
+ Course Code: <input type="text"
+ class="form-control"
+ placeholder="e.g. CSC240"
+ name="course_code">
+ </div>
+ <div class="form-group">
+ Year: <input type="text"
+ class="form-control"
+ placeholder="e.g. 2015"
+ name="year">
+ </div>
+ <div class="form-group">
+ Term:
+ <input type="radio" name="term" value="Fall"> Fall
+ <input type="radio" name="term" value="Winter"> Winter
+ <input type="radio" name="term" value="Summer"> Summer
+ </div>
+ <div class="form-group">
+ Type of test:
+ <input type="radio" name="type" value="Midterm"> Midterm
+ <input type="radio" name="type" value="Final"> Final
+ </div>
+
+ <div class="form-group">
+ <p> Campus: </p>
+ <input type="radio" name="campus" value="StGeorge"> St. George
+ <input type="radio" name="campus" value="Scarborough"> Scarborough
+ <input type="radio" name="campus" value="Mississauga"> Mississauga
+ </div>
+
+
+ <input type="hidden" name="_csrf" value="{{ csrfToken }}">
+ <button type="submit" class="btn btn-primary">Submit</button>
+ </form>
+ </div>
+
+ <!--- Remove Course --->
+ <div class="row cpnl-container" id="cpnl-removeCourse">
+ <h4>Remove Course</h4>
+ Pending. Need required database functionality.
+ </div>
+
+ <!--- Remove User --->
+ <div class="row cpnl-container" id="cpnl-removeUser">
+ <h4>Remove User</h4>
+ Pending. Need required database functionality.
+ </div>
+
+
+ <!-- Date, Edit, Logout (new row) -->
+ <div class="col-md-12 prf-sign-off">
+ <p class=" text-info"> July 4 2016 </p>
+ <a href="#">Logout</a>
+ <br>
+
+ </div>
+ </div>
+ </div>
+ </div>
+
+</div>
+</div>
</div>
</main> \ No newline at end of file
diff --git a/views/signup.hbs b/views/signup.hbs
index 54464e1..e7d9c9a 100644
--- a/views/signup.hbs
+++ b/views/signup.hbs
@@ -27,7 +27,7 @@
- <h2><i class="fa fa-user-plus" aria-hidden="true"></i> Sign Up</h2>
+ <h3><i class="fa fa-user-plus" aria-hidden="true"></i> Sign Up</h3>
<form action="/user/signup" method="post">
<div class="form-group">
<input type="text" class="form-control" placeholder="First Name" name="fname">
diff --git a/views/user_profile_alt.hbs b/views/user_profile_alt.hbs
index 8b102b8..413fd0f 100644
--- a/views/user_profile_alt.hbs
+++ b/views/user_profile_alt.hbs
@@ -32,7 +32,7 @@
<div class="rounded">
<div class="panel panel-info rounded">
<div class="panel-heading">
- <h3 class="panel-title">Walter White</h3>
+ <h3 class="panel-title">{{ user.f_name }} {{ user.l_name }}</h3>
</div>
<div class="panel-body">
<!--- User-Profile Pages -->
@@ -47,78 +47,69 @@
<table class="table table-user-information">
<tbody>
<tr>
- <td>Univeristy:</td>
- <td>U of T</td>
+ <td>Email:</td>
+ <td><a href="{{ user.email }}">{{ user.email }}</a></td>
</tr>
+ {{# if user.university }}
+ <tr>
+ <td>University:</td>
+ <td>{{ user.university }}</td>
+ </tr>
+ {{/if}}
+ {{# if user.department }}
<tr>
<td>Department:</td>
- <td>CS</td>
+ <td>{{ user.department }}</td>
</tr>
+ {{/if}}
<tr>
<td>Answered:</td>
- <td>50</td>
+ <td>{{ user.answered }}</td>
</tr>
<tr>
<tr>
<td>Messages:</td>
- <td>25</td>
+ <td>{{ user.messages }}</td>
</tr>
<tr>
<td>Comments:</td>
- <td>100</td>
- </tr>
- <tr>
- <td>Email:</td>
- <td><a href="mailto:info@support.com">info@support.com</a></td>
- </tr>
- <tr>
- <td>Phone Number:</td>
- <td>111-111-1111(Mobile)</td>
+ <td>{{ user.comments }}</td>
</tr>
+ {{# if user.phone_num}}
+ <tr>
+ <td>Phone Number:</td>
+ <td>{{ user.phone_num }}</td>
+ </tr>
+ {{/if}}
</tbody>
</table>
</div>
</div>
<div class="row" id="profile-follows">
- <h3>You are following:</h3>
- <div class="col-xs-offset-1 col-sm-offset-3 col-xs-10 col-sm-6">
- <table class="table-condensed">
- <tbody>
- <tr>
- <th>
- <img class="img-circle img-responsive"
- src="../assets/images/misc/user1.jpeg" alt="avatar">
- </th>
- <th>
- <h4>The Dude</h4>
- <p>3 comments</p>
- </th>
+ {{# if user.followers }}
+ <h3>You are being followed by:</h3>
+ <div class="col-xs-offset-1 col-sm-offset-3 col-xs-10 col-sm-6">
+ <table class="table-condensed">
+ <tbody>
+ {{# each user.followers}}
+ <tr>
+ <th>
+ <img class="img-circle img-responsive"
+ src="../assets/images/misc/user1.jpeg" alt="avatar">
+ </th>
+ <th>
+ <h4>The Dude</h4>
+ <p>3 comments</p>
+ </th>
- </tr>
- <tr>
- <th>
- <img class="img-circle img-responsive"
- src="../assets/images/misc/user2.jpeg" alt="avatar">
- </th>
- <th>
- <h4>He-Man</h4>
- <p>20 comments</p>
- </th>
- </tr>
- <tr>
- <th>
- <img class="img-circle img-responsive"
- src="../assets/images/misc/user3.jpeg" alt="avatar">
- </th>
- <th>
- <h4>Lady Lips</h4>
- <p>56 comments</p>
- </th>
- </tr>
- </tbody>
-
- </table>
- </div>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ </div>
+ {{ else }}
+ <h3>You do not have any followers.</h3>
+ {{/if}}
</div>
<div class="row" id="profile-friends">
<h3>Friends</h3>