Module: Decidim::Admin::BulkActionsHelper

Defined in:
app/helpers/decidim/admin/bulk_actions_helper.rb

Instance Method Summary collapse

Instance Method Details

#bulk_categories_for_select(scope) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 22

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.



15
16
17
18
19
20
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 15

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, options_for_select(categories, selected: [], disabled: disabled), prompt: prompt)
end

#bulk_components_select(siblings) ⇒ Object

Public: Generates a select field with the components.

siblings - A collection of components.

Returns a String.



51
52
53
54
55
56
57
58
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 51

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, options_for_select(components, selected: []), prompt: prompt)
end

#bulk_disabled_categories_for(scope) ⇒ Object



42
43
44
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 42

def bulk_disabled_categories_for(scope)
  scope.first_class.joins(:subcategories).pluck(:id)
end

#proposal_find(id) ⇒ Object



6
7
8
# File 'app/helpers/decidim/admin/bulk_actions_helper.rb', line 6

def proposal_find(id)
  Decidim::Proposals::Proposal.find(id)
end