Fix show profile page challenge filtering to use challengeType
This commit is contained in:
@ -210,19 +210,30 @@ module.exports = function(app) {
|
||||
return data;
|
||||
}, {});
|
||||
|
||||
const baseAndZip = profileUser.completedChallenges.filter(
|
||||
function(obj) {
|
||||
return obj.challengeType === 3 || obj.challengeType === 4;
|
||||
}
|
||||
function filterAlgos(challenge) {
|
||||
// test if name starts with hike/waypoint/basejump/zipline
|
||||
// fix for bug that saved different challenges with incorrect
|
||||
// challenge types
|
||||
return !(/^(waypoint|hike|zipline|basejump)/i).test(challenge.name) &&
|
||||
+challenge.challengeType === 5;
|
||||
}
|
||||
|
||||
function filterProjects(challenge) {
|
||||
return +challenge.challengeType === 3 ||
|
||||
+challenge.challengeType === 4;
|
||||
}
|
||||
|
||||
const completedChallenges = profileUser.completedChallenges.filter(
|
||||
({ name }) => typeof name === 'string'
|
||||
);
|
||||
|
||||
const bonfires = profileUser.completedChallenges.filter(function(obj) {
|
||||
return (obj.name || '').match(/^Bonfire/g);
|
||||
});
|
||||
const projects = completedChallenges.filter(filterProjects);
|
||||
|
||||
const waypoints = profileUser.completedChallenges.filter(function(obj) {
|
||||
return (obj.name || '').match(/^Waypoint|^Checkpoint/i);
|
||||
});
|
||||
const algos = completedChallenges.filter(filterAlgos);
|
||||
|
||||
const challenges = completedChallenges
|
||||
.filter(challenge => !filterAlgos(challenge))
|
||||
.filter(challenge => !filterProjects(challenge));
|
||||
|
||||
res.render('account/show', {
|
||||
title: 'Camper ' + profileUser.username + '\'s Code Portfolio',
|
||||
@ -253,9 +264,9 @@ module.exports = function(app) {
|
||||
|
||||
progressTimestamps: profileUser.progressTimestamps,
|
||||
|
||||
baseAndZip,
|
||||
bonfires,
|
||||
waypoints,
|
||||
projects,
|
||||
algos,
|
||||
challenges,
|
||||
moment,
|
||||
|
||||
longestStreak: profileUser.longestStreak,
|
||||
|
@ -2,7 +2,7 @@ const challengesRegex = /^(bonfire|waypoint|zipline|basejump|checkpoint):\s/i;
|
||||
|
||||
export default function jadeHelpers() {
|
||||
return function jadeHelpersMiddleware(req, res, next) {
|
||||
res.locals.removeOldTerms = function removeOldTerms(str) {
|
||||
res.locals.removeOldTerms = function removeOldTerms(str = '') {
|
||||
return str.replace(challengesRegex, '');
|
||||
};
|
||||
|
||||
|
@ -121,7 +121,7 @@ block content
|
||||
|
||||
|
||||
if (user && user.username == username || !isLocked)
|
||||
if (baseAndZip.length > 0)
|
||||
if (projects .length > 0)
|
||||
.col-sm-12
|
||||
table.table.table-striped
|
||||
thead
|
||||
@ -129,7 +129,7 @@ block content
|
||||
th.col-xs-6 Projects
|
||||
th.col-xs-3.hidden-xs Completed
|
||||
th.col-xs-3.hidden-xs Link
|
||||
for challenge in baseAndZip
|
||||
for challenge in projects
|
||||
tr
|
||||
td.col-xs-4.hidden-xs
|
||||
a(href='/challenges/' + removeOldTerms(challenge.name), target='_blank')= removeOldTerms(challenge.name)
|
||||
@ -138,31 +138,37 @@ block content
|
||||
a(href=challenge.solution, target='_blank') View my project
|
||||
td.col-xs-12.visible-xs
|
||||
a(href=challenge.solution, target='_blank')= removeOldTerms(challenge.name)
|
||||
if (bonfires.length > 0)
|
||||
if (algos.length > 0)
|
||||
.col-sm-12
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
th.col-xs-6 Bonfires
|
||||
th.col-xs-6 Algorithms
|
||||
th.col-xs-3.hidden-xs Completed
|
||||
th.col-xs-3.hidden-xs Solution
|
||||
for bonfire in bonfires
|
||||
for challenge in algos
|
||||
tr
|
||||
td.col-xs-6.hidden-xs= removeOldTerms(bonfire.name)
|
||||
td.col-xs-3.hidden-xs= bonfire.completedDate ? moment(bonfire.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available'
|
||||
td.col-xs-6.hidden-xs= removeOldTerms(challenge.name)
|
||||
td.col-xs-3.hidden-xs= challenge.completedDate ?moment(challenge.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available'
|
||||
td.col-xs-3.hidden-xs
|
||||
a(href='/challenges/' + removeOldTerms(bonfire.name) + '?solution=' + encodeURIComponent(encodeFcc(bonfire.solution)), target='_blank') View my solution
|
||||
if (challenge.solution)
|
||||
a(href='/challenges/' + removeOldTerms(challenge.name) + '?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank') View my solution
|
||||
else
|
||||
a(href='/challenges/' + removeOldTerms(challenge.name)) View this challenge
|
||||
td.col-xs-12.visible-xs
|
||||
a(href='/challenges/' + removeOldTerms(bonfire.name) + '?solution=' + encodeURIComponent(encodeFcc(bonfire.solution)), target='_blank')= removeOldTerms(bonfire.name)
|
||||
if (waypoints.length > 0)
|
||||
if (challenge.solution)
|
||||
a(href='/challenges/' + removeOldTerms(challenge.name) + '?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank')= removeOldTerms(challenge.name)
|
||||
else
|
||||
a(href='/challenges/' + removeOldTerms(challenge.name))= removeOldTerms(challenge.name)
|
||||
if (challenges.length > 0)
|
||||
.col-sm-12
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
th.col-xs-6 Waypoints
|
||||
th.col-xs-6 Challenges
|
||||
th.col-xs-3.hidden-xs Completed
|
||||
th.col-xs-3.hidden-xs Solution
|
||||
for challenge in waypoints
|
||||
for challenge in challenges
|
||||
tr
|
||||
td.col-xs-6.hidden-xs= removeOldTerms(challenge.name)
|
||||
td.col-xs-3.hidden-xs= challenge.completedDate ?moment(challenge.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available'
|
||||
|
Reference in New Issue
Block a user