Trim officer shifts by booth as well

This commit is contained in:
Bertocq
2017-10-18 20:49:30 +02:00
parent 86da0e5154
commit d15f150e98
2 changed files with 12 additions and 12 deletions

View File

@@ -1,23 +1,23 @@
module ShiftsHelper
def shift_vote_collection_dates(polls)
date_options((start_date(polls)..end_date(polls)), Poll::Shift.tasks[:vote_collection])
def shift_vote_collection_dates(booth, polls)
date_options((start_date(polls)..end_date(polls)), Poll::Shift.tasks[:vote_collection], booth)
end
def shift_recount_scrutiny_dates(polls)
def shift_recount_scrutiny_dates(booth, polls)
dates = polls.map(&:ends_at).map(&:to_date).sort.inject([]) do |total, date|
initial_date = date < Date.current ? Date.current : date
total << (initial_date..date + Poll::RECOUNT_DURATION).to_a
end
date_options(dates.flatten.uniq, Poll::Shift.tasks[:recount_scrutiny])
date_options(dates.flatten.uniq, Poll::Shift.tasks[:recount_scrutiny], booth)
end
def date_options(dates, task_id)
valid_dates(dates, task_id).map { |date| [l(date, format: :long), l(date)] }
def date_options(dates, task_id, booth)
valid_dates(dates, task_id, booth).map { |date| [l(date, format: :long), l(date)] }
end
def valid_dates(dates, task_id)
dates.reject { |date| officer_shifts(task_id).include?(date) }
def valid_dates(dates, task_id, booth)
dates.reject { |date| officer_shifts(task_id, booth).include?(date) }
end
def start_date(polls)
@@ -35,7 +35,7 @@ module ShiftsHelper
private
def officer_shifts(task_id)
@officer.shifts.where(task: task_id).map(&:date)
def officer_shifts(task_id, booth)
@officer.shifts.where(task: task_id, booth: booth).map(&:date)
end
end

View File

@@ -24,12 +24,12 @@
<div class="small-12 medium-3 column">
<label><%= t("admin.poll_shifts.new.date") %></label>
<%= select 'shift[date]', 'vote_collection_date',
options_for_select(shift_vote_collection_dates(@booth.polls.current_or_incoming)),
options_for_select(shift_vote_collection_dates(@booth, @booth.polls.current_or_incoming)),
{ prompt: t("admin.poll_shifts.new.select_date"),
label: false },
class: 'js-shift-vote-collection-dates' %>
<%= select 'shift[date]', 'recount_scrutiny_date',
options_for_select(shift_recount_scrutiny_dates(@booth.polls.current_or_recounting_or_incoming)),
options_for_select(shift_recount_scrutiny_dates(@booth, @booth.polls.current_or_recounting_or_incoming)),
{ prompt: t("admin.poll_shifts.new.select_date"),
label: false },
class: 'js-shift-recount-scrutiny-dates',