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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/presenters/decidim/elections/election_presenter.rb', line 27
def to_json(admin: false)
{
id: election.id,
ongoing: election.ongoing?,
scheduled: election.scheduled?,
status: election.status,
start_date: election.start_at&.iso8601,
end_date: election.end_at.iso8601,
title: election.translated_attribute(title),
description: election.translated_attribute(description),
allow_census_check_before_start: election.allow_census_check_before_start,
census_ready: election.census_ready?,
questions: questions.map do |question|
{
id: question.id,
body: translated_attribute(question.body),
position: question.position,
voting_enabled: question.voting_enabled?,
published_results: question.published_results?
}.tap do |hash|
next unless admin || result_published_questions.include?(question)
hash[:total_votes] = question.total_votes
hash[:total_votes_text] = I18n.t("total_votes", scope: "decidim.elections.elections.vote_results", count: question.total_votes)
end.merge(
response_options: question.response_options.map do |option|
{
id: option.id,
body: translated_attribute(option.body)
}.tap do |hash|
next unless admin || result_published_questions.include?(question)
hash[:votes_count] = option.votes_count
hash[:votes_count_text] = I18n.t("votes_count", scope: "decidim.elections.elections.show", count: option.votes_count)
hash[:votes_percent_text] = number_to_percentage(option.votes_percent, precision: 1)
hash[:votes_percent] = option.votes_percent
end
end
)
end
}
end
|