Module: Decidim::Elections::Admin::ElectionsHelper

Includes:
ApplicationHelper, LabelHelper
Defined in:
app/helpers/decidim/elections/admin/elections_helper.rb

Instance Method Summary collapse

Methods included from LabelHelper

#election_status_with_label

Instance Method Details

#census_count(election) ⇒ Object



10
11
12
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 10

def census_count(election)
  election.census&.count(election).to_i
end

#election_status_action_data(election) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 28

def election_status_action_data(election)
  if election.scheduled? && election.manual_start?
    {
      label: t("decidim.elections.admin.dashboard.calendar.start_election"),
      status_action: "start"
    }
  elsif election.ongoing?
    {
      label: t("decidim.elections.admin.dashboard.calendar.end_election"),
      status_action: "end"
    }
  end
end

#enable_question_voting_button(question) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 42

def enable_question_voting_button(question)
  return if question.published_results?

  if question.voting_enabled?
    return (:div, class: "status-label") do
      (:span, t("decidim.elections.status.voting_enabled"), class: "label warning")
    end
  end

  return unless question.can_enable_voting?

  button_to update_question_status_election_path(question.election),
            method: :put,
            params: { status_action: "enable_voting", question_id: question.id },
            class: "button button__xs button__secondary small" do
    t("decidim.elections.admin.dashboard.results.start_question_button")
  end
end

#present_user(election, user) ⇒ Object



22
23
24
25
26
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 22

def present_user(election, user)
  return user unless election.census

  election.census.user_presenter.constantize.new(user)
end

#preview_users(election) ⇒ Object



14
15
16
17
18
19
20
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 14

def preview_users(election)
  return unless election.census_ready?

  @preview_users ||= election.census&.users(election, 0)&.map do |user|
    present_user(election, user)
  end
end

#publish_election_button(election) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 79

def publish_election_button(election)
  button_to update_status_election_path(election),
            method: :put,
            disabled: election.published_results_at? || !election.finished?,
            params: { status_action: "publish_results" },
            class: "button button__xs button__secondary small" do
    t("decidim.elections.admin.dashboard.results.publish_button")
  end
end

#publish_question_button(question) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/decidim/elections/admin/elections_helper.rb', line 61

def publish_question_button(question)
  return if question.election.scheduled?

  if question.published_results?
    return (:div, class: "status-label") do
      (:span, t("decidim.elections.status.published_results"), class: "label success")
    end
  end

  button_to update_question_status_election_path(question.election),
            method: :put,
            params: { status_action: "publish_results", question_id: question.id },
            disabled: !question&.publishable_results?,
            class: "button button__xs button__secondary small" do
    t("decidim.elections.admin.dashboard.results.publish_button")
  end
end