Sha256: 07fe590ee88c60269ef5f91d6561b7764a9f1a71d4af2ed68ebcb8d2329c70c2

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true
module Blacklight
  class JsonPresenter
    include Blacklight::Facet

    # @param [Solr::Response] response raw solr response.
    # @param [Array<SolrDocument>] documents a list of documents
    # @param [Array] facets list of facets
    def initialize(response, documents, facets, blacklight_config)
      @response = response
      @documents = documents
      @facets = facets
      @blacklight_config = blacklight_config
    end

    attr_reader :documents, :blacklight_config

    def search_facets_as_json
      @facets.as_json.each do |f|
        f.delete "options"
        f["label"] = facet_configuration_for_field(f["name"]).label
        f["items"] = f["items"].as_json.each do |i|
          i['label'] ||= i['value']
        end
      end
    end


    # extract the pagination info from the response object
    def pagination_info
      h = {}

      [:current_page, :next_page, :prev_page, :total_pages,
       :limit_value, :offset_value, :total_count,
       :first_page?, :last_page?].each do |k|
        h[k] = @response.send(k)
      end

      h
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-6.5.0 app/presenters/blacklight/json_presenter.rb
blacklight-6.4.2 app/presenters/blacklight/json_presenter.rb
blacklight-6.4.1 app/presenters/blacklight/json_presenter.rb
blacklight-6.4.0 app/presenters/blacklight/json_presenter.rb
blacklight-6.3.3 app/presenters/blacklight/json_presenter.rb
blacklight-6.3.1 app/presenters/blacklight/json_presenter.rb
blacklight-6.3.0 app/presenters/blacklight/json_presenter.rb
blacklight-6.2.0 app/presenters/blacklight/json_presenter.rb
blacklight-6.1.0 app/presenters/blacklight/json_presenter.rb
blacklight-6.0.2 app/presenters/blacklight/json_presenter.rb
blacklight-6.0.1 app/presenters/blacklight/json_presenter.rb
blacklight-6.0.0 app/presenters/blacklight/json_presenter.rb