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
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

View File

@@ -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|

View File

@@ -1,6 +1,6 @@
<div class="row">
<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">
<%= text_field_tag :search,
@search,

View File

@@ -1,18 +1,18 @@
<% if @booths.blank? %>
<div class="callout alert margin-bottom">
<%= t('admin.polls.show.no_search_results') %>
<%= t('admin.shared.no_search_results') %>
</div>
<% else %>
<h3><%= t('admin.polls.show.search_results') %></h3>
<h3><%= t('admin.shared.search_results') %></h3>
<% end %>
<% if @booths.any? %>
<table>
<thead>
<tr>
<th><%= t("admin.polls.show.table_name") %></th>
<th><%= t("admin.polls.show.table_location") %></th>
<th class="text-center"><%= t("admin.polls.show.table_assignment") %></th>
<th><%= t("admin.poll_booth_assignments.index.table_name") %></th>
<th><%= t("admin.poll_booth_assignments.index.table_location") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</tr>
</thead>
<tbody>
@@ -26,13 +26,12 @@
</td>
<td class="text-center">
<% 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 %>

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>
<%= @poll.name %>
<% 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">
<li class="tabs-title is-active">
<%= link_to "#tab-questions" do %>
<ul class="menu simple clear" id="assigned-resources-tabs">
<li>
<%= link_to admin_poll_path(@poll) do %>
<%= t("admin.polls.show.questions_tab") %>
<span class="js-comments-count">(<%= @poll.questions.count %>)</span>
(<%= @poll.questions.count %>)
<% end %>
</li>
<li class="tabs-title">
<%= link_to "#tab-booths" do %>
<li>
<%= link_to admin_poll_booth_assignments_path(@poll) do %>
<%= t("admin.polls.show.booths_tab") %>
(<%= @poll.booths.count %>)
(<%= @poll.booth_assignments.select(:booth_id).distinct.count %>)
<% end %>
</li>
<li class="tabs-title">
<li>
<%= link_to "#tab-officers" do %>
<%= t("admin.polls.show.officers_tab") %>
(<%= @poll.officers.uniq.count %>)
(<%= @poll.officer_assignments.select(:officer_id).distinct.count %>)
<% end %>
</li>
<li class="tabs-title">
<li>
<%= link_to "#tab-recounts" do %>
<%= t("admin.polls.show.recounts_tab") %>
<% end %>
</li>
<li class="tabs-title">
<li>
<%= link_to "#tab-results" do %>
<%= t("admin.polls.show.results_tab") %>
<% 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? %>
<div class="callout alert margin-bottom">
<%= t('admin.polls.show.no_search_results') %>
<%= t('admin.shared.no_search_results') %>
</div>
<% else %>
<h3><%= t('admin.polls.show.search_results') %></h3>
<h3><%= t('admin.shared.search_results') %></h3>
<% end %>
<% if @officers.any? %>

View File

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

View File

@@ -1,34 +1,13 @@
<%= link_to t("admin.actions.edit"),
edit_admin_poll_path(@poll),
class: "button hollow float-right" %>
<%= render "poll_header" %>
<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 %>
<div id="poll-resources" class="tabs-content" data-tabs-content="assigned-resources-tabs">
<div id="poll-resources">
<%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-questions">
<div class="tabs-panel" id="tab-questions">
<%= render "search_questions" %>
<%= render "questions" %>
</div>
<div class="tabs-panel" id="tab-booths">
<%= render "search_booths" %>
<%= render "booths" %>
</div>
<div class="tabs-panel" id="tab-officers">
<%= render "search_officers" %>
<%= render 'officers' %>

View File

@@ -286,6 +286,11 @@ en:
final_recounts: "Final recounts"
final_recount: "Final recount (by officer)"
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:
location: "Location"
officers: "Officers"
@@ -298,6 +303,14 @@ en:
count_by_officer: "Daily recount (by officer)"
count_final: "Final recount (by officer)"
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:
index:
title: "List of polls"
@@ -317,28 +330,21 @@ en:
officers_tab: Officers
recounts_tab: Recounting
results_tab: Results
no_booths: "There are no booths 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_recounts: "There is nothing to be recounted"
no_results: "There are no results"
remove_booth: "Remove booth from poll"
booths_title: "List of booths"
officers_title: "List of officers"
questions_title: "List of questions"
recounting_title: "Recounts"
results_title: "Results"
remove_question: "Remove question from poll"
add_booth: "Assign booth"
add_question: "Include question"
add_officer_assignments: "Add shifts as officer"
edit_officer_assignments: "Edit officing shifts"
search_results: "Search results"
no_search_results: "No results found."
table_title: "Title"
table_assignment: "Assignment"
table_name: "Name"
table_location: "Location"
table_email: "Email"
table_booth_name: "Booth"
table_final_recount: "Final recount (by officer)"
@@ -394,12 +400,6 @@ en:
submit_button: "Update booth"
show:
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:
edit:
destroy: Remove 'Official' status
@@ -480,6 +480,8 @@ en:
user_search:
button: Search
placeholder: Search user by name or email'
search_results: "Search results"
no_search_results: "No results found."
spending_proposals:
index:
geozone_filter_all: All zones

View File

@@ -286,6 +286,11 @@ es:
final_recounts: "Recuentos finales"
final_recount: "Recuento final (presidente de mesa)"
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:
location: "Ubicación"
officers: "Presidentes de mesa"
@@ -298,6 +303,14 @@ es:
count_by_officer: "Recuento diario (presidente de mesa)"
count_final: "Recuento final (presidente de mesa)"
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:
index:
title: "Listado de votaciones"
@@ -317,28 +330,21 @@ es:
officers_tab: Presidentes de mesa
recounts_tab: Recuentos
results_tab: Resultados
no_booths: "No hay urnas 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_recounts: "No hay nada de lo que hacer recuento"
no_results: "No hay resultados"
remove_booth: "Desasignar urna"
booths_title: "Listado de urnas asignadas"
officers_title: "Listado de presidentes de mesa asignados"
questions_title: "Listado de preguntas asignadas"
recounting_title: "Recuentos"
results_title: "Resultados"
remove_question: "Desasignar pregunta"
add_booth: "Asignar urna"
add_question: "Incluir pregunta"
add_officer_assignments: "Añadir turnos como presidente de mesa"
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_assignment: "Asignación"
table_name: "Nombre"
table_location: "Ubicación"
table_email: "Email"
table_booth_name: "Urna"
table_final_recount: "Recuento final (presidente de mesa)"
@@ -394,12 +400,6 @@ es:
submit_button: "Actualizar urna"
show:
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:
edit:
destroy: Eliminar condición de 'Cargo Público'
@@ -480,6 +480,8 @@ es:
user_search:
button: Buscar
placeholder: Buscar usuario por nombre o email
search_results: "Resultados de la búsqueda"
no_search_results: "No se han encontrado resultados."
spending_proposals:
index:
geozone_filter_all: Todos los ámbitos de actuación

View File

@@ -208,13 +208,14 @@ Rails.application.routes.draw do
scope module: :poll do
resources :polls do
get :search_booths, on: :member
get :search_officers, on: :member
get :search_questions, on: :member
patch :add_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
resources :officers do
@@ -222,7 +223,6 @@ Rails.application.routes.draw do
end
resources :booths
resources :booth_assignments, only: [:create, :destroy]
resources :officer_assignments, only: [:index, :create, :destroy]
resources :questions
end