2013-04-22 15:07:08 +04:00
|
|
|
var querystring = require('querystring');
|
|
|
|
|
2013-04-11 15:53:36 +04:00
|
|
|
module.exports = function(app) {
|
|
|
|
|
2013-04-22 15:07:08 +04:00
|
|
|
app.param('section', function(req, res, next, section) {
|
|
|
|
if (section == 'programs') {
|
|
|
|
req.params.section = {
|
|
|
|
title: 'Programs',
|
|
|
|
set: 'program'
|
|
|
|
};
|
|
|
|
} else if (section == 'orgs') {
|
|
|
|
req.params.section = {
|
|
|
|
title: 'Organizations',
|
|
|
|
set: 'organization'
|
|
|
|
};
|
|
|
|
} else if (section == 'activities') {
|
|
|
|
req.params.section = {
|
|
|
|
title: 'Activities',
|
|
|
|
set: 'activity'
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return next(new Error('Learn section "' + section + '" not found'));
|
|
|
|
}
|
2013-04-11 15:53:36 +04:00
|
|
|
|
2013-04-22 15:07:08 +04:00
|
|
|
req.params.section.path = section;
|
2013-04-11 15:53:36 +04:00
|
|
|
|
2013-04-22 15:07:08 +04:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
app.param('item_id', function(req, res, next, id) {
|
|
|
|
var section = req.params.section;
|
|
|
|
|
|
|
|
// TODO - hook this into a model somewhere
|
|
|
|
req.params.item = {};
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
2013-06-02 02:44:36 +04:00
|
|
|
app.get('/explore/:section?/:item_id?', function(req, res) {
|
2013-04-22 15:07:08 +04:00
|
|
|
var section = req.params.section;
|
|
|
|
var item = req.params.item;
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
|
|
|
|
var itemOptions = [{
|
|
|
|
thumbnail: '/media/images/org.png',
|
2013-06-02 02:32:45 +04:00
|
|
|
description: 'Organization blah irure...',
|
2013-06-02 02:44:36 +04:00
|
|
|
url: '/explore/orgs/some-organization'
|
2013-04-22 15:07:08 +04:00
|
|
|
},{
|
|
|
|
thumbnail: '/media/images/program.png',
|
|
|
|
description: 'Program blah sed eiusmod...',
|
2013-06-02 02:44:36 +04:00
|
|
|
url: '/explore/programs/some-program'
|
2013-04-22 15:07:08 +04:00
|
|
|
},{
|
2013-04-22 16:13:31 +04:00
|
|
|
thumbnail: '/media/images/activity.png',
|
|
|
|
description: 'Activity id est laborum...',
|
2013-06-02 02:44:36 +04:00
|
|
|
url: '/explore/activities/some-activity'
|
2013-04-22 15:07:08 +04:00
|
|
|
}];
|
2013-04-11 15:53:36 +04:00
|
|
|
|
2013-04-22 15:07:08 +04:00
|
|
|
if (item)
|
2013-04-22 16:13:31 +04:00
|
|
|
return res.render('learn/' + section.set + '/single.html', {
|
2013-04-22 15:07:08 +04:00
|
|
|
item: item
|
|
|
|
});
|
|
|
|
|
|
|
|
if ('category' in req.query) {
|
|
|
|
var category = req.query['category'];
|
|
|
|
delete req.query['category'];
|
|
|
|
var query = querystring.stringify(req.query);
|
2013-06-02 02:44:36 +04:00
|
|
|
return res.redirect('/explore/' + category + '?' + query);
|
2013-04-22 15:07:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < 12; ++i) {
|
|
|
|
items.push(itemOptions[Math.floor(Math.random()*itemOptions.length)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var filters = [{
|
|
|
|
name: 'category',
|
|
|
|
label: 'Category',
|
|
|
|
selected: (section || {}).path,
|
|
|
|
options: {
|
|
|
|
activities: 'Activities',
|
|
|
|
orgs: 'Organizations',
|
|
|
|
programs: 'Programs'
|
|
|
|
}
|
|
|
|
},{
|
|
|
|
name: 'age',
|
|
|
|
label: 'Age',
|
|
|
|
options: {}
|
|
|
|
},{
|
|
|
|
name: 'topic',
|
|
|
|
label: 'Topic',
|
|
|
|
options: {}
|
|
|
|
},{
|
|
|
|
name: 'date',
|
|
|
|
label: 'Date',
|
|
|
|
options: {}
|
|
|
|
},{
|
|
|
|
name: 'search',
|
|
|
|
label: 'Search',
|
|
|
|
value: '',
|
|
|
|
type: 'search'
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (section)
|
|
|
|
return res.render('learn/' + section.set + '/list.html', {
|
|
|
|
filters: filters,
|
|
|
|
pageTitle: section.title,
|
|
|
|
items: items
|
|
|
|
});
|
|
|
|
|
|
|
|
res.render('learn/list.html', {
|
|
|
|
filters: filters,
|
|
|
|
items: items
|
2013-04-11 15:53:36 +04:00
|
|
|
});
|
2013-04-22 15:07:08 +04:00
|
|
|
});
|
|
|
|
|
2013-06-02 02:44:36 +04:00
|
|
|
app.get('/explore/:section/:item_id/:action', function(req, res, next) {
|
2013-04-22 15:07:08 +04:00
|
|
|
var item = req.params.item;
|
|
|
|
var action = req.params.action;
|
|
|
|
|
|
|
|
if (action === 'favorite')
|
|
|
|
return res.send('Favoriting ' + item);
|
|
|
|
|
|
|
|
if (action === 'unfavorite')
|
|
|
|
return res.send('Unfavoriting ' + item);
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
2013-04-11 15:53:36 +04:00
|
|
|
|
|
|
|
}
|