create infrastructure for advancing through wiki
This commit is contained in:
13
app.js
13
app.js
@ -515,15 +515,12 @@ app.post('/completed-bonfire/', bonfireController.completedBonfire);
|
|||||||
* Wiki related routes
|
* Wiki related routes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.get(
|
|
||||||
'/wiki/:wikiName',
|
|
||||||
wikiController.returnIndividualWiki
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get('/wiki/:wikiName', wikiController.returnIndividualWiki);
|
||||||
'/wiki',
|
|
||||||
wikiController.returnHomeWiki
|
app.get('/wiki', wikiController.returnNextWiki);
|
||||||
);
|
|
||||||
|
app.post('/completed-wiki/', wikiController.completedWiki);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -239,6 +239,17 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
allWikiIds: function() {
|
||||||
|
return wikis.map(function(elem) {
|
||||||
|
return {
|
||||||
|
_id: elem._id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(function(elem) {
|
||||||
|
return elem._id;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
allBonfireNames: function() {
|
allBonfireNames: function() {
|
||||||
return bonfires.map(function(elem) {
|
return bonfires.map(function(elem) {
|
||||||
return {
|
return {
|
||||||
|
@ -29,6 +29,7 @@ exports.returnIndividualWiki = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
res.render('wiki/show', {
|
res.render('wiki/show', {
|
||||||
title: wiki.name,
|
title: wiki.name,
|
||||||
|
wikiId: wiki._id,
|
||||||
description: wiki.description.join('')
|
description: wiki.description.join('')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -40,30 +41,57 @@ exports.showAllWikis = function(req, res) {
|
|||||||
res.send(data);
|
res.send(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnHomeWiki = function(req, res) {
|
exports.returnNextWiki = function(req, res, next) {
|
||||||
var dashedName = req.params.wikiName;
|
if (!req.user) {
|
||||||
|
return res.redirect('../wiki/a-guide-to-our-wiki');
|
||||||
|
}
|
||||||
|
|
||||||
Wiki.find({'name': 'A Guide to our Wiki'}, function(err, wiki) {
|
var completed = req.user.completedWikis;
|
||||||
|
|
||||||
|
req.user.uncompletedWikis = resources.allWikiIds().filter(function (elem) {
|
||||||
|
if (completed.indexOf(elem) === -1) {
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.user.save();
|
||||||
|
|
||||||
|
var uncompletedWikis = req.user.uncompletedWikis;
|
||||||
|
|
||||||
|
var displayedWikis = Wiki.find({'_id': uncompletedWikis[0]});
|
||||||
|
displayedWikis.exec(function(err, wiki) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wiki.length < 1) {
|
|
||||||
req.flash('errors', {
|
|
||||||
msg: "404: We couldn't find a wiki entry with that name. Please double check the name."
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.redirect('/wiki');
|
|
||||||
}
|
|
||||||
|
|
||||||
wiki = wiki.pop();
|
wiki = wiki.pop();
|
||||||
var dashedNameFull = wiki.name.toLowerCase().replace(/\s/g, '-');
|
if (wiki === undefined) {
|
||||||
if (dashedNameFull != dashedName) {
|
req.flash('errors', {
|
||||||
return res.redirect('../wiki/' + dashedNameFull);
|
msg: "It looks like you've read all our current Wiki entries. Let us know if you'd like to contribute to our wiki!"
|
||||||
}
|
|
||||||
res.render('wiki/show', {
|
|
||||||
title: wiki.name,
|
|
||||||
description: wiki.description.join('')
|
|
||||||
});
|
});
|
||||||
|
return res.redirect('../wiki/a-guide-to-our-wiki');
|
||||||
|
}
|
||||||
|
var nameString = wiki.name.toLowerCase().replace(/\s/g, '-');
|
||||||
|
return res.redirect('../wiki/' + nameString);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.completedWiki = function (req, res, next) {
|
||||||
|
debug('params in completedWiki', req.params);
|
||||||
|
var wikiId = req.body.wikiInfo.wikiId;
|
||||||
|
|
||||||
|
req.user.completedWikis.push(wikiId);
|
||||||
|
|
||||||
|
var index = req.user.uncompletedWikis.indexOf(wikiId);
|
||||||
|
if (index > -1) {
|
||||||
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
|
req.user.uncompletedWikis.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
req.user.save(function (err, user) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (user) {
|
||||||
|
res.send(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -127,6 +127,8 @@ var userSchema = new mongoose.Schema({
|
|||||||
verified: Boolean
|
verified: Boolean
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
completedWikis: [],
|
||||||
|
uncompletedWikis: [],
|
||||||
currentStreak: {
|
currentStreak: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
@ -52,6 +52,23 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function completedWiki(wikiId) {
|
||||||
|
if ($('.signup-btn-nav').length < 1) {
|
||||||
|
$.post(
|
||||||
|
'/completed-wiki',
|
||||||
|
{
|
||||||
|
wikiInfo: {
|
||||||
|
wikiId: wikiId
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(res) {
|
||||||
|
if (res) {
|
||||||
|
window.location.href = '/wiki'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$('.next-bonfire-button').on('click', function() {
|
$('.next-bonfire-button').on('click', function() {
|
||||||
var bonfireSolution = myCodeMirror.getValue();
|
var bonfireSolution = myCodeMirror.getValue();
|
||||||
var thisBonfireHash = passedBonfireHash || null;
|
var thisBonfireHash = passedBonfireHash || null;
|
||||||
@ -61,6 +78,11 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.next-wiki-button').on('click', function() {
|
||||||
|
var wikiId = $('#wikiId').text();
|
||||||
|
completedWiki(wikiId);
|
||||||
|
});
|
||||||
|
|
||||||
$("img").error(function () {
|
$("img").error(function () {
|
||||||
$(this).unbind("error").attr("src", "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png");
|
$(this).unbind("error").attr("src", "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png");
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,9 @@ block content
|
|||||||
div!= description
|
div!= description
|
||||||
.spacer
|
.spacer
|
||||||
.text-center
|
.text-center
|
||||||
#showAllButton.btn.btn-info.btn-big Show all Wiki Articles
|
.next-wiki-button.btn.btn-primary.btn-big Take me to the next article
|
||||||
|
.ten-pixel-break
|
||||||
|
#showAllButton.btn.btn-info.btn-big Show all wiki articles
|
||||||
.spacer
|
.spacer
|
||||||
.row
|
.row
|
||||||
.col-xs-12.text-center
|
.col-xs-12.text-center
|
||||||
@ -24,3 +26,4 @@ block content
|
|||||||
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
||||||
.modal-body
|
.modal-body
|
||||||
include ../partials/wikis
|
include ../partials/wikis
|
||||||
|
#wikiId.hidden= wikiId
|
||||||
|
Reference in New Issue
Block a user