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