diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 2c9755d6a..a6d9eecd0 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -1,31 +1,44 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController + before_action :load_poll, except: [:create, :destroy] + + def index + @booth_assignments = @poll.booth_assignments.includes(:booth) + end + + def search_booths + load_search + @booths = ::Poll::Booth.search(@search) + respond_to do |format| + format.js + end + end + + def show + @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id]) + @voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date} + end + def create @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll], booth_id: booth_assignment_params[:booth]) if @booth_assignment.save - notice = t("admin.booth_assignments.flash.create") + notice = t("admin.poll_booth_assignments.flash.create") else - notice = t("admin.booth_assignments.flash.error_create") + notice = t("admin.poll_booth_assignments.flash.error_create") end - redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice + redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice end def destroy @booth_assignment = ::Poll::BoothAssignment.find(params[:id]) if @booth_assignment.destroy - notice = t("admin.booth_assignments.flash.destroy") + notice = t("admin.poll_booth_assignments.flash.destroy") else - notice = t("admin.booth_assignments.flash.error_destroy") + notice = t("admin.poll_booth_assignments.flash.error_destroy") end - redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice - end - - def show - @poll = ::Poll.find(params[:poll_id]) - @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id]) - @voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date} + redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice end private @@ -38,4 +51,16 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController params.permit(:booth, :poll) end + def load_poll + @poll = ::Poll.find(params[:poll_id]) + end + + def search_params + params.permit(:poll_id, :search) + end + + def load_search + @search = search_params[:search] + end + end \ No newline at end of file diff --git a/app/controllers/admin/poll/officer_assignments_controller.rb b/app/controllers/admin/poll/officer_assignments_controller.rb index e52108645..b14f99a6a 100644 --- a/app/controllers/admin/poll/officer_assignments_controller.rb +++ b/app/controllers/admin/poll/officer_assignments_controller.rb @@ -1,11 +1,16 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController - before_action :redirect_if_blank_required_params, only: [:index] + before_action :load_poll + before_action :redirect_if_blank_required_params, only: [:by_officer] before_action :load_booth_assignment, only: [:create] def index - @poll = ::Poll.includes(:booths).find(officer_assignment_params[:poll]) - @officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer]) + @officers = @poll.officer_assignments.includes(officer: :user).select(:officer_id).distinct.map(&:officer) + end + + def by_officer + @poll = ::Poll.includes(:booths).find(params[:poll_id]) + @officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer_id]) @officer_assignments = ::Poll::OfficerAssignment. joins(:booth_assignment). includes(:recount, :final_recounts, booth_assignment: :booth). @@ -13,6 +18,15 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController order(:date) end + def search_officers + load_search + @officers = User.joins(:poll_officer).search(@search).order(username: :asc) + + respond_to do |format| + format.js + end + end + def create @officer_assignment = ::Poll::OfficerAssignment.new(booth_assignment: @booth_assignment, officer_id: create_params[:officer_id], @@ -24,7 +38,7 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController else notice = t("admin.poll_officer_assignments.flash.error_create") end - redirect_to admin_officer_assignments_path(officer: create_params[:officer_id], poll: create_params[:poll_id]), notice: notice + redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: create_params[:poll_id], officer_id: create_params[:officer_id]), notice: notice end def destroy @@ -35,13 +49,13 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController else notice = t("admin.poll_officer_assignments.flash.error_destroy") end - redirect_to admin_officer_assignments_path(officer: @officer_assignment.officer_id, poll: @officer_assignment.poll_id), notice: notice + redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: @officer_assignment.poll_id, officer_id: @officer_assignment.officer_id), notice: notice end private def officer_assignment_params - params.permit(:officer, :poll) + params.permit(:officer_id) end def create_params @@ -52,14 +66,22 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController @booth_assignment = ::Poll::BoothAssignment.includes(:poll).find_by(poll_id: create_params[:poll_id], booth_id: create_params[:booth_id]) end + def load_poll + @poll = ::Poll.find(params[:poll_id]) + end + def redirect_if_blank_required_params - if officer_assignment_params[:officer].blank? - if officer_assignment_params[:poll].blank? - redirect_to admin_polls_path - else - redirect_to admin_poll_path(officer_assignment_params[:poll]) - end + if officer_assignment_params[:officer_id].blank? + redirect_to admin_poll_path(@poll) end end + def search_params + params.permit(:poll_id, :search) + end + + def load_search + @search = search_params[:search] + end + end \ No newline at end of file diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 66a831d72..eda5736b0 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -8,12 +8,8 @@ class Admin::Poll::PollsController < Admin::BaseController end def show - @poll = Poll.includes(:questions, - booth_assignments: [:booth, - :final_recounts, - :recounts], - officers: [:user]). - order('poll_questions.title', 'poll_booths.name', 'users.username'). + @poll = Poll.includes(:questions). + order('poll_questions.title'). find(params[:id]) end @@ -48,7 +44,7 @@ class Admin::Poll::PollsController < Admin::BaseController else notice = t("admin.polls.flash.error_on_question_added") end - redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice + redirect_to admin_poll_path(@poll), notice: notice end def remove_question @@ -60,14 +56,7 @@ class Admin::Poll::PollsController < Admin::BaseController else notice = t("admin.polls.flash.error_on_question_removed") end - redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice - end - - def search_booths - @booths = ::Poll::Booth.search(@search) - respond_to do |format| - format.js - end + redirect_to admin_poll_path(@poll), notice: notice end def search_questions @@ -77,14 +66,6 @@ class Admin::Poll::PollsController < Admin::BaseController end end - def search_officers - @officers = User.joins(:poll_officer).search(@search).order(username: :asc) - - respond_to do |format| - format.js - end - end - private def load_geozones @geozones = Geozone.all.order(:name) diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb new file mode 100644 index 000000000..6df6e8ed5 --- /dev/null +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -0,0 +1,13 @@ +class Admin::Poll::RecountsController < Admin::BaseController + before_action :load_poll + + def index + @booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts) + end + + private + + def load_poll + @poll = ::Poll.find(params[:poll_id]) + end +end \ No newline at end of file diff --git a/app/controllers/admin/poll/results_controller.rb b/app/controllers/admin/poll/results_controller.rb new file mode 100644 index 000000000..2c5bbba27 --- /dev/null +++ b/app/controllers/admin/poll/results_controller.rb @@ -0,0 +1,13 @@ +class Admin::Poll::ResultsController < Admin::BaseController + before_action :load_poll + + def index + @partial_results = @poll.partial_results + end + + private + + def load_poll + @poll = ::Poll.includes(:questions).find(params[:poll_id]) + end +end \ No newline at end of file diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index dc0edf7f0..3f0d4db4b 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -25,7 +25,7 @@ module AdminHelper end def menu_polls? - ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments"].include? controller_name + ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name end def menu_profiles? diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index a45b69eb3..d30ac954c 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -61,7 +61,7 @@ <%= t("admin.menu.title_polls") %>