adds shifts
This commit is contained in:
53
app/controllers/admin/poll/shifts_controller.rb
Normal file
53
app/controllers/admin/poll/shifts_controller.rb
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
class Admin::Poll::ShiftsController < Admin::BaseController
|
||||||
|
|
||||||
|
before_action :load_booth
|
||||||
|
before_action :load_polls
|
||||||
|
|
||||||
|
def new
|
||||||
|
load_officers
|
||||||
|
load_shifts
|
||||||
|
@shift = ::Poll::Shift.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@shift = ::Poll::Shift.new(shift_params)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@shift = Poll::Shift.find(params[:id])
|
||||||
|
@shift.destroy
|
||||||
|
notice = t("admin.poll_shifts.flash.destroy")
|
||||||
|
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_booth
|
||||||
|
@booth = ::Poll::Booth.find(params[:booth_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_polls
|
||||||
|
@polls = ::Poll.current_or_incoming
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_officers
|
||||||
|
@officers = ::Poll::Officer.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_shifts
|
||||||
|
@shifts = @booth.shifts
|
||||||
|
end
|
||||||
|
|
||||||
|
def shift_params
|
||||||
|
params.require(:shift).permit(:booth_id, :officer_id, :date)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
23
app/helpers/shifts_helper.rb
Normal file
23
app/helpers/shifts_helper.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
module ShiftsHelper
|
||||||
|
|
||||||
|
def shift_dates_select_options(polls)
|
||||||
|
options = []
|
||||||
|
(start_date(polls)..end_date(polls)).each do |date|
|
||||||
|
options << [l(date, format: :long), l(date)]
|
||||||
|
end
|
||||||
|
options_for_select(options, params[:date])
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_date(polls)
|
||||||
|
polls.map(&:starts_at).min.to_date
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_date(polls)
|
||||||
|
polls.map(&:ends_at).max.to_date
|
||||||
|
end
|
||||||
|
|
||||||
|
def officer_select_options(officers)
|
||||||
|
officers.collect { |officer| [officer.name, officer.id] }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -35,6 +35,10 @@ class Poll < ActiveRecord::Base
|
|||||||
ends_at < timestamp
|
ends_at < timestamp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.current_or_incoming
|
||||||
|
current + incoming
|
||||||
|
end
|
||||||
|
|
||||||
def answerable_by?(user)
|
def answerable_by?(user)
|
||||||
user.present? &&
|
user.present? &&
|
||||||
user.level_two_or_three_verified? &&
|
user.level_two_or_three_verified? &&
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class Poll
|
|||||||
class Booth < ActiveRecord::Base
|
class Booth < ActiveRecord::Base
|
||||||
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
||||||
has_many :polls, through: :booth_assignments
|
has_many :polls, through: :booth_assignments
|
||||||
|
has_many :shifts
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
|||||||
22
app/models/poll/shift.rb
Normal file
22
app/models/poll/shift.rb
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
class Poll
|
||||||
|
class Shift < ActiveRecord::Base
|
||||||
|
belongs_to :booth
|
||||||
|
belongs_to :officer
|
||||||
|
|
||||||
|
validates :booth_id, presence: true
|
||||||
|
validates :officer_id, presence: true
|
||||||
|
validates :date, presence: true
|
||||||
|
validates :date, uniqueness: { scope: [:officer_id, :booth_id] }
|
||||||
|
|
||||||
|
after_create :create_officer_assignments
|
||||||
|
|
||||||
|
def create_officer_assignments
|
||||||
|
booth.booth_assignments.each do |booth_assignment|
|
||||||
|
attrs = { officer_id: officer_id,
|
||||||
|
date: date,
|
||||||
|
booth_assignment_id: booth_assignment.id }
|
||||||
|
Poll::OfficerAssignment.create!(attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
<%= booth.location %>
|
<%= booth.location %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
|
<%= link_to t("admin.booths.booth.shifts"),
|
||||||
|
new_admin_booth_shift_path(booth),
|
||||||
|
class: "button hollow" %>
|
||||||
<%= link_to t("admin.actions.edit"),
|
<%= link_to t("admin.actions.edit"),
|
||||||
edit_admin_booth_path(booth),
|
edit_admin_booth_path(booth),
|
||||||
class: "button hollow" %>
|
class: "button hollow" %>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<th><%= t("admin.booths.index.name") %></th>
|
<th><%= t("admin.booths.index.name") %></th>
|
||||||
<th><%= t("admin.booths.index.location") %></th>
|
<th><%= t("admin.booths.index.location") %></th>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
|
<th> </th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @booths.each do |booth| %>
|
<% @booths.each do |booth| %>
|
||||||
|
|||||||
24
app/views/admin/poll/shifts/_shifts.html.erb
Normal file
24
app/views/admin/poll/shifts/_shifts.html.erb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<h3><%= t("admin.poll_shifts.new.assignments") %></h3>
|
||||||
|
<table class="fixed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.poll_shifts.new.date") %></th>
|
||||||
|
<th><%= t("admin.poll_shifts.new.officer") %></th>
|
||||||
|
<th class="text-right"><%= t("admin.poll_shifts.new.assignment") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @shifts.each do |shift| %>
|
||||||
|
<tr id="shift_<%= shift.id %>" class="shift">
|
||||||
|
<td><%= l(shift.date.to_date, format: :long) %></td>
|
||||||
|
<td><%= shift.officer.name %></td>
|
||||||
|
<td class="text-right">
|
||||||
|
<%= link_to t("admin.poll_shifts.new.remove_assignment"),
|
||||||
|
admin_booth_shift_path(@booth, shift),
|
||||||
|
method: :delete,
|
||||||
|
class: "button hollow alert" %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
46
app/views/admin/poll/shifts/new.html.erb
Normal file
46
app/views/admin/poll/shifts/new.html.erb
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<%= back_link_to admin_booths_path %>
|
||||||
|
|
||||||
|
<h2><%= @booth.name %></h2>
|
||||||
|
|
||||||
|
<%= form_for @shift, as: :shift, url: admin_booth_shifts_path do |f| %>
|
||||||
|
<%= render "shared/errors", resource: @shift %>
|
||||||
|
|
||||||
|
<fieldset class="fieldset">
|
||||||
|
<legend>
|
||||||
|
<%= t("admin.poll_shifts.new.new_assignment") %>
|
||||||
|
</legend>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<label><%= t("admin.poll_shifts.new.date") %></label>
|
||||||
|
<%= f.select :date,
|
||||||
|
shift_dates_select_options(@polls),
|
||||||
|
prompt: t("admin.poll_shifts.new.select_date"),
|
||||||
|
label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<label><%= t("admin.poll_shifts.new.officer") %></label>
|
||||||
|
<%= f.select :officer_id,
|
||||||
|
officer_select_options(@officers),
|
||||||
|
prompt: t("admin.poll_shifts.new.select_officer"),
|
||||||
|
label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.hidden_field :booth_id, value: @booth.id %>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<%= f.submit t("admin.poll_shifts.new.add_assignment"),
|
||||||
|
class: "button expanded hollow margin-top" %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="shifts">
|
||||||
|
<% if @shifts.empty? %>
|
||||||
|
<div class="callout primary margin-top">
|
||||||
|
<%= t("admin.poll_shifts.new.no_assignments") %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<%= render "shifts" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -403,6 +403,7 @@ en:
|
|||||||
poll_officers: Poll officers
|
poll_officers: Poll officers
|
||||||
polls: Polls
|
polls: Polls
|
||||||
poll_booths: Booths location
|
poll_booths: Booths location
|
||||||
|
poll_shifts: Manage shifts
|
||||||
officials: Officials
|
officials: Officials
|
||||||
organizations: Organisations
|
organizations: Organisations
|
||||||
settings: Configuration settings
|
settings: Configuration settings
|
||||||
@@ -481,11 +482,6 @@ en:
|
|||||||
search: Search
|
search: Search
|
||||||
user_not_found: User not found
|
user_not_found: User not found
|
||||||
poll_officer_assignments:
|
poll_officer_assignments:
|
||||||
flash:
|
|
||||||
destroy: "Officing shift removed"
|
|
||||||
create: "Officing shift added"
|
|
||||||
error_destroy: "An error ocurred when removing officer assignment"
|
|
||||||
error_create: "An error ocurred when adding officer assignment"
|
|
||||||
index:
|
index:
|
||||||
officers_title: "List of officers"
|
officers_title: "List of officers"
|
||||||
no_officers: "There are no officers assigned to this poll."
|
no_officers: "There are no officers assigned to this poll."
|
||||||
@@ -494,18 +490,27 @@ en:
|
|||||||
add_officer_assignments: "Add shifts as officer"
|
add_officer_assignments: "Add shifts as officer"
|
||||||
edit_officer_assignments: "Edit officing shifts"
|
edit_officer_assignments: "Edit officing shifts"
|
||||||
by_officer:
|
by_officer:
|
||||||
new_assignment: "New shift"
|
|
||||||
date: "Date"
|
date: "Date"
|
||||||
booth: "Booth"
|
booth: "Booth"
|
||||||
assignment: "Assignment"
|
|
||||||
select_date: "Select day"
|
|
||||||
select_booth: "Select booth"
|
|
||||||
add_assignment: "Add shift"
|
|
||||||
remove_assignment: "Remove"
|
|
||||||
assignments: "Officing shifts in this poll"
|
assignments: "Officing shifts in this poll"
|
||||||
no_assignments: "This user has no officing shifts in this poll."
|
no_assignments: "This user has no officing shifts in this poll."
|
||||||
final_recounts: "Final recounts"
|
final_recounts: "Final recounts"
|
||||||
final_recount: "Final recount (by officer)"
|
final_recount: "Final recount (by officer)"
|
||||||
|
poll_shifts:
|
||||||
|
new:
|
||||||
|
new_assignment: "New shift"
|
||||||
|
date: "Date"
|
||||||
|
officer: "Officer"
|
||||||
|
assignment: "Assignment"
|
||||||
|
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"
|
||||||
|
flash:
|
||||||
|
create: "Shift added"
|
||||||
|
destroy: "Shift removed"
|
||||||
poll_booth_assignments:
|
poll_booth_assignments:
|
||||||
flash:
|
flash:
|
||||||
destroy: "Booth not assigned anymore"
|
destroy: "Booth not assigned anymore"
|
||||||
@@ -618,6 +623,8 @@ en:
|
|||||||
submit_button: "Update booth"
|
submit_button: "Update booth"
|
||||||
show:
|
show:
|
||||||
location: "Location"
|
location: "Location"
|
||||||
|
booth:
|
||||||
|
shifts: "Manage shifts"
|
||||||
officials:
|
officials:
|
||||||
edit:
|
edit:
|
||||||
destroy: Remove 'Official' status
|
destroy: Remove 'Official' status
|
||||||
|
|||||||
@@ -414,6 +414,7 @@ es:
|
|||||||
poll_officers: Presidentes de mesa
|
poll_officers: Presidentes de mesa
|
||||||
polls: Votaciones
|
polls: Votaciones
|
||||||
poll_booths: Ubicación de urnas
|
poll_booths: Ubicación de urnas
|
||||||
|
poll_shifts: Asignar turnos
|
||||||
officials: Cargos públicos
|
officials: Cargos públicos
|
||||||
organizations: Organizaciones
|
organizations: Organizaciones
|
||||||
settings: Configuración global
|
settings: Configuración global
|
||||||
@@ -481,11 +482,6 @@ es:
|
|||||||
search: Buscar
|
search: Buscar
|
||||||
user_not_found: Usuario no encontrado
|
user_not_found: Usuario no encontrado
|
||||||
poll_officer_assignments:
|
poll_officer_assignments:
|
||||||
flash:
|
|
||||||
destroy: "Eliminado turno de presidente de mesa"
|
|
||||||
create: "Añadido turno de presidente de mesa"
|
|
||||||
error_destroy: "Se ha producido un error al eliminar el turno"
|
|
||||||
error_create: "Se ha producido un error al intentar crear el turno"
|
|
||||||
index:
|
index:
|
||||||
officers_title: "Listado de presidentes de mesa asignados"
|
officers_title: "Listado de presidentes de mesa asignados"
|
||||||
no_officers: "No hay presidentes de mesa asignados a esta votación."
|
no_officers: "No hay presidentes de mesa asignados a esta votación."
|
||||||
@@ -494,18 +490,27 @@ es:
|
|||||||
add_officer_assignments: "Añadir turnos como presidente de mesa"
|
add_officer_assignments: "Añadir turnos como presidente de mesa"
|
||||||
edit_officer_assignments: "Editar turnos"
|
edit_officer_assignments: "Editar turnos"
|
||||||
by_officer:
|
by_officer:
|
||||||
new_assignment: "Nuevo turno"
|
|
||||||
date: "Fecha"
|
date: "Fecha"
|
||||||
booth: "Urna"
|
booth: "Urna"
|
||||||
assignment: "Asignación"
|
|
||||||
select_date: "Seleccionar día"
|
|
||||||
select_booth: "Seleccionar urna"
|
|
||||||
add_assignment: "Añadir turno"
|
|
||||||
remove_assignment: "Eliminar turno"
|
|
||||||
assignments: "Turnos como presidente de mesa en esta votación"
|
assignments: "Turnos como presidente de mesa en esta votación"
|
||||||
no_assignments: "No tiene turnos como presidente de mesa en esta votación."
|
no_assignments: "No tiene turnos como presidente de mesa en esta votación."
|
||||||
final_recounts: "Recuentos finales"
|
final_recounts: "Recuentos finales"
|
||||||
final_recount: "Recuento final (presidente de mesa)"
|
final_recount: "Recuento final (presidente de mesa)"
|
||||||
|
poll_shifts:
|
||||||
|
new:
|
||||||
|
new_assignment: "Nuevo turno"
|
||||||
|
date: "Fecha"
|
||||||
|
officer: "Presidente de mesa"
|
||||||
|
assignment: "Asignación"
|
||||||
|
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"
|
||||||
|
flash:
|
||||||
|
create: "Añadido turno de presidente de mesa"
|
||||||
|
destroy: "Eliminado turno de presidente de mesa"
|
||||||
poll_booth_assignments:
|
poll_booth_assignments:
|
||||||
flash:
|
flash:
|
||||||
destroy: "Urna desasignada"
|
destroy: "Urna desasignada"
|
||||||
@@ -618,6 +623,8 @@ es:
|
|||||||
submit_button: "Actualizar urna"
|
submit_button: "Actualizar urna"
|
||||||
show:
|
show:
|
||||||
location: "Ubicación"
|
location: "Ubicación"
|
||||||
|
booth:
|
||||||
|
shifts: "Asignar turnos"
|
||||||
officials:
|
officials:
|
||||||
edit:
|
edit:
|
||||||
destroy: Eliminar condición de 'Cargo Público'
|
destroy: Eliminar condición de 'Cargo Público'
|
||||||
|
|||||||
@@ -273,7 +273,10 @@ Rails.application.routes.draw do
|
|||||||
get :search, on: :collection
|
get :search, on: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :booths
|
resources :booths do
|
||||||
|
resources :shifts
|
||||||
|
end
|
||||||
|
|
||||||
resources :questions
|
resources :questions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
15
db/migrate/20170724190805_create_poll_shifts.rb
Normal file
15
db/migrate/20170724190805_create_poll_shifts.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreatePollShifts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :poll_shifts do |t|
|
||||||
|
t.integer :booth_id
|
||||||
|
t.integer :officer_id
|
||||||
|
t.date :date
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :poll_shifts, :booth_id
|
||||||
|
add_index :poll_shifts, :officer_id
|
||||||
|
add_index :poll_shifts, [:booth_id, :officer_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
14
db/schema.rb
14
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170719174326) do
|
ActiveRecord::Schema.define(version: 20170724190805) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -652,6 +652,18 @@ ActiveRecord::Schema.define(version: 20170719174326) do
|
|||||||
add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree
|
add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree
|
||||||
add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin
|
add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin
|
||||||
|
|
||||||
|
create_table "poll_shifts", force: :cascade do |t|
|
||||||
|
t.integer "booth_id"
|
||||||
|
t.integer "officer_id"
|
||||||
|
t.date "date"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "poll_shifts", ["booth_id", "officer_id"], name: "index_poll_shifts_on_booth_id_and_officer_id", using: :btree
|
||||||
|
add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree
|
||||||
|
add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree
|
||||||
|
|
||||||
create_table "poll_voters", force: :cascade do |t|
|
create_table "poll_voters", force: :cascade do |t|
|
||||||
t.string "document_number"
|
t.string "document_number"
|
||||||
t.string "document_type"
|
t.string "document_type"
|
||||||
|
|||||||
Reference in New Issue
Block a user