Class: SirTrevorRails::Blocks::BrowseBlock

Inherits:
SirTrevorRails::Block
  • Object
show all
Includes:
Displayable
Defined in:
app/models/sir_trevor_rails/blocks/browse_block.rb

Overview

Multi-up browse block

Direct Known Subclasses

LinkToSearchBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Displayable

#item_ids, #items, #ordered_items

Instance Attribute Details

#solr_helperObject (readonly)

Returns the value of attribute solr_helper.



8
9
10
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 8

def solr_helper
  @solr_helper
end

Instance Method Details

#as_jsonObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 32

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

#display_item_counts?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 28

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

#search_options(id) ⇒ Object



14
15
16
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 14

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

#searchesObject



18
19
20
21
22
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 18

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

#searches?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 24

def searches?
  !searches.empty?
end

#with_solr_helper(solr_helper) ⇒ Object



10
11
12
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 10

def with_solr_helper(solr_helper)
  @solr_helper = solr_helper
end