Sha256: 6853782538a264ad20dcb62e4f17c73317dcdcaadf8a1227759dc32b9dc54b72

Contents?: true

Size: 1.92 KB

Versions: 13

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module BulkActionsHelper
      # Public: Generates a select field with the categories. Only leaf categories can be set as selected.
      #
      # categories - A collection of categories.
      #
      # Returns a String.
      def bulk_categories_select(collection)
        categories = bulk_categories_for_select collection
        prompt = t("decidim.proposals.admin.proposals.index.change_category")
        select(:category, :id, options_for_select(categories, selected: []), prompt:)
      end

      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

      # Public: Generates a select field with the components.
      #
      # siblings - A collection of components.
      #
      # Returns a String.
      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:)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.4 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.29.0 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.3 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.29.0.rc4 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.29.0.rc3 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.29.0.rc2 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.29.0.rc1 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.2 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.1 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.0 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.0.rc5 app/helpers/decidim/admin/bulk_actions_helper.rb
decidim-admin-0.28.0.rc4 app/helpers/decidim/admin/bulk_actions_helper.rb