2015-03-05 22:38:35 +03:00
|
|
|
var make = require('../lib/makeapi').readOnly;
|
2013-11-06 21:31:28 +04:00
|
|
|
|
|
|
|
module.exports = function (options) {
|
|
|
|
return function (req, res, next) {
|
2015-03-05 22:38:35 +03:00
|
|
|
var DEFAULT_LAYOUT = 'index',
|
2013-11-06 21:31:28 +04:00
|
|
|
DEFAULT_LIMIT = 12,
|
|
|
|
layouts = {
|
|
|
|
index: {
|
2015-03-05 22:38:35 +03:00
|
|
|
template: 'make-teach.html',
|
2015-01-28 22:18:55 +03:00
|
|
|
tags: ['webmaker:featured']
|
2013-11-06 21:31:28 +04:00
|
|
|
}
|
2013-07-17 00:02:57 +04:00
|
|
|
};
|
|
|
|
|
2013-11-06 21:31:28 +04:00
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
// layout: Choose a layout - should it look like the home or teach page?
|
|
|
|
// Sets the processing function and template piece
|
|
|
|
var layoutName = options.layout || (req.query.layout || DEFAULT_LAYOUT).toString(),
|
|
|
|
layout = layouts[layoutName] || layouts[DEFAULT_LAYOUT];
|
|
|
|
layout.name = layoutName;
|
|
|
|
|
|
|
|
// page: This is for rendering the view.
|
|
|
|
var page = options.page || layoutName;
|
|
|
|
|
|
|
|
// limit
|
|
|
|
var limit = options.limit || DEFAULT_LIMIT;
|
|
|
|
|
2015-01-28 22:18:55 +03:00
|
|
|
make.setLang(req.localeInfo.momentLang);
|
2013-07-17 00:02:57 +04:00
|
|
|
|
2015-01-28 22:18:55 +03:00
|
|
|
make
|
|
|
|
.find({
|
|
|
|
tags: {
|
|
|
|
tags: layout.tags
|
|
|
|
},
|
2013-11-06 21:31:28 +04:00
|
|
|
limit: limit,
|
2015-03-05 22:38:35 +03:00
|
|
|
sortByField: ['createdAt', 'desc']
|
2015-01-28 22:18:55 +03:00
|
|
|
})
|
|
|
|
.process(function (err, makes, totalHits) {
|
2015-03-05 22:38:35 +03:00
|
|
|
res.render(page + '.html', {
|
2015-01-28 22:18:55 +03:00
|
|
|
makes: makes,
|
|
|
|
totalHits: totalHits,
|
|
|
|
limit: limit,
|
|
|
|
page: page,
|
|
|
|
layout: layout.name,
|
|
|
|
template: layout.template,
|
|
|
|
isAdmin: req.session.user ? req.session.user.isAdmin : false
|
|
|
|
});
|
|
|
|
}, req.session.user ? req.session.user.id : '');
|
2013-07-17 00:02:57 +04:00
|
|
|
};
|
2013-11-06 21:31:28 +04:00
|
|
|
};
|