-
Notifications
You must be signed in to change notification settings - Fork 25
/
proposal_metadata_cell.rb
54 lines (46 loc) · 1.74 KB
/
proposal_metadata_cell.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
module Decidim
module DecidimAwesome
module Voting
# This cell renders metadata for an instance of a Proposal
class ProposalMetadataCell < ::Decidim::Proposals::ProposalMetadataCell
private
def proposal_items
[coauthors_item, comments_count_item, endorsements_count_item, weight_count_item, state_item, emendation_item]
end
def current_vote
@current_vote ||= Decidim::Proposals::ProposalVote.find_by(author: current_user, proposal: resource)
end
def user_voted_weight
current_vote&.weight
end
def all_weights
@all_weights ||= begin
weights = [3, 2, 1]
weights << 0 if resource.component.settings.voting_cards_show_abstain
weights.index_with do |weight|
resource.weight_count(weight)
end
end
end
def weight_tags
@weight_tags ||= all_weights.map do |num, weight|
content_tag "span", title: resource.manifest.label_for(num), class: "voting-weight_#{num}" do
"#{t("decidim.decidim_awesome.voting.voting_cards.weights.weight_#{num}_short")} #{weight}"
end.html_safe
end
end
def weight_count_item
return unless resource.respond_to?(:weight_count)
return if resource.component.current_settings.votes_hidden?
return if resource&.rejected? || resource&.withdrawn?
{
text: weight_tags.join(" | ").html_safe,
icon: "#{user_voted_weight ? "checkbox" : "close"}-circle-line",
data_attributes: all_weights.transform_keys { |num| "weight-#{num}" }
}
end
end
end
end
end