From 2f819f8f2cfa5d2c5613f1f3d8b47b6a36331659 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Sun, 24 Jul 2016 17:48:06 -0400 Subject: Added voting to front end --- assets/css/style.css | 10 +++++++++- routes/index.js | 2 ++ routes/user.js | 19 ++++++++++++++++++- views/user_solutions.hbs | 20 ++++++++++++-------- 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 @@ - {{#each query}}
@@ -30,13 +29,18 @@
-
- -

{{this.votes}}

-
-
- -

-1

+
+
+ + + +
+
+ + + +
+

{{this.votes}}

-- cgit v1.2.3