Swap Poll White/Null/Total usage for Poll Recount
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(:total_results, :voters,
|
||||
@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
|
||||
|
||||
@@ -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(:total_results, booth_assignment: :booth).
|
||||
includes(:recounts, 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, :total_results, :voters).
|
||||
includes(:booth, :recounts, :voters).
|
||||
order("poll_booths.name").
|
||||
page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
@@ -26,9 +26,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
@partial_results = ::Poll::PartialResult.includes(:question).
|
||||
where(booth_assignment_id: index_params[:booth_assignment_id]).
|
||||
where(date: index_params[:date])
|
||||
@whites = ::Poll::WhiteResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
|
||||
@nulls = ::Poll::NullResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
|
||||
@total = ::Poll::TotalResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
|
||||
@recounts = ::Poll::Recount.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +50,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
go_back_to_new if question.blank?
|
||||
|
||||
results.each_pair do |answer_index, count|
|
||||
next unless count.present?
|
||||
next if count.blank?
|
||||
answer = question.valid_answers[answer_index.to_i]
|
||||
go_back_to_new if question.blank?
|
||||
|
||||
@@ -68,45 +66,21 @@ class Officing::ResultsController < Officing::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
build_white_results
|
||||
build_null_results
|
||||
build_total_results
|
||||
build_recounts
|
||||
end
|
||||
|
||||
def build_white_results
|
||||
if results_params[:whites].present?
|
||||
white_result = ::Poll::WhiteResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
def build_recounts
|
||||
recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
date: results_params[:date])
|
||||
white_result.officer_assignment_id = @officer_assignment.id
|
||||
white_result.amount = results_params[:whites].to_i
|
||||
white_result.author = current_user
|
||||
white_result.origin = 'booth'
|
||||
@results << white_result
|
||||
recount.officer_assignment_id = @officer_assignment.id
|
||||
recount.author = current_user
|
||||
recount.origin = 'booth'
|
||||
[:whites, :nulls, :total].each do |recount_type|
|
||||
if results_params[recount_type].present?
|
||||
recount["#{recount_type.to_s.singularize}_amount"] = results_params[recount_type].to_i
|
||||
end
|
||||
end
|
||||
|
||||
def build_null_results
|
||||
if results_params[:nulls].present?
|
||||
null_result = ::Poll::NullResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
date: results_params[:date])
|
||||
null_result.officer_assignment_id = @officer_assignment.id
|
||||
null_result.amount = results_params[:nulls].to_i
|
||||
null_result.author = current_user
|
||||
null_result.origin = 'booth'
|
||||
@results << null_result
|
||||
end
|
||||
end
|
||||
|
||||
def build_total_results
|
||||
if results_params[:total].present?
|
||||
total_result = ::Poll::TotalResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
date: results_params[:date])
|
||||
total_result.officer_assignment_id = @officer_assignment.id
|
||||
total_result.amount = results_params[:total].to_i
|
||||
total_result.author = current_user
|
||||
total_result.origin = 'booth'
|
||||
@results << total_result
|
||||
end
|
||||
@results << recount
|
||||
end
|
||||
|
||||
def go_back_to_new(alert = nil)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module PollRecountsHelper
|
||||
|
||||
def total_recounts_by_booth(booth_assignment)
|
||||
booth_assignment.total_results.any? ? booth_assignment.total_results.to_a.sum(&:amount) : nil
|
||||
booth_assignment.recounts.any? ? booth_assignment.recounts.to_a.sum(&:total_amount) : nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,9 +2,7 @@ class Poll < ActiveRecord::Base
|
||||
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
||||
has_many :booths, through: :booth_assignments
|
||||
has_many :partial_results, through: :booth_assignments
|
||||
has_many :white_results, through: :booth_assignments
|
||||
has_many :null_results, through: :booth_assignments
|
||||
has_many :total_results, through: :booth_assignments
|
||||
has_many :recounts, through: :booth_assignments
|
||||
has_many :voters
|
||||
has_many :officer_assignments, through: :booth_assignments
|
||||
has_many :officers, through: :officer_assignments
|
||||
|
||||
@@ -7,8 +7,6 @@ class Poll
|
||||
has_many :officers, through: :officer_assignments
|
||||
has_many :voters
|
||||
has_many :partial_results
|
||||
has_many :white_results
|
||||
has_many :null_results
|
||||
has_many :total_results
|
||||
has_many :recounts
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,7 @@ class Poll
|
||||
belongs_to :officer
|
||||
belongs_to :booth_assignment
|
||||
has_many :partial_results
|
||||
has_many :white_results
|
||||
has_many :null_results
|
||||
has_many :total_results
|
||||
has_many :recounts
|
||||
has_many :voters
|
||||
|
||||
validates :officer_id, presence: true
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
<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.total_results.any? %>
|
||||
<%= officer_assignment.total_results.to_a.sum(&:amount) %>
|
||||
<% if officer_assignment.recounts.any? %>
|
||||
<%= officer_assignment.recounts.to_a.sum(&:total_amount) %>
|
||||
<% else %>
|
||||
<span>-</span>
|
||||
<% end %>
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="white_results"><%= @poll.white_results.sum(:amount) %></td>
|
||||
<td id="null_results"><%= @poll.null_results.sum(:amount) %></td>
|
||||
<td id="total_results"><%= @poll.total_results.sum(:amount) %></td>
|
||||
<td id="white_results"><%= @poll.recounts.sum(:white_amount) %></td>
|
||||
<td id="null_results"><%= @poll.recounts.sum(:null_amount) %></td>
|
||||
<td id="total_results"><%= @poll.recounts.sum(:total_amount) %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="white_results"><%= @whites %></td>
|
||||
<td id="null_results"><%= @nulls %></td>
|
||||
<td id="total_results"><%= @total %></td>
|
||||
<td id="white_results"><%= @recounts.sum(:white_amount) %></td>
|
||||
<td id="null_results"><%= @recounts.sum(:null_amount) %></td>
|
||||
<td id="total_results"><%= @recounts.sum(:total_amount) %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -249,18 +249,18 @@ feature 'Admin polls' do
|
||||
booth_assignment_final_recounted = create(:poll_booth_assignment, poll: poll)
|
||||
|
||||
3.times do |i|
|
||||
create(:poll_total_result,
|
||||
create(:poll_recount,
|
||||
booth_assignment: booth_assignment,
|
||||
date: poll.starts_at + i.days,
|
||||
amount: 21)
|
||||
total_amount: 21)
|
||||
end
|
||||
|
||||
2.times { create(:poll_voter, booth_assignment: booth_assignment_final_recounted) }
|
||||
|
||||
create(:poll_total_result,
|
||||
create(:poll_recount,
|
||||
booth_assignment: booth_assignment_final_recounted,
|
||||
date: poll.ends_at,
|
||||
amount: 55555)
|
||||
total_amount: 55555)
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
|
||||
@@ -318,12 +318,10 @@ feature 'Admin polls' do
|
||||
answer: 'Tomorrow',
|
||||
amount: 5)
|
||||
end
|
||||
create(:poll_white_result,
|
||||
create(:poll_recount,
|
||||
booth_assignment: booth_assignment_1,
|
||||
amount: 21)
|
||||
create(:poll_null_result,
|
||||
booth_assignment: booth_assignment_3,
|
||||
amount: 44)
|
||||
white_amount: 21,
|
||||
null_amount: 44)
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
|
||||
|
||||
@@ -127,21 +127,13 @@ feature 'Officing Results' do
|
||||
date: @poll.ends_at,
|
||||
question: @question_1,
|
||||
amount: 33)
|
||||
white_result = create(:poll_white_result,
|
||||
poll_recount = create(:poll_recount,
|
||||
officer_assignment: @officer_assignment,
|
||||
booth_assignment: @officer_assignment.booth_assignment,
|
||||
date: @poll.ends_at,
|
||||
amount: 21)
|
||||
null_result = create(:poll_null_result,
|
||||
officer_assignment: @officer_assignment,
|
||||
booth_assignment: @officer_assignment.booth_assignment,
|
||||
date: @poll.ends_at,
|
||||
amount: 44)
|
||||
total_result = create(:poll_total_result,
|
||||
officer_assignment: @officer_assignment,
|
||||
booth_assignment: @officer_assignment.booth_assignment,
|
||||
date: @poll.ends_at,
|
||||
amount: 66)
|
||||
white_amount: 21,
|
||||
null_amount: 44,
|
||||
total_amount: 66)
|
||||
|
||||
visit officing_poll_results_path(@poll,
|
||||
date: I18n.l(@poll.ends_at.to_date),
|
||||
|
||||
Reference in New Issue
Block a user