diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 3773014ac..3a55feb4f 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -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 diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 4004a949b..07e07381f 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -24,12 +24,12 @@
<%= 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',