Class: Decidim::Lausanne::Budgets::Admin::ProjectForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Lausanne::Budgets::Admin::ProjectForm
- Includes:
- AttachmentAttributes, ApplicationHelper, TranslatableAttributes, TranslationsHelper
- Defined in:
- app/forms/decidim/lausanne/budgets/admin/project_form.rb
Overview
This class holds a Form to create/update projects from Decidim’s admin panel.
Instance Method Summary collapse
-
#budget ⇒ Object
Finds the Budget from the loz_budgets_budget_id.
-
#category ⇒ Object
Finds the Category from the decidim_category_id.
-
#decidim_scope_id ⇒ Object
Scope identifier.
- #map_model(model) ⇒ Object
- #proposals ⇒ Object
-
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses the component scope if missing.
Instance Method Details
#budget ⇒ Object
Finds the Budget from the loz_budgets_budget_id.
Returns a Decidim::Lausanne::Budgets:Budget
58 59 60 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 58 def budget @budget ||= context[:budget] end |
#category ⇒ Object
Finds the Category from the decidim_category_id.
Returns a Decidim::Category
65 66 67 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 65 def category @category ||= categories.find_by(id: decidim_category_id) end |
#decidim_scope_id ⇒ Object
Scope identifier
Returns the scope identifier related to the project
79 80 81 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 79 def decidim_scope_id @decidim_scope_id || scope&.id end |
#map_model(model) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 40 def map_model(model) self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id) self.selected = model.selected? return unless model.categorization self.decidim_category_id = model.categorization.decidim_category_id end |
#proposals ⇒ Object
49 50 51 52 53 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 49 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 the component scope if missing.
Returns a Decidim::Scope
72 73 74 |
# File 'app/forms/decidim/lausanne/budgets/admin/project_form.rb', line 72 def scope @scope ||= @decidim_scope_id ? current_component.scopes.find_by(id: @decidim_scope_id) : current_component.scope end |