adds system recounting to admin booth_assignments

This commit is contained in:
Juanjo Bazán
2017-01-27 15:19:03 +01:00
parent 3d28b317e2
commit e634e80113
4 changed files with 86 additions and 9 deletions

View File

@@ -24,7 +24,8 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
def show
@poll = ::Poll.find(params[:poll_id])
@booth_assignment = @poll.booth_assignments.includes(:recounts, officer_assignments: [officer: [:user]]).find(params[:id])
@booth_assignment = @poll.booth_assignments.includes(:recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
end
private

View File

@@ -0,0 +1,7 @@
module PollRecountsHelper
def recount_for_date(recounts, date)
recounts.select {|r| r.date.to_date == date}.first
end
end

View File

@@ -59,13 +59,23 @@
</tr>
</thead>
<tbody>
<% @booth_assignment.recounts.sort_by{|r| r.date}.each do |recount| %>
<tr id="recount_<%= recount.id %>" class="<%= 'count-error' if recount.count != 0 %>">
<td><%= l recount.date.to_date %></td>
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<% recount = recount_for_date(@booth_assignment.recounts, voting_date) %>
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<% if recount.present? %>
<tr id="recount_<%= recount.id %>" class="<%= 'count-error' if recount.count != system_count %>">
<td><%= l voting_date %></td>
<td class="text-center" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td>
<td class="text-center">0</td>
<td class="text-center"><%= system_count %></td>
</tr>
<% else %>
<tr id="recount_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<td class="text-center" title=""> - </td>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% end %>