From ee35fe075cb5d52dd38dc4d198b898c71e152481 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 1 Oct 2015 23:03:52 -0700 Subject: [PATCH] Feature show Waypoints on user profile page This PR also fixes some bugs in lockedDown mode --- common/models/user.json | 2 +- server/boot/user.js | 73 ++++++++++++++++++++-------------- server/views/account/show.jade | 25 ++++++++++-- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/common/models/user.json b/common/models/user.json index bc5e5796049..c46d1c2f13b 100644 --- a/common/models/user.json +++ b/common/models/user.json @@ -100,7 +100,7 @@ "type": "boolean", "default": true }, - "lockdownMode": { + "isLocked": { "type": "boolean", "default": false }, diff --git a/server/boot/user.js b/server/boot/user.js index 09e1034bcce..214c0b9264e 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -132,18 +132,18 @@ module.exports = function(app) { const { path } = req; User.findOne( { where: { username } }, - function(err, user) { + function(err, profileUser) { if (err) { return next(err); } - if (!user) { + if (!profileUser) { req.flash('errors', { msg: `404: We couldn't find path ${ path }` }); return res.redirect('/'); } - var cals = user + var cals = profileUser .progressTimestamps .map(objOrNum => { return typeof objOrNum === 'number' ? @@ -152,10 +152,10 @@ module.exports = function(app) { }) .sort(); - user.currentStreak = calcCurrentStreak(cals); - user.longestStreak = calcLongestStreak(cals); + profileUser.currentStreak = calcCurrentStreak(cals); + profileUser.longestStreak = calcLongestStreak(cals); - const data = user + const data = profileUser .progressTimestamps .map((objOrNum) => { return typeof objOrNum === 'number' ? @@ -170,42 +170,55 @@ module.exports = function(app) { return data; }, {}); - const challenges = user.completedChallenges.filter(function(obj) { + const baseAndZip = profileUser.completedChallenges.filter( + function(obj) { return obj.challengeType === 3 || obj.challengeType === 4; - }); + } + ); - const bonfires = user.completedChallenges.filter(function(obj) { + const bonfires = profileUser.completedChallenges.filter(function(obj) { return obj.challengeType === 5 && (obj.name || '').match(/Bonfire/g); }); + const waypoints = profileUser.completedChallenges.filter(function(obj) { + return (obj.name || '').match(/^Waypoint/i); + }); + res.render('account/show', { - title: 'Camper ' + user.username + '\'s portfolio', - username: user.username, - name: user.name, - isMigrationGrandfathered: user.isMigrationGrandfathered, - isGithubCool: user.isGithubCool, - location: user.location, - github: user.githubURL, - linkedin: user.linkedin, - google: user.google, - facebook: user.facebook, - twitter: user.twitter, - picture: user.picture, - progressTimestamps: user.progressTimestamps, + title: 'Camper ' + profileUser.username + '\'s portfolio', + username: profileUser.username, + name: profileUser.name, + isMigrationGrandfathered: profileUser.isMigrationGrandfathered, + isGithubCool: profileUser.isGithubCool, + isLocked: !!profileUser.isLocked, + + location: profileUser.location, calender: data, - challenges: challenges, - bonfires: bonfires, - moment: moment, - longestStreak: user.longestStreak, - currentStreak: user.currentStreak + + github: profileUser.githubURL, + linkedin: profileUser.linkedin, + google: profileUser.google, + facebook: profileUser.facebook, + twitter: profileUser.twitter, + picture: profileUser.picture, + + progressTimestamps: profileUser.progressTimestamps, + + baseAndZip, + bonfires, + waypoints, + moment, + + longestStreak: profileUser.longestStreak, + currentStreak: profileUser.currentStreak }); } ); } function toggleLockdownMode(req, res, next) { - if (req.user.lockdownMode === true) { - req.user.lockdownMode = false; + if (req.user.isLocked === true) { + req.user.isLocked = false; return req.user.save(function(err) { if (err) { return next(err); } @@ -219,7 +232,7 @@ module.exports = function(app) { res.redirect('/' + req.user.username); }); } - req.user.lockdownMode = true; + req.user.isLocked = true; return req.user.save(function(err) { if (err) { return next(err); } diff --git a/server/views/account/show.jade b/server/views/account/show.jade index d633f7f7b74..5f07918815e 100644 --- a/server/views/account/show.jade +++ b/server/views/account/show.jade @@ -97,8 +97,8 @@ block content h4.col-sm-6.text-left Current Streak: #{currentStreak} #{currentStreak + currentStreak === 1 ? ' day' : ' days'} - if (user.username == username || !user.lockdownMode) - if (challenges.length > 0) + if (user && user.username == username || !isLocked) + if (baseAndZip.length > 0) .col-sm-12 table.table.table-striped thead @@ -106,7 +106,7 @@ block content th.col-xs-4 Project th.col-xs-2 Completed th.col-xs-6 Link - for challenge in challenges + for challenge in baseAndZip tr td.col-xs-4 a(href='/challenges/' + challenge.name, target='_blank')= challenge.name @@ -127,6 +127,23 @@ block content td.col-xs-2= moment(bonfire.completedDate, 'x').format("MMM DD, YYYY") td.col-xs-6 a(href='/challenges/' + bonfire.name + '?solution=' + encodeURIComponent(bonfire.solution), target='_blank') View my solution + if (waypoints.length > 0) + .col-sm-12 + table.table.table-striped + thead + tr + th.col-xs-4 Waypoints + th.col-xs-2 Completed + th.col-xs-6 Solution + for challenge in waypoints + tr + td.col-xs-4= challenge.name + td.col-xs-2= moment(challenge.completedDate, 'x').format("MMM DD, YYYY") + td.col-xs-6 + if (challenge.solution) + a(href='/challenges/' + challenge.name + '?solution=' + encodeURIComponent(challenge.solution), target='_blank') View my solution + else + a(href='/challenges/' + challenge.name) View this challenge if (user && user.username === username) .panel.panel-info @@ -136,7 +153,7 @@ block content a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='mailto:team@freecodecamp.com') span.ion-email | Email us at team@freecodecamp.com - if (!user.lockdownMode) + if (!user.isLocked) .col-xs-12 a.btn.btn-lg.btn-block.btn-info.btn-link-social(href='/toggle-lockdown-mode') span.ion-locked