diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-25 06:59:56 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-25 06:59:56 +0000 |
| commit | 1032205c1a94ae31d780d2c339abbe628eb27fae (patch) | |
| tree | 7cc15d706f5fbd1c624341e781219710287088cf | |
| parent | 553e5d112f34c6be19b388fea110dcdceb7015bd (diff) | |
| parent | 2b0ca1332175139e44235c3ac3390d5f26eae7e1 (diff) | |
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
| -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-- | routes/user.js | 2 | ||||
| -rw-r--r-- | views/exams.hbs | 29 | ||||
| -rw-r--r-- | views/index.hbs | 16 | ||||
| -rw-r--r-- | views/partials/header.hbs | 17 | ||||
| -rw-r--r-- | views/user_search.hbs | 19 |
8 files changed, 109 insertions, 36 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 a3d0f6e..0290519 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..283b196 100644 --- a/routes/index.js +++ b/routes/index.js @@ -74,11 +74,37 @@ router.get('/exams/:id', function(req, res, next) { }); }); +/* Render user search page based on query */ +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/routes/user.js b/routes/user.js index f6ac438..b179236 100644 --- a/routes/user.js +++ b/routes/user.js @@ -101,7 +101,7 @@ router.post('/submit_solution/:examID/:qID', function(req,res){ comments = [], author = req.user.user_name; - var fields = [examID, qID, text, votes, comments, author]; + var fields = [examID, qID, text, author]; console.log(fields); // Add to database dbFile.add_solution(fields, function(addedSolution, statusMsg){ 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 diff --git a/views/user_search.hbs b/views/user_search.hbs new file mode 100644 index 0000000..fd08e84 --- /dev/null +++ b/views/user_search.hbs @@ -0,0 +1,19 @@ +<main id = 'solutions-main'> +<div class = 'search container' id = 'solutions-div'> + <h4 class='search-head'>Search results for "{{query}}"</h4> + {{# if users }} + {{# each users}} + <a href="/public_profile/{{this._id}}"> + <section class = 'solutions-card'> + <h3 class = 'solutions-title'>{{this.user_name}}</h3> + <p class = 'solutions-time' > + <em>Name: </em>{{this.f_name}} {{this.l_name}} </p> + </p> + </section> + </a> + {{/each}} + {{ else }} + <h3 class="solutions-title"> No results found. Sorry!</h3> + {{/if}} +</div> +</main> |
