Class: SirTrevorRails::Blocks::BrowseBlock
- Inherits:
-
SirTrevorRails::Block
- Object
- OpenStruct
- SirTrevorRails::Block
- SirTrevorRails::Blocks::BrowseBlock
- Includes:
- Displayable
- Defined in:
- app/models/sir_trevor_rails/blocks/browse_block.rb
Overview
Multi-up browse block
Direct Known Subclasses
Constant Summary
Constants inherited from SirTrevorRails::Block
SirTrevorRails::Block::DEFAULT_FORMAT
Instance Attribute Summary collapse
-
#solr_helper ⇒ Object
readonly
Returns the value of attribute solr_helper.
Attributes inherited from SirTrevorRails::Block
Instance Method Summary collapse
- #as_json ⇒ Object
- #display_item_counts? ⇒ Boolean
- #search_options(id) ⇒ Object
- #searches ⇒ Object
- #searches? ⇒ Boolean
- #with_solr_helper(solr_helper) ⇒ Object
Methods included from Displayable
#item_ids, #items, #ordered_items
Methods inherited from SirTrevorRails::Block
#alt_text?, alt_text?, block_class, block_class!, custom_block_type_alt_text_settings, custom_block_types, #format, from_hash, #initialize, #to_partial_path, type_klass
Constructor Details
This class inherits a constructor from SirTrevorRails::Block
Instance Attribute Details
#solr_helper ⇒ Object (readonly)
Returns the value of attribute solr_helper.
10 11 12 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 10 def solr_helper @solr_helper end |
Instance Method Details
#as_json ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 34 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
30 31 32 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 30 def display_item_counts? send(:'display-item-counts') == 'true' end |
#search_options(id) ⇒ Object
16 17 18 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 16 def (id) (items.detect { |x| x[:id] == id }) || {} end |
#searches ⇒ Object
20 21 22 23 24 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 20 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
26 27 28 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 26 def searches? !searches.empty? end |
#with_solr_helper(solr_helper) ⇒ Object
12 13 14 |
# File 'app/models/sir_trevor_rails/blocks/browse_block.rb', line 12 def with_solr_helper(solr_helper) @solr_helper = solr_helper end |