|
|
|
@ -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
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|