Sha256: b2154117e637c59d60fe7248b0203c8c717d0894e643150df8c0554f97b0ea15

Contents?: true

Size: 1.3 KB

Versions: 42

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module SirTrevorRails
  module Blocks
    ##
    # Multi-up browse block
    class BrowseBlock < SirTrevorRails::Block
      include Displayable

      attr_reader :solr_helper

      def with_solr_helper(solr_helper)
        @solr_helper = solr_helper
      end

      def search_options(id)
        (items.detect { |x| x[:id] == id }) || {}
      end

      def searches
        @searches ||= parent.exhibit.searches.published.where(slug: item_ids).sort do |a, b|
          ordered_items.index(a.slug) <=> ordered_items.index(b.slug)
        end
      end

      def searches?
        !searches.empty?
      end

      def display_item_counts?
        send(:'display-item-counts') == 'true'
      end

      def as_json(*)
        result = super

        result[:data][:item] ||= {}

        # TODO: This is a temporary fix that simply removes any item if the search identifier does not exist
        #       We should have a more permanent solution that will allow browse blocks to be updated without erroring
        result[:data][:item].select! { |_, v| parent.exhibit.searches.exists?(v['id']) }

        result[:data][:item].each_value do |v|
          v['thumbnail_image_url'] = parent.exhibit.searches.find(v['id']).thumbnail_image_url
        end

        result
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.5 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.4 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.3 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.2 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.1 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.3.0 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.2.0 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.1.2 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.1.1 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.1.0 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.0.3 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.0.2 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.0.1 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-4.0.0 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-3.6.0.beta10 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-3.6.0.beta9 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-3.6.0.beta8 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-3.5.0.4 app/models/sir_trevor_rails/blocks/browse_block.rb
blacklight-spotlight-3.6.0.beta7 app/models/sir_trevor_rails/blocks/browse_block.rb