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,6 +13,12 @@ class ActivitiesController < ApplicationController
13 13
   # GET /activities/1
14 14
   # GET /activities/1.json
15 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 22
   end
17 23
 
18 24
   # GET /activities/new

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

@@ -10,9 +10,12 @@
10 10
   <li>Deadline: <%= @activity.deadline %></li>
11 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 17
 <table class="table table-bordered">
15
-  <% @activity.participants.each do |p| %>
18
+  <% @participants.each do |p| %>
16 19
     <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">
17 20
       <td>
18 21
         <%= p.person.full_name %>