Files
nairobi/app/helpers/polls_helper.rb
Javi Martín ccbc708b5b Simplify poll select options helper
The `include_all` parameter was always used, and the option was
redundant because we already had a prompt offering the same
functionality.

I guess one possible reason was users would want to filter by all polls,
and having to click on "select a poll" to do so wasn't that intuitive.
So we're using "All" as the prompt instead.
2021-06-30 16:42:23 +02:00

56 lines
1.5 KiB
Ruby

module PollsHelper
def poll_select_options
options = @polls.map do |poll|
[poll.name, current_path_with_query_params(poll_id: poll.id)]
end
options_for_select(options, request.fullpath)
end
def poll_dates(poll)
if poll.starts_at.blank? || poll.ends_at.blank?
I18n.t("polls.no_dates")
else
I18n.t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
end
end
def booth_name_with_location(booth)
location = booth.location.blank? ? "" : " (#{booth.location})"
booth.name + location
end
def poll_voter_token(poll, user)
Poll::Voter.find_by(poll: poll, user: user, origin: "web")&.token || ""
end
def voted_before_sign_in(question)
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
end
def link_to_poll(text, poll)
if can?(:results, poll)
link_to text, results_poll_path(id: poll.slug || poll.id)
elsif can?(:stats, poll)
link_to text, stats_poll_path(id: poll.slug || poll.id)
else
link_to text, poll_path(id: poll.slug || poll.id)
end
end
def results_menu?
controller_name == "polls" && action_name == "results"
end
def stats_menu?
controller_name == "polls" && action_name == "stats"
end
def info_menu?
controller_name == "polls" && action_name == "show"
end
def show_polls_description?
@active_poll.present? && @current_filter == "current"
end
end