admin/manage/groups pagination

v1.18.x
Barış Soner Uşaklı 10 years ago
parent 1602b378e3
commit a12ecbc230

@ -7,12 +7,16 @@ define('admin/manage/groups', [
], function(translator, components) {
var Groups = {};
var intervalId = 0;
Groups.init = function() {
var createModal = $('#create-modal'),
createGroupName = $('#create-group-name'),
createModalGo = $('#create-modal-go'),
createModalError = $('#create-modal-error');
handleSearch();
createModal.on('keypress', function(e) {
if (e.keyCode === 13) {
createModalGo.click();
@ -76,8 +80,41 @@ define('admin/manage/groups', [
break;
}
});
};
function handleSearch() {
function doSearch() {
if (!queryEl.val()) {
return ajaxify.refresh();
}
$('.pagination').addClass('hide');
var groupsEl = $('.groups-list');
socket.emit('groups.search', {
query: queryEl.val(),
options: {
sort: 'date'
}
}, function(err, groups) {
templates.parse('admin/manage/groups', 'groups', {
groups: groups
}, function(html) {
groupsEl.find('[data-groupname]').remove();
groupsEl.find('tr').after(html);
});
});
}
var queryEl = $('#group-search');
queryEl.on('keyup', function() {
if (intervalId) {
clearTimeout(intervalId);
intervalId = 0;
}
intervalId = setTimeout(doSearch, 200);
});
}
return Groups;
});

@ -76,7 +76,8 @@ define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
socket.emit('groups.search', {
query: queryEl.val(),
options: {
sort: sortEl.val()
sort: sortEl.val(),
filterHidden: true
}
}, function(err, groups) {
templates.parse('partials/groups/list', {

@ -46,7 +46,9 @@ define('autocomplete', function() {
source: function(request, response) {
socket.emit('groups.search', {
query: request.term,
options: {}
options: {
filterHidden: true
}
}, function(err, results) {
if (err) {
return app.alertError(err.message);

@ -1,8 +1,11 @@
"use strict";
var async = require('async'),
db = require('../../database'),
groups = require('../../groups'),
meta = require('../../meta'),
pagination = require('../../pagination'),
helpers = require('../helpers');
@ -10,19 +13,40 @@ var groupsController = {};
groupsController.list = function(req, res, next) {
groups.getGroupsFromSet('groups:createtime', req.uid, 0, -1, function(err, groups) {
var page = parseInt(req.query.page, 10) || 1;
var groupsPerPage = 20;
var pageCount = 0;
async.waterfall([
function(next) {
db.getSortedSetRevRange('groups:createtime', 0, -1, next);
},
function(groupNames, next) {
groupNames = groupNames.filter(function(name) {
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
});
pageCount = Math.ceil(groupNames.length / groupsPerPage);
var start = (page - 1) * groupsPerPage;
var stop = start + groupsPerPage - 1;
groupNames = groupNames.slice(start, stop + 1);
groups.getGroupsData(groupNames, next);
},
function(groupData, next) {
groupData.forEach(groups.escapeGroupData);
next(null, {groups: groupData, pagination: pagination.create(page, pageCount)});
}
], function(err, data) {
if (err) {
return next(err);
}
groups = groups.filter(function(group) {
return group && group.name.indexOf(':privileges:') === -1 && group.name !== 'registered-users';
});
res.render('admin/manage/groups', {
groups: groups,
yourid: req.user.uid
});
groups: data.groups,
pagination: data.pagination,
yourid: req.user.uid
});
});
};

@ -22,9 +22,12 @@ module.exports = function(Groups) {
Groups.getGroupsData(groupNames, next);
},
function(groupsData, next) {
groupsData = groupsData.filter(function(group) {
return group && !group.hidden;
});
groupsData = groupsData.filter(Boolean);
if (options.filterHidden) {
groupsData = groupsData.filter(function(group) {
return !group.hidden;
});
}
groupsData.forEach(Groups.escapeGroupData);
Groups.sort(options.sort, groupsData, next);
}

@ -219,7 +219,7 @@ SocketGroups.search = function(socket, data, callback) {
if (!data) {
return callback(null, []);
}
data.options = data.options || {};
if (!data.query) {
var groupsPerPage = 15;
groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1, function(err, data) {

@ -3,6 +3,9 @@
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-group"></i> Groups List</div>
<div class="panel-body">
<input id="group-search" type="text" class="form-control" placeholder="Search" /><br/>
<table class="table table-striped groups-list">
<tr>
<th>Group Name</th>
@ -28,6 +31,7 @@
</tr>
<!-- END groups -->
</table>
<!-- IMPORT partials/paginator.tpl -->
</div>
</div>
</div>

Loading…
Cancel
Save