groups: misc groups fixes

This commit is contained in:
Tyler Renelle
2013-09-01 20:24:44 -04:00
parent 872b834f07
commit ac992ea865
3 changed files with 27 additions and 9 deletions

View File

@@ -50,6 +50,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
$scope.invite = function(group, uuid){
group.$invite({uuid:uuid}, function(){
$scope.invitee = '';
alert("User invited to group");
});
}
}
@@ -90,17 +91,25 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
}
])
.controller("PartyCtrl", ['$scope', 'Groups',
function($scope, Groups) {
.controller("PartyCtrl", ['$scope', 'Groups', 'User',
function($scope, Groups, User) {
$scope.type = 'party';
$scope.text = 'Party';
$scope.group = $scope.groups.party;
$scope.join = function(party){
// workaround since group isn't currently a resource, this won't get saved to the server
var group = new Groups({_id: party.id, name: party.name});
debugger
group.$join();
}
$scope.leave = function(group){
group.$leave(function(){
$parent.groups.party = {}
});
}
$scope.reject = function(){
User.user.invitations.party = undefined;
User.log({op:'set',data:{'invitations.party':{}}});
}
}
])

View File

@@ -16,6 +16,9 @@ var api = module.exports;
------------------------------------------------------------------------
*/
var usernameFields = 'auth.local.username auth.facebook.displayName auth.facebook.givenName auth.facebook.familyName auth.facebook.name';
var partyFields = 'profile preferences items stats achievements party backer ' + usernameFields;
/**
* Get groups. If req.query.type privided, returned as an array (so ngResource can use). If not, returned as
* object {guilds, public, party, tavern}. req.query.type can be comma-separated `type=guilds,party`
@@ -25,7 +28,7 @@ var api = module.exports;
*/
api.getGroups = function(req, res, next) {
var user = res.locals.user;
var usernameFields = 'auth.local.username auth.facebook.displayName auth.facebook.givenName auth.facebook.familyName auth.facebook.name';
var type = req.query.type && req.query.type.split(',');
// First get all groups
@@ -37,7 +40,7 @@ api.getGroups = function(req, res, next) {
.populate({
path: 'members',
//match: {_id: {$ne: user._id}}, //fixme this causes it to hang??
select: 'profile preferences items stats achievements party backer ' + usernameFields
select: partyFields
})
.exec(cb);
},
@@ -58,8 +61,10 @@ api.getGroups = function(req, res, next) {
if (err) return res.json(500, {err: err});
// Remove self from party (see above failing `match` directive in `populate`
if (results.party) {
var i = _.findIndex(results.party.members, {_id:user._id});
if (~i) results.party.members.splice(i,1);
}
// Sort public groups by members length (not easily doable in mongoose)
results.public = _.sortBy(results.public, function(group){
@@ -173,7 +178,11 @@ api.invite = function(req, res, next) {
//req.body.type in 'guild', 'party'
invite.invitations.party = {id:group._id, name: group.name}
invite.save();
Group.findById(group._id)
.populate('members', partyFields).exec(function(err, saved){
res.json(group);
});
}
});
}

View File

@@ -19,7 +19,7 @@ div(ng-controller='GroupsCtrl')
// {#with _user.invitations.party as :party}
h2 You're Invited To {{user.invitations.party.name}}
a.btn.btn-success(data-type='party', ng-click='join(user.invitations.party)') Accept
a.btn.btn-danger(x-bind='click:rejectInvitation') Reject
a.btn.btn-danger(ng-click='reject(group)') Reject
// {/}
div(ng-hide='user.invitations.party', ng-controller='PartyCtrl')
h2 Create A Party