@@ -26,9 +26,10 class GroupsController < ApplicationController | |||
|
26 | 26 | |
|
27 | 27 | def index |
|
28 | 28 | @groups = Group.sorted.all |
|
29 | ||
|
30 | 29 | respond_to do |format| |
|
31 | format.html | |
|
30 | format.html { | |
|
31 | @user_count_by_group_id = user_count_by_group_id | |
|
32 | } | |
|
32 | 33 | format.api |
|
33 | 34 | end |
|
34 | 35 | end |
@@ -138,4 +139,12 class GroupsController < ApplicationController | |||
|
138 | 139 | rescue ActiveRecord::RecordNotFound |
|
139 | 140 | render_404 |
|
140 | 141 | end |
|
142 | ||
|
143 | def user_count_by_group_id | |
|
144 | h = User.joins(:groups).group('group_id').count | |
|
145 | h.keys.each do |key| | |
|
146 | h[key.to_i] = h.delete(key) | |
|
147 | end | |
|
148 | h | |
|
149 | end | |
|
141 | 150 | end |
@@ -3,7 +3,6 | |||
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <%= title l(:label_group_plural) %> |
|
6 | ||
|
7 | 6 | <% if @groups.any? %> |
|
8 | 7 | <table class="list groups"> |
|
9 | 8 | <thead><tr> |
@@ -13,9 +12,9 | |||
|
13 | 12 | </tr></thead> |
|
14 | 13 | <tbody> |
|
15 | 14 | <% @groups.each do |group| %> |
|
16 | <tr class="<%= cycle 'odd', 'even' %>"> | |
|
15 | <tr id="group-<%= group.id %>" class="<%= cycle 'odd', 'even' %>"> | |
|
17 | 16 | <td class="name"><%= link_to h(group), edit_group_path(group) %></td> |
|
18 | <td><%= group.users.size %></td> | |
|
17 | <td class="user_count"><%= @user_count_by_group_id[group.id] || 0 %></td> | |
|
19 | 18 | <td class="buttons"><%= delete_link group %></td> |
|
20 | 19 | </tr> |
|
21 | 20 | <% end %> |
@@ -30,6 +30,12 class GroupsControllerTest < ActionController::TestCase | |||
|
30 | 30 | assert_template 'index' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | def test_index_should_show_user_count | |
|
34 | get :index | |
|
35 | assert_response :success | |
|
36 | assert_select 'tr#group-11 td.user_count', :text => '1' | |
|
37 | end | |
|
38 | ||
|
33 | 39 | def test_show |
|
34 | 40 | get :show, :id => 10 |
|
35 | 41 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now