remove field guide cruft and update all field guide links to wiki

This commit is contained in:
Quincy Larson
2015-07-31 21:55:49 -07:00
parent fd68501e16
commit feab8b508e
24 changed files with 74 additions and 1718 deletions

View File

@@ -1,180 +0,0 @@
var Rx = require('rx');
var debug = require('debug')('freecc:fieldguides');
var observeMethod = require('../utils/rx').observeMethod;
var saveUser = require('../utils/rx').saveUser;
var utils = require('../utils');
var allFieldGuideNamesAndIds = utils.allFieldGuideNamesAndIds();
// order here determine order on all-articles page
const categories = [
'orientation',
'FYI',
'outreach',
'contact'
];
module.exports = function(app) {
var router = app.loopback.Router();
var FieldGuide = app.models.FieldGuide;
var findFieldGuideById = observeMethod(FieldGuide, 'findById');
var findOneFieldGuide = observeMethod(FieldGuide, 'findOne');
router.get('/field-guide/all-articles', showAllFieldGuides);
router.get('/field-guide/:fieldGuideName', returnIndividualFieldGuide);
router.get('/field-guide/', returnNextFieldGuide);
router.post('/completed-field-guide/', completedFieldGuide);
app.use(router);
function returnIndividualFieldGuide(req, res, next) {
var dashedName = req.params.fieldGuideName;
var userSave = Rx.Observable.just(req.user)
.filter(function(user) {
debug('filtering user', !!user);
return !!user;
})
.map(function(user) {
var completed = user.completedFieldGuides;
var uncompletedFieldGuides = utils.allFieldGuideIds()
.filter(function(id) {
if (completed.indexOf(id) === -1) {
return id;
}
});
user.uncompletedFieldGuides = uncompletedFieldGuides;
return user;
})
.flatMap(function(user) {
debug('saving user');
return saveUser(user);
})
// always call onNext
.defaultIfEmpty(null);
var query = { where: { dashedName: { like: dashedName, options: 'i' } } };
debug('find fieldGuide', query);
Rx.Observable.combineLatest(
// find that field guide
findOneFieldGuide(query),
userSave,
Rx.helpers.identity
)
.subscribe(
// don't care about return from userSave
function(fieldGuide) {
debug('onNext', fieldGuide);
if (!fieldGuide) {
req.flash('errors', {
msg: '404: We couldn\'t find a field guide entry with ' +
'that name. Please double check the name.'
});
return res.redirect('/field-guide/all-articles');
}
if (fieldGuide.dashedName !== dashedName) {
return res.redirect('../field-guide/' + fieldGuide.dashedName);
}
res.render('field-guide/show', {
title: fieldGuide.name,
fieldGuideId: fieldGuide.id,
description: fieldGuide.description.join('')
});
},
next,
function() {
debug('onCompleted called');
}
);
}
function showAllFieldGuides(req, res) {
var completedFieldGuides = [];
if (req.user && req.user.completedFieldGuides) {
completedFieldGuides = req.user.completedFieldGuides;
}
// produces an array of arrays of field guides ordered by the above
// i.e. [[...orientFieldGuides][...FYIfieldGuides]...]
const orderFieldGuides = categories
.reduce((ordered, category) => {
const fieldGuidesForCategory = allFieldGuideNamesAndIds
.filter(fieldGuide => {
return category === fieldGuide.category;
});
return ordered.concat([fieldGuidesForCategory]);
}, []);
res.render('field-guide/all-articles', {
// leaving this property as legacy.
allFieldGuideNamesAndIds: allFieldGuideNamesAndIds,
completedFieldGuides: completedFieldGuides,
categories: categories,
fieldGuides: orderFieldGuides
});
}
function showCompletedFieldGuideFunction(req, res) {
req.flash(
'success',
{
msg: [
'You\'ve read all our current Field Guide entries. ' +
'If you have ideas for other Field Guide articles, ' +
'please let us know on ',
'<a href=\'https://github.com/freecodecamp/freecodecamp/' +
'issues/new?&body=Please describe your idea for a Field Guide' +
' article and include links if possible.\'>GitHub</a>.'
].join('')
}
);
return res.redirect('../field-guide/how-do-i-use-this-guide');
}
function returnNextFieldGuide(req, res, next) {
if (!req.user) {
return res.redirect('/field-guide/how-do-i-use-this-guide');
}
if (!req.user.uncompletedFieldGuides.length) {
return showCompletedFieldGuideFunction(req, res);
}
findFieldGuideById(req.user.uncompletedFieldGuides[0]).subscribe(
function(fieldGuide) {
if (!fieldGuide) {
debug(
'field guide %s not found',
req.user.uncompletedFieldGuides[0]
);
return res.redirect('../field-guide/how-do-i-use-this-guide');
}
return res.redirect('../field-guide/' + fieldGuide.dashedName);
},
next
);
}
function completedFieldGuide(req, res, next) {
var fieldGuideId = req.body.fieldGuideInfo.fieldGuideId;
req.user.completedFieldGuides.push(fieldGuideId);
var index = req.user.uncompletedFieldGuides.indexOf(fieldGuideId);
if (index > -1) {
req.user.progressTimestamps.push(Date.now());
req.user.uncompletedFieldGuides.splice(index, 1);
}
saveUser(req.user).subscribe(
function() {
res.send(true);
},
next
);
}
};

View File

@@ -12,7 +12,6 @@ module.exports = function(app) {
var User = app.models.User;
var Challenge = app.models.Challenge;
var Story = app.models.Story;
var FieldGuide = app.models.FieldGuide;
var Nonprofit = app.models.Nonprofit;
router.get('/api/github', githubCalls);
@@ -155,31 +154,6 @@ module.exports = function(app) {
);
}
});
},
fieldGuides: function(callback) {
FieldGuide.find(
{ field: { name: true } },
function(err, fieldGuides) {
if (err) {
debug('User err: ', err);
callback(err);
} else {
Rx.Observable.from(
fieldGuides,
null,
null,
Rx.Scheduler.default
)
.map(function(fieldGuide) {
return fieldGuide.name;
})
.toArray()
.subscribe(
callback.bind(callback, null),
callback
);
}
});
}
}, function(err, results) {
if (err) {
@@ -193,8 +167,7 @@ module.exports = function(app) {
users: results.users,
challenges: results.challenges,
stories: results.stories,
nonprofits: results.nonprofits,
fieldGuides: results.fieldGuides
nonprofits: results.nonprofits
});
});
}

View File

@@ -4,14 +4,7 @@ module.exports = function(app) {
router.get('/nonprofit-project-instructions', function(req, res) {
res.redirect(
301,
'/field-guide/how-do-free-code-camps-nonprofit-projects-work'
);
});
router.get('/coding-bootcamp-cost-calculator', function(req, res) {
res.redirect(
301,
'/field-guide/can-i-calculate-the-true-cost-of-a-bootcamp-with-a-coding-bootcamp-cost-calculator'
"https://github.com/FreeCodeCamp/freecodecamp/wiki/How-Free-Code-Camp's-Nonprofit-Projects-work"
);
});
@@ -21,7 +14,7 @@ module.exports = function(app) {
router.get('/privacy', function(req, res) {
res.redirect(
301, '/field-guide/what-is-the-free-code-camp-privacy-policy?'
301, "https://github.com/FreeCodeCamp/freecodecamp/wiki/Free-Code-Camp's-Privacy-Policy"
);
});

View File

@@ -35,10 +35,6 @@
"dataSource": "db",
"public": true
},
"fieldGuide": {
"dataSource": "db",
"public": true
},
"job": {
"dataSource": "db",
"public": true

View File

@@ -11,20 +11,10 @@ var path = require('path'),
resources = require('./resources.json'),
nonprofits = require('../../seed/nonprofits.json');
var fieldGuides = fs.readdirSync(
path.join(__dirname, '../../seed/field-guides')
)
.map(function(file) {
return require('../../seed/field-guides/' + file);
})
.reduce(function(allGuides, categoryGuides) {
return allGuides.concat(categoryGuides);
}, []);
/**
* Cached values
*/
var allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
var allNonprofitNames,
challengeMap, challengeMapForDisplay, challengeMapWithIds,
challengeMapWithNames, allChallengeIds,
challengeMapWithDashedNames;
@@ -162,33 +152,6 @@ module.exports = {
];
},
allFieldGuideIds: function() {
if (allFieldGuideIds) {
return allFieldGuideIds;
} else {
allFieldGuideIds = fieldGuides.map(function(elem) {
return elem.id;
});
return allFieldGuideIds;
}
},
allFieldGuideNamesAndIds: function() {
if (allFieldGuideNames) {
return allFieldGuideNames;
} else {
allFieldGuideNames = fieldGuides.map(function(elem) {
return {
name: elem.name,
dashedName: elem.dashedName,
id: elem.id,
category: elem.category
};
});
return allFieldGuideNames;
}
},
allNonprofitNames: function() {
if (allNonprofitNames) {
return allNonprofitNames;

View File

@@ -6,7 +6,7 @@
.modal-body.text-center
h3 This will take you to our pair programming room where you can request a pair.
h3 You'll need &thinsp;
a(href='/field-guide/how-do-i-install-screenhero' target='_blank') Screenhero
a(href='//github.com/FreeCodeCamp/freecodecamp/wiki/How-to-install-Screenhero' target='_blank') Screenhero
| .
h3 Other campers may then message you about pair programming.
a.btn.btn-lg.btn-primary.btn-block(href='https://gitter.im/FreeCodeCamp/LetsPair', data-dismiss='modal', aria-hidden='true' target='_blank') Take me to the pair programming room
@@ -30,7 +30,7 @@
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
.modal-body.text-center
h3 Remember to use &thinsp;
a(href='/field-guide/how-do-i-get-help-when-i-get-stuck' target='_blank') RSAP
a(href='//github.com/FreeCodeCamp/freecodecamp/wiki/How-to-get-help-when-you-get-stuck' target='_blank') RSAP
| .
h3 If you've already read the errors and searched Google, you should ask for help.
h3 This will take you to our help room.

View File

@@ -26,7 +26,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
priority= 0.9
url
loc http://www.freecodecamp.com/twitch
loc http://www.freecodecamp.com/coding-bootcamp-cost-calculator
changefreq weekly
lastmod= now
priority= 0.9
@@ -59,10 +59,3 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
lastmod= now
changefreq daily
priority= 0.9
each fieldGuide in fieldGuides
url
loc #{appUrl}/field-guide/#{fieldGuide.replace(/\s/g, '-')}
lastmod= now
changefreq daily
priority= 0.9