Class: Decidim::Votings::Voting

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasUploadValidations

#attached_uploader, #maximum_avatar_size, #maximum_upload_size

Methods included from Publicable

#publish!, #published?, #unpublish!

Methods included from Searchable

searchable_resources, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space

Methods included from Followable

#followers

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


100
101
102
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 100

def self.log_presenter_class_for(_log)
  Decidim::Votings::AdminLog::VotingPresenter
end

.ransackable_scopes(_auth_object = nil) ⇒ Object


167
168
169
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 167

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_date]
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

72
73
74
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 72

def active?
  start_time <= Time.now.utc && end_time >= Time.now.utc
end

#attachment_contextObject


119
120
121
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 119

def attachment_context
  :admin
end

#available_polling_officersObject


131
132
133
134
135
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 131

def available_polling_officers
  polling_officers
    .where(presided_polling_station_id: nil)
    .where(managed_polling_station_id: nil)
end

#complete_election_data(election, election_data) ⇒ Object

Methods for Votings Space <-> Elections Component interaction


151
152
153
154
155
156
157
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 151

def complete_election_data(election, election_data)
  election_data[:polling_stations] = polling_stations.map(&:slug)
  election_data[:ballot_styles] = ballot_styles.map do |ballot_style|
    questions = ballot_style.questions_for(election)
    [ballot_style.slug, questions.map(&:slug)] if questions.any?
  end.compact.to_h
end

#cta_button_text_keyObject


113
114
115
116
117
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 113

def cta_button_text_key
  return :vote if published? && active?

  :more_info
end

#electionsObject


141
142
143
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 141

def elections
  Decidim::Elections::Election.where(component: components)
end

#finished?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 76

def finished?
  end_time < Time.now.utc
end

#has_ballot_styles?Boolean

Returns:

  • (Boolean)

137
138
139
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 137

def has_ballot_styles?
  ballot_styles.exists?
end

#period_statusObject


80
81
82
83
84
85
86
87
88
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 80

def period_status
  if finished?
    :finished
  elsif active?
    :ongoing
  else
    :upcoming
  end
end

#polling_stations_with_missing_officers?Boolean

Returns:

  • (Boolean)

127
128
129
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 127

def polling_stations_with_missing_officers?
  !online_voting? && polling_stations.any?(&:missing_officers?)
end

#published_electionsObject


145
146
147
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 145

def published_elections
  Decidim::Elections::Election.where(component: components.published).published
end

#scopes_enabledObject


123
124
125
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 123

def scopes_enabled
  true
end

#to_paramObject


109
110
111
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 109

def to_param
  slug
end

#upcoming?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 68

def upcoming?
  start_time > Time.now.utc
end

#vote_flow_for(election) ⇒ Object


159
160
161
# File 'decidim-elections/app/models/decidim/votings/voting.rb', line 159

def vote_flow_for(election)
  Decidim::Votings::CensusVoteFlow.new(election)
end