Fix show profile page challenge filtering to use challengeType

This commit is contained in:
Berkeley Martinez
2016-01-18 15:15:09 -08:00
parent 7a53f88aad
commit e3ec56ef40
3 changed files with 43 additions and 26 deletions

View File

@ -210,19 +210,30 @@ module.exports = function(app) {
return data; return data;
}, {}); }, {});
const baseAndZip = profileUser.completedChallenges.filter( function filterAlgos(challenge) {
function(obj) { // test if name starts with hike/waypoint/basejump/zipline
return obj.challengeType === 3 || obj.challengeType === 4; // 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) { const projects = completedChallenges.filter(filterProjects);
return (obj.name || '').match(/^Bonfire/g);
});
const waypoints = profileUser.completedChallenges.filter(function(obj) { const algos = completedChallenges.filter(filterAlgos);
return (obj.name || '').match(/^Waypoint|^Checkpoint/i);
}); const challenges = completedChallenges
.filter(challenge => !filterAlgos(challenge))
.filter(challenge => !filterProjects(challenge));
res.render('account/show', { res.render('account/show', {
title: 'Camper ' + profileUser.username + '\'s Code Portfolio', title: 'Camper ' + profileUser.username + '\'s Code Portfolio',
@ -253,9 +264,9 @@ module.exports = function(app) {
progressTimestamps: profileUser.progressTimestamps, progressTimestamps: profileUser.progressTimestamps,
baseAndZip, projects,
bonfires, algos,
waypoints, challenges,
moment, moment,
longestStreak: profileUser.longestStreak, longestStreak: profileUser.longestStreak,

View File

@ -2,7 +2,7 @@ const challengesRegex = /^(bonfire|waypoint|zipline|basejump|checkpoint):\s/i;
export default function jadeHelpers() { export default function jadeHelpers() {
return function jadeHelpersMiddleware(req, res, next) { return function jadeHelpersMiddleware(req, res, next) {
res.locals.removeOldTerms = function removeOldTerms(str) { res.locals.removeOldTerms = function removeOldTerms(str = '') {
return str.replace(challengesRegex, ''); return str.replace(challengesRegex, '');
}; };

View File

@ -121,7 +121,7 @@ block content
if (user && user.username == username || !isLocked) if (user && user.username == username || !isLocked)
if (baseAndZip.length > 0) if (projects .length > 0)
.col-sm-12 .col-sm-12
table.table.table-striped table.table.table-striped
thead thead
@ -129,7 +129,7 @@ block content
th.col-xs-6 Projects th.col-xs-6 Projects
th.col-xs-3.hidden-xs Completed th.col-xs-3.hidden-xs Completed
th.col-xs-3.hidden-xs Link th.col-xs-3.hidden-xs Link
for challenge in baseAndZip for challenge in projects
tr tr
td.col-xs-4.hidden-xs td.col-xs-4.hidden-xs
a(href='/challenges/' + removeOldTerms(challenge.name), target='_blank')= removeOldTerms(challenge.name) 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 a(href=challenge.solution, target='_blank') View my project
td.col-xs-12.visible-xs td.col-xs-12.visible-xs
a(href=challenge.solution, target='_blank')= removeOldTerms(challenge.name) a(href=challenge.solution, target='_blank')= removeOldTerms(challenge.name)
if (bonfires.length > 0) if (algos.length > 0)
.col-sm-12 .col-sm-12
table.table.table-striped table.table.table-striped
thead thead
tr tr
th.col-xs-6 Bonfires th.col-xs-6 Algorithms
th.col-xs-3.hidden-xs Completed th.col-xs-3.hidden-xs Completed
th.col-xs-3.hidden-xs Solution th.col-xs-3.hidden-xs Solution
for bonfire in bonfires for challenge in algos
tr tr
td.col-xs-6.hidden-xs= removeOldTerms(bonfire.name) td.col-xs-6.hidden-xs= removeOldTerms(challenge.name)
td.col-xs-3.hidden-xs= bonfire.completedDate ? moment(bonfire.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available' td.col-xs-3.hidden-xs= challenge.completedDate ?moment(challenge.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available'
td.col-xs-3.hidden-xs 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 td.col-xs-12.visible-xs
a(href='/challenges/' + removeOldTerms(bonfire.name) + '?solution=' + encodeURIComponent(encodeFcc(bonfire.solution)), target='_blank')= removeOldTerms(bonfire.name) if (challenge.solution)
if (waypoints.length > 0) 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 .col-sm-12
table.table.table-striped table.table.table-striped
thead thead
tr tr
th.col-xs-6 Waypoints th.col-xs-6 Challenges
th.col-xs-3.hidden-xs Completed th.col-xs-3.hidden-xs Completed
th.col-xs-3.hidden-xs Solution th.col-xs-3.hidden-xs Solution
for challenge in waypoints for challenge in challenges
tr tr
td.col-xs-6.hidden-xs= removeOldTerms(challenge.name) 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= challenge.completedDate ?moment(challenge.completedDate, 'x').format("MMM DD, YYYY") : 'Not Available'