Module: Decidim::Admin::BulkActionsHelper
- Defined in:
- app/helpers/decidim/admin/bulk_actions_helper.rb
Instance Method Summary collapse
-
#bulk_action_recategorize ⇒ Object
Renders a form to change the category of selected items.
-
#bulk_actions_dropdown ⇒ Object
Renders an actions dropdown, including an item for each bulk action.
- #bulk_categories_for_select(scope) ⇒ Object
-
#bulk_categories_select(collection) ⇒ Object
Public: Generates a select field with the categories.
- #bulk_disabled_categories_for(scope) ⇒ Object
- #proposal_find(id) ⇒ Object
Instance Method Details
#bulk_action_recategorize ⇒ Object
Renders a form to change the category of selected items
Returns a rendered form.
17 18 19 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 17 def bulk_action_recategorize render partial: "decidim/admin/bulk_actions/recategorize" end |
#bulk_actions_dropdown ⇒ Object
Renders an actions dropdown, including an item for each bulk action.
Returns a rendered dropdown.
10 11 12 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 10 def bulk_actions_dropdown render partial: "decidim/admin/bulk_actions/dropdown" end |
#bulk_categories_for_select(scope) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 37 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.
30 31 32 33 34 35 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 30 def bulk_categories_select(collection) categories = bulk_categories_for_select collection disabled = bulk_disabled_categories_for collection prompt = t("decidim.proposals.admin.proposals.index.change_category") select(:category, :id, (categories, selected: [], disabled: disabled), prompt: prompt) end |
#bulk_disabled_categories_for(scope) ⇒ Object
57 58 59 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 57 def bulk_disabled_categories_for(scope) scope.first_class.joins(:subcategories).pluck(:id) end |
#proposal_find(id) ⇒ Object
21 22 23 |
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 21 def proposal_find(id) Decidim::Proposals::Proposal.find(id) end |