aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--node_simple.js5
-rw-r--r--routes/admin.js5
-rw-r--r--routes/index.js75
-rw-r--r--views/exams.hbs2
-rw-r--r--views/questions.hbs19
-rw-r--r--views/user_solutions.hbs50
6 files changed, 75 insertions, 81 deletions
diff --git a/node_simple.js b/node_simple.js
index c3431ed..65a233c 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -832,8 +832,6 @@ exports.remove_exam = function (fields, serverCallback) {
});
};
-
-
// callback(success, error, data)
exports.get_exam_byID = function (id, callback) {
@@ -851,9 +849,8 @@ exports.get_exam_byID = function (id, callback) {
callback(false, false, null);
}
else {
- // console.log(JSON.stringify(docs, null, 2));
- //console.log(docs);
callback(true, false, docs[0]);
+
}
});
})
diff --git a/routes/admin.js b/routes/admin.js
index 5aa22fe..7e5c7fe 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -8,8 +8,6 @@ var passport_file = require('../config/passport.js');
var csrfProtection = csrf();
router.use(csrfProtection); // router is protected
-
-
router.get('/', isAdmin, function(req,res){
res.render('admin', {csrfToken: req.csrfToken()});
});
@@ -65,7 +63,7 @@ router.post('/add/course', function(req,res){
res.redirect('/admin');
});
-// Add a new admin, redirect to admin panel
+/* Add a new admin, redirect to admin panel */
router.post('/add/admin', function(req,res){
var admin_data = {
fname: req.body.fname,
@@ -128,7 +126,6 @@ module.exports = router;
/************** Route protection ********************/
-
function isAdmin(req, res, next) {
if (req.user && !req.user.email){
return next();
diff --git a/routes/index.js b/routes/index.js
index 4a0e54c..d3c55e6 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -84,24 +84,73 @@ router.get('/search', function(req, res, next) {
res.redirect('/exams/' + courseName);
});
-/*EXAMPLE DATA GIVEN BELOW:
+
+/* This is a redirect from the exams page, route is generated in exams.hbs
+ *
+ * EXAMPLE DATA GIVEN BELOW:
* questions = [{id,count,comments},{id,count,comments}] --> array of "question" objects
*
* id = questions number
* count= number of solutions
* comments = number of comments*/
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) {
+ var examID = req.params.exam_id;
+ console.log(examID);
+ dbFile.get_exam_byID(examID, function(exam){
+
+ /* [
+ { q_id: 1, question: 'this is q1' },
+ { q_id: 2, question: 'this is q2' }
+ ]
+ */
+ var qList = exam.questions_list;
+
+ // Add comments/solutions
+ dbFile.get_exam_info_by_ID(examID, function (questionsInfo) {
+ qList.forEach(function(question){
+ question.count = 0;
+ question.comments = 0;
+
+ // Find q_id in questionsInfo, update comment/solutions count
+ questionsInfo.forEach(function(q){
+ if (q.id == question.id){
+ question.count += q.count;
+ question.comments += q.comments;
+ }
+ });
+ });
+
+ var examInfo = {
+ id : exam._id,
+ courseCode : exam.course_code,
+ term : toProperCase(exam.term),
+ type : toProperCase(exam.type),
+ year : exam.year,
+ instructors : exam.instructors.join(),
+ uploadDate : exam.upload_date,
+ uploader : exam.uploaded_by,
+ pageCount : exam.page_count,
+ questionCount : exam.questions_count
+ };
+ res.render('questions', {query: qList, examInfo: examInfo});
+ });
+
+
+ console.log(exam);
+ });
+
+ /*dbFile.get_exam_info_by_ID(examID, function (questions) {
console.log(questions);
res.render('questions', {query: questions});
- });
+ });*/
+
});
-/*GET the solutions for a given exam given the question number and the exam_id*/
-/*EXPECTED DATA GIVEN BELOW:
-array of solutions:
+/*GET the solutions for a given exam given the question number and the exam_id
+
+* EXPECTED DATA GIVEN BELOW:
+* array of solutions:
* solutions = [ {
* _id: "354ff71ed078933079d6467e"
* exam_id: "578a44ff71ed097fc3079d6e"
@@ -112,17 +161,17 @@ array of solutions:
* }
* {
* _id: ...
- * exam_id: ..
- * q_id: ...
- * text: ..
- * votes: ..
- * comments: ..
+ * exam_id: ..
+ * q_id: ...
+ * text: ..
+ * votes: ..
+ comments: ..
*
* }
* ]*/
router.get('/solutions/:exam_id/:q_num', function (req, res) {
dbFile.get_all_solutions(req.params.exam_id,req.params.q_num,function (solutions) {
- res.render('solutions', {query: solutions});
+ res.render('user_solutions', {query: solutions});
console.log(solutions);
});
});
diff --git a/views/exams.hbs b/views/exams.hbs
index d7697c3..b5e5092 100644
--- a/views/exams.hbs
+++ b/views/exams.hbs
@@ -2,7 +2,7 @@
<div class = 'search container' id = 'solutions-div'>
<h4 class='search-head'>Search results for "{{query}}"</h4>
{{# each result}}
- <a href="/questions/{{this.id}}">
+ <a href="/questions/{{this.id}}"> <!--- Attaches exam id to url --->
<section class = 'solutions-card'>
<h3 class = 'solutions-title'>{{this.title}}</h3>
<p class = 'solutions-time' ><em>Term: </em>{{this.term}} {{this.year}}</p>
diff --git a/views/questions.hbs b/views/questions.hbs
index ff9b3b2..48248c2 100644
--- a/views/questions.hbs
+++ b/views/questions.hbs
@@ -6,23 +6,22 @@
<a href="http://www.cs.toronto.edu/~fpitt/CSC148/20131/tests/test1-0101.pdf" target='_blank'><img src="assets/images/exam.png" class='exam-img img-responsive exam-info'></a>
<section class='exam-info'>
- <h3>CSC148</h3>
- <p>Winter 2015 exam</p>
- <p><em>Instructor(s): </em>Fairgrieve and Hangerman </p>
- <p><em>Upload date:</em> 2016-07-08</p>
- <p><em>Uploaded by:</em> John Smith</p>
- <p><em>Page count:</em> 22</p>
- <p><em>Question count:</em> 10</p>
+ <h3>{{examInfo.courseCode}}</h3>
+ <p>{{examInfo.term}} {{examInfo.year}} {{examInfo.type}}</p>
+ <p><em>Instructor(s): </em>{{examInfo.instructors}}</p>
+ <p><em>Upload date:</em> {{examInfo.uploadDate}}</p>
+ <p><em>Uploaded by:</em> {{examInfo.uploader}}</p>
+ <p><em>Page count:</em> {{examInfo.pageCount}}</p>
+ <p><em>Question count:</em> {{examInfo.questionCount}}</p>
</section>
<!-- QUESTION LISTINGS -->
{{#each query}}
-
- <a href="/user_solutions">
+ <a href="/solutions/{{../examInfo.id}}/{{this.q_id}}">
<section class = 'solutions-card row'>
<div class='pull-left col-sm-8 col-md-8'>
- <h3 class = 'questions-number'>Question {{this.id}}</h3>
+ <h3 class = 'questions-number'>Question {{this.q_id}}</h3>
<p><span class='questions-sol-num'>{{this.count}} solutions, </span> <span class = 'questions-comment'>{{this.comments}} comments</span></p>
</div>
<div class='pull-right right-arrow'>
diff --git a/views/user_solutions.hbs b/views/user_solutions.hbs
index 8380d53..847dfff 100644
--- a/views/user_solutions.hbs
+++ b/views/user_solutions.hbs
@@ -17,7 +17,7 @@
<!-- Solution 1 Example -->
<div class="row">
- <section id="sol-1" class="col-md-10 col-md-offset-1 rounded">
+ <section id="sol-" class="col-md-10 col-md-offset-1 rounded">
<div class="post-info">
<div class="">
<img class="img-responsive img-circle user-image" src="assets/images/misc/user1.jpeg">
@@ -72,54 +72,6 @@
</section>
</div>
- <!-- Solution 2 Example -->
- <div class="row">
- <section id="sol-2" class="col-md-10 col-md-offset-1 rounded">
- <div class="post-info">
- <div class="">
- <img class="img-responsive img-circle user-image" src="assets/images/misc/user3.jpeg">
- <p class="username"><a href="/user_profile">janeDoe456</a></p>
- </div>
-
- <div class="pull-right">
- <div class="upvoting">
- <button class="upvote"><img src="assets/images/up_arrow.png"></button>
- <p class="upvote num-upvotes">4</p>
- </div>
- <div class="downvoting">
- <button class="downvote"><img src="assets/images/down_arrow.png"></button>
- <p class=" downvote num-downvotes">-8</p>
- </div>
- </div>
- </div>
-
- <div class="user-sol">
- <h3>Solution</h3>
- <p><img src="assets/images/dummy-sol2.png"> </p>
- </div>
-
- <div class="comments">
-
- <h3><a data-toggle="collapse" data-target="#com2" href="#com2" aria-expanded="true"><span>2</span> comments <span class="caret"></span></a></h3>
-
- <div id="com2" class="panel-collapse collapse">
- <ul class="list-group">
- <li class="list-group-item">
- <img src="assets/images/misc/user5.jpeg" class="img-responsive img-circle comment-user-img">
- <p class="comment-username"><a href="/user_profile">catherineTheGreat</a></p>
- <p class="user-comment"> As a Portuguese, this was offensive and hilarious.</p>
- </li>
-
- <li class="list-group-item">
- <img src="assets/images/user-default.png" class="img-responsive img-circle comment-user-img">
- <p class="comment-username"><a href="/user_profile">alexStrav748</a></p>
- <p class="user-comment">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
- </li>
- </ul>
- </div>
- </div>
- </section>
- </div>
</div>
</div>
</main>