mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
search sorting
This commit is contained in:
@@ -39,12 +39,14 @@ define('forum/groups/list', function() {
|
|||||||
|
|
||||||
Groups.search = function() {
|
Groups.search = function() {
|
||||||
var groupsEl = $('#groups-list'),
|
var groupsEl = $('#groups-list'),
|
||||||
queryEl = $('#search-text');
|
queryEl = $('#search-text'),
|
||||||
|
sortEl = $('#search-sort');
|
||||||
|
|
||||||
socket.emit('groups.search', {
|
socket.emit('groups.search', {
|
||||||
query: queryEl.val(),
|
query: queryEl.val(),
|
||||||
options: {
|
options: {
|
||||||
expand: true
|
expand: true,
|
||||||
|
sort: sortEl.val()
|
||||||
}
|
}
|
||||||
}, function(err, groups) {
|
}, function(err, groups) {
|
||||||
templates.parse('partials/groups/list', {
|
templates.parse('partials/groups/list', {
|
||||||
|
|||||||
@@ -892,8 +892,29 @@ var async = require('async'),
|
|||||||
async.mapLimit(groupNames, 5, function(groupName, next) {
|
async.mapLimit(groupNames, 5, function(groupName, next) {
|
||||||
Groups.get(groupName, options || {}, next);
|
Groups.get(groupName, options || {}, next);
|
||||||
}, next);
|
}, next);
|
||||||
}
|
},
|
||||||
|
async.apply(Groups.sort, options.sort)
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Groups.sort = function(strategy, groups, next) {
|
||||||
|
switch(strategy) {
|
||||||
|
case 'count':
|
||||||
|
groups = groups.sort(function(a, b) {
|
||||||
|
return a.slug > b.slug;
|
||||||
|
}).sort(function(a, b) {
|
||||||
|
return a.memberCount < b.memberCount;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'alpha': // intentional fall-through
|
||||||
|
default:
|
||||||
|
groups = groups.sort(function(a, b) {
|
||||||
|
return a.slug > b.slug;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
next(null, groups);
|
||||||
|
};
|
||||||
|
|
||||||
}(module.exports));
|
}(module.exports));
|
||||||
|
|||||||
Reference in New Issue
Block a user