Merge pull request #1885 from consul/chore/remove_final_recounts
Remove Poll Final Recounts, replace with Total Results
This commit is contained in:
@@ -15,7 +15,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
@booth_assignment = @poll.booth_assignments.includes(:final_recounts, :voters,
|
||||
@booth_assignment = @poll.booth_assignments.includes(:total_results, :voters,
|
||||
officer_assignments: [officer: [:user]]).find(params[:id])
|
||||
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
|
||||
@officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer_id])
|
||||
@officer_assignments = ::Poll::OfficerAssignment.
|
||||
joins(:booth_assignment).
|
||||
includes(:final_recounts, booth_assignment: :booth).
|
||||
includes(:total_results, booth_assignment: :booth).
|
||||
where("officer_id = ? AND poll_booth_assignments.poll_id = ?", @officer.id, @poll.id).
|
||||
order(:date)
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ class Admin::Poll::RecountsController < Admin::Poll::BaseController
|
||||
|
||||
def index
|
||||
@booth_assignments = @poll.booth_assignments.
|
||||
includes(:booth, :final_recounts, :voters).
|
||||
includes(:booth, :total_results, :voters).
|
||||
order("poll_booths.name").
|
||||
page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
module OfficingHelper
|
||||
|
||||
def officer_assignments_select_options(officer_assignments)
|
||||
options = []
|
||||
officer_assignments.each do |oa|
|
||||
options << ["#{oa.booth_assignment.booth.name}: #{l(oa.date.to_date, format: :long)}", oa.id]
|
||||
end
|
||||
options_for_select(options)
|
||||
end
|
||||
|
||||
def booths_for_officer_select_options(officer_assignments)
|
||||
options = []
|
||||
officer_assignments.each do |oa|
|
||||
@@ -17,10 +9,6 @@ module OfficingHelper
|
||||
options_for_select(options, params[:oa])
|
||||
end
|
||||
|
||||
def system_recount_to_compare_with_final_recount(final_recount)
|
||||
final_recount.booth_assignment.voters.select {|v| v.created_at.to_date == final_recount.date}.size
|
||||
end
|
||||
|
||||
def answer_result_value(question_id, answer_index)
|
||||
return nil if params.blank?
|
||||
return nil if params[:questions].blank?
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
module PollFinalRecountsHelper
|
||||
|
||||
def final_recount_for_date(final_recounts, date)
|
||||
final_recounts.select {|f| f.date == date}.first
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module PollRecountsHelper
|
||||
|
||||
def booth_assignment_sum_final_recounts(ba)
|
||||
ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) : nil
|
||||
def total_recounts_by_booth(booth_assignment)
|
||||
booth_assignment.total_results.any? ? booth_assignment.total_results.to_a.sum(&:amount) : nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -28,11 +28,6 @@ module PollsHelper
|
||||
options_for_select(options, params[:d])
|
||||
end
|
||||
|
||||
def poll_final_recount_option(poll)
|
||||
final_date = poll.ends_at.to_date + 1.day
|
||||
options_for_select([[I18n.t("polls.final_date"), l(final_date)]])
|
||||
end
|
||||
|
||||
def poll_booths_select_options(poll)
|
||||
options = []
|
||||
poll.booths.each do |booth|
|
||||
@@ -46,4 +41,4 @@ module PollsHelper
|
||||
booth.name + location
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ class Poll
|
||||
belongs_to :poll
|
||||
|
||||
has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
|
||||
has_many :final_recounts, class_name: "Poll::FinalRecount", dependent: :destroy
|
||||
has_many :officers, through: :officer_assignments
|
||||
has_many :voters
|
||||
has_many :partial_results
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
class Poll
|
||||
class FinalRecount < ActiveRecord::Base
|
||||
belongs_to :booth_assignment, class_name: "Poll::BoothAssignment"
|
||||
belongs_to :officer_assignment, class_name: "Poll::OfficerAssignment"
|
||||
|
||||
validates :booth_assignment_id, presence: true
|
||||
validates :date, presence: true, uniqueness: {scope: :booth_assignment_id}
|
||||
validates :count, presence: true, numericality: {only_integer: true}
|
||||
|
||||
before_save :update_logs
|
||||
|
||||
def update_logs
|
||||
if count_changed? && count_was.present?
|
||||
self.count_log += ":#{count_was.to_s}"
|
||||
self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,8 +2,10 @@ class Poll
|
||||
class OfficerAssignment < ActiveRecord::Base
|
||||
belongs_to :officer
|
||||
belongs_to :booth_assignment
|
||||
has_many :final_recounts
|
||||
has_many :partial_results
|
||||
has_many :white_results
|
||||
has_many :null_results
|
||||
has_many :total_results
|
||||
has_many :voters
|
||||
|
||||
validates :officer_id, presence: true
|
||||
|
||||
@@ -49,18 +49,18 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.poll_booth_assignments.show.date") %></th>
|
||||
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_final") %></th>
|
||||
<th class="text-center"><%= t("admin.poll_booth_assignments.show.total_recount") %></th>
|
||||
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_system") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
|
||||
<% final_recount = final_recount_for_date(@booth_assignment.final_recounts, voting_date) %>
|
||||
<% total_recount = @booth_assignment.total_results.where(date: voting_date).first %>
|
||||
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
|
||||
<tr id="recounting_<%= voting_date.strftime('%Y%m%d') %>">
|
||||
<td><%= l voting_date %></td>
|
||||
<% if final_recount.present? %>
|
||||
<td class="text-center <%= 'count-error' if final_recount.count != system_count %>" title="<%= final_recount.officer_assignment.officer.name %>"><%= final_recount.count %></td>
|
||||
<% if total_recount.present? %>
|
||||
<td class="text-center <%= 'count-error' if total_recount.amount != system_count %>" title="<%= total_recount.officer_assignment.officer.name %>"><%= total_recount.amount %></td>
|
||||
<% else %>
|
||||
<td class="text-center" title=""> - </td>
|
||||
<% end %>
|
||||
|
||||
@@ -27,27 +27,24 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
<% final_officer_assignments = @officer_assignments.select{|oa| oa.final == true} %>
|
||||
<% if final_officer_assignments.any? %>
|
||||
<h3><%= t("admin.poll_officer_assignments.by_officer.final_recounts") %></h3>
|
||||
<table id="final_recount_list" class="fixed">
|
||||
<h3><%= t("admin.poll_officer_assignments.by_officer.total_recounts") %></h3>
|
||||
<table id="total_recount_list" class="fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.poll_officer_assignments.by_officer.date") %></th>
|
||||
<th><%= t("admin.poll_officer_assignments.by_officer.booth") %></th>
|
||||
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.final_recount") %></th>
|
||||
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.total_recount") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% final_officer_assignments.each do |officer_assignment| %>
|
||||
<tr id="final_recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
|
||||
<% @officer_assignments.each do |officer_assignment| %>
|
||||
<tr id="total_recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
|
||||
<td><%= l(officer_assignment.date.to_date) %></td>
|
||||
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
|
||||
<td class="text-right">
|
||||
<% if officer_assignment.final_recounts.any? %>
|
||||
<%= officer_assignment.final_recounts.to_a.sum(&:count) %>
|
||||
<% if officer_assignment.total_results.any? %>
|
||||
<%= officer_assignment.total_results.to_a.sum(&:amount) %>
|
||||
<% else %>
|
||||
<span>-</span>
|
||||
<% end %>
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
<table class="fixed margin">
|
||||
<thead>
|
||||
<th><%= t("admin.recounts.index.table_booth_name") %></th>
|
||||
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
|
||||
<th class="text-center"><%= t("admin.recounts.index.table_total_recount") %></th>
|
||||
<th class="text-center"><%= t("admin.recounts.index.table_system_count") %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @booth_assignments.each do |booth_assignment| %>
|
||||
<% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %>
|
||||
<% total_recounts = total_recounts_by_booth(booth_assignment) %>
|
||||
<% system_count = booth_assignment.voters.size %>
|
||||
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
|
||||
<td>
|
||||
@@ -25,9 +25,9 @@
|
||||
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
|
||||
</strong>
|
||||
</td>
|
||||
<td class="text-center <%= 'count-error' if final_recount.to_i != system_count %>">
|
||||
<% if final_recount.present? %>
|
||||
<strong><%= final_recount %></strong>
|
||||
<td class="text-center <%= 'count-error' if total_recounts.to_i != system_count %>">
|
||||
<% if total_recounts.present? %>
|
||||
<strong><%= total_recounts %></strong>
|
||||
<% else %>
|
||||
<span>-</span>
|
||||
<% end %>
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if ["final_recounts", "results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
|
||||
<li <%= "class=active" if ["results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
|
||||
<%= link_to final_officing_polls_path do %>
|
||||
<span class="icon-user"></span>
|
||||
<%= t("officing.menu.final_recounts") %>
|
||||
<%= t("officing.menu.total_recounts") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user