mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closes #4612
This commit is contained in:
@@ -32,6 +32,7 @@ define('forum/topic/posts', [
|
||||
});
|
||||
|
||||
updatePostCounts(data.posts);
|
||||
|
||||
ajaxify.data.postcount ++;
|
||||
postTools.updatePostCount(ajaxify.data.postcount);
|
||||
|
||||
@@ -60,15 +61,26 @@ define('forum/topic/posts', [
|
||||
ajaxify.data.pagination.pageCount = Math.max(1, Math.ceil((posts[0].topic.postcount - 1) / config.postsPerPage));
|
||||
var direction = config.topicPostSort === 'oldest_to_newest' || config.topicPostSort === 'most_votes' ? 1 : -1;
|
||||
|
||||
var isPostVisible = (ajaxify.data.pagination.currentPage === ajaxify.data.pagination.pageCount && direction === 1) || (ajaxify.data.pagination.currentPage === 1 && direction === -1);
|
||||
var isPostVisible = (ajaxify.data.pagination.currentPage === ajaxify.data.pagination.pageCount && direction === 1) ||
|
||||
(ajaxify.data.pagination.currentPage === 1 && direction === -1);
|
||||
|
||||
if (isPostVisible) {
|
||||
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, scrollToPost);
|
||||
} else if (ajaxify.data.scrollToMyPost && parseInt(posts[0].uid, 10) === parseInt(app.user.uid, 10)) {
|
||||
pagination.loadPage(ajaxify.data.pagination.pageCount, scrollToPost);
|
||||
} else {
|
||||
updatePagination();
|
||||
}
|
||||
}
|
||||
|
||||
function updatePagination() {
|
||||
$.get(config.relative_path + '/api/topic/pagination/' + ajaxify.data.tid, {page: ajaxify.data.pagination.currentPage}, function(paginationData) {
|
||||
app.parseAndTranslate('partials/paginator', {pagination: paginationData}, function(html) {
|
||||
$('[component="pagination"]').after(html).remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onNewPostInfiniteScroll(data) {
|
||||
var direction = config.topicPostSort === 'oldest_to_newest' || config.topicPostSort === 'most_votes' ? 1 : -1;
|
||||
|
||||
|
||||
@@ -327,5 +327,37 @@ topicsController.teaser = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
topicsController.pagination = function(req, res, callback) {
|
||||
var tid = req.params.topic_id;
|
||||
var currentPage = parseInt(req.query.page, 10) || 1;
|
||||
|
||||
if (!utils.isNumber(tid)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
privileges: async.apply(privileges.topics.get, tid, req.uid),
|
||||
settings: async.apply(user.getSettings, req.uid),
|
||||
topic: async.apply(topics.getTopicData, tid)
|
||||
}, function (err, results) {
|
||||
if (err || !results.topic) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!results.privileges.read || (parseInt(results.topic.deleted, 10) && !results.privileges.view_deleted)) {
|
||||
return helpers.notAllowed(req, res);
|
||||
}
|
||||
|
||||
var postCount = parseInt(results.topic.postcount, 10);
|
||||
var pageCount = Math.max(1, Math.ceil((postCount - 1) / results.settings.postsPerPage));
|
||||
|
||||
var paginationData = pagination.create(currentPage, pageCount);
|
||||
paginationData.rel.forEach(function(rel) {
|
||||
rel.href = nconf.get('url') + '/topic/' + results.topic.slug + rel.href;
|
||||
});
|
||||
|
||||
res.json(paginationData);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = topicsController;
|
||||
|
||||
@@ -24,6 +24,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
router.get('/recent/posts/:term?', controllers.api.getRecentPosts);
|
||||
router.get('/unread/:filter?/total', middleware.authenticate, controllers.unread.unreadTotal);
|
||||
router.get('/topic/teaser/:topic_id', controllers.topics.teaser);
|
||||
router.get('/topic/pagination/:topic_id', controllers.topics.pagination);
|
||||
|
||||
var multipart = require('connect-multiparty');
|
||||
var multipartMiddleware = multipart();
|
||||
|
||||
Reference in New Issue
Block a user