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
|
||||
load_and_authorize_resource
|
||||
before_action :load_search, only: [:search_booths]
|
||||
|
||||
def index
|
||||
end
|
||||
@@ -30,10 +31,25 @@ class Admin::Poll::PollsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def search_booths
|
||||
@booths = ::Poll::Booth.search(@search)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def poll_params
|
||||
params.require(:poll).permit(:name, :starts_at, :ends_at)
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def load_search
|
||||
@search = search_params[:search]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -38,19 +38,20 @@ module Abilities
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :create, :index, :summary], ::Valuator
|
||||
can [:search, :create, :index, :destroy], ::Manager
|
||||
can [:search, :create, :index, :destroy], ::Poll::Officer
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
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 [:manage], Poll
|
||||
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
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= link_to t("admin.polls.show.remove_booth"),
|
||||
"#",
|
||||
admin_booth_assignment_path(poll: @poll, booth: booth),
|
||||
method: :delete,
|
||||
class: "button hollow alert" %>
|
||||
</td>
|
||||
</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">
|
||||
<%= link_to "#tab-questions" do %>
|
||||
<%= 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),
|
||||
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" %>
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-questions">
|
||||
@@ -15,6 +15,7 @@
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-booths">
|
||||
<%= render "search_booths" %>
|
||||
<%= render "booths" %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -190,9 +190,12 @@ en:
|
||||
officers_title: "List of officers"
|
||||
questions_title: "List of questions"
|
||||
remove_question: "Remove question from poll"
|
||||
add_booth: "Assign booth"
|
||||
name: "Name"
|
||||
location: "Location"
|
||||
email: "Email"
|
||||
search_results: "Search results"
|
||||
no_search_results: "No results found"
|
||||
questions:
|
||||
index:
|
||||
title: "Questions"
|
||||
@@ -235,6 +238,12 @@ 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
|
||||
@@ -297,6 +306,9 @@ en:
|
||||
enable: "Enable"
|
||||
disable: "Disable"
|
||||
shared:
|
||||
booths_search:
|
||||
button: Search
|
||||
placeholder: Search booth by name
|
||||
proposal_search:
|
||||
button: Search
|
||||
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_officers: "No hay presidentes de mesa asignados."
|
||||
remove_booth: "Desasignar urna"
|
||||
booths_title: "Listado de urnas"
|
||||
officers_title: "Listado de presidentes de mesa"
|
||||
questions_title: "Listado de preguntas"
|
||||
booths_title: "Listado de urnas asignadas"
|
||||
officers_title: "Listado de presidentes de mesa asignados"
|
||||
questions_title: "Listado de preguntas asignadas"
|
||||
remove_question: "Desasignar pregunta"
|
||||
add_booth: "Asignar urna"
|
||||
name: "Nombre"
|
||||
location: "Ubicación"
|
||||
email: "Email"
|
||||
search_results: "Resultados de la búsqueda"
|
||||
no_search_results: "No se han encontrado resultados"
|
||||
questions:
|
||||
index:
|
||||
title: "Preguntas ciudadanas"
|
||||
@@ -235,6 +238,12 @@ 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'
|
||||
@@ -297,6 +306,9 @@ es:
|
||||
enable: "Activar"
|
||||
disable: "Desactivar"
|
||||
shared:
|
||||
booths_search:
|
||||
button: Buscar
|
||||
placeholder: Buscar urna por nombre
|
||||
proposal_search:
|
||||
button: Buscar
|
||||
placeholder: Buscar propuestas por título, código, descripción o pregunta
|
||||
|
||||
@@ -187,8 +187,12 @@ Rails.application.routes.draw do
|
||||
resources :officers do
|
||||
get :search, on: :collection
|
||||
end
|
||||
resources :polls
|
||||
resources :polls do
|
||||
get :search_booths, on: :member
|
||||
end
|
||||
|
||||
resources :booths
|
||||
resources :booth_assignments, only: [:create, :destroy]
|
||||
resources :questions
|
||||
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