diff --git a/app/controllers/officing/recounts_controller.rb b/app/controllers/officing/recounts_controller.rb new file mode 100644 index 000000000..0e0a79d69 --- /dev/null +++ b/app/controllers/officing/recounts_controller.rb @@ -0,0 +1,45 @@ +class Officing::RecountsController < Officing::BaseController + before_action :load_poll + before_action :load_officer_assignment, only: :create + + def new + @officer_assignments = ::Poll::OfficerAssignment. + includes(:recount, booth_assignment: :booth). + joins(:booth_assignment). + where(id: current_user.poll_officer.officer_assignment_ids). + where("poll_booth_assignments.poll_id = ?", @poll.id). + order(date: :asc) + @recounted = @officer_assignments.select {|oa| oa.recount.present?}.reverse + end + + def create + @recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, date: @officer_assignment.date) + @recount.officer_assignment_id = @officer_assignment.id + @recount.count = recount_params[:count] + + if @recount.save + notice = t("officing.recounts.flash.create") + else + notice = t("officing.recounts.flash.error_create") + end + redirect_to new_officing_poll_recount_path(@poll), notice: notice + end + + private + def load_poll + @poll = Poll.current.find(params[:poll_id]) + end + + def load_officer_assignment + @officer_assignment = current_user.poll_officer. + officer_assignments.find_by(id: recount_params[:officer_assignment_id]) + if @officer_assignment.blank? + redirect_to new_officing_poll_recount_path(@poll), notice: t("officing.recounts.flash.error_create") + end + end + + def recount_params + params.permit(:officer_assignment_id, :count) + end + +end \ No newline at end of file diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb deleted file mode 100644 index 03e638366..000000000 --- a/app/controllers/officing/results_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Officing::ResultsController < Officing::BaseController - layout 'admin' - - before_action :authenticate_user! - - def index - end - - def show - end - - def new - end - -end \ No newline at end of file diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 6d7ad8512..6cf321beb 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -1,7 +1,4 @@ class Officing::VotersController < Officing::BaseController - layout 'admin' - - before_action :authenticate_user! def new end diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb new file mode 100644 index 000000000..d1436c515 --- /dev/null +++ b/app/helpers/officing_helper.rb @@ -0,0 +1,11 @@ +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 + +end \ No newline at end of file diff --git a/app/views/officing/recounts/new.html.erb b/app/views/officing/recounts/new.html.erb new file mode 100644 index 000000000..dc78ccf89 --- /dev/null +++ b/app/views/officing/recounts/new.html.erb @@ -0,0 +1,63 @@ +<% if @officer_assignments.any? %> +
| <%= t("officing.recounts.new.date") %> | +<%= t("officing.recounts.new.booth") %> | +<%= t("officing.recounts.new.count") %> | + + + <% @recounted.each do |oa| %> +
|---|---|---|
| + <%= l(oa.date.to_date, format: :long) %> + | ++ <%= oa.booth_assignment.booth.name %> + | ++ <%= oa.recount.count %> + | +