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



60
61
62
63
64
65
66
67
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 60

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)


69
70
71
72
73
74
75
76
77
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 69

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

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

#from_proposals_listObject



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

def from_proposals_list
  options[:from_proposals_list]
end


41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 41

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



37
38
39
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 37

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

#proposal_votes(weight) ⇒ Object



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

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



54
55
56
57
58
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 54

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

#titleObject



83
84
85
86
87
88
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 83

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:,
    weight:
  }
end

#vote_instructionsObject



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

def vote_instructions
  translated_attribute(current_component.settings.voting_cards_instructions).presence || t("decidim.decidim_awesome.voting.voting_cards.default_instructions_html",
                                                                                           organization: current_organization.name)
end

#voted_for?(option) ⇒ Boolean

Returns:

  • (Boolean)


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

def voted_for?(option)
  user_voted_weight == option
end

#voted_for_any?Boolean

Returns:

  • (Boolean)


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

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