diff --git a/app/models/lottery_entrant.rb b/app/models/lottery_entrant.rb index 6cee157fe..6d2cc18fa 100644 --- a/app/models/lottery_entrant.rb +++ b/app/models/lottery_entrant.rb @@ -39,6 +39,8 @@ class LotteryEntrant < ApplicationRecord validates_presence_of :first_name, :last_name, :gender, :number_of_tickets validates_with ::LotteryEntrantUniqueValidator + # @param [String] param + # @return [ActiveRecord::Relation] def self.search(param) return all unless param.present? return none unless param.size > 2 @@ -46,6 +48,8 @@ def self.search(param) search_names_and_locations(param) end + # @param [String] param + # @return [ActiveRecord::Relation] def self.search_default_none(param) return none unless param && param.size > 2 @@ -56,6 +60,7 @@ def self.search_default_none(param) delegate :organization, to: :lottery delegate :draw_status, :accepted?, :waitlisted?, to: :division_ranking + # @return [String] def division_name if attributes.key?("division_name") attributes["division_name"] @@ -73,14 +78,17 @@ def draw_ticket! lottery.create_draw_for_ticket!(selected_ticket) end + # @return [Boolean] def drawn? tickets.joins(:draw).exists? end + # @return [Boolean] def service_completed? service_detail.present? && service_detail.completed_date? end + # @return [String] def to_s full_name end @@ -88,6 +96,7 @@ def to_s private # Needed to keep PersonalInfo#bio from breaking + # @return [nil] def current_age_approximate nil end diff --git a/app/presenters/lottery_presenter.rb b/app/presenters/lottery_presenter.rb index fbfa42112..1482c17df 100644 --- a/app/presenters/lottery_presenter.rb +++ b/app/presenters/lottery_presenter.rb @@ -16,10 +16,12 @@ def initialize(lottery, view_context) @params = view_context.prepared_params end + # @return [ActiveRecord::Relation] def ordered_divisions @ordered_divisions ||= divisions.ordered_by_name end + # @return [ActiveRecord::Relation] def lottery_draws_ordered lottery_draws .with_sortable_entrant_attributes @@ -27,10 +29,11 @@ def lottery_draws_ordered .most_recent_first end + # @return [ActiveRecord::Relation] def lottery_entrants_default_none unfiltered_entrants = lottery.entrants .with_division_name - .includes(:division) + .includes(:division, :division_ranking) entrant_id = params[:entrant_id] if entrant_id.present? @@ -40,18 +43,22 @@ def lottery_entrants_default_none end end + # @return [ActiveRecord::Relation] def lottery_entrants_paginated - @lottery_entrants_paginated ||= lottery_entrants_filtered.paginate(page: page, per_page: per_page).to_a + @lottery_entrants_paginated ||= lottery_entrants_filtered.paginate(page: page, per_page: per_page) end + # @return [String, nil] def next_page_url view_context.url_for(request.params.merge(page: page + 1)) if records_from_context_count == per_page end + # @return [ActiveRecord::Relation] def partners @partners ||= lottery.partners.order(:name) end + # @return [ActiveRecord::Relation, ActiveRecord::Relation] def records_from_context case display_style when "entrants" @@ -59,14 +66,16 @@ def records_from_context when "draws" lottery_draws else - [] + lottery_draws.none end end + # @return [Integer] def records_from_context_count @records_from_context_count ||= records_from_context.size end + # @return [Hash{String->Array}] def stats @stats ||= ::LotteryDivisionTicketStat.where(lottery: lottery).order(:division_name, :number_of_tickets).group_by(&:division_name) end @@ -88,14 +97,17 @@ def stats_chart_data(division_stats) ] end + # @return [Boolean] def viewable_results? lottery.live? || lottery.finished? || current_user&.authorized_for_lotteries?(lottery) end + # @return [String (frozen)] def display_style params[:display_style].presence || default_display_style end + # @return [String (frozen)] def default_display_style case status when "preview" then "entrants" @@ -105,14 +117,17 @@ def default_display_style end end + # @return [Partner, nil] def partner_with_banner @partner_with_banner ||= lottery.pick_partner_with_banner end + # @return [Boolean] def show_partner_banners? lottery.live? && partner_with_banner.present? end + # @return [Boolean] def tickets_not_generated? @tickets_not_generated ||= lottery_tickets.empty? end @@ -122,9 +137,10 @@ def tickets_not_generated? attr_reader :view_context delegate :current_user, :request, to: :view_context, private: true + # @return [ActiveRecord::Relation] def lottery_entrants_filtered lottery_entrants - .includes([:division_ranking, division: { lottery: :organization }]) + .includes([:division_ranking, :service_detail, division: { lottery: :organization }]) .search(search_text) .order(:last_name) end diff --git a/app/views/lotteries/_pre_selected_entrants_card.html.erb b/app/views/lotteries/_pre_selected_entrants_card.html.erb index 48cc02621..174da6e2d 100644 --- a/app/views/lotteries/_pre_selected_entrants_card.html.erb +++ b/app/views/lotteries/_pre_selected_entrants_card.html.erb @@ -24,7 +24,7 @@
- <%= render partial: "lottery_entrants/lottery_entrant_admin", collection: presenter.lottery_entrants.pre_selected, as: :record %> + <%= render partial: "lottery_entrants/lottery_entrant_admin", collection: presenter.lottery_entrants.pre_selected.includes(:division_ranking), as: :record %>
diff --git a/app/views/lotteries/_results.html.erb b/app/views/lotteries/_results.html.erb index 55a73c6a8..b6e9d9833 100644 --- a/app/views/lotteries/_results.html.erb +++ b/app/views/lotteries/_results.html.erb @@ -7,25 +7,25 @@

<%= "#{division.name}" %>

Accepted
- <% if division.accepted_entrants.present? %> + <% if division.accepted_entrants.any? %>
    - <%= render partial: "entrant_for_results", collection: division.accepted_entrants, as: :entrant %> + <%= render partial: "entrant_for_results", collection: division.accepted_entrants.includes(:service_detail), as: :entrant %>
<% else %>

No entrants have been drawn yet

<% end %> - <% if division.waitlisted_entrants.present? %> + <% if division.waitlisted_entrants.any? %>
Wait List
    - <%= render partial: "entrant_for_results", collection: division.waitlisted_entrants, as: :entrant %> + <%= render partial: "entrant_for_results", collection: division.waitlisted_entrants.includes(:service_detail), as: :entrant %>
<% end %> - <% if division.withdrawn_entrants.present? %> + <% if division.withdrawn_entrants.any? %>
Withdrawn
    - <%= render partial: "entrant_for_results", collection: division.withdrawn_entrants, as: :entrant %> + <%= render partial: "entrant_for_results", collection: division.withdrawn_entrants.includes(:service_detail), as: :entrant %>
<% end %>
diff --git a/app/views/lotteries/manage_entrants.html.erb b/app/views/lotteries/manage_entrants.html.erb index 281b7921b..dd0e08274 100644 --- a/app/views/lotteries/manage_entrants.html.erb +++ b/app/views/lotteries/manage_entrants.html.erb @@ -5,22 +5,22 @@ <%= render "lotteries/header", presenter: @presenter, breadcrumbs: ["Manage Entrants"] %>
- <% if @presenter.lottery_draws.present? %> + <% if @presenter.lottery_draws.any? %> <% @presenter.ordered_divisions.each do |division| %>

<%= "#{division.name}" %>

Accepted
- <%= render partial: "manage_entrants_table", locals: { entrants: division.accepted_entrants } %> + <%= render partial: "manage_entrants_table", locals: { entrants: division.accepted_entrants.includes(:service_detail) } %> - <% if division.waitlisted_entrants.present? %> + <% if division.waitlisted_entrants.any? %>
Wait List
- <%= render partial: "manage_entrants_table", locals: { entrants: division.waitlisted_entrants } %> + <%= render partial: "manage_entrants_table", locals: { entrants: division.waitlisted_entrants.includes(:service_detail) } %> <% end %> - <% if division.withdrawn_entrants.present? %> + <% if division.withdrawn_entrants.any? %>
Withdrawn
- <%= render partial: "manage_entrants_table", locals: { entrants: division.withdrawn_entrants } %> + <%= render partial: "manage_entrants_table", locals: { entrants: division.withdrawn_entrants.includes(:service_detail) } %> <% end %>
diff --git a/app/views/lotteries/setup.html.erb b/app/views/lotteries/setup.html.erb index 510fe2cd7..a9a05d391 100644 --- a/app/views/lotteries/setup.html.erb +++ b/app/views/lotteries/setup.html.erb @@ -165,7 +165,9 @@
<% if @presenter.lottery_entrants_default_none.present? %> - <%= render partial: "lottery_entrants/lottery_entrant_admin", collection: @presenter.lottery_entrants_default_none, as: :record %> + <%= render partial: "lottery_entrants/lottery_entrant_admin", + collection: @presenter.lottery_entrants_default_none, + as: :record %> <% else %>