diff --git a/app.js b/app.js index 0c7ab23611..49ca9c4976 100644 --- a/app.js +++ b/app.js @@ -163,21 +163,18 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink); /** * API examples routes. + * accepts a post request. the challenge id req.body.challengeNumber + * and updates user.challengesHash & user.challengesCompleted + * */ app.post('/completed_challenge', function(req, res) { - req.user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date() / 1000); - req.user.challengesCompleted = function() { - var completed = []; - var h = req.user.challengesHash; - for (i = 0; i < h.length; i++) { - console.log(h[i] > 0) - if (h[i] > 0) { - console.log(h[i]); - completed.push(i); - } - return completed; - } + req.user.challengesHash[parseInt(req.body.challengeNumber)] = Math.round(+new Date() / 1000); + var ch = req.user.challengesHash; + var p = 0; + for (k in ch) { + if (ch[k] > 0) { p += 1} } + req.user.points = p; req.user.save(); }); diff --git a/controllers/challenges.js b/controllers/challenges.js index 9d0b30291d..e7f951f0cc 100644 --- a/controllers/challenges.js +++ b/controllers/challenges.js @@ -19,8 +19,7 @@ exports.returnChallenge = function(req, res, next) { video: c.video, time: c.time, steps: c.steps, - cc: req.user.challengesCompleted, - ch: req.user.challengesHash + cc: req.user.challengesHash }); }); }; \ No newline at end of file diff --git a/models/User.js b/models/User.js index d9598ffe77..eaa6ed8672 100644 --- a/models/User.js +++ b/models/User.js @@ -14,208 +14,59 @@ var userSchema = new mongoose.Schema({ instagram: String, linkedin: String, tokens: Array, + points: { type: Number, default: 0 }, challengesCompleted: { type: Array, default: [] }, challengesHash: { - 0: { - type: Number, - default: 0, - }, - 1: { - type: Number, - default: 0, - }, - 2: { - type: Number, - default: 0, - }, - 3: { - type: Number, - default: 0, - }, - 4: { - type: Number, - default: 0, - }, - 5: { - type: Number, - default: 0, - }, - 6: { - type: Number, - default: 0, - }, - 7: { - type: Number, - default: 0, - }, - 8: { - type: Number, - default: 0, - }, - 9: { - type: Number, - default: 0, - }, - 10: { - type: Number, - default: 0, - }, - 11: { - type: Number, - default: 0, - }, - 12: { - type: Number, - default: 0, - }, - 13: { - type: Number, - default: 0, - }, - 14: { - type: Number, - default: 0, - }, - 15: { - type: Number, - default: 0, - }, - 16: { - type: Number, - default: 0, - }, - 17: { - type: Number, - default: 0, - }, - 18: { - type: Number, - default: 0, - }, - 19: { - type: Number, - default: 0, - }, - 20: { - type: Number, - default: 0, - }, - 21: { - type: Number, - default: 0, - }, - 22: { - type: Number, - default: 0, - }, - 23: { - type: Number, - default: 0, - }, - 24: { - type: Number, - default: 0, - }, - 25: { - type: Number, - default: 0, - }, - 26: { - type: Number, - default: 0, - }, - 27: { - type: Number, - default: 0, - }, - 28: { - type: Number, - default: 0, - }, - 29: { - type: Number, - default: 0, - }, - 30: { - type: Number, - default: 0, - }, - 31: { - type: Number, - default: 0, - }, - 32: { - type: Number, - default: 0, - }, - 33: { - type: Number, - default: 0, - }, - 34: { - type: Number, - default: 0, - }, - 35: { - type: Number, - default: 0, - }, - 36: { - type: Number, - default: 0, - }, - 37: { - type: Number, - default: 0, - }, - 38: { - type: Number, - default: 0, - }, - 39: { - type: Number, - default: 0, - }, - 40: { - type: Number, - default: 0, - }, - 41: { - type: Number, - default: 0, - }, - 42: { - type: Number, - default: 0, - }, - 43: { - type: Number, - default: 0, - }, - 44: { - type: Number, - default: 0, - }, - 45: { - type: Number, - default: 0, - }, - 46: { - type: Number, - default: 0, - }, - 47: { - type: Number, - default: 0, - }, - 48: { - type: Number, - default: 0, - }, - 49: { - type: Number, - default: 0, - } + 0: { type: Number, default: 0 }, + 1: { type: Number, default: 0 }, + 2: { type: Number, default: 0 }, + 3: { type: Number, default: 0 }, + 4: { type: Number, default: 0 }, + 5: { type: Number, default: 0 }, + 6: { type: Number, default: 0 }, + 7: { type: Number, default: 0 }, + 8: { type: Number, default: 0 }, + 9: { type: Number, default: 0 }, + 10: { type: Number, default: 0 }, + 11: { type: Number, default: 0 }, + 12: { type: Number, default: 0 }, + 13: { type: Number, default: 0 }, + 14: { type: Number, default: 0 }, + 15: { type: Number, default: 0 }, + 16: { type: Number, default: 0 }, + 17: { type: Number, default: 0 }, + 18: { type: Number, default: 0 }, + 19: { type: Number, default: 0 }, + 20: { type: Number, default: 0 }, + 21: { type: Number, default: 0 }, + 22: { type: Number, default: 0 }, + 23: { type: Number, default: 0 }, + 24: { type: Number, default: 0 }, + 25: { type: Number, default: 0 }, + 26: { type: Number, default: 0 }, + 27: { type: Number, default: 0 }, + 28: { type: Number, default: 0 }, + 29: { type: Number, default: 0 }, + 30: { type: Number, default: 0 }, + 31: { type: Number, default: 0 }, + 32: { type: Number, default: 0 }, + 33: { type: Number, default: 0 }, + 34: { type: Number, default: 0 }, + 35: { type: Number, default: 0 }, + 36: { type: Number, default: 0 }, + 37: { type: Number, default: 0 }, + 38: { type: Number, default: 0 }, + 39: { type: Number, default: 0 }, + 40: { type: Number, default: 0 }, + 41: { type: Number, default: 0 }, + 42: { type: Number, default: 0 }, + 43: { type: Number, default: 0 }, + 44: { type: Number, default: 0 }, + 45: { type: Number, default: 0 }, + 46: { type: Number, default: 0 }, + 47: { type: Number, default: 0 }, + 48: { type: Number, default: 0 }, + 49: { type: Number, default: 0 } }, profile: { name: { type: String, default: '' }, diff --git a/public/js/main.js b/public/js/main.js index a4aed45a49..c4d98b043d 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -20,14 +20,11 @@ $(document).ready(function() { $('#complete-dialog').modal('show'); l = location.pathname.split('/'); cn = l[l.length - 1] + console.log(cn); $.ajax({ type: 'POST', - data: {cn: cn}, - url: '/completed_challenge/', - success: function(data) { - console.log('success'); - console.log(JSON.stringify(data)); - } + data: {challengeNumber: cn}, + url: '/completed_challenge/' }); }); diff --git a/views/account/profile.jade b/views/account/profile.jade index 45c77cd68d..4eaf6f71a9 100644 --- a/views/account/profile.jade +++ b/views/account/profile.jade @@ -35,8 +35,7 @@ block content h1 Completed Challenges ul - //each val, index in user.challengesHash - //li= index + ': ' + val + h3 Danger Zone button.btn.btn-danger.confirm-deletion span.ion-trash-b diff --git a/views/partials/challenges.jade b/views/partials/challenges.jade index c253483f00..127bf2e0c3 100644 --- a/views/partials/challenges.jade +++ b/views/partials/challenges.jade @@ -4,133 +4,133 @@ ol(start='0') h4 Web Design li - a(href="/challenges/0", class="#{ cc.indexOf(0) > -1 ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp + a(href="/challenges/0", class="#{ cc[0] > 0 ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp |   (1 min) li - a(href="/challenges/1", class="#{ cc.indexOf(1) > -1 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room + a(href="/challenges/1", class="#{ cc[1] > 0 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room |   (10 mins) li - a(href="/challenges/2", class="#{ cc.indexOf(2) > -1 ? 'strikethrough' : '' }") Create a Website and Deploy it to the Internet + a(href="/challenges/2", class="#{ cc[2] > 0 ? 'strikethrough' : '' }") Create a Website and Deploy it to the Internet |   (5 mins) li - a(href="/challenges/3", class="#{ cc.indexOf(3) > -1 ? 'strikethrough' : '' }") Install Github's Atom Text Editor + a(href="/challenges/3", class="#{ cc[3] > 0 ? 'strikethrough' : '' }") Install Github's Atom Text Editor |   (5 mins) li - a(href="/challenges/4", class="#{ cc.indexOf(4) > -1 ? 'strikethrough' : '' }") Modify and Redeploy Your Website + a(href="/challenges/4", class="#{ cc[4] > 0 ? 'strikethrough' : '' }") Modify and Redeploy Your Website |   (5 mins) li - a(href="/challenges/5", class="#{ cc.indexOf(5) > -1 ? 'strikethrough' : '' }") Add Dynamic Content to your Website + a(href="/challenges/5", class="#{ cc[5] > 0 ? 'strikethrough' : '' }") Add Dynamic Content to your Website |   (10 mins) li - a(href="/challenges/6", class="#{ cc.indexOf(6) > -1 ? 'strikethrough' : '' }") Codecademy's HTML & CSS track + a(href="/challenges/6", class="#{ cc[6] > 0 ? 'strikethrough' : '' }") Codecademy's HTML & CSS track |   (7 hrs) li - a(href="/challenges/7", class="#{ cc.indexOf(7) > -1 ? 'strikethrough' : '' }") Experiment with HTML and CSS in CodePen + a(href="/challenges/7", class="#{ cc[7] > 0 ? 'strikethrough' : '' }") Experiment with HTML and CSS in CodePen |   (10 mins) li - a(href="/challenges/8", class="#{ cc.indexOf(8) > -1 ? 'strikethrough' : '' }") Codecademy's jQuery track + a(href="/challenges/8", class="#{ cc[8] > 0 ? 'strikethrough' : '' }") Codecademy's jQuery track |   (3 hrs) li - a(href="/challenges/9", class="#{ cc.indexOf(9) > -1 ? 'strikethrough' : '' }") Code School's Try jQuery + a(href="/challenges/9", class="#{ cc[9] > 0 ? 'strikethrough' : '' }") Code School's Try jQuery |   (4 hrs) li - a(href="/challenges/10", class="#{ cc.indexOf(10) > -1 ? 'strikethrough' : '' }") Code School's Discover DevTools + a(href="/challenges/10", class="#{ cc[10] > 0 ? 'strikethrough' : '' }") Code School's Discover DevTools |   (2 hrs) li - a(href="/challenges/11", class="#{ cc.indexOf(11) > -1 ? 'strikethrough' : '' }") jQuery Exercises + a(href="/challenges/11", class="#{ cc[11] > 0 ? 'strikethrough' : '' }") jQuery Exercises |   (1 hr) li - a(href="/challenges/12", class="#{ cc.indexOf(12) > -1 ? 'strikethrough' : '' }") Customize Bootstrap with Bootswatch + a(href="/challenges/12", class="#{ cc[12] > 0 ? 'strikethrough' : '' }") Customize Bootstrap with Bootswatch |   (10 mins) li - a(href="/challenges/13", class="#{ cc.indexOf(13) > -1 ? 'strikethrough' : '' }") Inject Life with CSS Transformations + a(href="/challenges/13", class="#{ cc[13] > 0 ? 'strikethrough' : '' }") Inject Life with CSS Transformations |   (15 mins) h4 Computer Science and JavaScript li - a(href="/challenges/14", class="#{ cc.indexOf(14) > -1 ? 'strikethrough' : '' }") Codecademy's JavaScript track + a(href="/challenges/14", class="#{ cc[14] > 0 ? 'strikethrough' : '' }") Codecademy's JavaScript track |   (10 hrs) li - a(href="/challenges/15", class="#{ cc.indexOf(15) > -1 ? 'strikethrough' : '' }") Stanford's Introduction to Computer Science + a(href="/challenges/15", class="#{ cc[15] > 0 ? 'strikethrough' : '' }") Stanford's Introduction to Computer Science |   (24 hrs) li - a(href="/challenges/16", class="#{ cc.indexOf(16) > -1 ? 'strikethrough' : '' }") Get Help The Hacker Way with RSAP + a(href="/challenges/16", class="#{ cc[16] > 0 ? 'strikethrough' : '' }") Get Help The Hacker Way with RSAP |   (30 mins) li - a(href="/challenges/17", class="#{ cc.indexOf(17) > -1 ? 'strikethrough' : '' }") Learn Regular Expressions + a(href="/challenges/17", class="#{ cc[17] > 0 ? 'strikethrough' : '' }") Learn Regular Expressions |   (1 hr) li - a(href="/challenges/18", class="#{ cc.indexOf(18) > -1 ? 'strikethrough' : '' }") Start Your First Pair Programming Session + a(href="/challenges/18", class="#{ cc[18] > 0 ? 'strikethrough' : '' }") Start Your First Pair Programming Session |   (30 mins | Pair) li - a(href="/challenges/19", class="#{ cc.indexOf(19) > -1 ? 'strikethrough' : '' }") Easy Algorithm Scripting Challenges on Coderbyte + a(href="/challenges/19", class="#{ cc[19] > 0 ? 'strikethrough' : '' }") Easy Algorithm Scripting Challenges on Coderbyte |   (15 hrs | Pair) li - a(href="/challenges/20", class="#{ cc.indexOf(20) > -1 ? 'strikethrough' : '' }") Stanford's Relational Databases Mini-course + a(href="/challenges/20", class="#{ cc[20] > 0 ? 'strikethrough' : '' }") Stanford's Relational Databases Mini-course |   (1 hr) li - a(href="/challenges/21", class="#{ cc.indexOf(21) > -1 ? 'strikethrough' : '' }") Stanford's SQL Mini-course + a(href="/challenges/21", class="#{ cc[21] > 0 ? 'strikethrough' : '' }") Stanford's SQL Mini-course |   (4 hrs | Pair) li - a(href="/challenges/22", class="#{ cc.indexOf(22) > -1 ? 'strikethrough' : '' }") Stanford's JSON Mini-course + a(href="/challenges/22", class="#{ cc[22] > 0 ? 'strikethrough' : '' }") Stanford's JSON Mini-course |   (1 hrs | Pair) li - a(href="/challenges/23", class="#{ cc.indexOf(23) > -1 ? 'strikethrough' : '' }") Medium Algorithm Scripting Challenges on Coderbyte + a(href="/challenges/23", class="#{ cc[23] > 0 ? 'strikethrough' : '' }") Medium Algorithm Scripting Challenges on Coderbyte |   (15 hrs | Pair) li - a.disabled(href="/challenges/24", class="#{ cc.indexOf(24) > -1 ? 'strikethrough' : '' }") Build an Interview Question Machine + a.disabled(href="/challenges/24", class="#{ cc[24] > 0 ? 'strikethrough' : '' }") Build an Interview Question Machine |   (5 hrs | Pair) li - a.disabled(href="/challenges/25", class="#{ cc.indexOf(25) > -1 ? 'strikethrough' : '' }") Build a Text-based Adventure + a.disabled(href="/challenges/25", class="#{ cc[25] > 0 ? 'strikethrough' : '' }") Build a Text-based Adventure |   (5 hrs | Pair) li - a.disabled(href="/challenges/26", class="#{ cc.indexOf(26) > -1 ? 'strikethrough' : '' }") Hard Algorithm Scripting Challenges on Coderbyte + a.disabled(href="/challenges/26", class="#{ cc[26] > 0 ? 'strikethrough' : '' }") Hard Algorithm Scripting Challenges on Coderbyte |   (15 hrs | Pair) h4 Full Stack JavaScript Development li - a.disabled(href="/challenges/27", class="#{ cc.indexOf(27) > -1 ? 'strikethrough' : '' }") Code School's Try Git + a.disabled(href="/challenges/27", class="#{ cc[27] > 0 ? 'strikethrough' : '' }") Code School's Try Git |   (30 mins) li - a.disabled(href="/challenges/28", class="#{ cc.indexOf(28) > -1 ? 'strikethrough' : '' }") Install Node.js + a.disabled(href="/challenges/28", class="#{ cc[28] > 0 ? 'strikethrough' : '' }") Install Node.js |   (1 hr) li - a.disabled(href="/challenges/29", class="#{ cc.indexOf(29) > -1 ? 'strikethrough' : '' }") Clone a Github Repo + a.disabled(href="/challenges/29", class="#{ cc[29] > 0 ? 'strikethrough' : '' }") Clone a Github Repo |   (15 mins) li - a.disabled(href="/challenges/30", class="#{ cc.indexOf(30) > -1 ? 'strikethrough' : '' }") Deploy an app to Heroku + a.disabled(href="/challenges/30", class="#{ cc[30] > 0 ? 'strikethrough' : '' }") Deploy an app to Heroku |   (15 mins) li - a.disabled(href="/challenges/31", class="#{ cc.indexOf(31) > -1 ? 'strikethrough' : '' }") Code School's Real-time web with Node.JS + a.disabled(href="/challenges/31", class="#{ cc[31] > 0 ? 'strikethrough' : '' }") Code School's Real-time web with Node.JS |   (5 hrs) li - a.disabled(href="/challenges/32", class="#{ cc.indexOf(32) > -1 ? 'strikethrough' : '' }") Try MongoDB + a.disabled(href="/challenges/32", class="#{ cc[32] > 0 ? 'strikethrough' : '' }") Try MongoDB |   (30 mins) li - a.disabled(href="/challenges/33", class="#{ cc.indexOf(33) > -1 ? 'strikethrough' : '' }") Explore your Network with the LinkedIn API + a.disabled(href="/challenges/33", class="#{ cc[33] > 0 ? 'strikethrough' : '' }") Explore your Network with the LinkedIn API |   (1 hr) li - a.disabled(href="/challenges/34", class="#{ cc.indexOf(34) > -1 ? 'strikethrough' : '' }") Build your first API + a.disabled(href="/challenges/34", class="#{ cc[34] > 0 ? 'strikethrough' : '' }") Build your first API |   (10 hrs | Pair) li - a.disabled(href="/challenges/35", class="#{ cc.indexOf(35) > -1 ? 'strikethrough' : '' }") Aggregate Data with Chron Jobs and Screen Scraping + a.disabled(href="/challenges/35", class="#{ cc[35] > 0 ? 'strikethrough' : '' }") Aggregate Data with Chron Jobs and Screen Scraping |   (10 hrs | Pair) li - a.disabled(href="/challenges/36", class="#{ cc.indexOf(36) > -1 ? 'strikethrough' : '' }") Code School's Shaping up with Angular.JS + a.disabled(href="/challenges/36", class="#{ cc[36] > 0 ? 'strikethrough' : '' }") Code School's Shaping up with Angular.JS |   (5 hrs) li - a.disabled(href="/challenges/37", class="#{ cc.indexOf(37) > -1 ? 'strikethrough' : '' }") Reverse Engineer SnapChat + a.disabled(href="/challenges/37", class="#{ cc[37] > 0 ? 'strikethrough' : '' }") Reverse Engineer SnapChat |   (50 hrs | Pair) li - a.disabled(href="/challenges/38", class="#{ cc.indexOf(38) > -1 ? 'strikethrough' : '' }") Reverse Engineer Reddit + a.disabled(href="/challenges/38", class="#{ cc[38] > 0 ? 'strikethrough' : '' }") Reverse Engineer Reddit |   (50 hrs | Pair) li - a.disabled(href="/challenges/39", class="#{ cc.indexOf(39) > -1 ? 'strikethrough' : '' }") Reverse Engineer Pintrest + a.disabled(href="/challenges/39", class="#{ cc[39] > 0 ? 'strikethrough' : '' }") Reverse Engineer Pintrest |   (50 hrs | Pair) li - a.disabled(href="/challenges/40", class="#{ cc.indexOf(40) > -1 ? 'strikethrough' : '' }") Help a Nonprofit: Team Project + a.disabled(href="/challenges/40", class="#{ cc[40] > 0 ? 'strikethrough' : '' }") Help a Nonprofit: Team Project |   (150 hrs | Pair) li - a.disabled(href="/challenges/41", class="#{ cc.indexOf(41) > -1 ? 'strikethrough' : '' }") Help a Nonprofit: Solo Project + a.disabled(href="/challenges/41", class="#{ cc[41] > 0 ? 'strikethrough' : '' }") Help a Nonprofit: Solo Project |   (150 hrs | Pair) li - a.disabled(href="/challenges/42", class="#{ cc.indexOf(42) > -1 ? 'strikethrough' : '' }") Crack the Coding Interview + a.disabled(href="/challenges/42", class="#{ cc[42] > 0 ? 'strikethrough' : '' }") Crack the Coding Interview |   (5 hrs) \ No newline at end of file diff --git a/views/partials/navbar.jade b/views/partials/navbar.jade index f27bf1d06f..b300af6021 100644 --- a/views/partials/navbar.jade +++ b/views/partials/navbar.jade @@ -20,8 +20,8 @@ img(src='#{user.profile.picture}') else img(src='#{user.gravatar(60)}') - | #{user.profile.name || user.email || user.id} [ #{user.challengesCompleted.length} ]  - i.caret + | #{user.profile.name || user.email || user.id} [ #{user.points} ] + i.caret ul.dropdown-menu li a(href='/')