extracts booth_assignment from admin's poll/show

This commit is contained in:
Juanjo Bazán
2017-02-14 13:00:19 +01:00
parent 22d9c17ab4
commit 20e31133a8
16 changed files with 156 additions and 133 deletions

View File

@@ -1,31 +1,44 @@
class Admin::Poll::BoothAssignmentsController < Admin::BaseController 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 def create
@booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll], booth_id: booth_assignment_params[:booth]) @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll], booth_id: booth_assignment_params[:booth])
if @booth_assignment.save if @booth_assignment.save
notice = t("admin.booth_assignments.flash.create") notice = t("admin.poll_booth_assignments.flash.create")
else else
notice = t("admin.booth_assignments.flash.error_create") notice = t("admin.poll_booth_assignments.flash.error_create")
end 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 end
def destroy def destroy
@booth_assignment = ::Poll::BoothAssignment.find(params[:id]) @booth_assignment = ::Poll::BoothAssignment.find(params[:id])
if @booth_assignment.destroy if @booth_assignment.destroy
notice = t("admin.booth_assignments.flash.destroy") notice = t("admin.poll_booth_assignments.flash.destroy")
else else
notice = t("admin.booth_assignments.flash.error_destroy") notice = t("admin.poll_booth_assignments.flash.error_destroy")
end 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 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}
end end
private private
@@ -38,4 +51,16 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
params.permit(:booth, :poll) params.permit(:booth, :poll)
end 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 end

View File

@@ -63,13 +63,6 @@ class Admin::Poll::PollsController < Admin::BaseController
redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice
end end
def search_booths
@booths = ::Poll::Booth.search(@search)
respond_to do |format|
format.js
end
end
def search_questions def search_questions
@questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc) @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc)
respond_to do |format| respond_to do |format|

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<%= 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| %>
<div class="input-group"> <div class="input-group">
<%= text_field_tag :search, <%= text_field_tag :search,
@search, @search,

View File

@@ -1,18 +1,18 @@
<% if @booths.blank? %> <% if @booths.blank? %>
<div class="callout alert margin-bottom"> <div class="callout alert margin-bottom">
<%= t('admin.polls.show.no_search_results') %> <%= t('admin.shared.no_search_results') %>
</div> </div>
<% else %> <% else %>
<h3><%= t('admin.polls.show.search_results') %></h3> <h3><%= t('admin.shared.search_results') %></h3>
<% end %> <% end %>
<% if @booths.any? %> <% if @booths.any? %>
<table> <table>
<thead> <thead>
<tr> <tr>
<th><%= t("admin.polls.show.table_name") %></th> <th><%= t("admin.poll_booth_assignments.index.table_name") %></th>
<th><%= t("admin.polls.show.table_location") %></th> <th><%= t("admin.poll_booth_assignments.index.table_location") %></th>
<th class="text-center"><%= t("admin.polls.show.table_assignment") %></th> <th class="text-center"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -26,13 +26,12 @@
</td> </td>
<td class="text-center"> <td class="text-center">
<% if @poll.booth_ids.include?(booth.id) %> <% if @poll.booth_ids.include?(booth.id) %>
<%= link_to t("admin.polls.show.remove_booth"), <%= link_to t("admin.poll_booth_assignments.index.remove_booth"),
admin_booth_assignment_path(poll: @poll, booth: booth),
method: :delete, method: :delete,
class: "button hollow alert" %> class: "button hollow alert" %>
<% else %> <% else %>
<%= link_to t("admin.polls.show.add_booth"), <%= link_to t("admin.poll_booth_assignments.index.add_booth"),
admin_booth_assignments_path(poll: @poll, booth: booth), admin_poll_booth_assignments_path(poll: @poll, booth: booth),
method: :post, method: :post,
class: "button hollow" %> class: "button hollow" %>
<% end %> <% end %>

View File

@@ -0,0 +1,41 @@
<%= render "/admin/poll/polls/poll_header" %>
<div id="poll-resources">
<%= render "/admin/poll/polls/filter_subnav" %>
<%= render "search_booths" %>
<h3><%= t("admin.poll_booth_assignments.index.booths_title") %></h3>
<% if @poll.booth_assignments.empty? %>
<div class="callout primary margin-top">
<%= t("admin.poll_booth_assignments.index.no_booths") %>
</div>
<% else %>
<table id="assigned_booths_list" class="fixed margin">
<thead>
<th><%= t("admin.poll_booth_assignments.index.table_name") %></th>
<th><%= t("admin.poll_booth_assignments.index.table_location") %></th>
<th class="text-right"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</thead>
<tbody>
<% @poll.booth_assignments.each do |booth_assignment| %>
<tr id="<%= dom_id(booth_assignment) %>" class="booth">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %>
</strong>
</td>
<td>
<%= booth_assignment.booth.location %>
</td>
<td class="text-right">
<%= link_to t("admin.poll_booth_assignments.index.remove_booth"),
admin_poll_booth_assignment_path(@poll, booth_assignment),
method: :delete,
class: "button hollow alert" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>

View File

@@ -1,4 +1,4 @@
<%= link_to admin_poll_path(@poll, anchor: 'tab-booths') do %> <%= link_to admin_poll_booth_assignments_path(@poll) do %>
<span class="icon-angle-left"></span> <span class="icon-angle-left"></span>
<%= @poll.name %> <%= @poll.name %>
<% end %> <% end %>

View File

@@ -1,35 +0,0 @@
<h3><%= t("admin.polls.show.booths_title") %></h3>
<% if @poll.booth_assignments.empty? %>
<div class="callout primary margin-top">
<%= t("admin.polls.show.no_booths") %>
</div>
<% else %>
<table id="assigned_booths_list" class="fixed margin">
<thead>
<th><%= t("admin.polls.show.table_name") %></th>
<th><%= t("admin.polls.show.table_location") %></th>
<th class="text-right"><%= t("admin.polls.show.table_assignment") %></th>
</thead>
<tbody>
<% @poll.booth_assignments.each do |booth_assignment| %>
<tr id="<%= dom_id(booth_assignment) %>" class="booth">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %>
</strong>
</td>
<td>
<%= booth_assignment.booth.location %>
</td>
<td class="text-right">
<%= link_to t("admin.polls.show.remove_booth"),
admin_booth_assignment_path(booth_assignment),
method: :delete,
class: "button hollow alert" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -1,28 +1,28 @@
<ul class="tabs" data-tabs id="assigned-resources-tabs"> <ul class="menu simple clear" id="assigned-resources-tabs">
<li class="tabs-title is-active"> <li>
<%= link_to "#tab-questions" do %> <%= link_to admin_poll_path(@poll) do %>
<%= t("admin.polls.show.questions_tab") %> <%= t("admin.polls.show.questions_tab") %>
<span class="js-comments-count">(<%= @poll.questions.count %>)</span> (<%= @poll.questions.count %>)
<% end %> <% end %>
</li> </li>
<li class="tabs-title"> <li>
<%= link_to "#tab-booths" do %> <%= link_to admin_poll_booth_assignments_path(@poll) do %>
<%= t("admin.polls.show.booths_tab") %> <%= t("admin.polls.show.booths_tab") %>
(<%= @poll.booths.count %>) (<%= @poll.booth_assignments.select(:booth_id).distinct.count %>)
<% end %> <% end %>
</li> </li>
<li class="tabs-title"> <li>
<%= link_to "#tab-officers" do %> <%= link_to "#tab-officers" do %>
<%= t("admin.polls.show.officers_tab") %> <%= t("admin.polls.show.officers_tab") %>
(<%= @poll.officers.uniq.count %>) (<%= @poll.officer_assignments.select(:officer_id).distinct.count %>)
<% end %> <% end %>
</li> </li>
<li class="tabs-title"> <li>
<%= link_to "#tab-recounts" do %> <%= link_to "#tab-recounts" do %>
<%= t("admin.polls.show.recounts_tab") %> <%= t("admin.polls.show.recounts_tab") %>
<% end %> <% end %>
</li> </li>
<li class="tabs-title"> <li>
<%= link_to "#tab-results" do %> <%= link_to "#tab-results" do %>
<%= t("admin.polls.show.results_tab") %> <%= t("admin.polls.show.results_tab") %>
<% end %> <% end %>

View File

@@ -0,0 +1,17 @@
<%= link_to t("admin.actions.edit"),
edit_admin_poll_path(@poll),
class: "button hollow float-right" %>
<h2 class="inline-block">
<%= @poll.name %>
</h2>
<br>
<span>
(<%= l @poll.starts_at.to_date %> - <%= l @poll.ends_at.to_date %>)
</span>
<% if @poll.geozone_restricted %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span>
<%= @poll.geozones.pluck(:name).to_sentence %>
<span>
<% end %>

View File

@@ -1,9 +1,9 @@
<% if @officers.blank? %> <% if @officers.blank? %>
<div class="callout alert margin-bottom"> <div class="callout alert margin-bottom">
<%= t('admin.polls.show.no_search_results') %> <%= t('admin.shared.no_search_results') %>
</div> </div>
<% else %> <% else %>
<h3><%= t('admin.polls.show.search_results') %></h3> <h3><%= t('admin.shared.search_results') %></h3>
<% end %> <% end %>
<% if @officers.any? %> <% if @officers.any? %>

View File

@@ -1,9 +1,9 @@
<% if @questions.blank? %> <% if @questions.blank? %>
<div class="callout alert margin-bottom"> <div class="callout alert margin-bottom">
<%= t('admin.polls.show.no_search_results') %> <%= t('admin.shared.no_search_results') %>
</div> </div>
<% else %> <% else %>
<h3><%= t('admin.polls.show.search_results') %></h3> <h3><%= t('admin.shared.search_results') %></h3>
<% end %> <% end %>
<% if @questions.any? %> <% if @questions.any? %>

View File

@@ -1,34 +1,13 @@
<%= link_to t("admin.actions.edit"), <%= render "poll_header" %>
edit_admin_poll_path(@poll),
class: "button hollow float-right" %>
<h2 class="inline-block"> <div id="poll-resources">
<%= @poll.name %>
</h2>
<br>
<span>
(<%= l @poll.starts_at.to_date %> - <%= l @poll.ends_at.to_date %>)
</span>
<% if @poll.geozone_restricted %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span>
<%= @poll.geozones.pluck(:name).to_sentence %>
<span>
<% end %>
<div id="poll-resources" class="tabs-content" data-tabs-content="assigned-resources-tabs">
<%= render "filter_subnav" %> <%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-questions"> <div class="tabs-panel" id="tab-questions">
<%= render "search_questions" %> <%= render "search_questions" %>
<%= render "questions" %> <%= render "questions" %>
</div> </div>
<div class="tabs-panel" id="tab-booths">
<%= render "search_booths" %>
<%= render "booths" %>
</div>
<div class="tabs-panel" id="tab-officers"> <div class="tabs-panel" id="tab-officers">
<%= render "search_officers" %> <%= render "search_officers" %>
<%= render 'officers' %> <%= render 'officers' %>

View File

@@ -286,6 +286,11 @@ en:
final_recounts: "Final recounts" final_recounts: "Final recounts"
final_recount: "Final recount (by officer)" final_recount: "Final recount (by officer)"
poll_booth_assignments: poll_booth_assignments:
flash:
destroy: "Booth not assigned anymore"
create: "Booth assigned"
error_destroy: "An error ocurred when removing booth assignment"
error_create: "An error ocurred when assigning booth to the poll"
show: show:
location: "Location" location: "Location"
officers: "Officers" officers: "Officers"
@@ -298,6 +303,14 @@ en:
count_by_officer: "Daily recount (by officer)" count_by_officer: "Daily recount (by officer)"
count_final: "Final recount (by officer)" count_final: "Final recount (by officer)"
count_by_system: "Votes (automatic)" count_by_system: "Votes (automatic)"
index:
booths_title: "List of booths"
no_booths: "There are no booths assigned to this poll."
table_name: "Name"
table_location: "Location"
table_assignment: "Assignment"
remove_booth: "Remove booth from poll"
add_booth: "Assign booth"
polls: polls:
index: index:
title: "List of polls" title: "List of polls"
@@ -317,28 +330,21 @@ en:
officers_tab: Officers officers_tab: Officers
recounts_tab: Recounting recounts_tab: Recounting
results_tab: Results results_tab: Results
no_booths: "There are no booths assigned to this poll."
no_questions: "There are no questions assigned to this poll." no_questions: "There are no questions assigned to this poll."
no_officers: "There are no officers assigned to this poll." no_officers: "There are no officers assigned to this poll."
no_recounts: "There is nothing to be recounted" no_recounts: "There is nothing to be recounted"
no_results: "There are no results" no_results: "There are no results"
remove_booth: "Remove booth from poll"
booths_title: "List of booths"
officers_title: "List of officers" officers_title: "List of officers"
questions_title: "List of questions" questions_title: "List of questions"
recounting_title: "Recounts" recounting_title: "Recounts"
results_title: "Results" results_title: "Results"
remove_question: "Remove question from poll" remove_question: "Remove question from poll"
add_booth: "Assign booth"
add_question: "Include question" add_question: "Include question"
add_officer_assignments: "Add shifts as officer" add_officer_assignments: "Add shifts as officer"
edit_officer_assignments: "Edit officing shifts" edit_officer_assignments: "Edit officing shifts"
search_results: "Search results"
no_search_results: "No results found."
table_title: "Title" table_title: "Title"
table_assignment: "Assignment" table_assignment: "Assignment"
table_name: "Name" table_name: "Name"
table_location: "Location"
table_email: "Email" table_email: "Email"
table_booth_name: "Booth" table_booth_name: "Booth"
table_final_recount: "Final recount (by officer)" table_final_recount: "Final recount (by officer)"
@@ -394,12 +400,6 @@ en:
submit_button: "Update booth" submit_button: "Update booth"
show: show:
location: "Location" location: "Location"
booth_assignments:
flash:
destroy: "Booth not assigned anymore"
create: "Booth assigned"
error_destroy: "An error ocurred when removing booth assignment"
error_create: "An error ocurred when assigning booth to the poll"
officials: officials:
edit: edit:
destroy: Remove 'Official' status destroy: Remove 'Official' status
@@ -480,6 +480,8 @@ en:
user_search: user_search:
button: Search button: Search
placeholder: Search user by name or email' placeholder: Search user by name or email'
search_results: "Search results"
no_search_results: "No results found."
spending_proposals: spending_proposals:
index: index:
geozone_filter_all: All zones geozone_filter_all: All zones

View File

@@ -286,6 +286,11 @@ es:
final_recounts: "Recuentos finales" final_recounts: "Recuentos finales"
final_recount: "Recuento final (presidente de mesa)" final_recount: "Recuento final (presidente de mesa)"
poll_booth_assignments: poll_booth_assignments:
flash:
destroy: "Urna desasignada"
create: "Urna asignada"
error_destroy: "Se ha producido un error al desasignar la urna"
error_create: "Se ha producido un error al intentar asignar la urna"
show: show:
location: "Ubicación" location: "Ubicación"
officers: "Presidentes de mesa" officers: "Presidentes de mesa"
@@ -298,6 +303,14 @@ es:
count_by_officer: "Recuento diario (presidente de mesa)" count_by_officer: "Recuento diario (presidente de mesa)"
count_final: "Recuento final (presidente de mesa)" count_final: "Recuento final (presidente de mesa)"
count_by_system: "Votos (automático)" count_by_system: "Votos (automático)"
index:
booths_title: "Listado de urnas asignadas"
no_booths: "No hay urnas asignadas a esta votación."
table_name: "Nombre"
table_location: "Ubicación"
table_assignment: "Asignación"
remove_booth: "Desasignar urna"
add_booth: "Asignar urna"
polls: polls:
index: index:
title: "Listado de votaciones" title: "Listado de votaciones"
@@ -317,28 +330,21 @@ es:
officers_tab: Presidentes de mesa officers_tab: Presidentes de mesa
recounts_tab: Recuentos recounts_tab: Recuentos
results_tab: Resultados results_tab: Resultados
no_booths: "No hay urnas asignadas a esta votación."
no_questions: "No hay preguntas asignadas a esta votación." no_questions: "No hay preguntas asignadas a esta votación."
no_officers: "No hay presidentes de mesa asignados a esta votación." no_officers: "No hay presidentes de mesa asignados a esta votación."
no_recounts: "No hay nada de lo que hacer recuento" no_recounts: "No hay nada de lo que hacer recuento"
no_results: "No hay resultados" no_results: "No hay resultados"
remove_booth: "Desasignar urna"
booths_title: "Listado de urnas asignadas"
officers_title: "Listado de presidentes de mesa asignados" officers_title: "Listado de presidentes de mesa asignados"
questions_title: "Listado de preguntas asignadas" questions_title: "Listado de preguntas asignadas"
recounting_title: "Recuentos" recounting_title: "Recuentos"
results_title: "Resultados" results_title: "Resultados"
remove_question: "Desasignar pregunta" remove_question: "Desasignar pregunta"
add_booth: "Asignar urna"
add_question: "Incluir pregunta" add_question: "Incluir pregunta"
add_officer_assignments: "Añadir turnos como presidente de mesa" add_officer_assignments: "Añadir turnos como presidente de mesa"
edit_officer_assignments: "Editar turnos" edit_officer_assignments: "Editar turnos"
search_results: "Resultados de la búsqueda"
no_search_results: "No se han encontrado resultados."
table_title: "Título" table_title: "Título"
table_assignment: "Asignación" table_assignment: "Asignación"
table_name: "Nombre" table_name: "Nombre"
table_location: "Ubicación"
table_email: "Email" table_email: "Email"
table_booth_name: "Urna" table_booth_name: "Urna"
table_final_recount: "Recuento final (presidente de mesa)" table_final_recount: "Recuento final (presidente de mesa)"
@@ -394,12 +400,6 @@ es:
submit_button: "Actualizar urna" submit_button: "Actualizar urna"
show: show:
location: "Ubicación" location: "Ubicación"
booth_assignments:
flash:
destroy: "Urna desasignada"
create: "Urna asignada"
error_destroy: "Se ha producido un error al desasignar la urna"
error_create: "Se ha producido un error al intentar asignar la urna"
officials: officials:
edit: edit:
destroy: Eliminar condición de 'Cargo Público' destroy: Eliminar condición de 'Cargo Público'
@@ -480,6 +480,8 @@ es:
user_search: user_search:
button: Buscar button: Buscar
placeholder: Buscar usuario por nombre o email placeholder: Buscar usuario por nombre o email
search_results: "Resultados de la búsqueda"
no_search_results: "No se han encontrado resultados."
spending_proposals: spending_proposals:
index: index:
geozone_filter_all: Todos los ámbitos de actuación geozone_filter_all: Todos los ámbitos de actuación

View File

@@ -208,13 +208,14 @@ Rails.application.routes.draw do
scope module: :poll do scope module: :poll do
resources :polls do resources :polls do
get :search_booths, on: :member
get :search_officers, on: :member get :search_officers, on: :member
get :search_questions, on: :member get :search_questions, on: :member
patch :add_question, on: :member patch :add_question, on: :member
patch :remove_question, on: :member patch :remove_question, on: :member
resources :booth_assignments, only: :show resources :booth_assignments, only: [:index, :show, :create, :destroy] do
get :search_booths, on: :collection
end
end end
resources :officers do resources :officers do
@@ -222,7 +223,6 @@ Rails.application.routes.draw do
end end
resources :booths resources :booths
resources :booth_assignments, only: [:create, :destroy]
resources :officer_assignments, only: [:index, :create, :destroy] resources :officer_assignments, only: [:index, :create, :destroy]
resources :questions resources :questions
end end