diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-25 05:57:14 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-25 05:57:14 +0000 |
| commit | 1904de750f421cce9bec21ab89c50ea7a38a37d4 (patch) | |
| tree | 813b3716d45c3c38c1ec3963bef73baf4d8c1c74 | |
| parent | 74fe077b29ee681f8e55d14afdbd7c93bc2c1048 (diff) | |
Added user search feature, fixed styilng, added some scripting
| -rw-r--r-- | assets/js/script.js | 20 | ||||
| -rw-r--r-- | node_simple.js | 7 | ||||
| -rw-r--r-- | routes/index.js | 35 | ||||
| -rw-r--r-- | views/exams.hbs | 29 | ||||
| -rw-r--r-- | views/index.hbs | 16 | ||||
| -rw-r--r-- | 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 @@ <main id = 'solutions-main'> <div class = 'search container' id = 'solutions-div'> <h4 class='search-head'>Search results for "{{query}}"</h4> - {{# each result}} - <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> - <p class = 'exam-instr'><em>Instructors: </em> - {{this.instructors}} - </p> - <p class = 'solutions-type'>{{result.type}}</p> - </section> - </a> - {{/each}} - + {{# if result }} + {{# each result}} + <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> + <p class = 'exam-instr'><em>Instructors: </em> + {{this.instructors}} + </p> + <p class = 'solutions-type'>{{result.type}}</p> + </section> + </a> + {{/each}} + {{ else }} + <h3 class="solutions-title"> No results found. Sorry!</h3> + {{/if}} </div> </main> 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 @@ <header> <div class="header-content"> - <form action="/search" method="get"> + <form action="/search/courses" method="get" id="search-field"> <section class="header-content-inner"> <p><strong>The solutions to all your problems</strong></p> <hr> <!-- Divider --> @@ -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"> + <span id="drop-down-value">Courses</span> <span class="caret"></span> </button> - <ul class="dropdown-menu"> - <li><a href="#">Courses</a></li> - <li><a href="#">Users</a> </li> + <ul class="dropdown-menu" id="search-type"> + + <!-- add classes to <a> refs, on click, check texts, hide/adjust, + change action etc. accordingly --> + + <li><a href="#" class="search-menu">Courses</a></li> + <li><a href="#" class="search-menu">Users</a> </li> </ul> </div> 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 @@ <li><a href="exams.html">Exams Pages</a></li>--> <li class="dropdown"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Courses <span class="caret"></span></a> + <a href="#" + class="dropdown-toggle" + data-toggle="dropdown" + role="button" aria-haspopup="true" + aria-expanded="false">Courses <span class="caret"></span></a> <ul class="dropdown-menu"> <li class="dropdown-submenu"> - <a tabindex="-1" href="#">First Year<i class="fa fa-chevron-right pull-right"></i></a> + <a tabindex="-1" href="#">First Year</a> <ul class="dropdown-menu"> <li><a tabindex="-1" href="/exams/csc108">CSC108</a></li> <li><a href="/exams/csc148">CSC148</a></li> @@ -62,7 +66,12 @@ <li><a href="/user/signup" >Sign up</a></li> {{/if}} <li class="dropdown"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Links <span class="caret"></span></a> + <a href="#" + class="dropdown-toggle" + data-toggle="dropdown" + role="button" + aria-haspopup="true" + aria-expanded="false">Links <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a tabindex="-1" href="/user_solutions">Solutions Page</a></li> <li><a href="/user/user_profile">Profile Page</a></li> @@ -79,4 +88,4 @@ <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> -</nav>
\ No newline at end of file +</nav> <!-- Ignore error, opening tag will be generated at render time -->
\ No newline at end of file |
