Merge pull request #3558 from FreeCodeCamp/feature/show-waypoints
Feature show Waypoints on user profile pagepull/3560/head
commit
5f9022475c
|
@ -100,7 +100,7 @@
|
|||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"lockdownMode": {
|
||||
"isLocked": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
|
|
|
@ -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); }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue