Module: Decidim::Admin::BulkActionsHelper
- Defined in:
- app/helpers/decidim/admin/bulk_actions_helper.rb
Instance Method Summary collapse
- #bulk_categories_for_select(scope) ⇒ Object
-
#bulk_categories_select(collection) ⇒ Object
Public: Generates a select field with the categories.
-
#bulk_components_select(siblings) ⇒ Object
Public: Generates a select field with the components.
Instance Method Details
#bulk_categories_for_select(scope) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 17 def bulk_categories_for_select(scope) sorted_main_categories = scope.first_class.includes(:subcategories).sort_by do |category| translated_attribute(category.name, category.participatory_space.organization) end sorted_main_categories.flat_map do |category| parent = [[translated_attribute(category.name, category.participatory_space.organization), category.id]] sorted_subcategories = category.subcategories.sort_by do |subcategory| translated_attribute(subcategory.name, subcategory.participatory_space.organization) end sorted_subcategories.each do |subcategory| parent << ["- #{translated_attribute(subcategory.name, subcategory.participatory_space.organization)}", subcategory.id] end parent end end |
#bulk_categories_select(collection) ⇒ Object
Public: Generates a select field with the categories. Only leaf categories can be set as selected.
categories - A collection of categories.
Returns a String.
11 12 13 14 15 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 11 def bulk_categories_select(collection) categories = bulk_categories_for_select collection prompt = t("decidim.proposals.admin.proposals.index.change_category") select(:category, :id, (categories, selected: []), prompt:) end |
#bulk_components_select(siblings) ⇒ Object
Public: Generates a select field with the components.
siblings - A collection of components.
Returns a String.
42 43 44 45 46 47 48 49 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 42 def bulk_components_select(siblings) components = siblings.map do |component| [translated_attribute(component.name, component.organization), component.id] end prompt = t("decidim.proposals.admin.proposals.index.select_component") select(:target_component_id, nil, (components, selected: []), prompt:) end |