properly translating strings in category nojs template, and added pagination (so not all topics are loaded on every request)

v1.18.x
Julian Lam 11 years ago
parent b71f1a410e
commit 0b0b74a559

@ -19,3 +19,10 @@
</li> </li>
<!-- END topics --> <!-- END topics -->
</ul> </ul>
<div class="text-center">
<ul class="pagination">
<!-- BEGIN pages -->
<li <!-- IF pages.active -->class="active"<!-- ENDIF pages.active -->><a href="?page={pages.page}">{pages.page}</a></li>
<!-- END pages -->
</ul>
</div>

@ -266,8 +266,8 @@ var path = require('path'),
return next(err); return next(err);
} }
var start = (page - 1) * settings.topicsPerPage; var start = (page - 1) * settings.topicsPerPage,
var end = start + settings.topicsPerPage - 1; end = start + settings.topicsPerPage - 1;
categoryTools.privileges(req.params.id, uid, function(err, privileges) { categoryTools.privileges(req.params.id, uid, function(err, privileges) {
if (!err && privileges.read) { if (!err && privileges.read) {

@ -672,7 +672,9 @@ module.exports.server = server;
}); });
app.get('/category/:category_id/:slug?', function (req, res, next) { app.get('/category/:category_id/:slug?', function (req, res, next) {
var cid = req.params.category_id; var cid = req.params.category_id,
page = req.query.page || 1,
uid = req.user ? req.user.uid : 0;
async.waterfall([ async.waterfall([
function(next) { function(next) {
@ -689,7 +691,14 @@ module.exports.server = server;
}); });
}, },
function (next) { function (next) {
categories.getCategoryById(cid, 0, -1, 0, function (err, categoryData) { user.getSettings(uid, function(err, settings) {
if (err) {
return next(err);
}
var start = (page - 1) * settings.topicsPerPage,
end = start + settings.topicsPerPage - 1;
categories.getCategoryById(cid, start, end, 0, function (err, categoryData) {
if (categoryData) { if (categoryData) {
if (parseInt(categoryData.disabled, 10) === 1) { if (parseInt(categoryData.disabled, 10) === 1) {
@ -699,6 +708,7 @@ module.exports.server = server;
next(err, categoryData); next(err, categoryData);
}); });
});
}, },
function (categoryData, next) { function (categoryData, next) {
app.build_header({ app.build_header({
@ -736,7 +746,7 @@ module.exports.server = server;
}, function (err, header) { }, function (err, header) {
next(err, { next(err, {
header: header, header: header,
categories: categoryData topics: categoryData
}); });
}); });
} }
@ -749,8 +759,8 @@ module.exports.server = server;
} }
} }
if(data.categories.link) { if(data.topics.link) {
return res.redirect(data.categories.link); return res.redirect(data.topics.link);
} }
var category_url = cid + (req.params.slug ? '/' + req.params.slug : ''); var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
@ -759,13 +769,24 @@ module.exports.server = server;
category_url += '?' + queryString; category_url += '?' + queryString;
} }
// Paginator for noscript
data.topics.pages = [];
for(var x=1;x<=data.topics.pageCount;x++) {
data.topics.pages.push({
page: x,
active: x === parseInt(page, 10)
});
}
translator.translate(templates['noscript/category'].parse(data.topics), function(translatedHTML) {
res.send( res.send(
data.header + data.header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(data.categories) + '\n\t</noscript>' + '\n\t<noscript>\n' + templates['noscript/header'] + translatedHTML + '\n\t</noscript>' +
'\n\t' + app.create_route('category/' + category_url) + templates.footer '\n\t' + app.create_route('category/' + category_url) + templates.footer
); );
}); });
}); });
});
app.get('/confirm/:code', function (req, res) { app.get('/confirm/:code', function (req, res) {
app.build_header({ app.build_header({

Loading…
Cancel
Save