Files
grecia/app/components/budgets/investments/votes_component.rb

63 lines
1.7 KiB
Ruby

class Budgets::Investments::VotesComponent < ApplicationComponent
attr_reader :investment
delegate :namespace, :current_user, :voted_for?, :image_absolute_url,
:link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers
def initialize(investment)
@investment = investment
end
def support_path
case namespace
when "management"
management_budget_investment_votes_path(investment.budget, investment)
else
budget_investment_votes_path(investment.budget, investment)
end
end
def remove_support_path
vote = investment.votes_for.find_by!(voter: current_user)
case namespace
when "management"
management_budget_investment_vote_path(investment.budget, investment, vote)
else
budget_investment_vote_path(investment.budget, investment, vote)
end
end
private
def reason
@reason ||= investment.reason_for_not_being_selectable_by(current_user)
end
def voting_allowed?
reason != :not_voting_allowed
end
def user_voted_for?
@user_voted_for = current_user&.voted_for?(investment) unless defined?(@user_voted_for)
@user_voted_for
end
def display_support_alert?
current_user &&
!current_user.voted_in_group?(investment.group) &&
investment.group.headings.count > investment.group.max_votable_headings
end
def confirm_vote_message
t("budgets.investments.votes.confirm_group", count: investment.group.max_votable_headings)
end
def support_aria_label
t("budgets.investments.votes.support_label", investment: investment.title)
end
def remove_support_aria_label
t("budgets.investments.votes.remove_support_label", investment: investment.title)
end
end