From e4e9020e1f4f058f16f68de0c0de813ce406c184 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 30 Jan 2015 15:48:17 -0500 Subject: [PATCH] added groups page to user profile --- public/src/client/groups/list.js | 4 ++-- src/controllers/accounts.js | 23 +++++++++++++++++++++++ src/routes/index.js | 1 + src/views/config.json | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/public/src/client/groups/list.js b/public/src/client/groups/list.js index 0410a9fa17..d0b4c69b50 100644 --- a/public/src/client/groups/list.js +++ b/public/src/client/groups/list.js @@ -8,9 +8,9 @@ define('forum/groups/list', function() { var groupsEl = $('#groups-list'); groupsEl.on('click', '.list-cover', function() { - var groupName = $(this).parents('[data-group]').attr('data-group'); + var groupSlug = $(this).parents('[data-slug]').attr('data-slug'); - ajaxify.go('groups/' + utils.slugify(groupName)); + ajaxify.go('groups/' + groupSlug); }); // Group creation diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 741de9a626..c55977a351 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -233,6 +233,29 @@ accountsController.getTopics = function(req, res, next) { getFromUserSet('account/topics', 'topics', topics.getTopicsFromSet, 'topics', req, res, next); }; +accountsController.getGroups = function(req, res, next) { + var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; + + getBaseUser(req.params.userslug, callerUID, function(err, userData) { + if (err) { + return next(err); + } + + if (!userData) { + return helpers.notFound(req, res); + } + + groups.getUserGroups([userData.uid], function(err, groups) { + if (err) { + return next(err); + } + + userData.groups = groups[0]; + + res.render('account/groups', userData); + }); + }); +}; function getFromUserSet(tpl, set, method, type, req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; diff --git a/src/routes/index.js b/src/routes/index.js index 1af03e0930..f8012c9456 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -68,6 +68,7 @@ function accountRoutes(app, middleware, controllers) { setupPageRoute(app, '/user/:userslug/followers', middleware, middlewares, controllers.accounts.getFollowers); setupPageRoute(app, '/user/:userslug/posts', middleware, middlewares, controllers.accounts.getPosts); setupPageRoute(app, '/user/:userslug/topics', middleware, middlewares, controllers.accounts.getTopics); + setupPageRoute(app, '/user/:userslug/groups', middleware, middlewares, controllers.accounts.getGroups); setupPageRoute(app, '/user/:userslug/favourites', middleware, accountMiddlewares, controllers.accounts.getFavourites); setupPageRoute(app, '/user/:userslug/watched', middleware, accountMiddlewares, controllers.accounts.getWatchedTopics); diff --git a/src/views/config.json b/src/views/config.json index 70997cf4a8..26ae7b692c 100644 --- a/src/views/config.json +++ b/src/views/config.json @@ -14,6 +14,7 @@ "^user/.*/watched": "account/watched", "^user/.*/posts": "account/posts", "^user/.*/topics": "account/topics", + "^user/.*/groups": "account/groups", "^user/[^\/]+": "account/profile", "^reset/.*": "reset_code", "^tags/.*": "tag",