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/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 66a831d72..340cbec71 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -63,13 +63,6 @@ class Admin::Poll::PollsController < Admin::BaseController 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 - end - def search_questions @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc) respond_to do |format| diff --git a/app/views/admin/poll/polls/_search_booths.html.erb b/app/views/admin/poll/booth_assignments/_search_booths.html.erb similarity index 81% rename from app/views/admin/poll/polls/_search_booths.html.erb rename to app/views/admin/poll/booth_assignments/_search_booths.html.erb index a02c9e6ec..e96e334c7 100644 --- a/app/views/admin/poll/polls/_search_booths.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths.html.erb @@ -1,6 +1,6 @@
- <%= form_tag(search_booths_admin_poll_path(@poll), method: :get, remote: true) do |f| %> + <%= form_tag(search_booths_admin_poll_booth_assignments_path(@poll), method: :get, remote: true) do |f| %>
<%= text_field_tag :search, @search, diff --git a/app/views/admin/poll/polls/_search_booths_results.html.erb b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb similarity index 55% rename from app/views/admin/poll/polls/_search_booths_results.html.erb rename to app/views/admin/poll/booth_assignments/_search_booths_results.html.erb index 3768fa222..8f11ff5ae 100644 --- a/app/views/admin/poll/polls/_search_booths_results.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb @@ -1,18 +1,18 @@ <% if @booths.blank? %>
- <%= t('admin.polls.show.no_search_results') %> + <%= t('admin.shared.no_search_results') %>
<% else %> -

<%= t('admin.polls.show.search_results') %>

+

<%= t('admin.shared.search_results') %>

<% end %> <% if @booths.any? %> - - - + + + @@ -26,13 +26,12 @@
<%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_location") %><%= t("admin.polls.show.table_assignment") %><%= t("admin.poll_booth_assignments.index.table_name") %><%= t("admin.poll_booth_assignments.index.table_location") %><%= t("admin.poll_booth_assignments.index.table_assignment") %>
<% if @poll.booth_ids.include?(booth.id) %> - <%= link_to t("admin.polls.show.remove_booth"), - admin_booth_assignment_path(poll: @poll, booth: booth), + <%= link_to t("admin.poll_booth_assignments.index.remove_booth"), method: :delete, class: "button hollow alert" %> <% else %> - <%= link_to t("admin.polls.show.add_booth"), - admin_booth_assignments_path(poll: @poll, booth: booth), + <%= link_to t("admin.poll_booth_assignments.index.add_booth"), + admin_poll_booth_assignments_path(poll: @poll, booth: booth), method: :post, class: "button hollow" %> <% end %> diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb new file mode 100644 index 000000000..e17281c98 --- /dev/null +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -0,0 +1,41 @@ +<%= render "/admin/poll/polls/poll_header" %> +
+ <%= render "/admin/poll/polls/filter_subnav" %> + <%= render "search_booths" %> + +

<%= t("admin.poll_booth_assignments.index.booths_title") %>

+ + <% if @poll.booth_assignments.empty? %> +
+ <%= t("admin.poll_booth_assignments.index.no_booths") %> +
+ <% else %> + + + + + + + + <% @poll.booth_assignments.each do |booth_assignment| %> + + + + + + <% end %> + +
<%= t("admin.poll_booth_assignments.index.table_name") %><%= t("admin.poll_booth_assignments.index.table_location") %><%= t("admin.poll_booth_assignments.index.table_assignment") %>
+ + <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %> + + + <%= booth_assignment.booth.location %> + + <%= link_to t("admin.poll_booth_assignments.index.remove_booth"), + admin_poll_booth_assignment_path(@poll, booth_assignment), + method: :delete, + class: "button hollow alert" %> +
+ <% end %> +
diff --git a/app/views/admin/poll/polls/search_booths.js.erb b/app/views/admin/poll/booth_assignments/search_booths.js.erb similarity index 100% rename from app/views/admin/poll/polls/search_booths.js.erb rename to app/views/admin/poll/booth_assignments/search_booths.js.erb diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index 7ce61791a..d8ca6eda5 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_poll_path(@poll, anchor: 'tab-booths') do %> +<%= link_to admin_poll_booth_assignments_path(@poll) do %> <%= @poll.name %> <% end %> diff --git a/app/views/admin/poll/polls/_booths.html.erb b/app/views/admin/poll/polls/_booths.html.erb deleted file mode 100644 index bea23b874..000000000 --- a/app/views/admin/poll/polls/_booths.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -

<%= t("admin.polls.show.booths_title") %>

- -<% if @poll.booth_assignments.empty? %> -
- <%= t("admin.polls.show.no_booths") %> -
-<% else %> - - - - - - - - <% @poll.booth_assignments.each do |booth_assignment| %> - - - - - - <% end %> - -
<%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_location") %><%= t("admin.polls.show.table_assignment") %>
- - <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %> - - - <%= booth_assignment.booth.location %> - - <%= link_to t("admin.polls.show.remove_booth"), - admin_booth_assignment_path(booth_assignment), - method: :delete, - class: "button hollow alert" %> -
-<% end %> diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index 7d1931093..a209cf761 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -1,28 +1,28 @@ -
    -
  • - <%= link_to "#tab-questions" do %> +