Sha256: c7d364a7294bda8ad2ee55d8a9820b9f75af46d2c800a06847465adc1852fcc0

Contents?: true

Size: 872 Bytes

Versions: 62

Compression:

Stored size: 872 Bytes

Contents

module Workarea
  class BulkActionSelections
    attr_reader :bulk_action, :params

    def initialize(id, params = {})
      @bulk_action = BulkAction.find(id)
      @params = params
    end

    def results
      @results ||=
        if bulk_action.ids.any?
          models = find_from_global_ids(bulk_action.ids)
          PagedArray.from(models, 1, models.size, models.size)
        else
          bulk_action.admin_query.class.new(query_params).results
        end
    end

    private

    def query_params
      bulk_action
        .params
        .merge(params)
        .merge(exclude_ids: excluded_search_ids)
    end

    def excluded_search_ids
      find_from_global_ids(bulk_action.exclude_ids).map do |model|
        Search::Admin.for(model).id
      end
    end

    def find_from_global_ids(ids)
      GlobalID::Locator.locate_many(ids)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.26 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.45 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.25 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.23 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.44 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.22 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.43 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.21 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.42 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.20 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.41 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.19 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.40 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.18 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.39 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.17 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.38 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.5.16 app/queries/workarea/bulk_action_selections.rb
workarea-core-3.4.37 app/queries/workarea/bulk_action_selections.rb