adds complete Booth management to admin

This commit is contained in:
Juanjo Bazán
2016-12-02 14:28:39 +01:00
parent 6f986f3750
commit f67f058b57
11 changed files with 58 additions and 142 deletions

View File

@@ -1,14 +1,11 @@
class Admin::Poll::BoothsController < Admin::BaseController
load_and_authorize_resource :poll
load_and_authorize_resource class: 'Poll::Booth', through: :poll
before_action :load_polls, only: :index
load_and_authorize_resource class: 'Poll::Booth'
def index
@booths = @booths.order(name: :asc).page(params[:page])
end
def show
@officers = Poll::Officer.all
end
def new
@@ -16,7 +13,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
def create
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
render :new
end
@@ -27,7 +24,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
def update
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
render :edit
end
@@ -36,11 +33,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
private
def booth_params
params.require(:poll_booth).permit(:name, :location, officer_ids: [])
end
def load_polls
@polls = Poll.all
params.require(:poll_booth).permit(:name, :location)
end
end

View File

@@ -1,18 +1,15 @@
<tr id="booth_<%= booth.id %>" class="booth">
<td>
<strong>
<%= link_to booth.name, admin_poll_booth_path(@poll, booth) %>
<%= link_to booth.name, admin_booth_path(booth) %>
</strong>
</td>
<td>
<%= booth.location %>
</td>
<td>
N <%= t("admin.booths.index.officers") %>
</td>
<td class="text-right">
<%= link_to t("admin.actions.edit"),
edit_admin_poll_booth_path(@poll, booth),
edit_admin_booth_path(booth),
class: "button hollow" %>
</td>
</tr>

View File

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

View File

@@ -1,18 +1,5 @@
<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? %>
<div class="callout primary">
<%= t("admin.booths.index.no_booths") %>
@@ -20,14 +7,14 @@
<% end %>
<%= link_to t("admin.booths.index.add_booth"),
new_admin_poll_booth_path(@poll),
new_admin_booth_path,
class: "button success" %>
<% if @booths.any? %>
<table>
<thead>
<th><%= t("admin.booths.index.name") %></th>
<th><%= t("admin.booths.index.location") %></th>
<th><%= t("admin.booths.index.officers") %></th>
<th>&nbsp;</th>
</thead>
<tbody>
@@ -36,3 +23,6 @@
<% end %>
</tbody>
</table>
<%= paginate @booths %>
<% end %>

View File

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

View File

@@ -1,55 +1,15 @@
<%= render 'shared/back_link' %>
<%= back_link_to admin_booths_path %>
<div class="clear"></div>
<h2 class="inline-block">
<%= @booth.name %>
</h2>
<%= link_to t("admin.actions.edit"),
edit_admin_poll_booth_path(@poll, @booth),
edit_admin_booth_path(@booth),
class: "button hollow float-right" %>
<p>
<strong><%= t("admin.booths.show.location") %></strong>:
<%= @booth.location %>
</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>

View File

@@ -202,23 +202,18 @@ en:
booths:
index:
title: "List of booths"
select_poll: "Select a poll"
title_list: "List of booths of poll %{poll}"
no_booths: "There are no booths in this poll."
no_booths: "There are no booths."
add_booth: "Add booth"
name: "Name"
location: "Location"
officers: "Officers"
new:
title: "Poll %{poll}"
subtitle: "New booth"
title: "New booth"
name: "Name"
reference: "Reference number"
location: "Location"
submit_button: "Create booth"
edit:
title: "Poll %{poll}"
subtitle: "Edit booth"
title: "Edit booth"
name: "Name"
reference: "Reference number"
location: "Location"

View File

@@ -202,23 +202,18 @@ es:
booths:
index:
title: "Lista de urnas"
select_poll: "Selecciona una votación"
title_list: "Lista de urnas de la votación %{poll}"
no_booths: "No hay urnas en esta votación."
no_booths: "No hay urnas."
add_booth: "Añadir urna"
name: "Nombre"
location: "Ubicación"
officers: "Presidentes de mesa"
new:
title: "Votación %{poll}"
subtitle: "Nueva urna"
title: "Nueva urna"
name: "Nombre"
reference: "Número de referencia"
location: "Ubicación"
submit_button: "Crear urna"
edit:
title: "Votación %{poll}"
subtitle: "Editar urna"
title: "Editar urna"
name: "Nombre"
reference: "Número de referencia"
location: "Ubicación"

View File

@@ -187,9 +187,8 @@ Rails.application.routes.draw do
resources :officers do
get :search, on: :collection
end
resources :polls do
resources :polls
resources :booths
end
resources :questions
end

View File

@@ -2,8 +2,6 @@ require 'rails_helper'
feature 'Admin booths' do
let!(:poll) { create(:poll) }
background do
admin = create(:administrator)
login_as(admin.user)
@@ -13,25 +11,21 @@ feature 'Admin booths' do
visit admin_root_path
within('#side_menu') do
click_link "Polls"
click_link "Booths"
end
click_link poll.name
expect(page).to have_content "There are no booths in this poll"
expect(page).to have_content "There are no booths"
end
scenario 'Index' do
3.times { create(:poll_booth, poll: poll) }
3.times { create(:poll_booth) }
visit admin_root_path
within('#side_menu') do
click_link "Polls"
click_link "Booths"
end
click_link poll.name
booths = Poll::Booth.all
booths.each do |booth|
within("#booth_#{booth.id}") do
@@ -43,9 +37,9 @@ feature 'Admin booths' do
end
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
expect(page).to have_content booth.name
@@ -53,47 +47,41 @@ feature 'Admin booths' do
end
scenario "Create" do
visit admin_poll_booths_path(poll)
visit admin_booths_path
click_link "Add booth"
expect(page).to have_content "Poll #{poll.name}"
fill_in "poll_booth_name", with: "Upcoming booth"
fill_in "poll_booth_location", with: "39th Street, number 2, ground floor"
click_button "Create booth"
expect(page).to have_content "Booth created successfully"
visit admin_booths_path
expect(page).to have_content "Upcoming booth"
expect(page).to have_content "39th Street, number 2, ground floor"
end
scenario "Edit" do
booth = create(:poll_booth, poll: poll)
booth = create(:poll_booth)
visit admin_poll_booths_path(poll)
visit admin_booths_path
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_location", with: "40th Street, number 1, firts floor"
click_button "Update booth"
expect(page).to have_content "Booth updated successfully"
visit admin_booths_path
within("#booth_#{booth.id}") do
expect(page).to have_content "Next booth"
expect(page).to have_content "40th Street, number 1, firts floor"
end
scenario 'Edit from index' do
booth = create(:poll_booth, poll: poll)
visit admin_poll_booths_path(poll)
within("#booth_#{booth.id}") do
click_link "Edit"
end
expect(current_path).to eq(edit_admin_poll_booth_path(poll, booth))
end
end

View File

@@ -102,5 +102,4 @@ RSpec.configure do |config|
# as the one that triggered the failure.
Kernel.srand config.seed
end