From 9159c1d2c1ce88f1d34ce04df8d685c7717d14dd Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 24 Jun 2015 12:13:37 +0530 Subject: [PATCH 1/2] Fixed audience scope --- app/views/event_attendances/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/event_attendances/index.html.erb b/app/views/event_attendances/index.html.erb index 6b2d3d6d..ce967a51 100644 --- a/app/views/event_attendances/index.html.erb +++ b/app/views/event_attendances/index.html.erb @@ -12,13 +12,13 @@ <%= "Trained?" if @event.training_required?(@audience.to_s) %> 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' %> 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' %> From c63dc4e1d6f9c5f4d72268e031bd35620d2c2bc2 Mon Sep 17 00:00:00 2001 From: Aayush Date: Thu, 2 Jul 2015 11:08:54 +0530 Subject: [PATCH 2/2] Changes in event rsvpd and attended --- app/models/event.rb | 12 ++++++++---- app/models/event_attendance.rb | 1 + app/views/rsvp/_event.html.erb | 2 +- app/views/visits/show.html.erb | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index 521b23ed..44cc71f1 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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. @@ -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) diff --git a/app/models/event_attendance.rb b/app/models/event_attendance.rb index 5516bc22..0273f9f0 100644 --- a/app/models/event_attendance.rb +++ b/app/models/event_attendance.rb @@ -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 diff --git a/app/views/rsvp/_event.html.erb b/app/views/rsvp/_event.html.erb index 6e78775a..bf4af7e9 100644 --- a/app/views/rsvp/_event.html.erb +++ b/app/views/rsvp/_event.html.erb @@ -27,7 +27,7 @@ diff --git a/app/views/visits/show.html.erb b/app/views/visits/show.html.erb index 4cf7009e..ec0884cd 100644 --- a/app/views/visits/show.html.erb +++ b/app/views/visits/show.html.erb @@ -25,9 +25,9 @@ > <%= 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? %> - <%=h @event.attendees.rsvpd(audience).count %> + <%=h @event.attendees.audience(audience).rsvpd.count %> <%=h audience ? @event["#{audience.to_s}_capacity"] : @event[:capacity] %> - <%=h @event.attendees.attended(audience).count %> + <%=h @event.attendees.audience(audience).attended.count %> <%= link_to "Details", event_event_attendances_path(@event, :audience => audience) unless audience.nil? %> <% end -%>