Class: Decidim::Proposals::Admin::ProposalsImportForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Proposals::Admin::ProposalsImportForm
- Includes:
- TranslatableAttributes
- Defined in:
- app/forms/decidim/proposals/admin/proposals_import_form.rb
Overview
A form object to be used when admin users want to import a collection of proposals from another component.
Instance Method Summary collapse
- #available_states(component_id = nil) ⇒ Object
- #origin_component ⇒ Object
- #origin_components ⇒ Object
- #origin_components_collection ⇒ Object
- #states ⇒ Object
- #states_collection ⇒ Object
Instance Method Details
#available_states(component_id = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 45 def available_states(component_id = nil) scope = Decidim::Proposals::ProposalState scope = scope.where(component: Decidim::Component.find(component_id)) if component_id.present? states = scope.pluck(:token).uniq.map do |token| OpenStruct.new(token:, title: token.humanize) end states + [OpenStruct.new(token: "not_answered", title: I18n.t("decidim.proposals.answers.not_answered"))] end |
#origin_component ⇒ Object
31 32 33 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 31 def origin_component @origin_component ||= origin_components.find_by(id: origin_component_id) end |
#origin_components ⇒ Object
35 36 37 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 35 def origin_components @origin_components ||= current_participatory_space.components.where.not(id: current_component.id).where(manifest_name: :proposals) end |
#origin_components_collection ⇒ Object
39 40 41 42 43 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 39 def origin_components_collection origin_components.map do |component| [component.name[I18n.locale.to_s], component.id] end end |
#states ⇒ Object
27 28 29 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 27 def states super.compact_blank end |
#states_collection ⇒ Object
20 21 22 23 24 25 |
# File 'app/forms/decidim/proposals/admin/proposals_import_form.rb', line 20 def states_collection @states_collection ||= ProposalState.where(component: current_component) + [ProposalState.new(token: "not_answered", title: I18n.t( :not_answered, scope: "decidim.proposals.answers" ))] end |