diff --git a/migrations/20131028_task_subdocs_tags_invites.js b/migrations/20131028_task_subdocs_tags_invites.js index 19ce289e83..55913562ea 100644 --- a/migrations/20131028_task_subdocs_tags_invites.js +++ b/migrations/20131028_task_subdocs_tags_invites.js @@ -67,4 +67,7 @@ db.groups.find().forEach(function(group){ $set:{memberCount: _.size(group.members)}, $pull:{challenges:1} }) -}); \ No newline at end of file +}); + +// HabitRPG => Tavern +db.groups.update({_id:'habitrpg'}, {$set:{name:'Tavern'}}); \ No newline at end of file diff --git a/public/js/controllers/challengesCtrl.js b/public/js/controllers/challengesCtrl.js index 6ecce55fad..0b523d248a 100644 --- a/public/js/controllers/challengesCtrl.js +++ b/public/js/controllers/challengesCtrl.js @@ -1,14 +1,13 @@ "use strict"; -habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', - function($scope, User, Challenges, Notification, $compile, Groups, $state) { +habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', 'API_URL', '$http', + function($scope, User, Challenges, Notification, $compile, Groups, $state, API_URL, $http) { // FIXME get this from cache - Groups.Group.query(function(groups){ - groups.tavern[0].name = 'Tavern'; - $scope.groups = groups.party.concat(groups.guilds).concat(groups.tavern); + Groups.Group.query({type:'party,guilds,tavern'}, function(groups){ + $scope.groups = groups; $scope.search = { - group: _.reduce($scope.groups, function(m,g){m[g._id]=true;return m;}, {}) + group: _.reduce(groups, function(m,g){m[g._id]=true;return m;}, {}) }; }); // FIXME $scope.challenges needs to be resolved first (see app.js) diff --git a/public/js/services/groupServices.js b/public/js/services/groupServices.js index ca820d7e5b..191ddbdfe7 100644 --- a/public/js/services/groupServices.js +++ b/public/js/services/groupServices.js @@ -42,19 +42,20 @@ angular.module('groupServices', ['ngResource']). // Note the _.once() to make sure it can never be called again fetchGuilds: _.once(function(){ + //TODO combine these as {type:'guilds,public'} and create a $filter() to separate them Group.query({type:'guilds'}, function(_groups){ guildsQ.resolve(_groups); - Members.populate(_groups); + //Members.populate(_groups); }); Group.query({type:'public'}, function(_groups){ publicQ.resolve(_groups); - Members.populate(_groups); + //Members.populate(_groups); }); }), fetchTavern: _.once(function(){ - Group.get({gid:'habitrpg'}, function(tavern){ - tavernQ.resolve(tavern); + Group.get({gid:'habitrpg'}, function(_groups){ + tavernQ.resolve(_groups[0]); }) }), diff --git a/src/controllers/groups.js b/src/controllers/groups.js index bc4e5311de..8ca641c1b1 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -41,7 +41,7 @@ api.list = function(req, res) { var user = res.locals.user; var groupFields = 'name description memberCount'; var sort = '-memberCount'; - var type = (req.query.type || 'party,guilds,public,tavern').split(','); + var type = req.query.type || 'party,guilds,public,tavern'; async.parallel({ @@ -88,15 +88,15 @@ api.list = function(req, res) { }, function(err, results){ if (err) return res.json(500, {err: err}); - - // If they're requesting a specific type, let's return it as an array so that $ngResource - // can utilize it properly - if (req.query.type) { - results = _.reduce(type, function(m,t){ - return m.concat(_.isArray(results[t]) ? results[t] : [results[t]]); - }, []); - } - res.json(results); + // ngResource expects everything as arrays. We used to send it down as a structured object: {public:[], party:{}, guilds:[], tavern:{}} + // but unfortunately ngResource top-level attrs are considered the ngModels in the list, so we had to do weird stuff and multiple + // requests to get it to work properly. Instead, we're not depending on the client to do filtering / organization, and we're + // just sending down a merged array. Revisit + var arr = _.reduce(results, function(m,v){ + if (_.isEmpty(v)) return m; + return m.concat(_.isArray(v) ? v : [v]); + }, []) + res.json(arr); }) };