Browse Source

Clean up activity.show template, better counts

Maarten van den Berg 8 years ago
parent
commit
28b22588ef
2 changed files with 11 additions and 2 deletions
  1. 6 0
      app/controllers/activities_controller.rb
  2. 5 2
      app/views/activities/show.html.erb

+ 6 - 0
app/controllers/activities_controller.rb

13
   # GET /activities/1
13
   # GET /activities/1
14
   # GET /activities/1.json
14
   # GET /activities/1.json
15
   def show
15
   def show
16
+    @participants = @activity.participants
17
+      .joins(:person)
18
+      .order(attending: :desc)
19
+      .order('people.first_name ASC')
20
+    @counts = @activity.state_counts
21
+    @num_participants = @counts.values.sum
16
   end
22
   end
17
 
23
 
18
   # GET /activities/new
24
   # GET /activities/new

+ 5 - 2
app/views/activities/show.html.erb

10
   <li>Deadline: <%= @activity.deadline %></li>
10
   <li>Deadline: <%= @activity.deadline %></li>
11
 </ul>
11
 </ul>
12
 
12
 
13
-<h2>Participants (<%= @activity.participants.count %> <%= render partial: "state_counts", locals: {counts:@activity.state_counts}%>)</h2>
13
+<h2>
14
+  <%= @num_participants %> participants
15
+  <%= render partial: "state_counts", locals: {counts:@counts}%>
16
+</h2>
14
 <table class="table table-bordered">
17
 <table class="table table-bordered">
15
-  <% @activity.participants.each do |p| %>
18
+  <% @participants.each do |p| %>
16
     <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">
19
     <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">
17
       <td>
20
       <td>
18
         <%= p.person.full_name %>
21
         <%= p.person.full_name %>