Merge pull request #2069 from consul/chore/fix_officing_final_result_date

Force Officer results to current date instead of datepicker
This commit is contained in:
BertoCQ
2017-10-18 10:59:07 +02:00
committed by GitHub
5 changed files with 10 additions and 33 deletions

View File

@@ -5,7 +5,7 @@ class Officing::ResultsController < Officing::BaseController
before_action :load_partial_results, only: :new
before_action :load_officer_assignment, only: :create
before_action :check_booth_and_date, only: :create
before_action :check_officer_assignment, only: :create
before_action :build_results, only: :create
def new
@@ -32,13 +32,9 @@ class Officing::ResultsController < Officing::BaseController
private
def check_booth_and_date
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
elsif results_params[:date].blank? ||
Date.parse(results_params[:date]) < @poll.starts_at.to_date ||
Date.parse(results_params[:date]) > @poll.ends_at.to_date
go_back_to_new(t("officing.results.flash.error_wrong_date"))
end
end
@@ -55,7 +51,7 @@ class Officing::ResultsController < Officing::BaseController
go_back_to_new if question.blank?
partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date],
date: Date.current,
question_id: question_id,
answer: answer)
partial_result.officer_assignment_id = @officer_assignment.id
@@ -71,7 +67,7 @@ class Officing::ResultsController < Officing::BaseController
def build_recounts
recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date])
date: Date.current)
recount.officer_assignment_id = @officer_assignment.id
recount.author = current_user
recount.origin = 'booth'
@@ -84,7 +80,7 @@ class Officing::ResultsController < Officing::BaseController
end
def go_back_to_new(alert = nil)
params[:d] = results_params[:date]
params[:d] = Date.current
params[:oa] = results_params[:officer_assignment_id]
flash.now[:alert] = (alert || t("officing.results.flash.error_create"))
load_officer_assignments
@@ -108,7 +104,7 @@ class Officing::ResultsController < Officing::BaseController
final.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id).
order(date: :asc)
where(date: Date.current)
end
def load_partial_results
@@ -119,7 +115,7 @@ class Officing::ResultsController < Officing::BaseController
end
def results_params
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls, :total)
params.permit(:officer_assignment_id, :questions, :whites, :nulls, :total)
end
def index_params

View File

@@ -12,16 +12,6 @@
</div>
</div>
<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.results.new.date") %></label>
<%= select_tag :date,
poll_dates_select_options(@poll),
{ prompt: t("officing.results.new.select_date"),
label: false } %>
</div>
</div>
<% @poll.questions.each do |question| %>
<div class="row">
<div class="small-12 column">
@@ -101,4 +91,3 @@
</table>
<% end %>