Browse Source

State counts, null-hiding

- Add method for quickly counting present, unknown and absent
participants for an activity.
- Add partial for these counts (needs css)
- Hide some null attributes in activities
Maarten van den Berg 8 years ago
parent
commit
5462ba9c1d

+ 5 - 0
app/models/activity.rb

76
     )
76
     )
77
   end
77
   end
78
 
78
 
79
+  # Query the database to determine the amount of participants that are present/absent/unknown
80
+  def state_counts
81
+    self.participants.group(:attending).count
82
+  end
83
+
79
   # Determine whether the passed Person may change this activity.
84
   # Determine whether the passed Person may change this activity.
80
   def may_change?(person)
85
   def may_change?(person)
81
     person.is_admin ||
86
     person.is_admin ||

+ 13 - 0
app/views/activities/_state_counts.html.haml

1
+(
2
+%span.state-count.present-count
3
+  = counts[true]
4
+  P
5
+,
6
+%span.state-count.unknown-count
7
+  = counts[nil]
8
+  ?
9
+,
10
+%span.state-count.absent-count
11
+  = counts[false]
12
+  A
13
+)

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

1
 <h2><%= @activity.public_name %></h2>
1
 <h2><%= @activity.public_name %></h2>
2
 
2
 
3
 <ul>
3
 <ul>
4
+  <% if @activity.secret_name %>
4
   <li>Secretly <%= @activity.secret_name %></li>
5
   <li>Secretly <%= @activity.secret_name %></li>
5
-  <li><%= @activity.description %></li>
6
-  <li><%= @activity.location %></li>
7
-  <li><%= @activity.start %> - <%= @activity.end %></li>
8
-  <li>Deadline <%= @activity.deadline %></li>
6
+  <% end %>
7
+  <li>Description:<%= @activity.description %></li>
8
+  <li>Location:<%= @activity.location %></li>
9
+  <li>Start: <%= @activity.start %> - <%= @activity.end %></li>
10
+  <li>Deadline: <%= @activity.deadline %></li>
9
 </ul>
11
 </ul>
10
 
12
 
11
-<h2>Participants (<%= @activity.participants.count %>)</h2>
13
+<h2>Participants (<%= @activity.participants.count %> <%= render partial: "state_counts", locals: {counts:@activity.state_counts}%>)</h2>
12
 <table class="table table-bordered">
14
 <table class="table table-bordered">
13
   <% @activity.participants.each do |p| %>
15
   <% @activity.participants.each do |p| %>
14
     <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">
16
     <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">

+ 4 - 1
app/views/dashboard/home.html.haml

66
                 %tr
66
                 %tr
67
                   %td
67
                   %td
68
                     = link_to group_activity_url(a.group, a) do
68
                     = link_to group_activity_url(a.group, a) do
69
-                      = "#{a.public_name} (#{a.secret_name})"
69
+                      = a.public_name
70
+                      - if a.secret_name
71
+                        = "(#{a.secret_name})"
72
+                      = render partial: "activities/state_counts", locals: {counts: a.state_counts}
70
 
73
 
71
   .row
74
   .row
72
     .col-md-12
75
     .col-md-12