Add Shift vote and recount date ranges, filter selected one on controller

This commit is contained in:
Bertocq
2017-09-27 18:08:03 +02:00
parent ce92dcd088
commit f40a0d09ed
3 changed files with 20 additions and 12 deletions

View File

@@ -54,7 +54,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
end end
def shift_params def shift_params
params.require(:shift).permit(:booth_id, :officer_id, :date, :task) shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date:[:vote_collection_date, :recount_scrutiny_date])
shift_params.merge(date: shift_params[:date]["#{shift_params[:task]}_date".to_sym])
end end
end end

View File

@@ -1,11 +1,15 @@
module ShiftsHelper module ShiftsHelper
def shift_dates_select_options(polls) def shift_vote_collection_dates(polls)
options = [] date_options((start_date(polls)..end_date(polls)))
(start_date(polls)..end_date(polls)).each do |date| end
options << [l(date, format: :long), l(date)]
end def shift_recount_scrutiny_dates(polls)
options_for_select(options, params[:date]) date_options(polls.map(&:ends_at).map(&:to_date).inject([]) { |total, date| total << (date..date + 1.week).to_a }.flatten.uniq)
end
def date_options(dates)
dates.map { |date| [l(date, format: :long), l(date)] }
end end
def start_date(polls) def start_date(polls)

View File

@@ -22,10 +22,14 @@
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<label><%= t("admin.poll_shifts.new.date") %></label> <label><%= t("admin.poll_shifts.new.date") %></label>
<%= f.select :date, <%= select 'shift[date]', 'vote_collection_date',
shift_dates_select_options(@polls), options_for_select(shift_vote_collection_dates(@polls)),
prompt: t("admin.poll_shifts.new.select_date"), prompt: t("admin.poll_shifts.new.select_date"),
label: false %> label: false %>
<%= select 'shift[date]', 'recount_scrutiny_date',
options_for_select(shift_recount_scrutiny_dates(@polls)),
prompt: t("admin.poll_shifts.new.select_date"),
label: false %>
</div> </div>
<%= f.hidden_field :booth_id, value: @booth.id %> <%= f.hidden_field :booth_id, value: @booth.id %>