Class: Decidim::Accountability::Admin::ResultForm
- Inherits:
-
Form
- Object
- Decidim::AttributeObject::Form
- Form
- Decidim::Accountability::Admin::ResultForm
- Defined in:
- decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb
Overview
This class holds a Form to create/update results from Decidim’s admin panel.
Constant Summary
Constants included from Decidim::AttributeObject::TypeMap
Decidim::AttributeObject::TypeMap::Boolean, Decidim::AttributeObject::TypeMap::Decimal
Instance Attribute Summary
Attributes inherited from Decidim::AttributeObject::Form
Instance Method Summary collapse
-
#decidim_scope_id ⇒ Object
Scope identifier.
- #geocoded? ⇒ Boolean
- #geocoding_enabled? ⇒ Boolean
- #has_address? ⇒ Boolean
- #map_model(model) ⇒ Object
- #parent ⇒ Object
- #participatory_space_manifest ⇒ Object
- #projects ⇒ Object
- #proposals ⇒ Object
-
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
- #status ⇒ Object
Methods included from TranslationsHelper
empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?
Methods included from TranslatableAttributes
Methods inherited from Decidim::AttributeObject::Form
ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context
Methods included from Decidim::AttributeObject::Model
#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h
Instance Method Details
#decidim_scope_id ⇒ Object
Scope identifier
Returns the scope identifier related to the result
68 69 70 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 68 def decidim_scope_id super || scope&.id end |
#geocoded? ⇒ Boolean
80 81 82 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 80 def geocoded? latitude.present? && longitude.present? end |
#geocoding_enabled? ⇒ Boolean
72 73 74 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 72 def geocoding_enabled? Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled? end |
#has_address? ⇒ Boolean
76 77 78 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 76 def has_address? geocoding_enabled? && address.present? end |
#map_model(model) ⇒ Object
37 38 39 40 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 37 def map_model(model) self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id) self.project_ids = model.linked_resources(:projects, "included_projects").pluck(:id) end |
#parent ⇒ Object
84 85 86 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 84 def parent @parent ||= Decidim::Accountability::Result.find_by(component: current_component, id: parent_id) end |
#participatory_space_manifest ⇒ Object
42 43 44 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 42 def participatory_space_manifest @participatory_space_manifest ||= current_component.participatory_space.manifest.name end |
#projects ⇒ Object
53 54 55 56 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 53 def projects @projects ||= Decidim.find_resource_manifest(:projects).try(:resource_scope, current_component)&.order(title: :asc) &.select(:title, :id)&.map { |a| [a.title[I18n.locale.to_s], a.id] } end |
#proposals ⇒ Object
46 47 48 49 50 51 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 46 def proposals @proposals ||= Decidim.find_resource_manifest(:proposals) .try(:resource_scope, current_component) &.where(id: proposal_ids) &.order(title: :asc) end |
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
Returns a Decidim::Scope
61 62 63 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 61 def scope @scope ||= @attributes["decidim_scope_id"].value ? current_component.scopes.find_by(id: @attributes["decidim_scope_id"].value) : current_component.scope end |
#status ⇒ Object
88 89 90 |
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 88 def status @status ||= Decidim::Accountability::Status.find_by(component: current_component, id: decidim_accountability_status_id) end |