From 0b0b74a559b3e9a9c96ea454dc84d4817378141b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2014 19:23:36 -0500 Subject: [PATCH 1/3] properly translating strings in category nojs template, and added pagination (so not all topics are loaded on every request) --- public/templates/noscript/category.tpl | 9 ++++- src/routes/api.js | 4 +- src/webserver.js | 51 ++++++++++++++++++-------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/public/templates/noscript/category.tpl b/public/templates/noscript/category.tpl index d0c7fa612b..ccfeffd740 100644 --- a/public/templates/noscript/category.tpl +++ b/public/templates/noscript/category.tpl @@ -18,4 +18,11 @@ - \ No newline at end of file + +
+ +
\ No newline at end of file diff --git a/src/routes/api.js b/src/routes/api.js index 0ddbc04582..301c2ea671 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -266,8 +266,8 @@ var path = require('path'), return next(err); } - var start = (page - 1) * settings.topicsPerPage; - var end = start + settings.topicsPerPage - 1; + var start = (page - 1) * settings.topicsPerPage, + end = start + settings.topicsPerPage - 1; categoryTools.privileges(req.params.id, uid, function(err, privileges) { if (!err && privileges.read) { diff --git a/src/webserver.js b/src/webserver.js index ed33ff4316..c17ac5f7b9 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -672,7 +672,9 @@ module.exports.server = server; }); 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([ function(next) { @@ -689,15 +691,23 @@ module.exports.server = server; }); }, 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 (parseInt(categoryData.disabled, 10) === 1) { - return next(new Error('Category disabled'), null); + if (categoryData) { + if (parseInt(categoryData.disabled, 10) === 1) { + return next(new Error('Category disabled'), null); + } } - } - next(err, categoryData); + next(err, categoryData); + }); }); }, function (categoryData, next) { @@ -736,7 +746,7 @@ module.exports.server = server; }, function (err, header) { next(err, { header: header, - categories: categoryData + topics: categoryData }); }); } @@ -749,8 +759,8 @@ module.exports.server = server; } } - if(data.categories.link) { - return res.redirect(data.categories.link); + if(data.topics.link) { + return res.redirect(data.topics.link); } var category_url = cid + (req.params.slug ? '/' + req.params.slug : ''); @@ -759,11 +769,22 @@ module.exports.server = server; category_url += '?' + queryString; } - res.send( - data.header + - '\n\t' + - '\n\t' + app.create_route('category/' + category_url) + templates.footer - ); + // 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( + data.header + + '\n\t' + + '\n\t' + app.create_route('category/' + category_url) + templates.footer + ); + }); }); }); From bc7eb501c87a644e8062efcb5f3b057a85eaf7ef Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2014 19:41:02 -0500 Subject: [PATCH 2/3] same for topics (translation + pagination) --- public/templates/noscript/topic.tpl | 9 ++++- src/webserver.js | 51 +++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/public/templates/noscript/topic.tpl b/public/templates/noscript/topic.tpl index 787712400f..f3d5180fe2 100644 --- a/public/templates/noscript/topic.tpl +++ b/public/templates/noscript/topic.tpl @@ -27,4 +27,11 @@ - \ No newline at end of file + +
+ +
\ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index c17ac5f7b9..d87c58b66d 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -524,7 +524,9 @@ module.exports.server = server; }); app.get('/topic/:topic_id/:slug?', function (req, res, next) { - var tid = req.params.topic_id; + var tid = req.params.topic_id, + page = req.query.page || 1, + uid = req.user ? req.user.uid : 0; async.waterfall([ function(next) { @@ -541,14 +543,23 @@ module.exports.server = server; }); }, function (next) { - topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), 0, -1, true, function (err, topicData) { - if (topicData) { - if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) { - return next(new Error('Topic deleted'), null); - } + user.getSettings(uid, function(err, settings) { + if (err) { + return next(err); } - next(err, topicData); + var start = (page - 1) * settings.topicsPerPage, + end = start + settings.topicsPerPage - 1; + + topics.getTopicWithPosts(tid, uid, start, end, true, function (err, topicData) { + if (topicData) { + if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) { + return next(new Error('Topic deleted'), null); + } + } + + next(err, topicData); + }); }); }, function (topicData, next) { @@ -644,7 +655,7 @@ module.exports.server = server; }, function (err, header) { next(err, { header: header, - topics: topicData + posts: topicData }); }); }, @@ -663,11 +674,22 @@ module.exports.server = server; topic_url += '?' + queryString; } - res.send( - data.header + - '\n\t' + - '\n\t' + app.create_route('topic/' + topic_url) + templates.footer - ); + // Paginator for noscript + data.posts.pages = []; + for(var x=1;x<=data.posts.pageCount;x++) { + data.posts.pages.push({ + page: x, + active: x === parseInt(page, 10) + }); + } + + translator.translate(templates['noscript/topic'].parse(data.posts), function(translatedHTML) { + res.send( + data.header + + '\n\t' + + '\n\t' + app.create_route('topic/' + topic_url) + templates.footer + ); + }); }); }); @@ -678,7 +700,7 @@ module.exports.server = server; async.waterfall([ function(next) { - CategoryTools.privileges(cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) { + CategoryTools.privileges(cid, uid, function(err, privileges) { if (!err) { if (!privileges.read) { next(new Error('not-enough-privileges')); @@ -698,6 +720,7 @@ module.exports.server = server; var start = (page - 1) * settings.topicsPerPage, end = start + settings.topicsPerPage - 1; + categories.getCategoryById(cid, start, end, 0, function (err, categoryData) { if (categoryData) { From b5496b56807d367f0a955bc84f9fcb886fb18660 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2014 19:41:50 -0500 Subject: [PATCH 3/3] fixed executable help echo --- nodebb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodebb b/nodebb index 020017cfae..e514db0051 100755 --- a/nodebb +++ b/nodebb @@ -59,7 +59,7 @@ case "$1" in *) echo "Welcome to NodeBB" - echo $"Usage: $0 {start|dev|watch|language}" + echo $"Usage: $0 {start|dev|watch|upgrade}" echo '' column -s ' ' -t <<< ' start Start NodeBB in production mode