Skip to content

Commit

Permalink
Show progress bars in public lottery draw page
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Nov 27, 2023
1 parent 8fcdde6 commit 755607b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
3 changes: 2 additions & 1 deletion app/models/lottery_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def withdrawn_entrants
private

def broadcast_lottery_draw_header
broadcast_replace_to self, :lottery_draw_header, target: "draw_tickets_header_lottery_division_#{id}", partial: "lottery_divisions/draw_tickets_header", locals: {division: self}
broadcast_replace_to self, :lottery_draw_header, target: "draw_tickets_header_lottery_division_#{id}", partial: "lottery_divisions/draw_tickets_header", locals: { division: self }
broadcast_replace_to self, :lottery_header, target: "lottery_header_lottery_division_#{id}", partial: "lottery_divisions/tickets_progress_bars", locals: { division: self, show_pre_selected: false }
end

def ordered_drawn_entrants
Expand Down
10 changes: 10 additions & 0 deletions app/views/lotteries/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
</div>
<% end %>

<div class="row">
<% @presenter.ordered_divisions.each do |division| %>
<%= turbo_stream_from division, :lottery_header, class: "d-none" %>
<div class="col-12 col-md-6 col-lg-4 col-xl">
<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { division: division, show_pre_selected: false } %>
</div>
<% end %>
</div>
<hr/>

<div id="lottery_draws">
<%= render partial: "lottery_draws/lottery_draw", collection: @presenter.lottery_draws_ordered %>
</div>
Expand Down
39 changes: 2 additions & 37 deletions app/views/lottery_divisions/_draw_tickets_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,6 @@
</div>
</div>

<div class="card mt-3">
<div class="card-body">
<div class="row">
<div class="col-8">
<h6 class="fw-bold">Accepted</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.accepted_entrants.count}/#{division.maximum_entries})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_entries, current_value: division.accepted_entrants.count, color: "success") %>
</div>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Wait List</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.wait_list_entrants.count}/#{division.maximum_wait_list})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_wait_list, current_value: division.wait_list_entrants.count, color: "warning") %>
</div>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Pre-selected</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.entrants.pre_selected.drawn.count}/#{division.entrants.pre_selected.count})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.entrants.pre_selected.count, current_value: division.entrants.pre_selected.drawn.count, color: "secondary") %>
</div>
</div>
</div>
<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { division: division, show_pre_selected: true} %>

</div>
41 changes: 41 additions & 0 deletions app/views/lottery_divisions/_tickets_progress_bars.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%# locals: (division:, show_pre_selected:) -%>

<div id="<%= dom_id(division, :lottery_header) %>" class="card mt-3">
<div class="card-body">
<div class="row">
<div class="col-8">
<h6 class="fw-bold">Accepted</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.accepted_entrants.count}/#{division.maximum_entries})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_entries, current_value: division.accepted_entrants.count, color: "success") %>
</div>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Wait List</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.wait_list_entrants.count}/#{division.maximum_wait_list})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_wait_list, current_value: division.wait_list_entrants.count, color: "warning") %>
</div>
<% if show_pre_selected %>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Pre-selected</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.entrants.pre_selected.drawn.count}/#{division.entrants.pre_selected.count})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.entrants.pre_selected.count, current_value: division.entrants.pre_selected.drawn.count, color: "secondary") %>
</div>
<% end %>
</div>
</div>

0 comments on commit 755607b

Please sign in to comment.