Przeglądaj źródła

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 lat temu
rodzic
commit
5462ba9c1d

+ 5 - 0
app/models/activity.rb

@@ -76,6 +76,11 @@ class Activity < ApplicationRecord
76 76
     )
77 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 84
   # Determine whether the passed Person may change this activity.
80 85
   def may_change?(person)
81 86
     person.is_admin ||

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

@@ -0,0 +1,13 @@
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,14 +1,16 @@
1 1
 <h2><%= @activity.public_name %></h2>
2 2
 
3 3
 <ul>
4
+  <% if @activity.secret_name %>
4 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 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 14
 <table class="table table-bordered">
13 15
   <% @activity.participants.each do |p| %>
14 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,7 +66,10 @@
66 66
                 %tr
67 67
                   %td
68 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 74
   .row
72 75
     .col-md-12