adds complete Booth management to admin
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
class Admin::Poll::BoothsController < Admin::BaseController
|
class Admin::Poll::BoothsController < Admin::BaseController
|
||||||
load_and_authorize_resource :poll
|
load_and_authorize_resource class: 'Poll::Booth'
|
||||||
load_and_authorize_resource class: 'Poll::Booth', through: :poll
|
|
||||||
|
|
||||||
before_action :load_polls, only: :index
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@booths = @booths.order(name: :asc).page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@officers = Poll::Officer.all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -16,7 +13,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
if @booth.save
|
if @booth.save
|
||||||
redirect_to admin_poll_booth_path(@poll, @booth), notice: t("flash.actions.create.poll_booth")
|
redirect_to admin_booths_path, notice: t("flash.actions.create.poll_booth")
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
@@ -27,7 +24,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
if @booth.update(booth_params)
|
if @booth.update(booth_params)
|
||||||
redirect_to admin_poll_booth_path(@poll, @booth), notice: t("flash.actions.update.poll_booth")
|
redirect_to admin_booth_path(@booth), notice: t("flash.actions.update.poll_booth")
|
||||||
else
|
else
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
@@ -36,11 +33,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def booth_params
|
def booth_params
|
||||||
params.require(:poll_booth).permit(:name, :location, officer_ids: [])
|
params.require(:poll_booth).permit(:name, :location)
|
||||||
end
|
|
||||||
|
|
||||||
def load_polls
|
|
||||||
@polls = Poll.all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
<tr id="booth_<%= booth.id %>" class="booth">
|
<tr id="booth_<%= booth.id %>" class="booth">
|
||||||
<td>
|
<td>
|
||||||
<strong>
|
<strong>
|
||||||
<%= link_to booth.name, admin_poll_booth_path(@poll, booth) %>
|
<%= link_to booth.name, admin_booth_path(booth) %>
|
||||||
</strong>
|
</strong>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= booth.location %>
|
<%= booth.location %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
N <%= t("admin.booths.index.officers") %>
|
|
||||||
</td>
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t("admin.actions.edit"),
|
<%= link_to t("admin.actions.edit"),
|
||||||
edit_admin_poll_booth_path(@poll, booth),
|
edit_admin_booth_path(booth),
|
||||||
class: "button hollow" %>
|
class: "button hollow" %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<%= render 'shared/back_link' %>
|
<%= back_link_to admin_booths_path %>
|
||||||
|
|
||||||
<h2><%= t("admin.booths.edit.title", poll: @poll.name) %>: <%= t("admin.booths.edit.subtitle") %></h2>
|
<h2><%= t("admin.booths.edit.title") %></h2>
|
||||||
|
|
||||||
<%= form_for @booth, url: admin_poll_booth_path(@poll, @booth) do |f| %>
|
<%= form_for @booth, url: admin_booth_path(@booth) do |f| %>
|
||||||
<%= render "form", f: f %>
|
<%= render "form", f: f %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
<h2><%= t("admin.booths.index.title") %></h2>
|
<h2><%= t("admin.booths.index.title") %></h2>
|
||||||
|
|
||||||
<div class="small-12 medium-6">
|
|
||||||
<%= form_tag '', method: :get do %>
|
|
||||||
<%= select_tag "poll_id",
|
|
||||||
options_for_select(@polls.collect {|poll|
|
|
||||||
[poll.name, admin_poll_booths_path(poll)]
|
|
||||||
}),
|
|
||||||
prompt: t("admin.booths.index.select_poll"),
|
|
||||||
class: "js-location-changer" %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3><%= t("admin.booths.index.title_list", poll: @poll.name) %></h3>
|
|
||||||
|
|
||||||
<% if @booths.empty? %>
|
<% if @booths.empty? %>
|
||||||
<div class="callout primary">
|
<div class="callout primary">
|
||||||
<%= t("admin.booths.index.no_booths") %>
|
<%= t("admin.booths.index.no_booths") %>
|
||||||
@@ -20,19 +7,22 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= link_to t("admin.booths.index.add_booth"),
|
<%= link_to t("admin.booths.index.add_booth"),
|
||||||
new_admin_poll_booth_path(@poll),
|
new_admin_booth_path,
|
||||||
class: "button success" %>
|
class: "button success" %>
|
||||||
|
|
||||||
<table>
|
<% if @booths.any? %>
|
||||||
<thead>
|
<table>
|
||||||
<th><%= t("admin.booths.index.name") %></th>
|
<thead>
|
||||||
<th><%= t("admin.booths.index.location") %></th>
|
<th><%= t("admin.booths.index.name") %></th>
|
||||||
<th><%= t("admin.booths.index.officers") %></th>
|
<th><%= t("admin.booths.index.location") %></th>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @booths.each do |booth| %>
|
<% @booths.each do |booth| %>
|
||||||
<%= render partial: "booth", locals: { booth: booth } %>
|
<%= render partial: "booth", locals: { booth: booth } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @booths %>
|
||||||
|
<% end %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<%= render 'shared/back_link' %>
|
<%= back_link_to admin_booths_path %>
|
||||||
|
|
||||||
<h2><%= t("admin.booths.new.title", poll: @poll.name) %>: <%= t("admin.booths.new.subtitle") %></h2>
|
<h2><%= t("admin.booths.new.title") %></h2>
|
||||||
|
|
||||||
<%= form_for @booth, url: admin_poll_booths_path(@poll) do |f| %>
|
<%= form_for @booth, url: admin_booths_path(@booth) do |f| %>
|
||||||
<%= render "form", f: f %>
|
<%= render "form", f: f %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -1,55 +1,15 @@
|
|||||||
<%= render 'shared/back_link' %>
|
<%= back_link_to admin_booths_path %>
|
||||||
|
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
|
||||||
<h2 class="inline-block">
|
<h2 class="inline-block">
|
||||||
<%= @booth.name %>
|
<%= @booth.name %>
|
||||||
</h2>
|
</h2>
|
||||||
<%= link_to t("admin.actions.edit"),
|
<%= link_to t("admin.actions.edit"),
|
||||||
edit_admin_poll_booth_path(@poll, @booth),
|
edit_admin_booth_path(@booth),
|
||||||
class: "button hollow float-right" %>
|
class: "button hollow float-right" %>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong><%= t("admin.booths.show.location") %></strong>:
|
<strong><%= t("admin.booths.show.location") %></strong>:
|
||||||
<%= @booth.location %>
|
<%= @booth.location %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3><%= t("admin.booths.show.officers_list") %></h3>
|
|
||||||
|
|
||||||
<% if @booth.officers.empty? %>
|
|
||||||
<div class="callout primary">
|
|
||||||
<%= t("admin.booths.show.no_officers") %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="small-12 column">
|
|
||||||
<%= form_for @booth, url: admin_poll_booth_path(@poll, @booth) do |f| %>
|
|
||||||
|
|
||||||
<%= f.label :officer_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
|
|
||||||
<%= f.collection_check_boxes :officer_ids, @officers, :id, :email do |b| %>
|
|
||||||
<% b.label { b.check_box + truncate(officer_label(b.object), length: 60) } %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= f.submit t("admin.booths.show.assign_officer"), class: "button success" %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table id="assigned_officers">
|
|
||||||
<% @booth.officers.each do |officer| %>
|
|
||||||
<tr id="officer_<%= officer.id %>" class="officer">
|
|
||||||
<td>
|
|
||||||
<%= officer.name %>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<%= officer.email %>
|
|
||||||
</td>
|
|
||||||
<td class="text-right">
|
|
||||||
<%= link_to t('admin.poll_officers.officer.delete'), "#", class: "button hollow alert" %>
|
|
||||||
<%# link_to t('admin.poll_officers.officer.delete'),
|
|
||||||
admin_poll_officer_path(Poll.last, officer),
|
|
||||||
method: :delete,
|
|
||||||
class: "button hollow alert"
|
|
||||||
%>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</table>
|
|
||||||
@@ -202,23 +202,18 @@ en:
|
|||||||
booths:
|
booths:
|
||||||
index:
|
index:
|
||||||
title: "List of booths"
|
title: "List of booths"
|
||||||
select_poll: "Select a poll"
|
no_booths: "There are no booths."
|
||||||
title_list: "List of booths of poll %{poll}"
|
|
||||||
no_booths: "There are no booths in this poll."
|
|
||||||
add_booth: "Add booth"
|
add_booth: "Add booth"
|
||||||
name: "Name"
|
name: "Name"
|
||||||
location: "Location"
|
location: "Location"
|
||||||
officers: "Officers"
|
|
||||||
new:
|
new:
|
||||||
title: "Poll %{poll}"
|
title: "New booth"
|
||||||
subtitle: "New booth"
|
|
||||||
name: "Name"
|
name: "Name"
|
||||||
reference: "Reference number"
|
reference: "Reference number"
|
||||||
location: "Location"
|
location: "Location"
|
||||||
submit_button: "Create booth"
|
submit_button: "Create booth"
|
||||||
edit:
|
edit:
|
||||||
title: "Poll %{poll}"
|
title: "Edit booth"
|
||||||
subtitle: "Edit booth"
|
|
||||||
name: "Name"
|
name: "Name"
|
||||||
reference: "Reference number"
|
reference: "Reference number"
|
||||||
location: "Location"
|
location: "Location"
|
||||||
|
|||||||
@@ -202,23 +202,18 @@ es:
|
|||||||
booths:
|
booths:
|
||||||
index:
|
index:
|
||||||
title: "Lista de urnas"
|
title: "Lista de urnas"
|
||||||
select_poll: "Selecciona una votación"
|
no_booths: "No hay urnas."
|
||||||
title_list: "Lista de urnas de la votación %{poll}"
|
|
||||||
no_booths: "No hay urnas en esta votación."
|
|
||||||
add_booth: "Añadir urna"
|
add_booth: "Añadir urna"
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
location: "Ubicación"
|
location: "Ubicación"
|
||||||
officers: "Presidentes de mesa"
|
|
||||||
new:
|
new:
|
||||||
title: "Votación %{poll}"
|
title: "Nueva urna"
|
||||||
subtitle: "Nueva urna"
|
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
reference: "Número de referencia"
|
reference: "Número de referencia"
|
||||||
location: "Ubicación"
|
location: "Ubicación"
|
||||||
submit_button: "Crear urna"
|
submit_button: "Crear urna"
|
||||||
edit:
|
edit:
|
||||||
title: "Votación %{poll}"
|
title: "Editar urna"
|
||||||
subtitle: "Editar urna"
|
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
reference: "Número de referencia"
|
reference: "Número de referencia"
|
||||||
location: "Ubicación"
|
location: "Ubicación"
|
||||||
|
|||||||
@@ -187,9 +187,8 @@ Rails.application.routes.draw do
|
|||||||
resources :officers do
|
resources :officers do
|
||||||
get :search, on: :collection
|
get :search, on: :collection
|
||||||
end
|
end
|
||||||
resources :polls do
|
resources :polls
|
||||||
resources :booths
|
resources :booths
|
||||||
end
|
|
||||||
resources :questions
|
resources :questions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Admin booths' do
|
feature 'Admin booths' do
|
||||||
|
|
||||||
let!(:poll) { create(:poll) }
|
|
||||||
|
|
||||||
background do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
@@ -13,25 +11,21 @@ feature 'Admin booths' do
|
|||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
within('#side_menu') do
|
within('#side_menu') do
|
||||||
click_link "Polls"
|
click_link "Booths"
|
||||||
end
|
end
|
||||||
|
|
||||||
click_link poll.name
|
expect(page).to have_content "There are no booths"
|
||||||
|
|
||||||
expect(page).to have_content "There are no booths in this poll"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Index' do
|
scenario 'Index' do
|
||||||
3.times { create(:poll_booth, poll: poll) }
|
3.times { create(:poll_booth) }
|
||||||
|
|
||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
within('#side_menu') do
|
within('#side_menu') do
|
||||||
click_link "Polls"
|
click_link "Booths"
|
||||||
end
|
end
|
||||||
|
|
||||||
click_link poll.name
|
|
||||||
|
|
||||||
booths = Poll::Booth.all
|
booths = Poll::Booth.all
|
||||||
booths.each do |booth|
|
booths.each do |booth|
|
||||||
within("#booth_#{booth.id}") do
|
within("#booth_#{booth.id}") do
|
||||||
@@ -43,9 +37,9 @@ feature 'Admin booths' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Show' do
|
scenario 'Show' do
|
||||||
booth = create(:poll_booth, poll: poll)
|
booth = create(:poll_booth)
|
||||||
|
|
||||||
visit admin_poll_booths_path(poll)
|
visit admin_booths_path
|
||||||
click_link booth.name
|
click_link booth.name
|
||||||
|
|
||||||
expect(page).to have_content booth.name
|
expect(page).to have_content booth.name
|
||||||
@@ -53,47 +47,41 @@ feature 'Admin booths' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Create" do
|
scenario "Create" do
|
||||||
visit admin_poll_booths_path(poll)
|
visit admin_booths_path
|
||||||
click_link "Add booth"
|
click_link "Add booth"
|
||||||
|
|
||||||
expect(page).to have_content "Poll #{poll.name}"
|
|
||||||
|
|
||||||
fill_in "poll_booth_name", with: "Upcoming booth"
|
fill_in "poll_booth_name", with: "Upcoming booth"
|
||||||
fill_in "poll_booth_location", with: "39th Street, number 2, ground floor"
|
fill_in "poll_booth_location", with: "39th Street, number 2, ground floor"
|
||||||
click_button "Create booth"
|
click_button "Create booth"
|
||||||
|
|
||||||
expect(page).to have_content "Booth created successfully"
|
expect(page).to have_content "Booth created successfully"
|
||||||
|
|
||||||
|
visit admin_booths_path
|
||||||
expect(page).to have_content "Upcoming booth"
|
expect(page).to have_content "Upcoming booth"
|
||||||
expect(page).to have_content "39th Street, number 2, ground floor"
|
expect(page).to have_content "39th Street, number 2, ground floor"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Edit" do
|
scenario "Edit" do
|
||||||
booth = create(:poll_booth, poll: poll)
|
booth = create(:poll_booth)
|
||||||
|
|
||||||
visit admin_poll_booths_path(poll)
|
visit admin_booths_path
|
||||||
|
|
||||||
click_link "Edit"
|
within("#booth_#{booth.id}") do
|
||||||
|
click_link "Edit"
|
||||||
expect(page).to have_content "Poll #{poll.name}"
|
end
|
||||||
|
|
||||||
fill_in "poll_booth_name", with: "Next booth"
|
fill_in "poll_booth_name", with: "Next booth"
|
||||||
fill_in "poll_booth_location", with: "40th Street, number 1, firts floor"
|
fill_in "poll_booth_location", with: "40th Street, number 1, firts floor"
|
||||||
click_button "Update booth"
|
click_button "Update booth"
|
||||||
|
|
||||||
expect(page).to have_content "Booth updated successfully"
|
expect(page).to have_content "Booth updated successfully"
|
||||||
expect(page).to have_content "Next booth"
|
|
||||||
expect(page).to have_content "40th Street, number 1, firts floor"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Edit from index' do
|
visit admin_booths_path
|
||||||
booth = create(:poll_booth, poll: poll)
|
|
||||||
visit admin_poll_booths_path(poll)
|
|
||||||
|
|
||||||
within("#booth_#{booth.id}") do
|
within("#booth_#{booth.id}") do
|
||||||
click_link "Edit"
|
expect(page).to have_content "Next booth"
|
||||||
|
expect(page).to have_content "40th Street, number 1, firts floor"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(current_path).to eq(edit_admin_poll_booth_path(poll, booth))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -102,5 +102,4 @@ RSpec.configure do |config|
|
|||||||
# as the one that triggered the failure.
|
# as the one that triggered the failure.
|
||||||
Kernel.srand config.seed
|
Kernel.srand config.seed
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user