Correctly sorting unsolved bonfires
This commit is contained in:
23
app.js
23
app.js
@ -326,6 +326,17 @@ app.post('/completed-bonfire/', function (req, res) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
|
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
|
|
||||||
|
if (index > -1) {
|
||||||
|
req.user.uncompletedBonfires.splice(index,1)
|
||||||
|
}
|
||||||
|
|
||||||
|
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
|
if (index > -1) {
|
||||||
|
pairedWith.uncompletedBonfires.splice(index,1)
|
||||||
|
}
|
||||||
|
|
||||||
pairedWith = pairedWith.pop();
|
pairedWith = pairedWith.pop();
|
||||||
pairedWith.completedBonfires.push({
|
pairedWith.completedBonfires.push({
|
||||||
_id: bonfireHash,
|
_id: bonfireHash,
|
||||||
@ -341,17 +352,8 @@ app.post('/completed-bonfire/', function (req, res) {
|
|||||||
solution: isSolution
|
solution: isSolution
|
||||||
})
|
})
|
||||||
|
|
||||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
|
||||||
|
|
||||||
if (index > -1) {
|
|
||||||
req.user.uncompletedBonfires.splice(index,1)
|
|
||||||
}
|
|
||||||
|
|
||||||
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
|
||||||
if (index > -1) {
|
|
||||||
req.user.uncompletedBonfires.splice(index,1)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
debug('saving user with a pair');
|
||||||
req.user.save();
|
req.user.save();
|
||||||
pairedWith.save();
|
pairedWith.save();
|
||||||
|
|
||||||
@ -370,6 +372,7 @@ app.post('/completed-bonfire/', function (req, res) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
req.user.uncompletedBonfires.splice(index,1)
|
req.user.uncompletedBonfires.splice(index,1)
|
||||||
}
|
}
|
||||||
|
debug("Saving user without a pair");
|
||||||
req.user.save();
|
req.user.save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -30,25 +30,19 @@ exports.index = function(req, res) {
|
|||||||
bonfireHash: 'test'
|
bonfireHash: 'test'
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Bonfire.find({}, null, { sort: { difficulty: 1 } }, function(err, c) {
|
|
||||||
if (err) {
|
|
||||||
debug('bonfire err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnNextBonfire = function(req, res, next) {
|
exports.returnNextBonfire = function(req, res, next) {
|
||||||
var bonfireNumber;
|
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
req.user = new User();
|
req.user = new User();
|
||||||
//return res.redirect('/bonfires/meet-bonfire');
|
|
||||||
}
|
}
|
||||||
var currentTime = parseInt(+new Date() / 1000)
|
var currentTime = parseInt(+new Date() / 1000)
|
||||||
if (currentTime - req.user.lastContentSync > 86400) {
|
if (currentTime - req.user.lastContentSync > 86400) {
|
||||||
req.user.lastContentSync = currentTime;
|
req.user.lastContentSync = currentTime;
|
||||||
var completed = req.user.completedBonfires;
|
var completed = req.user.completedBonfires.map(function(elem) {
|
||||||
|
return elem._id;
|
||||||
|
});
|
||||||
// TODO : remove debug statement
|
// TODO : remove debug statement
|
||||||
debug(req.user, 'this is the user');
|
debug(req.user, 'this is the user');
|
||||||
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function(elem) {
|
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function(elem) {
|
||||||
@ -57,6 +51,8 @@ exports.returnNextBonfire = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
debug('These are completed bonfires', completed);
|
||||||
|
debug('These are uncompleted bonfires', req.user.uncompletedBonfires);
|
||||||
|
|
||||||
var uncompletedBonfires = req.user.uncompletedBonfires;
|
var uncompletedBonfires = req.user.uncompletedBonfires;
|
||||||
|
|
||||||
@ -66,7 +62,7 @@ exports.returnNextBonfire = function(req, res, next) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
debug('Finding next bonfire for user', bonfire);
|
|
||||||
nameString = bonfire[0].name.toLowerCase().replace(/\s/g, '-');
|
nameString = bonfire[0].name.toLowerCase().replace(/\s/g, '-');
|
||||||
return res.redirect('/bonfires/' + nameString);
|
return res.redirect('/bonfires/' + nameString);
|
||||||
//res.render('bonfire/show', {
|
//res.render('bonfire/show', {
|
||||||
|
@ -6,7 +6,8 @@ var User = require('../models/User'),
|
|||||||
Challenge = require('./../models/Challenge'),
|
Challenge = require('./../models/Challenge'),
|
||||||
bonfires = require('../seed_data/bonfires.json');
|
bonfires = require('../seed_data/bonfires.json');
|
||||||
Client = require('node-rest-client').Client,
|
Client = require('node-rest-client').Client,
|
||||||
client = new Client();
|
client = new Client(),
|
||||||
|
debug = require('debug')('freecc:cntr:bonfires');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /
|
* GET /
|
||||||
@ -14,161 +15,161 @@ var User = require('../models/User'),
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
privacy: function privacy(req, res) {
|
privacy: function privacy(req, res) {
|
||||||
res.render('resources/privacy', {
|
res.render('resources/privacy', {
|
||||||
title: 'Privacy'
|
title: 'Privacy'
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
stats: function stats(req, res) {
|
|
||||||
var date1 = new Date("10/15/2014");
|
|
||||||
var date2 = new Date();
|
|
||||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
|
||||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
||||||
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, response) {
|
|
||||||
var nonprofitProjects = (trello && trello.length) || 15;
|
|
||||||
User.count({'points': {'$gt': 2}}, function(err, c3) { if (err) { debug('User err: ', err); next(err); }
|
|
||||||
User.count({'points': {'$gt': 9}}, function(err, c10) { if (err) { debug('User err: ', err); next(err); }
|
|
||||||
User.count({'points': {'$gt': 29}}, function(err, c30) { if (err) { debug('User err: ', err); next(err); }
|
|
||||||
User.count({'points': {'$gt': 53}}, function(err, all) { if (err) { debug('User err: ', err); next(err); }
|
|
||||||
res.render('resources/stats', {
|
|
||||||
title: 'Free Code Camp Stats:',
|
|
||||||
daysRunning: daysRunning,
|
|
||||||
nonprofitProjects: nonprofitProjects,
|
|
||||||
c3: c3,
|
|
||||||
c10: c10,
|
|
||||||
c30: c30,
|
|
||||||
all: all
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
deployAWebsite: function deployAWebsite(req, res) {
|
stats: function stats(req, res) {
|
||||||
res.render('resources/deploy-a-website', {
|
var date1 = new Date("10/15/2014");
|
||||||
title: 'Deploy a Dynamic Website in 7 Minutes'
|
var date2 = new Date();
|
||||||
});
|
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||||
},
|
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||||
|
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, response) {
|
||||||
nonprofitProjectInstructions: function nonprofitProjectInstructions(req, res) {
|
var nonprofitProjects = (trello && trello.length) || 15;
|
||||||
res.render('resources/nonprofit-project-instructions', {
|
User.count({'points': {'$gt': 2}}, function(err, c3) { if (err) { debug('User err: ', err); next(err); }
|
||||||
title: 'Nonprofit Project Instructions'
|
User.count({'points': {'$gt': 9}}, function(err, c10) { if (err) { debug('User err: ', err); next(err); }
|
||||||
});
|
User.count({'points': {'$gt': 29}}, function(err, c30) { if (err) { debug('User err: ', err); next(err); }
|
||||||
},
|
User.count({'points': {'$gt': 53}}, function(err, all) { if (err) { debug('User err: ', err); next(err); }
|
||||||
|
res.render('resources/stats', {
|
||||||
gmailShortcuts: function gmailShortcuts(req, res) {
|
title: 'Free Code Camp Stats:',
|
||||||
res.render('resources/gmail-shortcuts', {
|
daysRunning: daysRunning,
|
||||||
title: 'These Gmail Shortcuts will save you Hours'
|
nonprofitProjects: nonprofitProjects,
|
||||||
});
|
c3: c3,
|
||||||
},
|
c10: c10,
|
||||||
|
c30: c30,
|
||||||
controlShortcuts: function controlShortcuts(req, res) {
|
all: all
|
||||||
res.render('resources/control-shortcuts', {
|
});
|
||||||
title: 'These Control Shortcuts will save you Hours'
|
});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
chromebook: function chromebook(req, res) {
|
|
||||||
res.render('resources/chromebook', {
|
|
||||||
title: 'Win a Chromebook'
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
jqueryExercises: function jqueryExercises(req, res) {
|
|
||||||
res.render('resources/jquery-exercises', {
|
|
||||||
title: 'jQuery Exercises'
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
livePairProgramming: function(req, res) {
|
|
||||||
res.render('resources/live-pair-programming', {
|
|
||||||
title: 'Live Pair Programming'
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
javaScriptInYourInbox: function(req, res) {
|
|
||||||
res.render('resources/javascript-in-your-inbox', {
|
|
||||||
title: 'JavaScript in your Inbox'
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
pairProgramWithTeamViewer: function(req, res) {
|
|
||||||
Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
|
|
||||||
if (err) {
|
|
||||||
debug('Challenge err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
res.render('resources/pair-program-with-team-viewer', {
|
|
||||||
title: 'Challenge: Pair Program with Team Viewer',
|
|
||||||
name: 'Pair Program with Team Viewer',
|
|
||||||
video: '',
|
|
||||||
time: 30,
|
|
||||||
steps: steps,
|
|
||||||
cc: req.user ? req.user.challengesHash : undefined,
|
|
||||||
points: req.user ? req.user.points : undefined,
|
|
||||||
challenges: c
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
about: function(req, res) {
|
|
||||||
var date1 = new Date("10/15/2014");
|
|
||||||
var date2 = new Date();
|
|
||||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
|
||||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
||||||
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, res2) {
|
|
||||||
client.get('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function(blogger, res3) {
|
|
||||||
var nonprofitProjects = trello.length || 15;
|
|
||||||
var blog = JSON.parse(blogger);
|
|
||||||
User.count({'points': {'$gt': 2}}, function (err, c3) {
|
|
||||||
if (err) {
|
|
||||||
debug('User err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
User.count({'points': {'$gt': 9}}, function (err, c10) {
|
|
||||||
if (err) {
|
|
||||||
debug('User err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
User.count({'points': {'$gt': 29}}, function (err, c30) {
|
|
||||||
if (err) {
|
|
||||||
debug('User err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
User.count({'points': {'$gt': 53}}, function (err, all) {
|
|
||||||
if (err) {
|
|
||||||
debug('User err: ', err);
|
|
||||||
next(err);
|
|
||||||
}
|
|
||||||
res.render('resources/learn-to-code', {
|
|
||||||
title: 'About Free Code Camp and Our Team of Volunteers',
|
|
||||||
daysRunning: daysRunning,
|
|
||||||
nonprofitProjects: nonprofitProjects,
|
|
||||||
c3: c3,
|
|
||||||
c10: c10,
|
|
||||||
c30: c30,
|
|
||||||
all: all,
|
|
||||||
blog1Title: blog["items"][0]["title"],
|
|
||||||
blog1Link: blog["items"][0]["url"],
|
|
||||||
blog2Title: blog["items"][1]["title"],
|
|
||||||
blog2Link: blog["items"][1]["url"],
|
|
||||||
blog3Title: blog["items"][2]["title"],
|
|
||||||
blog3Link: blog["items"][2]["url"],
|
|
||||||
blog4Title: blog["items"][3]["title"],
|
|
||||||
blog4Link: blog["items"][3]["url"],
|
|
||||||
blog5Title: blog["items"][4]["title"],
|
|
||||||
blog5Link: blog["items"][4]["url"]
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
});
|
|
||||||
},
|
deployAWebsite: function deployAWebsite(req, res) {
|
||||||
|
res.render('resources/deploy-a-website', {
|
||||||
|
title: 'Deploy a Dynamic Website in 7 Minutes'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
nonprofitProjectInstructions: function nonprofitProjectInstructions(req, res) {
|
||||||
|
res.render('resources/nonprofit-project-instructions', {
|
||||||
|
title: 'Nonprofit Project Instructions'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
gmailShortcuts: function gmailShortcuts(req, res) {
|
||||||
|
res.render('resources/gmail-shortcuts', {
|
||||||
|
title: 'These Gmail Shortcuts will save you Hours'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
controlShortcuts: function controlShortcuts(req, res) {
|
||||||
|
res.render('resources/control-shortcuts', {
|
||||||
|
title: 'These Control Shortcuts will save you Hours'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
chromebook: function chromebook(req, res) {
|
||||||
|
res.render('resources/chromebook', {
|
||||||
|
title: 'Win a Chromebook'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
jqueryExercises: function jqueryExercises(req, res) {
|
||||||
|
res.render('resources/jquery-exercises', {
|
||||||
|
title: 'jQuery Exercises'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
livePairProgramming: function(req, res) {
|
||||||
|
res.render('resources/live-pair-programming', {
|
||||||
|
title: 'Live Pair Programming'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
javaScriptInYourInbox: function(req, res) {
|
||||||
|
res.render('resources/javascript-in-your-inbox', {
|
||||||
|
title: 'JavaScript in your Inbox'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
pairProgramWithTeamViewer: function(req, res) {
|
||||||
|
Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
|
||||||
|
if (err) {
|
||||||
|
debug('Challenge err: ', err);
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
res.render('resources/pair-program-with-team-viewer', {
|
||||||
|
title: 'Challenge: Pair Program with Team Viewer',
|
||||||
|
name: 'Pair Program with Team Viewer',
|
||||||
|
video: '',
|
||||||
|
time: 30,
|
||||||
|
steps: steps,
|
||||||
|
cc: req.user ? req.user.challengesHash : undefined,
|
||||||
|
points: req.user ? req.user.points : undefined,
|
||||||
|
challenges: c
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
about: function(req, res) {
|
||||||
|
var date1 = new Date("10/15/2014");
|
||||||
|
var date2 = new Date();
|
||||||
|
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||||
|
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||||
|
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, res2) {
|
||||||
|
client.get('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function(blogger, res3) {
|
||||||
|
var nonprofitProjects = trello.length || 15;
|
||||||
|
var blog = JSON.parse(blogger);
|
||||||
|
User.count({'points': {'$gt': 2}}, function (err, c3) {
|
||||||
|
if (err) {
|
||||||
|
debug('User err: ', err);
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
User.count({'points': {'$gt': 9}}, function (err, c10) {
|
||||||
|
if (err) {
|
||||||
|
debug('User err: ', err);
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
User.count({'points': {'$gt': 29}}, function (err, c30) {
|
||||||
|
if (err) {
|
||||||
|
debug('User err: ', err);
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
User.count({'points': {'$gt': 53}}, function (err, all) {
|
||||||
|
if (err) {
|
||||||
|
debug('User err: ', err);
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
res.render('resources/learn-to-code', {
|
||||||
|
title: 'About Free Code Camp and Our Team of Volunteers',
|
||||||
|
daysRunning: daysRunning,
|
||||||
|
nonprofitProjects: nonprofitProjects,
|
||||||
|
c3: c3,
|
||||||
|
c10: c10,
|
||||||
|
c30: c30,
|
||||||
|
all: all,
|
||||||
|
blog1Title: blog["items"][0]["title"],
|
||||||
|
blog1Link: blog["items"][0]["url"],
|
||||||
|
blog2Title: blog["items"][1]["title"],
|
||||||
|
blog2Link: blog["items"][1]["url"],
|
||||||
|
blog3Title: blog["items"][2]["title"],
|
||||||
|
blog3Link: blog["items"][2]["url"],
|
||||||
|
blog4Title: blog["items"][3]["title"],
|
||||||
|
blog4Link: blog["items"][3]["url"],
|
||||||
|
blog5Title: blog["items"][4]["title"],
|
||||||
|
blog5Link: blog["items"][4]["url"]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
randomPhrase: function() {
|
randomPhrase: function() {
|
||||||
var phrases = resources.phrases;
|
var phrases = resources.phrases;
|
||||||
|
@ -33,12 +33,15 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
||||||
$('#complete-bonfire-dialog').modal('show');
|
$('#complete-bonfire-dialog').modal('show');
|
||||||
// Only post to server if there is an authenticated user
|
// Only post to server if there is an authenticated user
|
||||||
if ($('.signup-btn-nav').length < 1) {
|
if ($('.signup-btn-nav').length < 1) {
|
||||||
l = location.pathname.split('/');
|
l = location.pathname.split('/');
|
||||||
cn = l[l.length - 1];
|
cn = l[l.length - 1];
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
@ -49,7 +52,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
url: '/completed-bonfire/'
|
url: '/completed-bonfire/'
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,15 +69,14 @@ $(document).ready(function() {
|
|||||||
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
|
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: refactor this to create meaningful variable names, what the heck i l?
|
|
||||||
$('.next-bonfire-button').on('click', function() {
|
$('.next-bonfire-button').on('click', function() {
|
||||||
var bonfireSolution = myCodeMirror.getValue();
|
var bonfireSolution = myCodeMirror.getValue();
|
||||||
var thisBonfireHash = passedBonfireHash || null;
|
var thisBonfireHash = passedBonfireHash || null;
|
||||||
var didCompleteWith = $('#completed-with').val() || null;
|
var didCompleteWith = $('#completed-with').val() || null;
|
||||||
console.log(didCompleteWith);
|
|
||||||
console.log(bonfireSolution, thisBonfireHash);
|
|
||||||
completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash);
|
completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash);
|
||||||
window.location = '/bonfires/';
|
window.location('/bonfires');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Bonfire instructions functions
|
// Bonfire instructions functions
|
||||||
|
Reference in New Issue
Block a user