Class: Decidim::DecidimAwesome::Voting::VotingCardsProposalCell

Inherits:
VotingCardsBaseCell
  • Object
show all
Defined in:
app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb

Constant Summary collapse

VOTE_WEIGHTS =
[0, 1, 2, 3].freeze

Instance Method Summary collapse

Methods inherited from VotingCardsBaseCell

#component_settings, #current_component, #current_vote, #proposal, #sanitized_title, #user_voted_weight

Instance Method Details

#classes_for(weight) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 55

def classes_for(weight)
  ops = ["weight_#{weight}"]
  ops << "voted" if voted_for?(weight)
  ops << "dim" if voted_for_any? && !voted_for?(weight)
  ops << "disabled" if disabled?

  ops.join(" ")
end

#disabled?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 64

def disabled?
  return true if voted_for_any? || current_settings.votes_blocked?

  if proposal.maximum_votes_reached? && !proposal.can_accumulate_supports_beyond_threshold && current_component.participatory_space.can_participate?(current_user)
    return true
  end

  return true if vote_limit_enabled? && remaining_votes_count_for(current_user) <= 0
end

#from_proposals_listObject



28
29
30
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 28

def from_proposals_list
  options[:from_proposals_list]
end


36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 36

def link_options(weight)
  ops = {
    class: "vote-action vote-card #{classes_for(weight)}"
  }
  if current_user
    ops.merge!({
                 remote: true,
                 method: :post
               })
  end
  ops
end

#proposal_vote_path(weight) ⇒ Object



32
33
34
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 32

def proposal_vote_path(weight)
  proposal_proposal_vote_path(proposal_id: proposal.id, from_proposals_list: from_proposals_list, weight: weight)
end

#proposal_votes(weight) ⇒ Object



20
21
22
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 20

def proposal_votes(weight)
  model.weight_count(weight)
end

#showObject



9
10
11
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 9

def show
  render :show
end

#svg_path(weight) ⇒ Object



49
50
51
52
53
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 49

def svg_path(weight)
  card = "handcard"
  card = "handcheck" if voted_for?(weight)
  "#{asset_pack_path("media/images/#{card}.svg")}#handcard"
end

#titleObject



78
79
80
81
82
83
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 78

def title
  txt ||= translated_attribute(current_component.settings.voting_cards_box_title)
  return "" if txt == "-"

  txt.presence || t("decidim.decidim_awesome.voting.voting_cards.default_box_title")
end

#vote_block_for(proposal, weight) ⇒ Object



13
14
15
16
17
18
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 13

def vote_block_for(proposal, weight)
  render partial: "vote_block", locals: {
    proposal: proposal,
    weight: weight
  }
end

#voted_for?(option) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 24

def voted_for?(option)
  user_voted_weight == option
end

#voted_for_any?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 74

def voted_for_any?
  VOTE_WEIGHTS.any? { |opt| voted_for?(opt) }
end