aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/css/style.css10
-rw-r--r--routes/index.js2
-rw-r--r--routes/user.js19
-rw-r--r--views/user_solutions.hbs20
4 files changed, 41 insertions, 10 deletions
diff --git a/assets/css/style.css b/assets/css/style.css
index 7b1538c..ab422cd 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -149,7 +149,7 @@ main [id^="sol-"] img.user-image {
margin-left: 25px;
}
-.upvoting, .downvoting, .upvote, .downvote, .user-image, .username {
+.upvoting, .downvoting, .upvote, .downvote, .user-image, .username, .num-votes{
display: inline-block;
}
@@ -181,6 +181,10 @@ main [id^="sol-"] p.username {
main [id^="sol-"] p.num-downvotes {
margin-right: 25px;
}
+main [id^="sol-"] .voting{
+ margin-right: 25px;
+}
+
main [id^="sol-"] div.user-sol h3 {
font-size: 1.17em;
@@ -253,6 +257,10 @@ main [id^="sol-"] div.comments ul li p.user-comment {
background-color: white;
border-radius: 5px;
}
+
+main [id^="sol-"] .voting form{
+ display: inline;
+}
/*** USER SOLUTIONS END***/
/*** EXAM PAGE ***/
diff --git a/routes/index.js b/routes/index.js
index d8cfd36..23cd7c3 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -182,9 +182,11 @@ router.get('/questions/:exam_id', function (req,res) {
*/
router.get('/solutions/:exam_id/:q_num', function (req, res) {
+ console.log("index.js::Getting solutions");
var examID = req.params.exam_id;
var qID = req.params.q_num;
dbFile.get_all_solutions(examID, qID, function (solutions) {
+ console.log("index.js::GOT solutions");
solutions.forEach(function(soln){
soln.commentCount = soln.comments.length;
});
diff --git a/routes/user.js b/routes/user.js
index c466e3c..f5dab0c 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -257,10 +257,27 @@ router.post('/comment/submit/:examID/:qID/:solID', function(req, res, next){
}
});
+router.post('/solution/vote/:examID/:qID/:solID', function(req, res, next){
+ var vote = req.body.vote;
+ var examID = req.params.examID;
+ var qID = req.params.qID;
+ var solutionID = req.params.solID;
+ dbFile.vote_solution(solutionID, vote, function(voteCounted, statusMsg){
+ if(voteCounted){
+ console.log("Success!");
+ }else{
+ console.log("Action failed!");
+ }
+ console.log(statusMsg); // Change to display message above
+ res.redirect('/solutions/' + examID + '/' + qID);
+ });
+
+
+});
+
module.exports = router;
/************** Route protection ********************/
-
function loggedIn(req, res, next) {
if (req.isAuthenticated()) {
return next();
diff --git a/views/user_solutions.hbs b/views/user_solutions.hbs
index 598e63d..b00b098 100644
--- a/views/user_solutions.hbs
+++ b/views/user_solutions.hbs
@@ -19,7 +19,6 @@
</div>
<!-- Solution 1 Example -->
-
{{#each query}}
<div class="row">
<section id="sol-" class="col-md-10 col-md-offset-1 rounded">
@@ -30,13 +29,18 @@
</div>
<div class="pull-right">
- <div class="upvoting">
- <button class="upvote"><img src="/assets/images/up_arrow.png"></button>
- <p class="upvote num-upvotes">{{this.votes}}</p>
- </div>
- <div class="downvoting">
- <button class="downvote"><img src="/assets/images/down_arrow.png"></button>
- <p class=" downvote num-downvotes">-1</p>
+ <div class="voting">
+ <form action="/user/solution/vote/{{../examID}}/{{../qID}}/{{this._id}}" method="post">
+ <input type="hidden" name="vote" value="up"/>
+ <button class="upvote" type="submit"><img src="/assets/images/up_arrow.png"></button>
+ <input type="hidden" name="_csrf" value="{{../csrfToken }}">
+ </form>
+ <form action="/user/solution/vote/{{../examID}}/{{../qID}}/{{this._id}}" method="post">
+ <input type="hidden" name="vote" value="down"/>
+ <button class="downvote"><img src="/assets/images/down_arrow.png"></button>
+ <input type="hidden" name="_csrf" value="{{../csrfToken }}">
+ </form>
+ <p class="num-votes">{{this.votes}}</p>
</div>
</div>
</div>