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:
1
app.js
1
app.js
@ -326,6 +326,7 @@ app.post('/completed-bonfire/', bonfireController.completedBonfire);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
app.get('/coursewares/', coursewareController.returnNextCourseware);
|
app.get('/coursewares/', coursewareController.returnNextCourseware);
|
||||||
|
app.get('/coursewares/getCoursewareList', coursewareController.showAllCoursewares);
|
||||||
app.get(
|
app.get(
|
||||||
'/coursewares/:coursewareName',
|
'/coursewares/:coursewareName',
|
||||||
coursewareController.returnIndividualCourseware
|
coursewareController.returnIndividualCourseware
|
||||||
|
@ -2,16 +2,23 @@ var _ = require('lodash'),
|
|||||||
debug = require('debug')('freecc:cntr:courseware'),
|
debug = require('debug')('freecc:cntr:courseware'),
|
||||||
Courseware = require('./../models/Courseware'),
|
Courseware = require('./../models/Courseware'),
|
||||||
User = require('./../models/User'),
|
User = require('./../models/User'),
|
||||||
resources = require('./resources');
|
resources = require('./resources'),
|
||||||
|
R = require('ramda');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Courseware controller
|
* Courseware controller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.coursewareNames = function(req, res) {
|
exports.showAllCoursewares = function(req, res) {
|
||||||
res.render('coursewares/showList', {
|
var completedCoursewares = req.user.completedCoursewares.map(function(elem) {
|
||||||
coursewareList: resources.allCoursewareNames()
|
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) {
|
exports.returnNextCourseware = function(req, res) {
|
||||||
@ -29,13 +36,15 @@ exports.returnNextCourseware = function(req, res) {
|
|||||||
});
|
});
|
||||||
req.user.save();
|
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) {
|
displayedCoursewares.exec(function(err, courseware) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
debug('This is the courseware object returned from mongo', courseware);
|
||||||
courseware = courseware.pop();
|
courseware = courseware.pop();
|
||||||
if (courseware === undefined) {
|
if (courseware === undefined) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
|
@ -239,15 +239,19 @@ module.exports = {
|
|||||||
return coursewares.map(function(elem) {
|
return coursewares.map(function(elem) {
|
||||||
return {
|
return {
|
||||||
name: elem.name,
|
name: elem.name,
|
||||||
difficulty: elem.difficulty
|
difficulty: elem.difficulty,
|
||||||
|
_id: elem._id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort(function(a, b) {
|
.sort(function(a, b) {
|
||||||
return a.difficulty - b.difficulty;
|
return a.difficulty - b.difficulty;
|
||||||
})
|
})
|
||||||
.map(function(elem) {
|
.map (function(elem) {
|
||||||
return elem.name;
|
return {
|
||||||
});
|
name : elem.name,
|
||||||
|
_id: elem._id
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
whichEnvironment: function() {
|
whichEnvironment: function() {
|
||||||
return process.env.NODE_ENV;
|
return process.env.NODE_ENV;
|
||||||
|
@ -78,6 +78,14 @@ $(document).ready(function() {
|
|||||||
editor.focus();
|
editor.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#showAllCoursewares').on('click', function() {
|
||||||
|
$('#all-coursewares-dialog').modal('show');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#all-coursewares-dialog').on('hidden.bs.modal', function() {
|
||||||
|
editor.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#complete-courseware-dialog').on('hidden.bs.modal', function() {
|
$('#complete-courseware-dialog').on('hidden.bs.modal', function() {
|
||||||
editor.focus();
|
editor.focus();
|
||||||
@ -90,12 +98,12 @@ $(document).ready(function() {
|
|||||||
coursewareInfo: {
|
coursewareInfo: {
|
||||||
coursewareHash: passedCoursewareHash
|
coursewareHash: passedCoursewareHash
|
||||||
}
|
}
|
||||||
},
|
}).success(
|
||||||
function(res) {
|
function() {
|
||||||
if (res) {
|
window.location.href = '/coursewares';
|
||||||
window.location.href = '/coursewares'
|
}
|
||||||
}
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
require('dotenv').load();
|
require('dotenv').load();
|
||||||
var Challenge = require('../models/Challenge.js'),
|
var Bonfire = require('../models/Bonfire.js'),
|
||||||
Bonfire = require('../models/Bonfire.js'),
|
|
||||||
Courseware = require('../models/Courseware.js'),
|
Courseware = require('../models/Courseware.js'),
|
||||||
mongoose = require('mongoose'),
|
mongoose = require('mongoose'),
|
||||||
secrets = require('../config/secrets'),
|
secrets = require('../config/secrets'),
|
||||||
challenges = require('./challenges.json'),
|
|
||||||
coursewares = require('./coursewares.json'),
|
coursewares = require('./coursewares.json'),
|
||||||
bonfires = require('./bonfires.json');
|
bonfires = require('./bonfires.json');
|
||||||
|
|
||||||
mongoose.connect(secrets.db);
|
mongoose.connect(secrets.db);
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var offerings = 3;
|
var offerings = 2;
|
||||||
|
|
||||||
var CompletionMonitor = function() {
|
var CompletionMonitor = function() {
|
||||||
counter++;
|
counter++;
|
||||||
@ -22,24 +20,8 @@ var CompletionMonitor = function() {
|
|||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
Challenge.remove({}, function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
} else {
|
|
||||||
console.log('Deleted ', data);
|
|
||||||
}
|
|
||||||
Challenge.create(challenges, function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
console.log('Saved ', data);
|
|
||||||
}
|
|
||||||
CompletionMonitor();
|
|
||||||
});
|
|
||||||
console.log('challenges');
|
|
||||||
});
|
|
||||||
|
|
||||||
Bonfire.remove({}, function(err, data) {
|
Bonfire.remove({}, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -18,6 +18,8 @@ block content
|
|||||||
script(src='/js/lib/codemirror/mode/xml/xml.js')
|
script(src='/js/lib/codemirror/mode/xml/xml.js')
|
||||||
script(src='/js/lib/codemirror/mode/css/css.js')
|
script(src='/js/lib/codemirror/mode/css/css.js')
|
||||||
script(src='/js/lib/codemirror/mode/htmlmixed/htmlmixed.js')
|
script(src='/js/lib/codemirror/mode/htmlmixed/htmlmixed.js')
|
||||||
|
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
|
||||||
|
|
||||||
.row.courseware-height
|
.row.courseware-height
|
||||||
.col-xs-12.col-sm-12.col-md-3.col-lg-3
|
.col-xs-12.col-sm-12.col-md-3.col-lg-3
|
||||||
.well
|
.well
|
||||||
@ -40,6 +42,7 @@ block content
|
|||||||
span.ion-help-circled
|
span.ion-help-circled
|
||||||
| Less information
|
| Less information
|
||||||
br
|
br
|
||||||
|
.btn.btn-info#showAllCoursewares
|
||||||
|
|
||||||
- if (cc)
|
- if (cc)
|
||||||
a.btn.btn-primary.btn-lg.btn-block#next-courseware-button
|
a.btn.btn-primary.btn-lg.btn-block#next-courseware-button
|
||||||
@ -88,3 +91,11 @@ block content
|
|||||||
span.completion-icon.ion-checkmark-circled.text-primary
|
span.completion-icon.ion-checkmark-circled.text-primary
|
||||||
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
||||||
script(src="/js/lib/coursewares/coursewaresHCJQFramework_v0.1.1.js")
|
script(src="/js/lib/coursewares/coursewaresHCJQFramework_v0.1.1.js")
|
||||||
|
|
||||||
|
#all-coursewares-dialog.modal(tabindex='-1')
|
||||||
|
.modal-dialog.animated.fadeInUp.fast-animation
|
||||||
|
.modal-content
|
||||||
|
.modal-header.all-list-header Challenges
|
||||||
|
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
||||||
|
.modal-body
|
||||||
|
include ../partials/coursewares
|
||||||
|
@ -47,7 +47,7 @@ block content
|
|||||||
script(type="text/javascript").
|
script(type="text/javascript").
|
||||||
var tests = !{JSON.stringify(tests)};
|
var tests = !{JSON.stringify(tests)};
|
||||||
var challengeSeed = !{JSON.stringify(challengeSeed)};
|
var challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||||
var passedBonfireHash = !{JSON.stringify(coursewareHash)};
|
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
|
||||||
var challengeName = !{JSON.stringify(name)};
|
var challengeName = !{JSON.stringify(name)};
|
||||||
var started = Math.floor(Date.now() / 1000);
|
var started = Math.floor(Date.now() / 1000);
|
||||||
.col-xs-12.col-sm-12.col-md-8
|
.col-xs-12.col-sm-12.col-md-8
|
||||||
@ -67,10 +67,10 @@ block content
|
|||||||
span.completion-icon.ion-checkmark-circled.text-primary
|
span.completion-icon.ion-checkmark-circled.text-primary
|
||||||
- if (cc)
|
- if (cc)
|
||||||
|
|
||||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-courseware-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid && existingUser.length > 0') Go to my next challenge (ctrl + enter)
|
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid && existingUser.length > 0') Go to my next challenge (ctrl + enter)
|
||||||
- if (points && points > 2)
|
- if (points && points > 2)
|
||||||
a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank")
|
a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Challenge:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank")
|
||||||
i.fa.fa-twitter
|
i.fa.fa-twitter
|
||||||
= phrase
|
= phrase
|
||||||
- else
|
- else
|
||||||
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
@ -16,7 +16,7 @@ h3
|
|||||||
if (R.contains(data.bonfireList[i]._id, data.completedList)) {
|
if (R.contains(data.bonfireList[i]._id, data.completedList)) {
|
||||||
$(li).addClass('strikethrough');
|
$(li).addClass('strikethrough');
|
||||||
}
|
}
|
||||||
$(li).html("<a href='/bonfires/" + linkedName + "'>" + data.bonfireList[i].name + "</a>");
|
$(li).html("<a href='/bonfires/" + linkedName + "'>" + data.bonfireList[i].name + "</a></li>");
|
||||||
$(li).appendTo($('#bonfireList'));
|
$(li).appendTo($('#bonfireList'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
23
views/partials/coursewares.jade
Normal file
23
views/partials/coursewares.jade
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
h3
|
||||||
|
ol#coursewareList
|
||||||
|
script.
|
||||||
|
var getLinkedName = function getLinkedName(name) {
|
||||||
|
return name.toLowerCase().replace(/\s/g, '-');
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: '/coursewares/getCoursewareList',
|
||||||
|
type: 'GET'
|
||||||
|
})
|
||||||
|
.success(
|
||||||
|
function(data) {
|
||||||
|
for (var i = 0; i < data.coursewareList.length; i++) {
|
||||||
|
var li = document.createElement('li');
|
||||||
|
var linkedName = getLinkedName(data.coursewareList[i].name);
|
||||||
|
if (R.contains(data.coursewareList[i]._id, data.completedList)) {
|
||||||
|
$(li).addClass('strikethrough');
|
||||||
|
}
|
||||||
|
$(li).html("<a href='/coursewares/" + linkedName + "'>" + data.coursewareList[i].name + "</a></li>");
|
||||||
|
$(li).appendTo($('#coursewareList'));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
Reference in New Issue
Block a user