group member search change

v1.18.x
Barış Soner Uşaklı 8 years ago
parent f6890cd971
commit 7a405da60f

@ -42,7 +42,7 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
var $this = $(this);
var bottom = ($this[0].scrollHeight - $this.innerHeight()) * 0.9;
if ($this.scrollTop() > bottom) {
if ($this.scrollTop() > bottom && !$('[component="groups/members/search"]').val()) {
loadMoreMembers();
}
});
@ -86,7 +86,7 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
}
function parseAndTranslate(users, callback) {
app.parseAndTranslate(templateName, 'members', {
app.parseAndTranslate(templateName, 'group.members', {
group: {
members: users,
isOwner: ajaxify.data.group.isOwner,

@ -39,7 +39,7 @@ usersController.search = function (req, res, next) {
query: req.query.term,
searchBy: req.query.searchBy || 'username',
page: req.query.page || 1,
sortBy: req.query.sortBy,
sortBy: req.query.sortBy || 'joindate',
onlineOnly: req.query.onlineOnly === 'true',
bannedOnly: req.query.bannedOnly === 'true',
flaggedOnly: req.query.flaggedOnly === 'true',

@ -63,29 +63,6 @@ module.exports = function (Groups) {
};
Groups.searchMembers = function (data, callback) {
function findUids(query, searchBy, callback) {
query = query.toLowerCase();
async.waterfall([
function (next) {
Groups.getMembers(data.groupName, 0, -1, next);
},
function (members, next) {
user.getUsersFields(members, ['uid'].concat([searchBy]), next);
},
function (users, next) {
var uids = [];
for (var i = 0; i < users.length; i += 1) {
var field = users[i][searchBy];
if (field.toLowerCase().startsWith(query)) {
uids.push(users[i].uid);
}
}
next(null, uids);
},
], callback);
}
if (!data.query) {
Groups.getOwnersAndMembers(data.groupName, data.uid, 0, 19, function (err, users) {
callback(err, { users: users });
@ -93,10 +70,10 @@ module.exports = function (Groups) {
return;
}
data.findUids = findUids;
var results;
async.waterfall([
function (next) {
data.paginate = false;
user.search(data, next);
},
function (_results, next) {
@ -104,6 +81,16 @@ module.exports = function (Groups) {
var uids = results.users.map(function (user) {
return user && user.uid;
});
Groups.isMembers(uids, data.groupName, next);
},
function (isMembers, next) {
results.users = results.users.filter(function (user, index) {
return isMembers[index];
});
var uids = results.users.map(function (user) {
return user && user.uid;
});
Groups.ownership.isOwners(uids, data.groupName, next);
},
function (isOwners, next) {

@ -23,11 +23,8 @@ module.exports = function (User) {
var searchResult = {};
async.waterfall([
function (next) {
if (data.findUids) {
data.findUids(query, searchBy, next);
} else {
findUids(query, searchBy, next);
}
var searchMethod = data.findUids || findUids;
searchMethod(query, searchBy, data.hardCap, next);
},
function (uids, next) {
filterAndSortUids(uids, data, next);
@ -57,7 +54,7 @@ module.exports = function (User) {
], callback);
};
function findUids(query, searchBy, callback) {
function findUids(query, searchBy, hardCap, callback) {
if (!query) {
return callback(null, []);
}
@ -66,7 +63,7 @@ module.exports = function (User) {
var max = query.substr(0, query.length - 1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1);
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
var hardCap = resultsPerPage * 10;
hardCap = hardCap || resultsPerPage * 10;
async.waterfall([
function (next) {
@ -82,9 +79,11 @@ module.exports = function (User) {
}
function filterAndSortUids(uids, data, callback) {
var sortBy = data.sortBy || 'joindate';
var fields = [];
var fields = ['uid', sortBy];
if (data.sortBy) {
fields.push(data.sortBy);
}
if (data.onlineOnly) {
fields = fields.concat(['status', 'lastonline']);
}
@ -95,6 +94,12 @@ module.exports = function (User) {
fields.push('flags');
}
if (!fields.length) {
return callback(null, uids);
}
fields = ['uid'].concat(fields);
async.waterfall([
function (next) {
User.getUsersFields(uids, fields, next);
@ -118,7 +123,9 @@ module.exports = function (User) {
});
}
sortUsers(userData, sortBy);
if (data.sortBy) {
sortUsers(userData, data.sortBy);
}
uids = userData.map(function (user) {
return user && user.uid;

Loading…
Cancel
Save