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",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"lockdownMode": {
|
"isLocked": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
|
|
@ -132,18 +132,18 @@ module.exports = function(app) {
|
||||||
const { path } = req;
|
const { path } = req;
|
||||||
User.findOne(
|
User.findOne(
|
||||||
{ where: { username } },
|
{ where: { username } },
|
||||||
function(err, user) {
|
function(err, profileUser) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
if (!user) {
|
if (!profileUser) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: `404: We couldn't find path ${ path }`
|
msg: `404: We couldn't find path ${ path }`
|
||||||
});
|
});
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
var cals = user
|
var cals = profileUser
|
||||||
.progressTimestamps
|
.progressTimestamps
|
||||||
.map(objOrNum => {
|
.map(objOrNum => {
|
||||||
return typeof objOrNum === 'number' ?
|
return typeof objOrNum === 'number' ?
|
||||||
|
@ -152,10 +152,10 @@ module.exports = function(app) {
|
||||||
})
|
})
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
user.currentStreak = calcCurrentStreak(cals);
|
profileUser.currentStreak = calcCurrentStreak(cals);
|
||||||
user.longestStreak = calcLongestStreak(cals);
|
profileUser.longestStreak = calcLongestStreak(cals);
|
||||||
|
|
||||||
const data = user
|
const data = profileUser
|
||||||
.progressTimestamps
|
.progressTimestamps
|
||||||
.map((objOrNum) => {
|
.map((objOrNum) => {
|
||||||
return typeof objOrNum === 'number' ?
|
return typeof objOrNum === 'number' ?
|
||||||
|
@ -170,42 +170,55 @@ module.exports = function(app) {
|
||||||
return data;
|
return data;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const challenges = user.completedChallenges.filter(function(obj) {
|
const baseAndZip = profileUser.completedChallenges.filter(
|
||||||
|
function(obj) {
|
||||||
return obj.challengeType === 3 || obj.challengeType === 4;
|
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);
|
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', {
|
res.render('account/show', {
|
||||||
title: 'Camper ' + user.username + '\'s portfolio',
|
title: 'Camper ' + profileUser.username + '\'s portfolio',
|
||||||
username: user.username,
|
username: profileUser.username,
|
||||||
name: user.name,
|
name: profileUser.name,
|
||||||
isMigrationGrandfathered: user.isMigrationGrandfathered,
|
isMigrationGrandfathered: profileUser.isMigrationGrandfathered,
|
||||||
isGithubCool: user.isGithubCool,
|
isGithubCool: profileUser.isGithubCool,
|
||||||
location: user.location,
|
isLocked: !!profileUser.isLocked,
|
||||||
github: user.githubURL,
|
|
||||||
linkedin: user.linkedin,
|
location: profileUser.location,
|
||||||
google: user.google,
|
|
||||||
facebook: user.facebook,
|
|
||||||
twitter: user.twitter,
|
|
||||||
picture: user.picture,
|
|
||||||
progressTimestamps: user.progressTimestamps,
|
|
||||||
calender: data,
|
calender: data,
|
||||||
challenges: challenges,
|
|
||||||
bonfires: bonfires,
|
github: profileUser.githubURL,
|
||||||
moment: moment,
|
linkedin: profileUser.linkedin,
|
||||||
longestStreak: user.longestStreak,
|
google: profileUser.google,
|
||||||
currentStreak: user.currentStreak
|
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) {
|
function toggleLockdownMode(req, res, next) {
|
||||||
if (req.user.lockdownMode === true) {
|
if (req.user.isLocked === true) {
|
||||||
req.user.lockdownMode = false;
|
req.user.isLocked = false;
|
||||||
return req.user.save(function(err) {
|
return req.user.save(function(err) {
|
||||||
if (err) { return next(err); }
|
if (err) { return next(err); }
|
||||||
|
|
||||||
|
@ -219,7 +232,7 @@ module.exports = function(app) {
|
||||||
res.redirect('/' + req.user.username);
|
res.redirect('/' + req.user.username);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
req.user.lockdownMode = true;
|
req.user.isLocked = true;
|
||||||
return req.user.save(function(err) {
|
return req.user.save(function(err) {
|
||||||
if (err) { return next(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'}
|
h4.col-sm-6.text-left Current Streak: #{currentStreak} #{currentStreak + currentStreak === 1 ? ' day' : ' days'}
|
||||||
|
|
||||||
|
|
||||||
if (user.username == username || !user.lockdownMode)
|
if (user && user.username == username || !isLocked)
|
||||||
if (challenges.length > 0)
|
if (baseAndZip.length > 0)
|
||||||
.col-sm-12
|
.col-sm-12
|
||||||
table.table.table-striped
|
table.table.table-striped
|
||||||
thead
|
thead
|
||||||
|
@ -106,7 +106,7 @@ block content
|
||||||
th.col-xs-4 Project
|
th.col-xs-4 Project
|
||||||
th.col-xs-2 Completed
|
th.col-xs-2 Completed
|
||||||
th.col-xs-6 Link
|
th.col-xs-6 Link
|
||||||
for challenge in challenges
|
for challenge in baseAndZip
|
||||||
tr
|
tr
|
||||||
td.col-xs-4
|
td.col-xs-4
|
||||||
a(href='/challenges/' + challenge.name, target='_blank')= challenge.name
|
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-2= moment(bonfire.completedDate, 'x').format("MMM DD, YYYY")
|
||||||
td.col-xs-6
|
td.col-xs-6
|
||||||
a(href='/challenges/' + bonfire.name + '?solution=' + encodeURIComponent(bonfire.solution), target='_blank') View my solution
|
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)
|
if (user && user.username === username)
|
||||||
.panel.panel-info
|
.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')
|
a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='mailto:team@freecodecamp.com')
|
||||||
span.ion-email
|
span.ion-email
|
||||||
| Email us at team@freecodecamp.com
|
| Email us at team@freecodecamp.com
|
||||||
if (!user.lockdownMode)
|
if (!user.isLocked)
|
||||||
.col-xs-12
|
.col-xs-12
|
||||||
a.btn.btn-lg.btn-block.btn-info.btn-link-social(href='/toggle-lockdown-mode')
|
a.btn.btn-lg.btn-block.btn-info.btn-link-social(href='/toggle-lockdown-mode')
|
||||||
span.ion-locked
|
span.ion-locked
|
||||||
|
|
Loading…
Reference in New Issue