Class: Decidim::Votings::Voting
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Votings::Voting
- Includes:
- FilterableResource, Followable, HasAttachmentCollections, HasAttachments, HasUploadValidations, Participable, ParticipatorySpaceResourceable, Publicable, Randomable, ScopableParticipatorySpace, Searchable, TranslatableResource, Loggable, Traceable
- Defined in:
- app/models/decidim/votings/voting.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #attachment_context ⇒ Object
- #available_polling_officers ⇒ Object
- #check_census_enabled? ⇒ Boolean
-
#complete_election_data(election, election_data) ⇒ Object
Methods for Votings Space <-> Elections Component interaction.
- #cta_button_text_key ⇒ Object
- #elections ⇒ Object
- #finished? ⇒ Boolean
- #has_ballot_styles? ⇒ Boolean
- #period_status ⇒ Object
- #polling_stations_with_missing_officers? ⇒ Boolean
- #published_elections ⇒ Object
- #scopes_enabled ⇒ Object
- #to_param ⇒ Object
- #upcoming? ⇒ Boolean
- #vote_flow_for(election) ⇒ Object
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
100 101 102 |
# File '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
171 172 173 |
# File 'app/models/decidim/votings/voting.rb', line 171 def self.ransackable_scopes(_auth_object = nil) [:with_any_date] end |
Instance Method Details
#active? ⇒ Boolean
72 73 74 |
# File 'app/models/decidim/votings/voting.rb', line 72 def active? start_time <= Time.now.utc && end_time >= Time.now.utc end |
#attachment_context ⇒ Object
119 120 121 |
# File 'app/models/decidim/votings/voting.rb', line 119 def :admin end |
#available_polling_officers ⇒ Object
131 132 133 134 135 |
# File '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 |
#check_census_enabled? ⇒ Boolean
141 142 143 |
# File 'app/models/decidim/votings/voting.rb', line 141 def check_census_enabled? dataset.present? && show_check_census? end |
#complete_election_data(election, election_data) ⇒ Object
Methods for Votings Space <-> Elections Component interaction
155 156 157 158 159 160 161 |
# File 'app/models/decidim/votings/voting.rb', line 155 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_key ⇒ Object
113 114 115 116 117 |
# File 'app/models/decidim/votings/voting.rb', line 113 def return :vote if published? && active? :more_info end |
#elections ⇒ Object
145 146 147 |
# File 'app/models/decidim/votings/voting.rb', line 145 def elections Decidim::Elections::Election.where(component: components) end |
#finished? ⇒ Boolean
76 77 78 |
# File 'app/models/decidim/votings/voting.rb', line 76 def finished? end_time < Time.now.utc end |
#has_ballot_styles? ⇒ Boolean
137 138 139 |
# File 'app/models/decidim/votings/voting.rb', line 137 def has_ballot_styles? ballot_styles.exists? end |
#period_status ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File '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
127 128 129 |
# File 'app/models/decidim/votings/voting.rb', line 127 def polling_stations_with_missing_officers? !online_voting? && polling_stations.any?(&:missing_officers?) end |
#published_elections ⇒ Object
149 150 151 |
# File 'app/models/decidim/votings/voting.rb', line 149 def published_elections Decidim::Elections::Election.where(component: components.published).published end |
#scopes_enabled ⇒ Object
123 124 125 |
# File 'app/models/decidim/votings/voting.rb', line 123 def scopes_enabled true end |
#to_param ⇒ Object
109 110 111 |
# File 'app/models/decidim/votings/voting.rb', line 109 def to_param slug end |
#upcoming? ⇒ Boolean
68 69 70 |
# File 'app/models/decidim/votings/voting.rb', line 68 def upcoming? start_time > Time.now.utc end |
#vote_flow_for(election) ⇒ Object
163 164 165 |
# File 'app/models/decidim/votings/voting.rb', line 163 def vote_flow_for(election) Decidim::Votings::CensusVoteFlow.new(election) end |