mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
Include members count on groups page.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.GroupController = Discourse.ObjectController.extend({
|
Discourse.GroupController = Discourse.ObjectController.extend({
|
||||||
postsCount: null,
|
counts: null,
|
||||||
|
|
||||||
// It would be nice if bootstrap marked action lists as selected when their links
|
// It would be nice if bootstrap marked action lists as selected when their links
|
||||||
// were 'active' not the `li` tags.
|
// were 'active' not the `li` tags.
|
||||||
|
@ -154,9 +154,9 @@ Discourse.Group.reopenClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
findPostsCount: function(name) {
|
findGroupCounts: function(name) {
|
||||||
return Discourse.ajax("/groups/" + name + "/posts_count.json").then(function(g) {
|
return Discourse.ajax("/groups/" + name + "/counts.json").then(function (result) {
|
||||||
return g.posts_count;
|
return Em.Object.create(result.counts);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -14,15 +14,15 @@ Discourse.GroupRoute = Discourse.Route.extend({
|
|||||||
|
|
||||||
afterModel: function(model) {
|
afterModel: function(model) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.Group.findPostsCount(model.get('name')).then(function (c) {
|
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
|
||||||
self.set('postsCount', c);
|
self.set('counts', counts);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
controller.setProperties({
|
controller.setProperties({
|
||||||
model: model,
|
model: model,
|
||||||
postsCount: this.get('postsCount')
|
counts: this.get('counts')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
<ul class='action-list nav-stacked'>
|
<ul class='action-list nav-stacked'>
|
||||||
<li {{bind-attr class="showingIndex:active"}}>
|
<li {{bind-attr class="showingIndex:active"}}>
|
||||||
{{#link-to 'group.index' model}}{{i18n groups.posts}}
|
{{#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}}
|
<span class='fa fa-chevron-right'></span>{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
<li {{bind-attr class="showingMembers:active"}}>
|
<li {{bind-attr class="showingMembers:active"}}>
|
||||||
{{#link-to 'group.members' model}}{{i18n groups.members}}
|
{{#link-to 'group.members' model}}{{i18n groups.members}}
|
||||||
|
<span class='count'>({{counts.members}})</span>
|
||||||
<span class='fa fa-chevron-right'></span>{{/link-to}}
|
<span class='fa fa-chevron-right'></span>{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -6,10 +6,11 @@ class GroupsController < ApplicationController
|
|||||||
render_serialized(group, BasicGroupSerializer)
|
render_serialized(group, BasicGroupSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts_count
|
def counts
|
||||||
group = Group.where(name: params.require(:group_id)).first
|
group = Group.where(name: params.require(:group_id)).first
|
||||||
guardian.ensure_can_see!(group)
|
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
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
|
@ -192,7 +192,7 @@ Discourse::Application.routes.draw do
|
|||||||
resources :groups do
|
resources :groups do
|
||||||
get 'members'
|
get 'members'
|
||||||
get 'posts'
|
get 'posts'
|
||||||
get 'posts_count'
|
get 'counts'
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :posts do
|
resources :posts do
|
||||||
|
@ -18,17 +18,17 @@ describe GroupsController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "posts_count" do
|
describe "counts" do
|
||||||
it "ensures the group can be seen" do
|
it "ensures the group can be seen" do
|
||||||
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
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
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "performs the query and responds with JSON" do
|
it "performs the query and responds with JSON" do
|
||||||
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
||||||
Group.any_instance.expects(:posts_for).returns(Group.none)
|
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
|
response.should be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user