adds booth assignation to admin poll
This commit is contained in:
35
app/controllers/admin/poll/booth_assignments_controller.rb
Normal file
35
app/controllers/admin/poll/booth_assignments_controller.rb
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
class Admin::Poll::BoothAssignmentsController < Admin::BaseController
|
||||||
|
|
||||||
|
before_action :load_booth_assignment, only: :destroy
|
||||||
|
|
||||||
|
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")
|
||||||
|
else
|
||||||
|
notice = t("admin.booth_assignments.flash.error_create")
|
||||||
|
end
|
||||||
|
redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @booth_assignment.destroy
|
||||||
|
notice = t("admin.booth_assignments.flash.destroy")
|
||||||
|
else
|
||||||
|
notice = t("admin.booth_assignments.flash.error_destroy")
|
||||||
|
end
|
||||||
|
redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_booth_assignment
|
||||||
|
@booth_assignment = ::Poll::BoothAssignment.find_by(poll: params[:poll], booth: params[:booth])
|
||||||
|
end
|
||||||
|
|
||||||
|
def booth_assignment_params
|
||||||
|
params.permit(:booth, :poll)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class Admin::Poll::PollsController < Admin::BaseController
|
class Admin::Poll::PollsController < Admin::BaseController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
before_action :load_search, only: [:search_booths]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
@@ -30,10 +31,25 @@ class Admin::Poll::PollsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_booths
|
||||||
|
@booths = ::Poll::Booth.search(@search)
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def poll_params
|
def poll_params
|
||||||
params.require(:poll).permit(:name, :starts_at, :ends_at)
|
params.require(:poll).permit(:name, :starts_at, :ends_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:poll_id, :search)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_search
|
||||||
|
@search = search_params[:search]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -38,19 +38,20 @@ module Abilities
|
|||||||
can [:search, :create, :index, :destroy], ::Moderator
|
can [:search, :create, :index, :destroy], ::Moderator
|
||||||
can [:search, :create, :index, :summary], ::Valuator
|
can [:search, :create, :index, :summary], ::Valuator
|
||||||
can [:search, :create, :index, :destroy], ::Manager
|
can [:search, :create, :index, :destroy], ::Manager
|
||||||
can [:search, :create, :index, :destroy], ::Poll::Officer
|
|
||||||
|
|
||||||
can :manage, Annotation
|
can :manage, Annotation
|
||||||
|
|
||||||
can [:read, :update, :destroy, :summary], SpendingProposal
|
can [:read, :update, :destroy, :summary], SpendingProposal
|
||||||
|
|
||||||
can [:read, :create, :update], Poll::Question
|
|
||||||
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0
|
|
||||||
|
|
||||||
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
||||||
|
|
||||||
can [:manage], Poll
|
can [:manage], Poll
|
||||||
can [:manage], Poll::Booth
|
can [:manage], Poll::Booth
|
||||||
|
can [:search, :create, :index, :destroy], ::Poll::Officer
|
||||||
|
can [:create, :destroy], ::Poll::BoothAssignment
|
||||||
|
can [:create, :destroy], ::Poll::OfficerAssignment
|
||||||
|
can [:read, :create, :update], Poll::Question
|
||||||
|
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t("admin.polls.show.remove_booth"),
|
<%= link_to t("admin.polls.show.remove_booth"),
|
||||||
"#",
|
admin_booth_assignment_path(poll: @poll, booth: booth),
|
||||||
|
method: :delete,
|
||||||
class: "button hollow alert" %>
|
class: "button hollow alert" %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<ul class="tabs" data-tabs id="example-tabs">
|
<ul class="tabs" data-tabs id="assigned-resources-tabs">
|
||||||
<li class="tabs-title is-active">
|
<li class="tabs-title is-active">
|
||||||
<%= link_to "#tab-questions" do %>
|
<%= link_to "#tab-questions" do %>
|
||||||
<%= t("admin.polls.show.questions_tab") %>
|
<%= t("admin.polls.show.questions_tab") %>
|
||||||
|
|||||||
14
app/views/admin/poll/polls/_search_booths.html.erb
Normal file
14
app/views/admin/poll/polls/_search_booths.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<%= form_tag(search_booths_admin_poll_path(@poll), method: :get, remote: true) do |f| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= text_field_tag :search,
|
||||||
|
@search,
|
||||||
|
placeholder: t("admin.shared.booths_search.placeholder"), id: "search-booths" %>
|
||||||
|
</div>
|
||||||
|
<div class="form-inline small-12 medium-3 column end">
|
||||||
|
<%= submit_tag t("admin.shared.booths_search.button"), class: "button" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="search-booths-results"></div>
|
||||||
32
app/views/admin/poll/polls/_search_booths_results.html.erb
Normal file
32
app/views/admin/poll/polls/_search_booths_results.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="3"><%= @booths.blank? ? t('admin.polls.show.no_search_results') : t('admin.polls.show.search_results') %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @booths.each do |booth| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= booth.name %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= booth.location %>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<% if @poll.booth_ids.include?(booth.id) %>
|
||||||
|
<%= link_to t("admin.polls.show.remove_booth"),
|
||||||
|
admin_booth_assignment_path(poll: @poll, booth: booth),
|
||||||
|
method: :delete,
|
||||||
|
class: "button hollow alert" %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("admin.polls.show.add_booth"),
|
||||||
|
admin_booth_assignments_path(poll: @poll, booth: booth),
|
||||||
|
method: :post,
|
||||||
|
class: "button hollow" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
1
app/views/admin/poll/polls/search_booths.js.erb
Normal file
1
app/views/admin/poll/polls/search_booths.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#search-booths-results").html("<%= j render 'search_booths_results' %>");
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
edit_admin_poll_path(@poll),
|
edit_admin_poll_path(@poll),
|
||||||
class: "button hollow float-right" %>
|
class: "button hollow float-right" %>
|
||||||
|
|
||||||
<div class="tabs-content" data-tabs-content="example-tabs">
|
<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 is-active" id="tab-questions">
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tabs-panel" id="tab-booths">
|
<div class="tabs-panel" id="tab-booths">
|
||||||
|
<%= render "search_booths" %>
|
||||||
<%= render "booths" %>
|
<%= render "booths" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -190,9 +190,12 @@ en:
|
|||||||
officers_title: "List of officers"
|
officers_title: "List of officers"
|
||||||
questions_title: "List of questions"
|
questions_title: "List of questions"
|
||||||
remove_question: "Remove question from poll"
|
remove_question: "Remove question from poll"
|
||||||
|
add_booth: "Assign booth"
|
||||||
name: "Name"
|
name: "Name"
|
||||||
location: "Location"
|
location: "Location"
|
||||||
email: "Email"
|
email: "Email"
|
||||||
|
search_results: "Search results"
|
||||||
|
no_search_results: "No results found"
|
||||||
questions:
|
questions:
|
||||||
index:
|
index:
|
||||||
title: "Questions"
|
title: "Questions"
|
||||||
@@ -235,6 +238,12 @@ 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
|
||||||
@@ -297,6 +306,9 @@ en:
|
|||||||
enable: "Enable"
|
enable: "Enable"
|
||||||
disable: "Disable"
|
disable: "Disable"
|
||||||
shared:
|
shared:
|
||||||
|
booths_search:
|
||||||
|
button: Search
|
||||||
|
placeholder: Search booth by name
|
||||||
proposal_search:
|
proposal_search:
|
||||||
button: Search
|
button: Search
|
||||||
placeholder: Search proposals by title, code, description or question
|
placeholder: Search proposals by title, code, description or question
|
||||||
|
|||||||
@@ -186,13 +186,16 @@ es:
|
|||||||
no_questions: "No hay preguntas asignadas a esta votación todavía."
|
no_questions: "No hay preguntas asignadas a esta votación todavía."
|
||||||
no_officers: "No hay presidentes de mesa asignados."
|
no_officers: "No hay presidentes de mesa asignados."
|
||||||
remove_booth: "Desasignar urna"
|
remove_booth: "Desasignar urna"
|
||||||
booths_title: "Listado de urnas"
|
booths_title: "Listado de urnas asignadas"
|
||||||
officers_title: "Listado de presidentes de mesa"
|
officers_title: "Listado de presidentes de mesa asignados"
|
||||||
questions_title: "Listado de preguntas"
|
questions_title: "Listado de preguntas asignadas"
|
||||||
remove_question: "Desasignar pregunta"
|
remove_question: "Desasignar pregunta"
|
||||||
|
add_booth: "Asignar urna"
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
location: "Ubicación"
|
location: "Ubicación"
|
||||||
email: "Email"
|
email: "Email"
|
||||||
|
search_results: "Resultados de la búsqueda"
|
||||||
|
no_search_results: "No se han encontrado resultados"
|
||||||
questions:
|
questions:
|
||||||
index:
|
index:
|
||||||
title: "Preguntas ciudadanas"
|
title: "Preguntas ciudadanas"
|
||||||
@@ -235,6 +238,12 @@ 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'
|
||||||
@@ -297,6 +306,9 @@ es:
|
|||||||
enable: "Activar"
|
enable: "Activar"
|
||||||
disable: "Desactivar"
|
disable: "Desactivar"
|
||||||
shared:
|
shared:
|
||||||
|
booths_search:
|
||||||
|
button: Buscar
|
||||||
|
placeholder: Buscar urna por nombre
|
||||||
proposal_search:
|
proposal_search:
|
||||||
button: Buscar
|
button: Buscar
|
||||||
placeholder: Buscar propuestas por título, código, descripción o pregunta
|
placeholder: Buscar propuestas por título, código, descripción o pregunta
|
||||||
|
|||||||
@@ -187,8 +187,12 @@ Rails.application.routes.draw do
|
|||||||
resources :officers do
|
resources :officers do
|
||||||
get :search, on: :collection
|
get :search, on: :collection
|
||||||
end
|
end
|
||||||
resources :polls
|
resources :polls do
|
||||||
|
get :search_booths, on: :member
|
||||||
|
end
|
||||||
|
|
||||||
resources :booths
|
resources :booths
|
||||||
|
resources :booth_assignments, only: [:create, :destroy]
|
||||||
resources :questions
|
resources :questions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
66
spec/features/admin/poll/booth_assigments_spec.rb
Normal file
66
spec/features/admin/poll/booth_assigments_spec.rb
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Admin booths assignments' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Assign booth to poll', :js do
|
||||||
|
poll = create(:poll)
|
||||||
|
booth = create(:poll_booth)
|
||||||
|
|
||||||
|
visit admin_poll_path(poll)
|
||||||
|
within('#poll-resources') do
|
||||||
|
click_link 'Booths (0)'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content 'There are no booths in this poll'
|
||||||
|
|
||||||
|
fill_in 'search-booths', with: booth.name
|
||||||
|
click_button 'Search'
|
||||||
|
|
||||||
|
within('#search-booths-results') do
|
||||||
|
click_link 'Assign booth'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content 'Booth assigned'
|
||||||
|
|
||||||
|
visit admin_poll_path(poll)
|
||||||
|
within('#poll-resources') do
|
||||||
|
click_link 'Booths (1)'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_content 'There are no booths in this poll'
|
||||||
|
expect(page).to have_content booth.name
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'remove booth from poll', :js do
|
||||||
|
poll = create(:poll)
|
||||||
|
booth = create(:poll_booth)
|
||||||
|
create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
|
|
||||||
|
visit admin_poll_path(poll)
|
||||||
|
within('#poll-resources') do
|
||||||
|
click_link 'Booths (1)'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_content 'There are no booths in this poll'
|
||||||
|
expect(page).to have_content booth.name
|
||||||
|
|
||||||
|
within("#booth_#{booth.id}") do
|
||||||
|
click_link 'Remove booth from poll'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content 'Booth not assigned anymore'
|
||||||
|
|
||||||
|
visit admin_poll_path(poll)
|
||||||
|
within('#poll-resources') do
|
||||||
|
click_link 'Booths (0)'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content 'There are no booths in this poll'
|
||||||
|
expect(page).to_not have_content booth.name
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user