Class: Decidim::Budgets::Admin::ProjectForm

Inherits:
Form
  • Object
show all
Includes:
AttachmentAttributes, ApplicationHelper, TranslatableAttributes, TranslationsHelper
Defined in:
app/forms/decidim/budgets/admin/project_form.rb

Overview

This class holds a Form to create/update projects from Decidim’s admin panel.

Instance Method Summary collapse

Instance Method Details

#budgetObject

Finds the Budget from the decidim_budgets_budget_id.

Returns a Decidim::Budgets:Budget



55
56
57
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 55

def budget
  @budget ||= context[:budget]
end

#categoryObject

Finds the Category from the decidim_category_id.

Returns a Decidim::Category



62
63
64
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 62

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

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the project



76
77
78
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 76

def decidim_scope_id
  @decidim_scope_id || scope&.id
end

#map_model(model) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 37

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

#proposalsObject



46
47
48
49
50
# File 'app/forms/decidim/budgets/admin/project_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 the component scope if missing.

Returns a Decidim::Scope



69
70
71
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 69

def scope
  @scope ||= @decidim_scope_id ? current_component.scopes.find_by(id: @decidim_scope_id) : current_component.scope
end