From 68be8844ddc1e30e34745a0589fa3395ae6ec198 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Thu, 21 Jul 2016 04:58:24 -0400 Subject: Added templating for questions, made a minor adjustments to index.js --- routes/index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'routes/index.js') diff --git a/routes/index.js b/routes/index.js index 52a0ca6..708e532 100644 --- a/routes/index.js +++ b/routes/index.js @@ -86,14 +86,6 @@ router.get('/search', function(req, res, next) { res.redirect('/exams/' + courseName); }); - -/* REDIRECT - exam -> questions page*/ -router.get('/exam_click',function (req,res) { - //TODO:get needs to have exam_id attached - var examId = req.query.exam_id; - res.redirect('/questions/'+examId); -}); - /*EXAMPLE DATA GIVEN BELOW: * questions = [{id,count,comments},{id,count,comments}] --> array of "question" objects * @@ -101,9 +93,10 @@ router.get('/exam_click',function (req,res) { * count= number of solutions * comments = number of comments*/ router.get('/questions/:exam_id', function (req,res) { + console.log(req.params.exam_id); dbFile.get_exam_info_by_ID(req.params.exam_id, function (questions) { - res.render('questions', {query: questions}); + console.log(questions); }); }); @@ -148,7 +141,6 @@ app.get('/exams.html', function (req,res) { res.sendFile(__dirname+'/exams.html'); });*/ - function getExamsForCourseCode(courseCode) { dbFile.get_all_exams(courseCode, function (exams) { if (exams.length == 0){ @@ -160,7 +152,6 @@ function getExamsForCourseCode(courseCode) { }); } - module.exports = router; function toProperCase(string) { -- cgit v1.2.3 From 7f385f73ebc024e2c07e628fc1500bcb21b69837 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Thu, 21 Jul 2016 06:09:30 -0400 Subject: added admin page, fixed some minor issues --- routes/index.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'routes/index.js') diff --git a/routes/index.js b/routes/index.js index 708e532..bea28da 100644 --- a/routes/index.js +++ b/routes/index.js @@ -34,6 +34,10 @@ router.get('/questions', function(req, res, next) { res.render('questions'); }); +router.get('/admin', function(req,res){ + res.render('admin'); +}); + /* Render/GET exam page */ /* Render/GET exam page */ //EXAMPLE EXPECTED DATA GIVEN BELOW: -- cgit v1.2.3 From 797b4fe83ed4ebbed47930c7d0d0a34cd37703c6 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Thu, 21 Jul 2016 17:53:14 -0400 Subject: Made appropriate changes to add admin panel for adding exams, still need to add validation and fix minor glitches. Added servercallback for get_all_exams and find_exams in node_simple.js --- routes/index.js | 104 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 33 deletions(-) (limited to 'routes/index.js') diff --git a/routes/index.js b/routes/index.js index bea28da..1e3f1e0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -35,26 +35,61 @@ router.get('/questions', function(req, res, next) { }); router.get('/admin', function(req,res){ - res.render('admin'); + res.render('admin', {csrfToken: req.csrfToken()}); }); -/* Render/GET exam page */ -/* Render/GET exam page */ + +router.post('/admin/update', function(req,res){ + var course_code = req.body.course_code, + year = req.body.year, + type = req.body.type, + term = req.body.term, + instructors = parseStringArray(req.body.instructors), + page_count = req.body.page_count, + questions_count = req.body.questions_count, + questions_list = parseStringArray(req.body.questions_list), + upload_date = req.body.upload_date, + uploaded_by = req.body.uploaded_by; + + var fields = [ + course_code, // String + year, // Int + type, // String; Needs to be added to database code + term, // String + instructors, // Array of strings + page_count, // Int + questions_count, // Int + upload_date, // String + uploaded_by]; // String + + dbFile.add_exam(fields, questions_list, function(examAdded, statusMessage){ + if(examAdded){ + console.log("Success!"); + }else{ + console.log("Failed!"); + } + console.log(statusMessage); + }); + res.redirect('/admin'); +}); + + //EXAMPLE EXPECTED DATA GIVEN BELOW: -/*[ { courseCode: 'CSC240', - year: 2016, - term: 'Fall', - instructors: [ 'Faith Ellen', 'Tom F.' ], - type: 'Midterm Examination', - title: 'Thry of Computation' }, - { courseCode: 'CSC240', - year: 2014, - term: 'Fall', - instructors: [ 'Faith Ellen', 'Tom F.' ], - type: 'Midterm Examination', - title: 'Thry of Computation' } ] - */ +/*[ {courseCode: 'CSC240', + year: 2016, + term: 'Fall', + instructors: ['Faith Ellen', 'Tom F.'], + type: 'Midterm Examination', + title: 'Thry of Computation' }, + + {courseCode: 'CSC240', + year: 2014, + term: 'Fall', + instructors: ['Faith Ellen', 'Tom F.'], + type: 'Midterm Examination', + title: 'Thry of Computation' } ] + */ router.get('/exams/:id', function(req, res, next) { var minExamInfoArray = []; dbFile.get_all_exams(req.params.id, function (exams) { @@ -65,6 +100,7 @@ router.get('/exams/:id', function(req, res, next) { //console.log(exams); //only pass over the information that is necessary for the exams page for (var i = 0; i