groups.list added start stop

v1.18.x
Barış Soner Uşaklı 10 years ago
parent a065a73637
commit 8117b4459a

@ -381,12 +381,7 @@ adminController.extend.rewards = function(req, res, next) {
};
adminController.groups.get = function(req, res, next) {
groups.list({
expand: true,
truncateUserList: true,
isAdmin: true,
showSystemGroups: true
}, function(err, groups) {
groups.list(req.uid, 0, -1, function(err, groups) {
if (err) {
return next(err);
}

@ -9,11 +9,7 @@ var async = require('async'),
groupsController = {};
groupsController.list = function(req, res, next) {
groups.list({
truncateUserList: true,
expand: true,
uid: req.uid
}, function(err, groups) {
groups.list(req.uid, 0, -1, function(err, groups) {
if (err) {
return next(err);
}

@ -80,8 +80,8 @@ var async = require('async'),
return ephemeralGroups;
};
Groups.list = function(options, callback) {
db.getSortedSetRevRange('groups:createtime', 0, -1, function (err, groupNames) {
Groups.list = function(uid, start, stop, callback) {
db.getSortedSetRevRange('groups:createtime', start, stop, function (err, groupNames) {
if (err) {
return callback(err);
}
@ -91,16 +91,25 @@ var async = require('async'),
});
async.parallel({
groups: async.apply(async.map, groupNames, function (groupName, next) {
Groups.get(groupName, options, next);
}),
isAdmin: function(next) {
if (!options.uid || parseInt(options.uid, 10) === 0) { return next(null, false); }
user.isAdministrator(parseInt(options.uid, 10), next);
groups: function(next) {
Groups.getGroupsData(groupNames, next);
},
members: function(next) {
Groups.getMemberUsers(groupNames, 0, 3, next);
}
}, function (err, data) {
options.isAdmin = options.isAdmin || data.isAdmin;
callback(err, internals.filterGroups(data.groups, options));
if (err) {
return callback(err);
}
data.groups.forEach(function(group, index) {
if (!group) {
return;
}
group.members = data.members[index] || [];
group.truncated = group.memberCount > data.members.length;
});
callback(null, data.groups);
});
});
};
@ -260,7 +269,6 @@ var async = require('async'),
results.base.hidden = !!parseInt(results.base.hidden, 10);
results.base.system = !!parseInt(results.base.system, 10);
results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true;
results.base.deletable = !results.base.system;
results.base.truncated = truncated;
results.base.isMember = results.isMember;
results.base.isPending = results.isPending;
@ -413,7 +421,8 @@ var async = require('async'),
group.labelColor = group.labelColor || '#000000';
group.createtimeISO = utils.toISOString(group.createtime);
group.hidden = parseInt(group.hidden, 10) === 1;
group.system = parseInt(group.system, 10) === 1;
group.private = parseInt(group.private, 10) === 1;
if (!group['cover:url']) {
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
group['cover:position'] = '50% 50%';

@ -181,6 +181,18 @@ module.exports = function(Groups) {
db.getSortedSetRevRange('group:' + groupName + ':members', start, stop, callback);
};
Groups.getMemberUsers = function(groupNames, start, stop, callback) {
async.map(groupNames, function(groupName, next) {
Groups.getMembers(groupName, start, stop, function(err, uids) {
if (err) {
return next(err);
}
user.getMultipleUserFields(uids, ['uid', 'username', 'picture', 'userslug'], next);
});
}, callback);
};
Groups.getMembersOfGroups = function(groupNames, callback) {
db.getSortedSetsMembers(groupNames.map(function(name) {
return 'group:' + name + ':members';

@ -18,9 +18,9 @@
<div class="btn-group">
<button class="btn btn-default" data-action="members">Edit</button>
<!-- IF groups.deletable -->
<!-- IF !groups.system -->
<button class="btn btn-danger" data-action="delete">Delete Group</button>
<!-- ENDIF groups.deletable -->
<!-- ENDIF !groups.system -->
</div>
</div>
<div class="col-lg-4">

Loading…
Cancel
Save