All coursewares list now displays properly, coursewares properly direct to the follow on, courseware controller now properly finds the next courseware
This commit is contained in:
@@ -2,16 +2,23 @@ var _ = require('lodash'),
|
||||
debug = require('debug')('freecc:cntr:courseware'),
|
||||
Courseware = require('./../models/Courseware'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources');
|
||||
resources = require('./resources'),
|
||||
R = require('ramda');
|
||||
|
||||
/**
|
||||
* Courseware controller
|
||||
*/
|
||||
|
||||
exports.coursewareNames = function(req, res) {
|
||||
res.render('coursewares/showList', {
|
||||
coursewareList: resources.allCoursewareNames()
|
||||
exports.showAllCoursewares = function(req, res) {
|
||||
var completedCoursewares = req.user.completedCoursewares.map(function(elem) {
|
||||
return elem._id;
|
||||
});
|
||||
|
||||
var noDuplicatedCoursewares = R.uniq(completedCoursewares);
|
||||
var data = {};
|
||||
data.coursewareList = resources.allCoursewareNames();
|
||||
data.completedList = noDuplicatedCoursewares;
|
||||
res.send(data);
|
||||
};
|
||||
|
||||
exports.returnNextCourseware = function(req, res) {
|
||||
@@ -29,13 +36,15 @@ exports.returnNextCourseware = function(req, res) {
|
||||
});
|
||||
req.user.save();
|
||||
|
||||
var uncompletedCoursewares = req.user.uncompletedCoursewares;
|
||||
var uncompletedCoursewares = req.user.uncompletedCoursewares.shift();
|
||||
|
||||
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares[0]});
|
||||
|
||||
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares});
|
||||
displayedCoursewares.exec(function(err, courseware) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
debug('This is the courseware object returned from mongo', courseware);
|
||||
courseware = courseware.pop();
|
||||
if (courseware === undefined) {
|
||||
req.flash('errors', {
|
||||
|
@@ -239,15 +239,19 @@ module.exports = {
|
||||
return coursewares.map(function(elem) {
|
||||
return {
|
||||
name: elem.name,
|
||||
difficulty: elem.difficulty
|
||||
difficulty: elem.difficulty,
|
||||
_id: elem._id
|
||||
}
|
||||
})
|
||||
.sort(function(a, b) {
|
||||
return a.difficulty - b.difficulty;
|
||||
})
|
||||
.map(function(elem) {
|
||||
return elem.name;
|
||||
});
|
||||
.map (function(elem) {
|
||||
return {
|
||||
name : elem.name,
|
||||
_id: elem._id
|
||||
}
|
||||
});
|
||||
},
|
||||
whichEnvironment: function() {
|
||||
return process.env.NODE_ENV;
|
||||
|
Reference in New Issue
Block a user