Simplify passing polls in shifts form component
This commit is contained in:
@@ -22,11 +22,11 @@
|
||||
<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(voting_polls)),
|
||||
options_for_select(shift_vote_collection_dates),
|
||||
{ prompt: voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") },
|
||||
class: "js-shift-vote-collection-dates" %>
|
||||
<%= select "shift[date]", "recount_scrutiny_date",
|
||||
options_for_select(shift_recount_scrutiny_dates(recount_polls)),
|
||||
options_for_select(shift_recount_scrutiny_dates),
|
||||
{ prompt: t("admin.poll_shifts.new.select_date") },
|
||||
class: "js-shift-recount-scrutiny-dates",
|
||||
hidden: "hidden" %>
|
||||
|
||||
@@ -17,16 +17,16 @@ class Admin::Poll::Shifts::FormComponent < ApplicationComponent
|
||||
booth.polls.current_or_recounting
|
||||
end
|
||||
|
||||
def shift_vote_collection_dates(polls)
|
||||
return [] if polls.blank?
|
||||
def shift_vote_collection_dates
|
||||
return [] if voting_polls.blank?
|
||||
|
||||
date_options((start_date(polls)..end_date(polls)), Poll::Shift.tasks[:vote_collection])
|
||||
date_options((voting_start_date..voting_end_date), Poll::Shift.tasks[:vote_collection])
|
||||
end
|
||||
|
||||
def shift_recount_scrutiny_dates(polls)
|
||||
return [] if polls.blank?
|
||||
def shift_recount_scrutiny_dates
|
||||
return [] if recount_polls.blank?
|
||||
|
||||
dates = polls.map(&:ends_at).map(&:to_date).sort.reduce([]) do |total, date|
|
||||
dates = recount_polls.map(&:ends_at).map(&:to_date).sort.reduce([]) do |total, date|
|
||||
initial_date = [date, Date.current].max
|
||||
total << (initial_date..date + Poll::RECOUNT_DURATION).to_a
|
||||
end
|
||||
@@ -41,13 +41,13 @@ class Admin::Poll::Shifts::FormComponent < ApplicationComponent
|
||||
dates.reject { |date| officer_shifts(task_id).include?(date) }
|
||||
end
|
||||
|
||||
def start_date(polls)
|
||||
start_date = polls.minimum(:starts_at).to_date
|
||||
def voting_start_date
|
||||
start_date = voting_polls.minimum(:starts_at).to_date
|
||||
[start_date, Date.current].max
|
||||
end
|
||||
|
||||
def end_date(polls)
|
||||
polls.maximum(:ends_at).to_date
|
||||
def voting_end_date
|
||||
voting_polls.maximum(:ends_at).to_date
|
||||
end
|
||||
|
||||
def officer_shifts(task_id)
|
||||
|
||||
Reference in New Issue
Block a user