start refactoring basejumps and ziplines to just be normal challenges, make all timestamps miliseconds

This commit is contained in:
Michael Q Larson
2015-03-27 14:36:17 -07:00
parent ac8487a4fc
commit f7f7fb39b9
17 changed files with 145 additions and 295 deletions

View File

@ -224,26 +224,26 @@ exports.generateChallenge = function(req, res) {
exports.completedBonfire = function (req, res) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000);
var isCompletedDate = Math.round(+new Date());
var bonfireHash = req.body.bonfireInfo.bonfireHash;
var isSolution = req.body.bonfireInfo.solution;
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith.toLowerCase()}).limit(1);
var paired = User.find({"profile.username": isCompletedbWith.toLowerCase()}).limit(1);
paired.exec(function (err, pairedWith) {
if (err) {
return err;
} else {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() / 1000 | 0);
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedBonfires.splice(index, 1)
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() / 1000 | 0);
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedBonfires.splice(index, 1);
}
@ -260,7 +260,7 @@ exports.completedBonfire = function (req, res) {
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: isSolution
})
});
req.user.save(function (err, user) {
pairedWith.save(function (err, paired) {
@ -285,7 +285,7 @@ exports.completedBonfire = function (req, res) {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() / 1000 | 0);
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedBonfires.splice(index, 1)
}

View File

@ -91,8 +91,6 @@ exports.returnIndividualCourseware = function(req, res, next) {
details: courseware.description.slice(1),
tests: courseware.tests,
challengeSeed: courseware.challengeSeed,
cc: !!req.user,
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
@ -110,13 +108,10 @@ exports.returnIndividualCourseware = function(req, res, next) {
details: courseware.description.slice(1),
tests: courseware.tests,
challengeSeed: courseware.challengeSeed,
cc: !!req.user,
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
environment: resources.whichEnvironment()
});
},
@ -129,13 +124,43 @@ exports.returnIndividualCourseware = function(req, res, next) {
details: courseware.description,
tests: courseware.tests,
video: courseware.challengeSeed[0],
cc: !!req.user,
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
environment: resources.whichEnvironment()
challengeType: 'video'
});
},
3: function() {
res.render('coursewares/showVideo', {
title: courseware.name,
dashedName: dashedName,
name: courseware.name,
details: courseware.description,
tests: courseware.tests,
video: courseware.challengeSeed[0],
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
challengeType: 'zipline'
});
},
4: function() {
res.render('coursewares/showVideo', {
title: courseware.name,
dashedName: dashedName,
name: courseware.name,
details: courseware.description,
tests: courseware.tests,
video: courseware.challengeSeed[0],
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
challengeType: 'basejump'
});
}
};
@ -212,9 +237,9 @@ exports.generateChallenge = function(req, res) {
res.send(response);
};
exports.completedCourseware = function (req, res) {
exports.completedCourseware = function (req, res, next) {
var isCompletedDate = Math.round(+new Date() / 1000);
var isCompletedDate = Math.round(+new Date());
var coursewareHash = req.body.coursewareInfo.coursewareHash;
debug('this is the coursewarehash we got', coursewareHash);
@ -226,18 +251,100 @@ exports.completedCourseware = function (req, res) {
});
var index = req.user.completedCoursewares.indexOf(coursewareHash);
debug('this is the index of the found courseware', index);
if (index === -1) {
req.user.progressTimestamps.push(Date.now() / 1000 | 0);
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedCoursewares.splice(index, 1);
}
req.user.save(function (err, user) {
if (err) {
throw err;
return next(err);
}
if (user) {
res.send(true);
}
});
};
exports.completedZiplineOrBasejump = function (req, res, next) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date());
var coursewareHash = req.body.coursewareInfo.coursewareHash;
var solutionLink = req.body.coursewareInfo.solutionLink;
if(!solutionLink) {
// flash error and redirect
}
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith.toLowerCase()}).limit(1);
paired.exec(function (err, pairedWith) {
if (err) {
return err;
} else {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedBonfires.splice(index, 1)
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedBonfires.splice(index, 1);
}
pairedWith.completedBonfires.push({
_id: bonfireHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: isSolution
});
req.user.completedBonfires.push({
_id: bonfireHash,
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: isSolution
});
req.user.save(function (err, user) {
pairedWith.save(function (err, paired) {
if (err) {
throw err;
}
if (user && paired) {
res.send(true);
}
})
});
}
})
} else {
req.user.completedBonfires.push({
_id: bonfireHash,
completedWith: null,
completedDate: isCompletedDate,
solution: isSolution
});
var index = req.user.uncompletedCourse.indexOf(bonfireHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedBonfires.splice(index, 1)
}
req.user.save(function (err, user) {
if (err) {
throw err;
}
if (user) {
debug('Saving user');
res.send(true)
}
});
}
};

View File

@ -199,7 +199,7 @@ module.exports = {
var date1 = new Date('10/15/2014');
var date2 = new Date();
var progressTimestamps = req.user.progressTimestamps;
var now = Date.now() / 1000 | 0;
var now = Date.now() || 0;
if (req.user.pointsNeedMigration) {
var challengesHash = req.user.challengesHash;
for (var key in challengesHash) {
@ -211,7 +211,8 @@ module.exports = {
var timeStamps = [];
R.keys(req.user.challengesHash).forEach(function(key) {
"use strict";
timeStamps.push({timeStamp: challengesHash[key]});
var timeStamp = parseInt(challengesHash[key], 10);
timeStamps.push({timeStamp: timeStamp.length !== 13 ? (+timeStamp) : (+timeStamp * 1000)});
});
req.user.completedCoursewares = Array.zip(timeStamps, coursewares,

View File

@ -1,161 +0,0 @@
var _ = require('lodash'),
debug = require('debug')('freecc:cntr:zipline'),
Zipline = require('./../models/Zipline'),
User = require('./../models/User'),
resources = require('./resources'),
R = require('ramda');
/**
* Bonfire controller
*/
exports.showAllZiplines = function(req, res) {
var completedZiplines = req.user.completedZiplines.map(function(elem) {
return elem._id;
});
var noDuplicateZiplines = R.uniq(completedZiplines);
var data = {};
data.ziplineList = resources.allZiplineNames();
data.completedList = noDuplicateZiplines;
res.send(data);
};
exports.index = function(req, res) {
res.render('ziplines/show.jade', {
completedWith: null,
title: 'Choose Your Zipline',
name: 'Choose Your Zipline',
difficulty: 0,
//cc: req.user ? req.user.bonfiresHash : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliments: resources.randomCompliment(),
ziplines: []
//ziplineHash: 'test'
});
};
exports.returnIndividualZipline = function(req, res, next) {
var dashedName = req.params.ziplineName;
ziplineName = dashedName.replace(/\-/g, ' ');
Zipline.find({"name" : new RegExp(ziplineName, 'i')}, function(err, zipline) {
if (err) {
next(err);
}
if (zipline.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
});
return res.redirect('/ziplines');
}
zipline = zipline.pop();
var dashedNameFull = zipline.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
return res.redirect('../ziplines/' + dashedNameFull);
}
res.render('ziplines/show', {
completedWith: null,
title: zipline.name,
dashedName: dashedName,
name: zipline.name,
difficulty: Math.floor(+zipline.difficulty),
details: zipline.details,
tests: zipline.tests,
challengeSeed: zipline.challengeSeed,
//cc: !!req.user,
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
ziplines: zipline
//ziplineHash: zipline._id
});
});
};
exports.completedZipline = function (req, res) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000);
//var ziplineHash = req.body.bonfireInfo.bonfireHash;
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith.toLowerCase()}).limit(1);
paired.exec(function (err, pairedWith) {
if (err) {
return err;
} else {
//var index = req.user.uncompletedZiplines.indexOf(ziplineHash);
//if (index > -1) {
// req.user.progressTimestamps.push(Date.now() / 1000 | 0);
// req.user.uncompletedZiplines.splice(index, 1)
//}
//pairedWith = pairedWith.pop();
//
//index = pairedWith.uncompletedZiplines.indexOf(bonfiHash);
//if (index > -1) {
// pairedWith.progressTimestamps.push(Date.now() / 1000 | 0);
// pairedWith.uncompletedZiplines.splice(index, 1);
//
//}
//
//pairedWith.completedBonfires.push({
// _id: bonfireHash,
// completedWith: req.user._id,
// completedDate: isCompletedDate,
// solution: isSolution
//});
//
//req.user.completedBonfires.push({
// _id: bonfireHash,
// completedWith: pairedWith._id,
// completedDate: isCompletedDate,
// solution: isSolution
//})
//
//req.user.save(function (err, user) {
// pairedWith.save(function (err, paired) {
// if (err) {
// throw err;
// }
// if (user && paired) {
// res.send(true);
// }
// })
//});
}
})
} else {
//req.user.completedBonfires.push({
// _id: bonfireHash,
// completedWith: null,
// completedDate: isCompletedDate,
// solution: isSolution
//});
//
//var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
//if (index > -1) {
// req.user.progressTimestamps.push(Date.now() / 1000 | 0);
// req.user.uncompletedBonfires.splice(index, 1)
//}
//
//req.user.save(function (err, user) {
// if (err) {
// throw err;
// }
// if (user) {
// debug('Saving user');
// res.send(true)
// }
//});
}
};

View File

@ -1,12 +0,0 @@
var mongoose = require('mongoose');
var secrets = require('../config/secrets');
var basejumpCompletionSchema = new mongoose.Schema({
dateCompleted: Number,
completedWith: ObjectId,
basejumpHash: ObjectId,
githubUrl: String,
demoUrl: String
});
module.exports = mongoose.model('BasejumpCompletion', basejumpCompletionSchema);

View File

@ -1,11 +0,0 @@
var mongoose = require('mongoose');
var secrets = require('../config/secrets');
var bonfireCompletionSchema = new mongoose.Schema({
dateCompleted: Number,
completedWith: ObjectId,
bonfireHash: ObjectId,
solution: String
});
module.exports = mongoose.model('BonfireCompletion', bonfireCompletionSchema);

View File

@ -21,7 +21,7 @@ var userSchema = new mongoose.Schema({
type: Number,
default: 0
},
progressTimestamps: { type: Array, default: [] },
progressTimestamps: { type: Array, default: [Date] },
challengesCompleted: { type: Array, default: [] },
pointsNeedMigration: { type: Boolean, default: true },
challengesHash: {

View File

@ -1,12 +0,0 @@
var mongoose = require('mongoose');
var secrets = require('../config/secrets');
var ziplineCompletionSchema = new mongoose.Schema({
dateCompleted: Number,
completedWith: ObjectId,
basejumpHash: ObjectId,
githubUrl: String,
demoUrl: String
});
module.exports = mongoose.model('ziplineCompletion', ziplineCompletionSchema);

View File

@ -250,7 +250,7 @@ var runTests = function(err, data) {
};
function showCompletion() {
var time = Math.floor(Date.now() / 1000) - started;
var time = Math.floor(Date.now()) - started;
ga('send', 'event', 'Challenge', 'solved', challengeName + ', Time: ' + time +', Attempts: ' + attempts);
$('#complete-bonfire-dialog').modal('show');
$('#complete-bonfire-dialog').keydown(function(e) {

View File

@ -138,7 +138,7 @@ function doLinting () {
//$('#testSuite').empty();
function showCompletion() {
var time = Math.floor(Date.now() / 1000) - started;
var time = Math.floor(Date.now()) - started;
ga('send', 'event', 'Challenge', 'solved', challengeName + ', Time: ' + time);
$('#next-courseware-button').removeAttr('disabled');
$('#next-courseware-button').addClass('animated tada');

View File

@ -235,7 +235,7 @@ var runTests = function(err, data) {
};
function showCompletion() {
var time = Math.floor(Date.now() / 1000) - started;
var time = Math.floor(Date.now()) - started;
ga('send', 'event', 'Challenge', 'solved', challengeName + ', Time: ' + time +', Attempts: ' + attempts);
$('#complete-courseware-dialog').modal('show');
$('#complete-courseware-dialog').keydown(function(e) {

View File

@ -90,7 +90,7 @@ block content
var challengeSeed = !{JSON.stringify(challengeSeed)};
var passedBonfireHash = !{JSON.stringify(bonfireHash)};
var challengeName = !{JSON.stringify(name)};
var started = Math.floor(Date.now() / 1000);
var started = Math.floor(Date.now());
var _ = R;
var dashed = !{JSON.stringify(dashedName)};
.col-xs-12.col-sm-12.col-md-8
@ -111,7 +111,7 @@ block content
.text-center
.animated.zoomInDown.delay-half
span.completion-icon.ion-checkmark-circled.text-primary
- if (cc)
- if (user)
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
.form-group.text-center
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2.animated.fadeIn
@ -126,7 +126,7 @@ block content
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-bonfire-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid && existingUser.length > 0') Go to my next bonfire (ctrl + enter)
- if (points && points > 2)
- if (user.progressTimestamps.length > 2)
a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(target="_blank")
i.fa.fa-twitter &thinsp;
= phrase
@ -139,16 +139,4 @@ block content
.modal-header.all-list-header Bonfires
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
.modal-body
include ../partials/bonfires
script.
$.ajax({
url: 'https://api-ssl.bitly.com/v3/shorten?access_token=75e7931a19befaafcf108021b6d597e554b2c5c3&longUrl=http%3A%2F%2Ffreecodecamp.com%2Fbonfires%2F' + dashed + '&format=txt'
})
.success(
function (data) {
console.log(data);
url = "https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=" + data + "&hashtags=LearnToCode, JavaScript";
$('.btn-twitter').attr('href', url);
}
);
include ../partials/bonfires

View File

@ -38,7 +38,7 @@ block content
span.ion-arrow-up-b
| Less information
br
- if (cc)
- if (user)
a.btn.btn-primary.btn-lg.btn-block#next-courseware-button
| Go to my next challenge
br
@ -60,7 +60,7 @@ block content
var challengeName = !{JSON.stringify(name)};
var passedCoursewareName = challengeName;
var prodOrDev = !{JSON.stringify(environment)};
var started = Math.floor(Date.now() / 1000);
var started = Math.floor(Date.now());
.col-xs-12.col-sm-12.col-md-5.col-lg-6
#mainEditorPanel
form.code

View File

@ -47,7 +47,7 @@ block content
var challengeSeed = !{JSON.stringify(challengeSeed)};
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
var challengeName = !{JSON.stringify(name)};
var started = Math.floor(Date.now() / 1000);
var started = Math.floor(Date.now());
.col-xs-12.col-sm-12.col-md-8
#mainEditorPanel
form.code
@ -63,7 +63,7 @@ block content
.text-center
.animated.zoomInDown.delay-half
span.completion-icon.ion-checkmark-circled.text-primary
- if (cc)
- if (user)
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)
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")

View File

@ -12,7 +12,7 @@ block content
.embed-responsive.embed-responsive-16by9
iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}')
br
- if (cc)
- if (user)
a.btn.btn-primary.btn-lg.btn-block#completed-courseware I've completed this challenge (ctrl + enter)
script.
var userLoggedIn = true;
@ -26,7 +26,7 @@ block content
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
var challengeName = !{JSON.stringify(name)};
var passedCoursewareName = challengeName;
var started = Math.floor(Date.now() / 1000);
var started = Math.floor(Date.now());
#complete-courseware-dialog.modal(tabindex='-1')
.modal-dialog.animated.zoomIn.fast-animation
.modal-content
@ -36,9 +36,9 @@ block content
.text-center
.animated.zoomInDown.delay-half
span.completion-icon.ion-checkmark-circled.text-primary
- if (cc)
- if (user)
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) Go to my next challenge (ctrl + enter)
- if (points && points > 2)
- if (user.progressTimestamps.length > 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")
i.fa.fa-twitter &thinsp;
= phrase

View File

@ -1,50 +0,0 @@
extends ../layout-wide
block content
.row
.col-xs-12.col-sm-12.col-md-4.bonfire-top
h1.text-center= name
.well
h4
ol
for step in details
li!= step
.col-xs-12.col-sm-12.col-md-8
.embed-responsive.embed-responsive-16by9
iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}')
br
- if (cc)
a.btn.btn-primary.btn-lg.btn-block#completed-zipline I've completed this Zipline (ctrl + enter)
script.
var userLoggedIn = true;
- else
a.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
script.
var userLoggedIn = false;
br
script(type="text/javascript").
var tests = !{JSON.stringify(tests)};
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
var challengeName = !{JSON.stringify(name)};
var passedCoursewareName = challengeName;
var started = Math.floor(Date.now() / 1000);
#complete-courseware-dialog.modal(tabindex='-1')
.modal-dialog.animated.zoomIn.fast-animation
.modal-content
.modal-header.challenge-list-header= compliment
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
.modal-body(ng-controller="pairedWithController")
.text-center
.animated.zoomInDown.delay-half
span.completion-icon.ion-checkmark-circled.text-primary
- if (cc)
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) Go to my next challenge (ctrl + enter)
- 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")
i.fa.fa-twitter &thinsp;
= phrase
- else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
h1 #{name}
script.
var challengeName = !{JSON.stringify(name)};
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};