Class: Decidim::Accountability::Admin::ResultImportProjectsForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Accountability::Admin::ResultImportProjectsForm
- 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
- #origin_component ⇒ Object
- #origin_components ⇒ Object
- #origin_components_collection ⇒ Object
- #project_already_copied?(original_project) ⇒ Boolean
- #selected_projects_count(component) ⇒ Object
Instance Method Details
#origin_component ⇒ Object
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_components ⇒ Object
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_collection ⇒ Object
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
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 |