Sha256: 8356015b50938091062a1e302be6ac77dfd415859170dc281c5bd3d31e86f733

Contents?: true

Size: 1.21 KB

Versions: 35

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      module ProposalBulkActionsHelper
        # Public: Generates a select field with the valuators of the given participatory space.
        #
        # participatory_space - A participatory space instance.
        # prompt - An i18n string to show as prompt
        #
        # Returns a String.
        def bulk_valuators_select(participatory_space, prompt)
          options_for_select = find_valuators_for_select(participatory_space)
          select(:valuator_role, :id, options_for_select, prompt: prompt)
        end

        # Internal: A method to cache to queries to find the valuators for the
        # current space.
        def find_valuators_for_select(participatory_space)
          return @valuators_for_select if @valuators_for_select

          valuator_roles = participatory_space.user_roles(:valuator)
          valuators = Decidim::User.where(id: valuator_roles.pluck(:decidim_user_id)).to_a

          @valuators_for_select = valuator_roles.map do |role|
            valuator = valuators.find { |user| user.id == role.decidim_user_id }

            [valuator.name, role.id]
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
decidim-proposals-0.26.10 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.9 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.8 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.7 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.5 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.4 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.3 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.2 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.1 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.0 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.0.rc2 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.26.0.rc1 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.2 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.1 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.0 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.0.rc4 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.0.rc3 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.0.rc2 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.25.0.rc1 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb
decidim-proposals-0.24.3 app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb