From 1904de750f421cce9bec21ab89c50ea7a38a37d4 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Mon, 25 Jul 2016 01:57:14 -0400 Subject: Added user search feature, fixed styilng, added some scripting --- assets/js/script.js | 20 ++++++++++++++++++++ node_simple.js | 7 ------- routes/index.js | 35 ++++++++++++++++++++++++++++++----- views/exams.hbs | 29 ++++++++++++++++------------- views/index.hbs | 16 ++++++++++------ views/partials/header.hbs | 17 +++++++++++++---- 6 files changed, 89 insertions(+), 35 deletions(-) diff --git a/assets/js/script.js b/assets/js/script.js index 5531c1e..1657f9b 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -129,5 +129,25 @@ function main(){ $(this).parent('li').removeClass('active'); }); + $('.search-menu').bind('click', function(e) { + e.preventDefault(); + $("#search-drop-down").click(); + var type = $(this).text(); + + switch(type) { + case "Courses": + $("#search-field").attr("action","/search/courses"); + $("#user-input").attr("placeholder", "Enter coure code"); + $("#drop-down-value").text("Courses"); + break; + case "Users": + $("#search-field").attr("action","/search/users"); + $("#user-input").attr("placeholder", "Enter user info"); + $("#drop-down-value").text("Users"); + break; + default: + console.log("Error: Click not registered"); + } + }); } $(document).ready(main); \ No newline at end of file diff --git a/node_simple.js b/node_simple.js index 447c605..eeaf5e5 100644 --- a/node_simple.js +++ b/node_simple.js @@ -104,13 +104,6 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/ /*refer to testImports.js*/ //****************************FUNCTIONS************************************************| -exports.closeDB = function(){ - mongoFactory.getConnection(uri).then(function(db) { - db.close(); - }).catch(function(err){ - console.error(err); - }); -}; /** * Remvove a course from ONLY the courses table IN CASE of accidental diff --git a/routes/index.js b/routes/index.js index 698305b..b8c92e1 100644 --- a/routes/index.js +++ b/routes/index.js @@ -74,11 +74,37 @@ router.get('/exams/:id', function(req, res, next) { }); }); +// WORK IN PROGRESS +router.get('/user/:query', function(req,res,next){ + var query = req.params.query; + // Need to validate query + + + dbFile.search_users(query, function(success, result){ + if(success){ + console.log(result); + res.render('user_search', {users : result, query : query}); + }else{ + console.log(result); + res.redirect('/'); + } + }); +}); + /* Render/GET search (exam) page */ -router.get('/search', function(req, res, next) { +router.get('/search/:type', function(req, res, next) { + + var searchType = req.params.type; console.log(req.query.search); - var courseName = req.query.search; - res.redirect('/exams/' + courseName); + console.log(searchType); + if(searchType == "courses"){ + var courseName = req.query.search; + res.redirect('/exams/' + courseName); + }else{ + var userInfo = req.query.search; + res.redirect('/user/' + userInfo); + } + }); /* This is a redirect from the exams page, route is generated in exams.hbs @@ -166,8 +192,7 @@ router.get('/questions/:exam_id', function (req,res) { "by": "some_user name" }, * - */ - + * router.get('/solutions/:exam_id/:q_num', function (req, res) { var examID = req.params.exam_id; var qID = req.params.q_num; diff --git a/views/exams.hbs b/views/exams.hbs index b5e5092..8b179f3 100644 --- a/views/exams.hbs +++ b/views/exams.hbs @@ -1,18 +1,21 @@
diff --git a/views/index.hbs b/views/index.hbs index 59c589f..c3cbeab 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -1,7 +1,7 @@
-
+

The solutions to all your problems


@@ -14,13 +14,17 @@ class="btn btn-default dropdown-toggle search-button" data-toggle="dropdown" aria-haspopup="true" - aria-expanded="false"> - Courses + aria-expanded="false" id="search-drop-down"> + Courses -
diff --git a/views/partials/header.hbs b/views/partials/header.hbs index 901b249..08dc92f 100644 --- a/views/partials/header.hbs +++ b/views/partials/header.hbs @@ -30,10 +30,14 @@
  • Exams Pages
  • -->