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