Create helper methods in resources. Get map view working.
This commit is contained in:
@ -253,6 +253,10 @@ exports.returnIndividualChallenge = function(req, res, next) {
|
|||||||
challengeId: challenge._id,
|
challengeId: challenge._id,
|
||||||
challengeType: challenge.challengeType
|
challengeType: challenge.challengeType
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
5: function() {
|
||||||
|
// bonfire
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,13 +4,11 @@ var async = require('async'),
|
|||||||
Story = require('./../models/Story'),
|
Story = require('./../models/Story'),
|
||||||
Nonprofit = require('./../models/Nonprofit'),
|
Nonprofit = require('./../models/Nonprofit'),
|
||||||
Comment = require('./../models/Comment'),
|
Comment = require('./../models/Comment'),
|
||||||
Courseware = require('./../models/Courseware'),
|
Challenge = require('./../models/Challenge'),
|
||||||
resources = require('./resources'),
|
resources = require('./resources'),
|
||||||
steps = resources.steps,
|
steps = resources.steps,
|
||||||
secrets = require('./../config/secrets'),
|
secrets = require('./../config/secrets'),
|
||||||
bonfires = require('../seed_data/bonfires.json'),
|
|
||||||
nonprofits = require('../seed_data/nonprofits.json'),
|
nonprofits = require('../seed_data/nonprofits.json'),
|
||||||
coursewares = require('../seed_data/coursewares.json'),
|
|
||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
https = require('https'),
|
https = require('https'),
|
||||||
debug = require('debug')('freecc:cntr:resources'),
|
debug = require('debug')('freecc:cntr:resources'),
|
||||||
@ -18,38 +16,94 @@ var async = require('async'),
|
|||||||
request = require('request'),
|
request = require('request'),
|
||||||
R = require('ramda');
|
R = require('ramda');
|
||||||
|
|
||||||
|
var challengeTypes = {
|
||||||
|
'HTML_CSS_JQ': 0,
|
||||||
|
'JAVASCRIPT': 1,
|
||||||
|
'VIDEO': 2,
|
||||||
|
'ZIPLINE': 3,
|
||||||
|
'BASEJUMP': 4,
|
||||||
|
'BONFIRE': 5
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
challengeMap: function challengeMap(req, res) {
|
challengeMap: function challengeMap(req, res) {
|
||||||
var completedBonfires = [];
|
var completedBonfires = [];
|
||||||
var completedList = [];
|
var completedList = [];
|
||||||
|
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
completedBonfires = req.user.completedBonfires.map(function (elem) {
|
completedBonfires = req.user.completedChallenges
|
||||||
return elem._id;
|
.filter(function (elem) {
|
||||||
});
|
return elem.challengeType === challengeTypes.BONFIRE;
|
||||||
|
})
|
||||||
|
.map(function(elem) {
|
||||||
|
return elem._id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
completedList = req.user.completedCoursewares.map(function (elem) {
|
completedList = req.user.completedChallenges
|
||||||
return elem._id;
|
.filter(function (elem) {
|
||||||
});
|
return elem.challengeType !== challengeTypes.BONFIRE;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var noDuplicateBonfires = R.uniq(completedBonfires);
|
var noDuplicateBonfires = R.uniq(completedBonfires);
|
||||||
var noDuplicatedCoursewares = R.uniq(completedList);
|
var noDuplicatedChallenges = R.uniq(completedList);
|
||||||
|
|
||||||
bonfireList = resources.allBonfireNames();
|
var completedBonfireList = noDuplicateBonfires
|
||||||
completedBonfireList = noDuplicateBonfires;
|
.map(function(bonfire) {
|
||||||
coursewareList = resources.allCoursewareNames();
|
return bonfire._id;
|
||||||
completedCoursewareList = noDuplicatedCoursewares;
|
});
|
||||||
waypoints = coursewareList.filter(function(challenge) {
|
var challengeList = resources.allChallenges();
|
||||||
if (challenge.challengeType === 2 || challenge.challengeType === 0) { return challenge }
|
var completedChallengeList = noDuplicatedChallenges
|
||||||
|
.map(function(challenge) {
|
||||||
|
return challenge._id;
|
||||||
|
});
|
||||||
|
|
||||||
|
var bonfireList = challengeList
|
||||||
|
.filter(function(challenge) {
|
||||||
|
return challenge.challengeType === challengeTypes.BONFIRE;
|
||||||
|
})
|
||||||
|
.map(function(bonfire) {
|
||||||
|
return ({
|
||||||
|
'_id': bonfire._id,
|
||||||
|
'name': bonfire.name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var waypoints = challengeList.filter(function(challenge) {
|
||||||
|
if (challenge.challengeType === challengeTypes.VIDEO
|
||||||
|
|| challenge.challengeType === challengeTypes.HTML_CSS_JQ
|
||||||
|
|| challenge.challengeType === challengeTypes.JAVASCRIPT) {
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
}).map(function(waypoint) {
|
||||||
|
return ({
|
||||||
|
'_id': waypoint._id,
|
||||||
|
'name': waypoint.name
|
||||||
|
});
|
||||||
});
|
});
|
||||||
ziplines = coursewareList.filter(function(challenge) {
|
|
||||||
if (challenge.challengeType === 3) { return challenge }
|
var ziplines = challengeList.filter(function(challenge) {
|
||||||
|
if (challenge.challengeType === challengeTypes.ZIPLINE) {
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
}).map(function(zipline) {
|
||||||
|
return ({
|
||||||
|
'_id': zipline._id,
|
||||||
|
'name': zipline.name
|
||||||
|
});
|
||||||
});
|
});
|
||||||
basejumps = coursewareList.filter(function(challenge) {
|
|
||||||
if (challenge.challengeType === 4) { return challenge }
|
var basejumps = challengeList.filter(function(challenge) {
|
||||||
|
if (challenge.challengeType === challengeTypes.BASEJUMP) {
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
}).map(function(basejump) {
|
||||||
|
return ({
|
||||||
|
'_id': basejump._id,
|
||||||
|
'name': basejump.name
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function numberWithCommas(x) {
|
function numberWithCommas(x) {
|
||||||
@ -66,6 +120,7 @@ module.exports = {
|
|||||||
debug('User err: ', err);
|
debug('User err: ', err);
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
debug('Data for render is: ', completedBonfireList, completedChallengeList);
|
||||||
res.render('challengeMap/show', {
|
res.render('challengeMap/show', {
|
||||||
daysRunning: daysRunning,
|
daysRunning: daysRunning,
|
||||||
camperCount: numberWithCommas(camperCount),
|
camperCount: numberWithCommas(camperCount),
|
||||||
@ -75,7 +130,7 @@ module.exports = {
|
|||||||
ziplines: ziplines,
|
ziplines: ziplines,
|
||||||
basejumps: basejumps,
|
basejumps: basejumps,
|
||||||
completedBonfireList: completedBonfireList,
|
completedBonfireList: completedBonfireList,
|
||||||
completedCoursewareList: completedCoursewareList
|
completedChallengeList: completedChallengeList
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ var async = require('async'),
|
|||||||
var allBonfireIds, allBonfireNames, allCoursewareIds, allCoursewareNames,
|
var allBonfireIds, allBonfireNames, allCoursewareIds, allCoursewareNames,
|
||||||
allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
|
allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
|
||||||
allBonfireIndexesAndNames, challengeMap, challengeMapWithIds,
|
allBonfireIndexesAndNames, challengeMap, challengeMapWithIds,
|
||||||
challengeMapWithNames, allChallengeIds;
|
challengeMapWithNames, allChallengeIds, allChallenges;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /
|
* GET /
|
||||||
@ -70,9 +70,7 @@ Array.zip = function(left, right, combinerFunction) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
getChallengeMapWithIds: function() {
|
getChallengeMapWithIds: function() {
|
||||||
if (challengeMapWithIds) {
|
if (!challengeMapWithIds) {
|
||||||
return challengeMapWithIds;
|
|
||||||
} else {
|
|
||||||
challengeMapWithIds = {};
|
challengeMapWithIds = {};
|
||||||
Object.keys(challengeMap).forEach(function (key) {
|
Object.keys(challengeMap).forEach(function (key) {
|
||||||
var onlyIds = challengeMap[key].challenges.map(function (elem) {
|
var onlyIds = challengeMap[key].challenges.map(function (elem) {
|
||||||
@ -80,17 +78,15 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
challengeMapWithIds[key] = onlyIds;
|
challengeMapWithIds[key] = onlyIds;
|
||||||
});
|
});
|
||||||
return challengeMapWithIds;
|
|
||||||
}
|
}
|
||||||
|
return challengeMapWithIds;
|
||||||
},
|
},
|
||||||
|
|
||||||
allChallengeIds: function() {
|
allChallengeIds: function() {
|
||||||
|
|
||||||
if (allChallengeIds) {
|
if (!allChallengeIds) {
|
||||||
return allChallengeIds;
|
|
||||||
} else {
|
|
||||||
allChallengeIds = [];
|
allChallengeIds = [];
|
||||||
Object.keys(challengeMapWithIds).forEach(function(key) {
|
Object.keys(this.getChallengeMapWithIds()).forEach(function(key) {
|
||||||
allChallengeIds.push(challengeMapWithIds[key]);
|
allChallengeIds.push(challengeMapWithIds[key]);
|
||||||
});
|
});
|
||||||
allChallengeIds = R.flatten(allChallengeIds);
|
allChallengeIds = R.flatten(allChallengeIds);
|
||||||
@ -98,10 +94,19 @@ module.exports = {
|
|||||||
return allChallengeIds;
|
return allChallengeIds;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
allChallenges: function() {
|
||||||
|
if (!allChallenges) {
|
||||||
|
allChallenges = [];
|
||||||
|
Object.keys(this.getChallengeMapWithNames()).forEach(function(key) {
|
||||||
|
allChallenges.push(challengeMap[key].challenges);
|
||||||
|
});
|
||||||
|
allChallenges = R.flatten(allChallenges);
|
||||||
|
}
|
||||||
|
return allChallenges;
|
||||||
|
},
|
||||||
|
|
||||||
getChallengeMapWithNames: function() {
|
getChallengeMapWithNames: function() {
|
||||||
if (challengeMapWithNames) {
|
if (!challengeMapWithNames) {
|
||||||
return challengeMapWithNames;
|
|
||||||
} else {
|
|
||||||
challengeMapWithNames = {};
|
challengeMapWithNames = {};
|
||||||
Object.keys(challengeMap).
|
Object.keys(challengeMap).
|
||||||
forEach(function (key) {
|
forEach(function (key) {
|
||||||
@ -110,8 +115,8 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
challengeMapWithNames[key] = onlyNames;
|
challengeMapWithNames[key] = onlyNames;
|
||||||
});
|
});
|
||||||
return challengeMapWithNames;
|
|
||||||
}
|
}
|
||||||
|
return challengeMapWithNames;
|
||||||
},
|
},
|
||||||
|
|
||||||
sitemap: function sitemap(req, res, next) {
|
sitemap: function sitemap(req, res, next) {
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
extends ../layout
|
extends ../layout
|
||||||
block content
|
block content
|
||||||
|
script.
|
||||||
|
var bonfireList = !{JSON.stringify(bonfires)};
|
||||||
|
var waypointList = !{JSON.stringify(waypoints)};
|
||||||
|
var ziplineList = !{JSON.stringify(ziplines)};
|
||||||
|
var basejumpList = !{JSON.stringify(basejumps)};
|
||||||
|
var completedBonfires = !{JSON.stringify(completedBonfireList)};
|
||||||
|
var completedChallenges = !{JSON.stringify(completedChallengeList)};
|
||||||
.panel.panel-info
|
.panel.panel-info
|
||||||
.panel-heading.text-center
|
.panel-heading.text-center
|
||||||
h1 Challenge Map
|
h1 Challenge Map
|
||||||
@ -24,7 +31,7 @@ block content
|
|||||||
h3.negative-15
|
h3.negative-15
|
||||||
ol
|
ol
|
||||||
for waypoint in waypoints
|
for waypoint in waypoints
|
||||||
if completedCoursewareList.indexOf(waypoint._id) > -1
|
if completedChallengeList.indexOf(waypoint._id) > -1
|
||||||
.row
|
.row
|
||||||
.hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center
|
.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
|
.col-xs-12.col-sm-9.col-md-10
|
||||||
@ -65,7 +72,7 @@ block content
|
|||||||
h3.negative-15
|
h3.negative-15
|
||||||
ol
|
ol
|
||||||
for zipline in ziplines
|
for zipline in ziplines
|
||||||
if completedCoursewareList.indexOf(zipline._id) > -1
|
if completedChallengeList.indexOf(zipline._id) > -1
|
||||||
.row
|
.row
|
||||||
.hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center
|
.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
|
.col-xs-12.col-sm-9.col-md-10
|
||||||
@ -85,7 +92,7 @@ block content
|
|||||||
h3.negative-15
|
h3.negative-15
|
||||||
ol
|
ol
|
||||||
for basejump in basejumps
|
for basejump in basejumps
|
||||||
if completedCoursewareList.indexOf(basejump._id) > -1
|
if completedChallengeList.indexOf(basejump._id) > -1
|
||||||
.row
|
.row
|
||||||
.hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center
|
.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
|
.col-xs-12.col-sm-9.col-md-10
|
||||||
|
Reference in New Issue
Block a user