Now the view is more readable and it's possible to customize these methods writing a custom class, without changing or copying the view.
36 lines
943 B
Ruby
36 lines
943 B
Ruby
class Budgets::Investments::VotesComponent < ApplicationComponent
|
|
attr_reader :investment, :investment_votes, :vote_url
|
|
delegate :current_user, :voted_for?, :image_absolute_url,
|
|
:link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers
|
|
|
|
def initialize(investment, investment_votes:, vote_url:)
|
|
@investment = investment
|
|
@investment_votes = investment_votes
|
|
@vote_url = vote_url
|
|
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 ||= voted_for?(investment_votes, investment)
|
|
end
|
|
|
|
def display_support_alert?
|
|
current_user &&
|
|
!current_user.voted_in_group?(investment.group) &&
|
|
investment.group.headings.count > 1
|
|
end
|
|
|
|
def css_for_aria_hidden
|
|
reason.present? ? "true" : ""
|
|
end
|
|
end
|