Class: Decidim::Accountability::Admin::ResultImportProjectsForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/accountability/admin/result_import_projects_form.rb

Overview

A form object to be used when admin users want to import a collection of projects from another component into Accountability component.

Instance Method Summary collapse

Instance Method Details

#origin_componentObject



16
17
18
# File 'app/forms/decidim/accountability/admin/result_import_projects_form.rb', line 16

def origin_component
  @origin_component ||= origin_components.find_by(id: origin_component_id)
end

#origin_componentsObject



26
27
28
# File 'app/forms/decidim/accountability/admin/result_import_projects_form.rb', line 26

def origin_components
  @budgets_component ||= current_participatory_space.components.where(manifest_name: "budgets")
end

#origin_components_collectionObject



20
21
22
23
24
# File 'app/forms/decidim/accountability/admin/result_import_projects_form.rb', line 20

def origin_components_collection
  origin_components.map do |component|
    [component.name[I18n.locale.to_s], component.id]
  end
end

#project_already_copied?(original_project) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'app/forms/decidim/accountability/admin/result_import_projects_form.rb', line 37

def project_already_copied?(original_project)
  original_project.linked_resources(:results, "included_projects").any? do |result|
    result.component == current_component
  end
end

#selected_projects_count(component) ⇒ Object



30
31
32
33
34
35
# File 'app/forms/decidim/accountability/admin/result_import_projects_form.rb', line 30

def selected_projects_count(component)
  projects = Decidim::Budgets::Project.joins(:budget).selected.where(
    budget: { component: }
  )
  projects.reject { |project| project_already_copied?(project) }.count
end