From ab6c84471b7dc38ae0cc59599448d7e8e993c292 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 14 Jan 2016 18:43:00 +0200 Subject: [PATCH] some search/sort changes --- public/src/client/users.js | 27 ++++++++++++++++++++++++--- src/socket.io/user/search.js | 5 ++++- src/user.js | 2 +- src/user/search.js | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/public/src/client/users.js b/public/src/client/users.js index a32cf3841e..2f8bec16a2 100644 --- a/public/src/client/users.js +++ b/public/src/client/users.js @@ -31,6 +31,9 @@ define('forum/users', ['translator'], function(translator) { }; function loadMoreUsers() { + if ($('#search-user').val()) { + return; + } var set = ''; var activeSection = getActiveSection(); if (activeSection === 'sort-posts') { @@ -114,7 +117,7 @@ define('forum/users', ['translator'], function(translator) { query: username, page: page, searchBy: 'username', - sortBy: $('.search select').val(), + sortBy: $('.search select').val() || getSortBy(), onlineOnly: $('.search .online-only').is(':checked') }, function(err, data) { if (err) { @@ -125,8 +128,25 @@ define('forum/users', ['translator'], function(translator) { }); } + function getSortBy() { + var sortBy; + var activeSection = getActiveSection(); + if (activeSection === 'sort-posts') { + sortBy = 'postcount'; + } else if (activeSection === 'sort-reputation') { + sortBy = 'reputation'; + } else if (activeSection === 'users') { + sortBy = 'joindate'; + } + return sortBy; + } + function loadPage(page) { - socket.emit('user.loadSearchPage', {page: page, onlineOnly: $('.search .online-only').is(':checked')}, function(err, data) { + socket.emit('user.loadSearchPage', { + page: page, + sortBy: getSortBy(), + onlineOnly: $('.search .online-only').is(':checked') + }, function(err, data) { if (err) { return app.alertError(err.message); } @@ -143,10 +163,11 @@ define('forum/users', ['translator'], function(translator) { templates.parse('users', 'users', data, function(html) { translator.translate(html, function(translated) { + translated = $(translated) $('#users-container').html(translated); + translated.find('span.timeago').timeago(); }); }); - } function onUserStatusChange(data) { diff --git a/src/socket.io/user/search.js b/src/socket.io/user/search.js index c59b2798d6..0cdb69edd8 100644 --- a/src/socket.io/user/search.js +++ b/src/socket.io/user/search.js @@ -8,6 +8,7 @@ var meta = require('../../meta'); var pagination = require('../../pagination'); module.exports = function(SocketUser) { + SocketUser.search = function(socket, data, callback) { if (!data) { return callback(new Error('[[error:invalid-data]]')); @@ -27,6 +28,7 @@ module.exports = function(SocketUser) { return callback(err); } result.pagination = pagination.create(data.page, result.pageCount); + result['route_users:' + data.sortBy] = true; callback(null, result); }); }; @@ -44,6 +46,7 @@ module.exports = function(SocketUser) { pagination: pagination.create(data.page, pageCount), pageCount: pageCount }; + userData['route_users:' + data.sortBy] = true; callback(null, userData); } @@ -69,7 +72,7 @@ module.exports = function(SocketUser) { } }, done); } else { - controllers.getUsersAndCount('users:joindate', socket.uid, start, stop, done); + controllers.getUsersAndCount('users:' + data.sortBy, socket.uid, start, stop, done); } }; diff --git a/src/user.js b/src/user.js index f60d03ffd6..cbdf7966e1 100644 --- a/src/user.js +++ b/src/user.js @@ -116,7 +116,7 @@ var async = require('async'), user.administrator = results.isAdmin[index]; user.banned = parseInt(user.banned, 10) === 1; user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1; - user.lastonlineISO = utils.toISOString(user.lastonline); + user.lastonlineISO = utils.toISOString(user.lastonline) || user.joindateISO; } }); plugins.fireHook('filter:userlist.get', {users: results.userData, uid: uid}, next); diff --git a/src/user/search.js b/src/user/search.js index 59a3cd063b..2d239163d1 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -108,7 +108,7 @@ module.exports = function(User) { } function sortUsers(userData, sortBy) { - if (sortBy === 'joindate' || sortBy === 'postcount') { + if (sortBy === 'joindate' || sortBy === 'postcount' || sortBy === 'reputation') { userData.sort(function(u1, u2) { return u2[sortBy] - u1[sortBy]; });