Include members count on groups page.

This commit is contained in:
Robin Ward 2014-02-18 16:17:04 -05:00
parent 535c6b272f
commit f19b0b5fe0
7 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,7 @@
@module Discourse
**/
Discourse.GroupController = Discourse.ObjectController.extend({
postsCount: null,
counts: null,
// It would be nice if bootstrap marked action lists as selected when their links
// were 'active' not the `li` tags.

View File

@ -154,9 +154,9 @@ Discourse.Group.reopenClass({
});
},
findPostsCount: function(name) {
return Discourse.ajax("/groups/" + name + "/posts_count.json").then(function(g) {
return g.posts_count;
findGroupCounts: function(name) {
return Discourse.ajax("/groups/" + name + "/counts.json").then(function (result) {
return Em.Object.create(result.counts);
});
},

View File

@ -14,15 +14,15 @@ Discourse.GroupRoute = Discourse.Route.extend({
afterModel: function(model) {
var self = this;
return Discourse.Group.findPostsCount(model.get('name')).then(function (c) {
self.set('postsCount', c);
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
self.set('counts', counts);
});
},
setupController: function(controller, model) {
controller.setProperties({
model: model,
postsCount: this.get('postsCount')
counts: this.get('counts')
});
}
});

View File

@ -3,11 +3,12 @@
<ul class='action-list nav-stacked'>
<li {{bind-attr class="showingIndex:active"}}>
{{#link-to 'group.index' model}}{{i18n groups.posts}}
<span class='count'>({{postsCount}})</span>
<span class='count'>({{counts.posts}})</span>
<span class='fa fa-chevron-right'></span>{{/link-to}}
</li>
<li {{bind-attr class="showingMembers:active"}}>
{{#link-to 'group.members' model}}{{i18n groups.members}}
<span class='count'>({{counts.members}})</span>
<span class='fa fa-chevron-right'></span>{{/link-to}}
</li>
</ul>

View File

@ -6,10 +6,11 @@ class GroupsController < ApplicationController
render_serialized(group, BasicGroupSerializer)
end
def posts_count
def counts
group = Group.where(name: params.require(:group_id)).first
guardian.ensure_can_see!(group)
render json: {posts_count: group.posts_for(guardian).count}
render json: {counts: { posts: group.posts_for(guardian).count,
members: group.users.count } }
end
def posts

View File

@ -192,7 +192,7 @@ Discourse::Application.routes.draw do
resources :groups do
get 'members'
get 'posts'
get 'posts_count'
get 'counts'
end
resources :posts do

View File

@ -18,17 +18,17 @@ describe GroupsController do
end
end
describe "posts_count" do
describe "counts" do
it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
xhr :get, :posts_count, group_id: group.name
xhr :get, :counts, group_id: group.name
response.should_not be_success
end
it "performs the query and responds with JSON" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
Group.any_instance.expects(:posts_for).returns(Group.none)
xhr :get, :posts_count, group_id: group.name
xhr :get, :counts, group_id: group.name
response.should be_success
end
end