Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed audience scope #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ def attended_count
end

# Returns the number of RSVP'd (for the given audience, if provided)
def rsvpd_count(audience)
attendees.rsvpd(audience).size
def rsvpd_count(audience = nil)
if audience.nil?
attendees.rsvpd.size
else
attendees.audience(audience).rsvpd.size
end
end

# For now, only Visit type events can have attendance options.
Expand All @@ -63,13 +67,13 @@ def capacity(person_or_type = nil)
# If capacity is 0 or nil, this method always returns false.
def full?(person_or_type = nil)
return false if capacity(person_or_type).nil? || capacity(person_or_type) <= 0
attendees.rsvpd(person_or_type).size >= capacity(person_or_type)
attendees.audience(person_or_type).rsvpd.size >= capacity(person_or_type)
end

# How full is this event in percentage.
def percent_full(person_or_type = nil)
return false if capacity(person_or_type).nil? || capacity(person_or_type) <= 0
attendees.rsvpd(person_or_type).size.to_f / capacity(person_or_type).to_f * 100
attendees.audience(person_or_type).rsvpd.size.to_f / capacity(person_or_type).to_f * 100
end

def <=>(o)
Expand Down
1 change: 1 addition & 0 deletions app/models/event_attendance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def update_filter_cache

# Class method to use along with other named scopes to limit results to a specific audience group.
def self.audience(audience_name = Person)
audience_name ||= Person
joins(:person).where(["(audience = :audience) OR (people.type = :audience AND audience IS NULL)", {:audience => audience_name.to_s.classify}])
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/event_attendances/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<%= "<th class='centered'>Trained?</th>" if @event.training_required?(@audience.to_s) %>
<th class="centered">RSVP'd?
<%= link_to "E-mail",
"mailto:#{@event.attendees.rsvpd(@audience).collect{|a| a.email rescue nil }.compact.join(",")}",
"mailto:#{@event.attendees.audience(@audience).rsvpd.collect{|a| a.email rescue nil }.compact.join(",")}",
:class => 'email button',
:id => 'attending_email_link' %>
</th>
<th class="centered">Attended?
<%= link_to "E-mail",
"mailto:#{@event.attendees.attended(@audience).collect{|a| a.email rescue nil }.compact.join(",")}",
"mailto:#{@event.attendees.audience(@audience).attended.collect{|a| a.email rescue nil }.compact.join(",")}",
:class => 'email button',
:id => 'attended_email_link' %>
</th>
Expand Down
2 changes: 1 addition & 1 deletion app/views/rsvp/_event.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
</div>
<div class="signup-numbers">
<%= content_tag :span, event.attendees.rsvpd(event_audience).size %>
<%= content_tag :span, event.attendees.audience(event_audience).rsvpd.size %>
of
<%= content_tag :span, event.capacity(event_audience) %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/visits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<tr <%= "class=total" if audience.nil? %>>
<td><%= audience.nil? ? "Total" : audience.to_s.titleize.pluralize %>
<%= content_tag :span, "not shown", :class => 'outline tag' unless @event["show_for_#{audience.to_s.pluralize}"] || audience.nil? %></td>
<td><%=h @event.attendees.rsvpd(audience).count %></td>
<td><%=h @event.attendees.audience(audience).rsvpd.count %></td>
<td><%=h audience ? @event["#{audience.to_s}_capacity"] : @event[:capacity] %></td>
<td><%=h @event.attendees.attended(audience).count %></td>
<td><%=h @event.attendees.audience(audience).attended.count %></td>
<td class="functions"><%= link_to "Details", event_event_attendances_path(@event, :audience => audience) unless audience.nil? %></td>
</tr>
<% end -%>
Expand Down