Node.js based forum software built for the modern web
add pagination to user profile
Barış Soner Uşaklıb38a10f96a6e
diff --git a/package.json b/package.jsonindex 9692119156..e85e3ec0f6 100644--- a/package.json+++ b/package.json@@ -63,8 +63,8 @@"nodebb-plugin-spam-be-gone": "0.4.10","nodebb-rewards-essentials": "0.0.9","nodebb-theme-lavender": "3.0.15",- "nodebb-theme-persona": "4.1.82",- "nodebb-theme-vanilla": "5.1.54",+ "nodebb-theme-persona": "4.1.83",+ "nodebb-theme-vanilla": "5.1.55","nodebb-widget-essentials": "2.0.13","nodemailer": "2.6.4","nodemailer-sendmail-transport": "1.0.0",diff --git a/public/src/client/account/profile.js b/public/src/client/account/profile.jsindex f1d41db46f..b1eaa218cf 100644--- a/public/src/client/account/profile.js+++ b/public/src/client/account/profile.js@@ -8,8 +8,8 @@ define('forum/account/profile', ['translator','components'], function (header, infinitescroll, translator) {- var Account = {},- theirid;+ var Account = {};+ var theirid;Account.init = function () {header.init();@@ -22,8 +22,10 @@ define('forum/account/profile', [socket.removeListener('event:user_status_change', onUserStatusChange);socket.on('event:user_status_change', onUserStatusChange);-- infinitescroll.init(loadMorePosts);++ if (!config.usePagination) {+ infinitescroll.init(loadMorePosts);+ }};function processPage() {diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.jsindex f0fa1e1378..8ee8979b43 100644--- a/src/controllers/accounts/profile.js+++ b/src/controllers/accounts/profile.js@@ -10,7 +10,7 @@ var plugins = require('../../plugins');var meta = require('../../meta');var accountHelpers = require('./helpers');var helpers = require('../helpers');-+var pagination = require('../../pagination');var profileController = {};@@ -24,7 +24,10 @@ profileController.get = function (req, res, callback) {return res.redirect(nconf.get('relative_path') + '/user/' + lowercaseSlug);}}-+ var page = Math.max(1, parseInt(req.query.page, 10) || 1);+ var itemsPerPage = 10;+ var start = (page - 1) * itemsPerPage;+ var stop = start + itemsPerPage - 1;var userData;async.waterfall([function (next) {@@ -47,7 +50,7 @@ profileController.get = function (req, res, callback) {user.isFollowing(req.uid, userData.theirid, next);},posts: function (next) {- posts.getPostSummariesFromSet('uid:' + userData.theirid + ':posts', req.uid, 0, 9, next);+ posts.getPostSummariesFromSet('uid:' + userData.theirid + ':posts', req.uid, start, stop, next);},signature: function (next) {posts.parseSignature(userData, req.uid, next);@@ -75,6 +78,8 @@ profileController.get = function (req, res, callback) {userData.isFollowing = results.isFollowing;userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username}]);userData.title = userData.username;+ var pageCount = Math.ceil(userData.postcount / itemsPerPage);+ userData.pagination = pagination.create(page, pageCount, req.query);userData['cover:url'] = userData['cover:url'] || require('../../coverPhoto').getDefaultProfileCover(userData.uid);userData['cover:position'] = userData['cover:position'] || '50% 50%';