mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
group searching
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/* globals app, define, ajaxify, socket, bootbox, utils */
|
/* globals app, define, ajaxify, socket, bootbox, utils, templates */
|
||||||
|
|
||||||
define('forum/groups/list', function() {
|
define('forum/groups/list', function() {
|
||||||
var Groups = {};
|
var Groups = {};
|
||||||
@@ -29,6 +29,32 @@ define('forum/groups/list', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Group searching
|
||||||
|
$('#search-text').on('keydown', function(e) {
|
||||||
|
if (e.keyCode === 13) { Groups.search($(this).val()); }
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search-button').on('click', function() {
|
||||||
|
Groups.search($(this).siblings('input').val());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Groups.search = function(query) {
|
||||||
|
var groupsEl = $('.groups.row');
|
||||||
|
|
||||||
|
socket.emit('groups.search', {
|
||||||
|
query: query,
|
||||||
|
options: {
|
||||||
|
expand: true
|
||||||
|
}
|
||||||
|
}, function(err, groups) {
|
||||||
|
templates.parse('partials/group_list', {
|
||||||
|
groups: groups
|
||||||
|
}, function(html) {
|
||||||
|
groupsEl.empty().append(html);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return Groups;
|
return Groups;
|
||||||
|
|||||||
@@ -898,4 +898,23 @@ var async = require('async'),
|
|||||||
db.setRemove('group:' + groupName + ':owners', toUid, callback);
|
db.setRemove('group:' + groupName + ':owners', toUid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Groups.search = function(query, options, callback) {
|
||||||
|
if (!query || !query.length) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(db.getObjectValues, 'groupslug:groupname'),
|
||||||
|
function(groupNames, next) {
|
||||||
|
groupNames = groupNames.filter(function(name) {
|
||||||
|
return name.match(new RegExp(query, 'i'));
|
||||||
|
});
|
||||||
|
|
||||||
|
async.mapLimit(groupNames, 5, function(groupName, next) {
|
||||||
|
Groups.get(groupName, options || {}, next);
|
||||||
|
}, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
}(module.exports));
|
}(module.exports));
|
||||||
|
|||||||
@@ -126,6 +126,14 @@ SocketGroups.delete = function(socket, data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketGroups.search = function(socket, data, callback) {
|
||||||
|
if (!data || !data.query) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
groups.search(data.query, data.options || {}, callback);
|
||||||
|
};
|
||||||
|
|
||||||
SocketGroups.cover = {};
|
SocketGroups.cover = {};
|
||||||
|
|
||||||
SocketGroups.cover.get = function(socket, data, callback) {
|
SocketGroups.cover.get = function(socket, data, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user