Class: Decidim::DecidimAwesome::Voting::VotingCardsProposalCell
Constant Summary
collapse
- VOTE_WEIGHTS =
[0, 1, 2, 3].freeze
Instance Method Summary
collapse
#component_settings, #current_component, #current_vote, #proposal, #sanitized_title, #user_voted_weight
Instance Method Details
#classes_for(weight) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 53
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
|
#container_classes ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 81
def container_classes
classes = ["awesome-voting-card"]
classes << if from_proposals_list
"from-list"
else
"flex flex-col justify-center"
end
classes.join(" ")
end
|
#disabled? ⇒ Boolean
62
63
64
65
66
67
68
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 62
def disabled?
return true if voted_for_any? || current_settings.votes_blocked?
return true if proposal.maximum_votes_reached? && !proposal.can_accumulate_votes_beyond_threshold && current_component.participatory_space.can_participate?(current_user)
true if vote_limit_enabled? && remaining_votes_count_for_user <= 0
end
|
#from_proposals_list ⇒ Object
21
22
23
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 21
def from_proposals_list
options[:from_proposals_list]
end
|
#link_options(weight) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 29
def link_options(weight)
css_classes = ["vote-action"]
css_classes << "vote-card" unless from_proposals_list
css_classes << classes_for(weight)
ops = {
class: css_classes.join(" ")
}
if current_user
ops.merge!({
resource: proposal,
remote: true,
method: :post
})
end
ops
end
|
#proposal_vote_path(weight) ⇒ Object
25
26
27
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 25
def proposal_vote_path(weight)
proposal_proposal_vote_path(proposal_id: proposal.id, from_proposals_list:, weight:)
end
|
#proposal_votes(weight) ⇒ Object
13
14
15
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 13
def proposal_votes(weight)
model.weight_count(weight)
end
|
#show ⇒ Object
9
10
11
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 9
def show
render(:show)
end
|
#show_title? ⇒ Boolean
91
92
93
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 91
def show_title?
!from_proposals_list
end
|
#svg_path(weight) ⇒ Object
47
48
49
50
51
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 47
def svg_path(weight)
card = "handcard"
card = "handcheck" if voted_for?(weight)
"#{asset_pack_path("media/images/#{card}.svg")}#handcard"
end
|
#title ⇒ Object
74
75
76
77
78
79
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 74
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
99
100
101
102
103
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 99
def vote_block_for(proposal, weight)
@proposal = proposal
@weight = weight
render :vote_block_for
end
|
#voted_for?(option) ⇒ Boolean
17
18
19
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 17
def voted_for?(option)
user_voted_weight == option
end
|
#voted_for_any? ⇒ Boolean
70
71
72
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 70
def voted_for_any?
VOTE_WEIGHTS.any? { |opt| voted_for?(opt) }
end
|
#wrap_change_vote? ⇒ Boolean
95
96
97
|
# File 'app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb', line 95
def wrap_change_vote?
!from_proposals_list
end
|