diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb
index 8a808a7a9..168284474 100644
--- a/app/controllers/admin/poll/shifts_controller.rb
+++ b/app/controllers/admin/poll/shifts_controller.rb
@@ -2,20 +2,21 @@ class Admin::Poll::ShiftsController < Admin::BaseController
before_action :load_booth
before_action :load_polls
+ before_action :load_officer
def new
- load_officers
load_shifts
@shift = ::Poll::Shift.new
end
def create
@shift = ::Poll::Shift.new(shift_params)
+ @officer = @shift.officer
+
if @shift.save
notice = t("admin.poll_shifts.flash.create")
redirect_to new_admin_booth_shift_path(@shift.booth), notice: notice
else
- load_officers
load_shifts
render :new
end
@@ -28,6 +29,10 @@ class Admin::Poll::ShiftsController < Admin::BaseController
redirect_to new_admin_booth_shift_path(@booth), notice: notice
end
+ def search_officers
+ @officers = User.search(params[:search]).order(username: :asc)
+ end
+
private
def load_booth
@@ -38,14 +43,16 @@ class Admin::Poll::ShiftsController < Admin::BaseController
@polls = ::Poll.current_or_incoming
end
- def load_officers
- @officers = ::Poll::Officer.all
- end
-
def load_shifts
@shifts = @booth.shifts
end
+ def load_officer
+ if params[:officer_id].present?
+ @officer = ::Poll::Officer.find(params[:officer_id])
+ end
+ end
+
def shift_params
params.require(:shift).permit(:booth_id, :officer_id, :date)
end
diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb
index 0dbb62cdf..05044dd0e 100644
--- a/app/views/admin/poll/booths/index.html.erb
+++ b/app/views/admin/poll/booths/index.html.erb
@@ -15,8 +15,7 @@
<%= t("admin.booths.index.name") %>
<%= t("admin.booths.index.location") %>
-
-
+ <%= t("admin.actions.actions") %>
| <%= t("admin.poll_shifts.new.table_name") %> | +<%= t("admin.poll_shifts.new.table_email") %> | ++ <%= t("admin.poll_shifts.new.table_shift") %> + | +
|---|---|---|
| + <%= user.name %> + | ++ <%= user.email %> + | ++ <%= link_to t("admin.poll_shifts.new.edit_shifts"), + new_admin_booth_shift_path(officer_id: user.poll_officer.id), + class: "button hollow" %> + | +
| <%= t("admin.poll_shifts.new.date") %> | <%= t("admin.poll_shifts.new.officer") %> | -<%= t("admin.poll_shifts.new.assignment") %> | +<%= t("admin.poll_shifts.new.shift") %> | <%= l(shift.date.to_date, format: :long) %> | <%= shift.officer.name %> |
- <%= link_to t("admin.poll_shifts.new.remove_assignment"),
+ <%= link_to t("admin.poll_shifts.new.remove_shift"),
admin_booth_shift_path(@booth, shift),
method: :delete,
class: "button hollow alert" %>
diff --git a/app/views/admin/poll/shifts/new.html.erb b/app/views/admin/poll/shifts/new.html.erb
index c997dc35f..b975c40a9 100644
--- a/app/views/admin/poll/shifts/new.html.erb
+++ b/app/views/admin/poll/shifts/new.html.erb
@@ -2,45 +2,21 @@
<%= @booth.name %>-<%= form_for @shift, as: :shift, url: admin_booth_shifts_path do |f| %> - <%= render "shared/errors", resource: @shift %> - - +<% if @officer.blank? %> ++ <%= t("admin.poll_shifts.new.search_officer_text") %> + + <%= render "search_officers" %> +<% else %> + <%= render "form" %> <% end %>
<% if @shifts.empty? %>
-
diff --git a/app/views/admin/poll/shifts/search_officers.js.erb b/app/views/admin/poll/shifts/search_officers.js.erb
new file mode 100644
index 000000000..ba621d8f7
--- /dev/null
+++ b/app/views/admin/poll/shifts/search_officers.js.erb
@@ -0,0 +1 @@
+$("#search-officers-results").html("<%= j render 'search_officers_results' %>");
\ No newline at end of file
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index c91719104..3e5cb9d31 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -498,16 +498,22 @@ en:
final_recount: "Final recount (by officer)"
poll_shifts:
new:
- new_assignment: "New shift"
+ add_shift: "Add shift"
+ shift: "Assignment"
+ shifts: "Shifts in this booth"
date: "Date"
+ edit_shifts: Edit shifts
+ new_shift: "New shift"
+ no_shifts: "This booth has no shifts"
officer: "Officer"
- assignment: "Assignment"
+ remove_shift: "Remove"
+ search_officer_button: Search
+ search_officer_placeholder: Search officer
+ search_officer_text: Search for an officer to assign a new shift
select_date: "Select day"
- select_officer: "Select officer"
- add_assignment: "Add shift"
- remove_assignment: "Remove"
- assignments: "Shifts in this booth"
- no_assignments: "This booth has no shifts"
+ table_shift: "Shift"
+ table_email: "Email"
+ table_name: "Name"
flash:
create: "Shift added"
destroy: "Shift removed"
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index 93075d3dc..321887388 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -175,6 +175,7 @@ en:
proposal_notification: "Notification"
spending_proposal: Spending proposal
budget/investment: Investment
+ poll/shift: Shift
user: Account
verification/sms: phone
signature_sheet: Signature sheet
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 58fd31aa1..1b98adaf2 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -498,18 +498,24 @@ es:
final_recount: "Recuento final (presidente de mesa)"
poll_shifts:
new:
- new_assignment: "Nuevo turno"
+ add_shift: "Añadir turno"
+ shift: "Asignación"
+ shifts: "Turnos en esta urna"
date: "Fecha"
+ edit_shifts: Asignar turno
+ new_shift: "Nuevo turno"
+ no_shifts: "Esta urna no tiene turnos asignados"
officer: "Presidente de mesa"
- assignment: "Asignación"
+ remove_shift: "Eliminar turno"
+ search_officer_button: Buscar
+ search_officer_placeholder: Buscar presidentes de mesa
+ search_officer_text: Busca al presidente de mesa para asignar un turno
select_date: "Seleccionar día"
- select_officer: "Seleccionar presidente de mesa"
- add_assignment: "Añadir turno"
- remove_assignment: "Eliminar turno"
- assignments: "Turnos en esta urna"
- no_assignments: "Esta urna no tiene turnos asignados"
+ table_shift: "Turno"
+ table_email: "Email"
+ table_name: "Nombre"
flash:
- create: "Añadido turno de presidente de mesa"
+ create: "Añadido turno de presidente de mesa"
destroy: "Eliminado turno de presidente de mesa"
poll_booth_assignments:
flash:
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 18597d347..c4fd431b9 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -175,6 +175,7 @@ es:
proposal_notification: "la notificación"
spending_proposal: la propuesta de gasto
budget/investment: la propuesta de inversión
+ poll/shift: el turno
user: la cuenta
verification/sms: el teléfono
signature_sheet: la hoja de firmas
diff --git a/config/routes.rb b/config/routes.rb
index a3f351e60..a41e8d429 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -288,8 +288,10 @@ Rails.application.routes.draw do
resources :booths do
get :available, on: :collection
-
- resources :shifts
+
+ resources :shifts do
+ get :search_officers, on: :collection
+ end
end
resources :questions
diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb
index fd9b9f4ca..b55e40c7c 100644
--- a/spec/features/admin/poll/shifts_spec.rb
+++ b/spec/features/admin/poll/shifts_spec.rb
@@ -30,7 +30,7 @@ feature 'Admin shifts' do
expect(page).to have_content officer.name
end
- scenario "Create" do
+ scenario "Create", :js do
poll = create(:poll)
booth = create(:poll_booth)
officer = create(:poll_officer)
@@ -41,10 +41,13 @@ feature 'Admin shifts' do
click_link "Manage shifts"
end
- select I18n.l(poll.starts_at.to_date, format: :long), from: 'shift_date'
- select officer.name, from: 'shift_officer_id'
- click_button "Add shift"
+ fill_in "search", with: officer.email
+ click_button "Search"
+ click_link "Edit shifts"
+ select I18n.l(poll.starts_at.to_date, format: :long), from: 'shift_date'
+ click_button "Add shift"
+
expect(page).to have_content "Shift added"
within("#shifts") do
@@ -54,6 +57,25 @@ feature 'Admin shifts' do
end
end
+ scenario "Erros on create", :js do
+ poll = create(:poll)
+ booth = create(:poll_booth)
+ officer = create(:poll_officer)
+
+ visit admin_booths_path
+
+ within("#booth_#{booth.id}") do
+ click_link "Manage shifts"
+ end
+
+ fill_in "search", with: officer.email
+ click_button "Search"
+ click_link "Edit shifts"
+ click_button "Add shift"
+
+ expect(page).to have_content "can't be blank"
+ end
+
scenario "Destroy" do
poll = create(:poll)
booth = create(:poll_booth)
- <%= t("admin.poll_shifts.new.no_assignments") %>
+
\ No newline at end of file
+
+ <%= t("admin.poll_shifts.new.no_shifts") %>
<% else %>
<%= render "shifts" %>
<% end %>
- |
|---|