Class: Decidim::Accountability::Admin::ResultForm

Inherits:
Form show all
Includes:
TranslatableAttributes, TranslationsHelper
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

#context

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

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

#categoryObject



72
73
74
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 72

def category
  @category ||= categories.find_by(id: decidim_category_id)
end

#decidim_scope_idObject

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

#map_model(model) ⇒ Object



40
41
42
43
44
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 40

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)
  self.decidim_category_id = model.category.try(:id)
end

#parentObject



76
77
78
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 76

def parent
  @parent ||= Decidim::Accountability::Result.find_by(component: current_component, id: parent_id)
end

#projectsObject



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

#proposalsObject



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

#scopeObject

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

#statusObject



80
81
82
# File 'decidim-accountability/app/forms/decidim/accountability/admin/result_form.rb', line 80

def status
  @status ||= Decidim::Accountability::Status.find_by(component: current_component, id: decidim_accountability_status_id)
end