From fb3447c366f648d7154874fb8b2652729bd5680f Mon Sep 17 00:00:00 2001 From: terakilobyte Date: Mon, 25 May 2015 16:02:25 -0400 Subject: [PATCH] Update challengeMap display, more consistent dasherization --- controllers/challenge.js | 13 +++++-- controllers/challengeMap.js | 2 +- controllers/fieldGuide.js | 15 +++++--- controllers/resources.js | 17 ++++++++-- seed_data/challenges/basic-html5-and-css.json | 2 +- views/challengeMap/show.jade | 34 ++++++++++--------- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/controllers/challenge.js b/controllers/challenge.js index bbda541e63..06f33e704a 100644 --- a/controllers/challenge.js +++ b/controllers/challenge.js @@ -135,7 +135,8 @@ exports.returnCurrentChallenge = function(req, res, next) { } var nameString = req.user.currentChallenge.challengeName.trim() .toLowerCase() - .replace(/\s/g, '-'); + .replace(/\s/g, '-') + .replace(/[^a-z0-9\-]/gi, ''); req.user.save(function(err) { if (err) { return next(err); @@ -147,7 +148,10 @@ exports.returnCurrentChallenge = function(req, res, next) { exports.returnIndividualChallenge = function(req, res, next) { var dashedName = req.params.challengeName; - var challengeName = dashedName.replace(/\-/g, ' '); + var challengeName = dashedName.replace(/\-/g, ' ') + .split(' ') + .slice(1) + .join(' '); Challenge.find({'name': new RegExp(challengeName, 'i')}, function(err, challengeFromMongo) { @@ -164,7 +168,10 @@ exports.returnIndividualChallenge = function(req, res, next) { } var challenge = challengeFromMongo.pop(); // Redirect to full name if the user only entered a partial - var dashedNameFull = challenge.name.toLowerCase().replace(/\s/g, '-'); + var dashedNameFull = challenge.name + .toLowerCase() + .replace(/\s/g, '-') + .replace(/[^a-z0-9\-]/gi, ''); if (dashedNameFull !== dashedName) { return res.redirect('../challenges/' + dashedNameFull); } else { diff --git a/controllers/challengeMap.js b/controllers/challengeMap.js index 945c5e9aee..aef68cc4ce 100644 --- a/controllers/challengeMap.js +++ b/controllers/challengeMap.js @@ -23,7 +23,7 @@ module.exports = { var noDuplicatedChallenges = R.uniq(completedList); - var challengeList = resources.allChallenges(); + var challengeList = resources.getChallengeMapForDisplay(); var completedChallengeList = noDuplicatedChallenges .map(function(challenge) { return challenge._id; diff --git a/controllers/fieldGuide.js b/controllers/fieldGuide.js index 2d0809b6a3..49e4d80dab 100644 --- a/controllers/fieldGuide.js +++ b/controllers/fieldGuide.js @@ -5,7 +5,8 @@ var R = require('ramda'), exports.returnIndividualFieldGuide = function(req, res, next) { var dashedName = req.params.fieldGuideName; - var fieldGuideName = dashedName.replace(/\-/g, ' '); + var fieldGuideName = dashedName.replace(/\-/g, ' ') + .replace(/[^a-z0-9\s]/gi, ''); if (req.user) { var completed = req.user.completedFieldGuides; @@ -39,7 +40,9 @@ exports.returnIndividualFieldGuide = function(req, res, next) { var fieldGuide = R.head(fieldGuideFromMongo); var dashedNameFull = - fieldGuide.name.toLowerCase().replace(/\s/g, '-').replace(/\?/g, ''); + fieldGuide.name.toLowerCase() + .replace(/\s/g, '-') + .replace(/[^a-z0-9\-]/gi, ''); if (dashedNameFull !== dashedName) { return res.redirect('../field-guide/' + dashedNameFull); @@ -68,7 +71,7 @@ exports.showAllFieldGuides = function(req, res) { exports.returnNextFieldGuide = function(req, res, next) { if (!req.user) { - return res.redirect('/field-guide/how-do-i-use-this-guide?'); + return res.redirect('/field-guide/how-do-i-use-this-guide'); } var displayedFieldGuides = @@ -89,9 +92,11 @@ exports.returnNextFieldGuide = function(req, res, next) { ].join('') }); } - return res.redirect('../field-guide/how-do-i-use-this-guide?'); + return res.redirect('../field-guide/how-do-i-use-this-guide'); } - var nameString = fieldGuide.name.toLowerCase().replace(/\s/g, '-'); + var nameString = fieldGuide.name.toLowerCase() + .replace(/\s/g, '-') + .replace(/[^a-z0-9\-]/gi, ''); return res.redirect('../field-guide/' + nameString); }); }; diff --git a/controllers/resources.js b/controllers/resources.js index 8d852292a4..0fcef198ab 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -28,7 +28,7 @@ var async = require('async'), * Cached values */ var allFieldGuideIds, allFieldGuideNames, allNonprofitNames, - challengeMap, challengeMapWithIds, + challengeMap, challengeMapForDisplay, challengeMapWithIds, challengeMapWithNames, allChallengeIds, allChallenges; /** @@ -67,13 +67,24 @@ Array.zip = function(left, right, combinerFunction) { }); challengeMap = _.cloneDeep(localChallengeMap); } - //todo remove this debug - debug(challengeMap); })(); module.exports = { + getChallengeMapForDisplay: function() { + if (!challengeMapForDisplay) { + challengeMapForDisplay = {}; + Object.keys(challengeMap).forEach(function(key) { + challengeMapForDisplay[key] = { + name: challengeMap[key].name, + challenges: challengeMap[key].challenges + } + }); + } + return challengeMapForDisplay; + }, + getChallengeMapWithIds: function() { if (!challengeMapWithIds) { challengeMapWithIds = {}; diff --git a/seed_data/challenges/basic-html5-and-css.json b/seed_data/challenges/basic-html5-and-css.json index a3827c4395..1ba903a877 100644 --- a/seed_data/challenges/basic-html5-and-css.json +++ b/seed_data/challenges/basic-html5-and-css.json @@ -1,5 +1,5 @@ { - "name": "Waypoint: Basic HTML5 and CSS", + "name": "Basic HTML5 and CSS", "order" : 0.002, "challenges": [ { diff --git a/views/challengeMap/show.jade b/views/challengeMap/show.jade index 43f06a04d3..0cb1ace524 100644 --- a/views/challengeMap/show.jade +++ b/views/challengeMap/show.jade @@ -23,23 +23,25 @@ block content span.text-primary #{daysRunning}   | days ago. .spacer - h3.negative-15 - ol - for challenge in challengeList - if completedChallengeList.indexOf(challenge._id) > -1 - .row - .hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center - .col-xs-12.col-sm-9.col-md-10 - li.faded - a(href="/challenges/#{challenge.name}")= challenge.name + .negative-15 + for challengeBlock in challengeList + h3 #{challengeBlock.name} + ol + for challenge in challengeBlock.challenges + if completedChallengeList.indexOf(challenge._id) > -1 + .row + .hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center.large-p + .col-xs-12.col-sm-9.col-md-10 + li.faded.large-p + a(href="/challenges/#{challenge.name}")= challenge.name - else - .row - .hidden-xs.col-sm-3.col-md-2 - span - .col-xs-12.col-sm-9.col-md-10 - li - a(href="/challenges/#{challenge.name}")= challenge.name + else + .row + .hidden-xs.col-sm-3.col-md-2 + span + .col-xs-12.col-sm-9.col-md-10 + li.large-p + a(href="/challenges/#{challenge.name}")= challenge.name h2 span.ion-ios-heart   Nonprofit Projects (800 hours of real-world experience)*