adds automatic recount to admin poll and paginates recounts
This commit is contained in:
@@ -2,7 +2,10 @@ class Admin::Poll::RecountsController < Admin::BaseController
|
|||||||
before_action :load_poll
|
before_action :load_poll
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts)
|
@booth_assignments = @poll.booth_assignments.
|
||||||
|
includes(:booth, :recounts, :final_recounts, :voters).
|
||||||
|
order(created_at: :desc).
|
||||||
|
page(params[:page]).per(50)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -4,4 +4,12 @@ module PollRecountsHelper
|
|||||||
recounts.select {|r| r.date == date}.first
|
recounts.select {|r| r.date == date}.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def booth_assignment_sum_recounts(ba)
|
||||||
|
ba.recounts.any? ? ba.recounts.to_a.sum(&:count) : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def booth_assignment_sum_final_recounts(ba)
|
||||||
|
ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) :nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -14,32 +14,45 @@
|
|||||||
<th><%= t("admin.recounts.index.table_booth_name") %></th>
|
<th><%= t("admin.recounts.index.table_booth_name") %></th>
|
||||||
<th class="text-center"><%= t("admin.recounts.index.table_recounts") %></th>
|
<th class="text-center"><%= t("admin.recounts.index.table_recounts") %></th>
|
||||||
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
|
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
|
||||||
|
<th class="text-center"><%= t("admin.recounts.index.table_system_count") %></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @booth_assignments.each do |booth_assignment| %>
|
<% @booth_assignments.each do |booth_assignment| %>
|
||||||
|
<% recount = booth_assignment_sum_recounts(booth_assignment) %>
|
||||||
|
<% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %>
|
||||||
|
<% system_count = booth_assignment.voters.size %>
|
||||||
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
|
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
|
||||||
<td>
|
<td>
|
||||||
<strong>
|
<strong>
|
||||||
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
|
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
|
||||||
</strong>
|
</strong>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center <%= 'count-error' if recount.to_i != system_count %>">
|
||||||
<% if booth_assignment.recounts.any? %>
|
<% if recount.present? %>
|
||||||
<%= booth_assignment.recounts.to_a.sum(&:count) %>
|
<%= recount %>
|
||||||
|
<% else %>
|
||||||
|
<span>-</span>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="text-center <%= 'count-error' if final_recount.to_i != system_count %>">
|
||||||
|
<% if final_recount.present? %>
|
||||||
|
<strong><%= final_recount %></strong>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span>-</span>
|
<span>-</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<% if booth_assignment.final_recounts.any? %>
|
<% if system_count.present? %>
|
||||||
<strong><%= booth_assignment.final_recounts.to_a.sum(&:count) %></strong>
|
<strong><%= system_count %></strong>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span>-</span>
|
<span>0</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @booth_assignments %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
@@ -381,6 +381,7 @@ en:
|
|||||||
table_booth_name: "Booth"
|
table_booth_name: "Booth"
|
||||||
table_recounts: "Accumulated daily recounts (by officer)"
|
table_recounts: "Accumulated daily recounts (by officer)"
|
||||||
table_final_recount: "Final recount (by officer)"
|
table_final_recount: "Final recount (by officer)"
|
||||||
|
table_system_count: "Votes (automatic)"
|
||||||
results:
|
results:
|
||||||
index:
|
index:
|
||||||
title: "Results"
|
title: "Results"
|
||||||
|
|||||||
@@ -381,6 +381,7 @@ es:
|
|||||||
table_booth_name: "Urna"
|
table_booth_name: "Urna"
|
||||||
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
|
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
|
||||||
table_final_recount: "Recuento final (presidente de mesa)"
|
table_final_recount: "Recuento final (presidente de mesa)"
|
||||||
|
table_system_count: "Votos (automático)"
|
||||||
results:
|
results:
|
||||||
index:
|
index:
|
||||||
title: "Resultados"
|
title: "Resultados"
|
||||||
|
|||||||
@@ -258,6 +258,9 @@ feature 'Admin polls' do
|
|||||||
date: poll.starts_at + i.days,
|
date: poll.starts_at + i.days,
|
||||||
count: 21) }
|
count: 21) }
|
||||||
|
|
||||||
|
2.times { create(:poll_voter,
|
||||||
|
booth_assignment: booth_assignment_final_recounted) }
|
||||||
|
|
||||||
create(:poll_recount,
|
create(:poll_recount,
|
||||||
booth_assignment: booth_assignment_recounted,
|
booth_assignment: booth_assignment_recounted,
|
||||||
date: poll.ends_at,
|
date: poll.ends_at,
|
||||||
@@ -290,6 +293,7 @@ feature 'Admin polls' do
|
|||||||
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
|
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
|
||||||
expect(page).to have_content('-')
|
expect(page).to have_content('-')
|
||||||
expect(page).to have_content('55555')
|
expect(page).to have_content('55555')
|
||||||
|
expect(page).to have_content('2')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user