Class: SirTrevorRails::Blocks::SolrDocumentsBlock

Inherits:
SirTrevorRails::Block show all
Includes:
Displayable, Textable
Defined in:
app/models/sir_trevor_rails/blocks/solr_documents_block.rb

Overview

Multi-up document viewer with text block

Constant Summary

Constants inherited from SirTrevorRails::Block

SirTrevorRails::Block::DEFAULT_FORMAT

Instance Attribute Summary collapse

Attributes inherited from SirTrevorRails::Block

#parent, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Displayable

#item_ids, #items, #ordered_items

Methods included from Textable

#content_align, #text, #text?, #text_align

Methods inherited from SirTrevorRails::Block

#alt_text?, #as_json, 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_helperObject (readonly)

Returns the value of attribute solr_helper.



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

def solr_helper
  @solr_helper
end

Class Method Details

.alt_text?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 16

def self.alt_text?
  true
end

Instance Method Details

#document_caption(presenter, caption_field, default: nil) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 55

def document_caption(presenter, caption_field, default: nil)
  caption_field ||= default

  return unless caption_field
  return presenter.heading if caption_field == Spotlight::PageConfigurations::DOCUMENT_TITLE_KEY

  presenter.field_value(solr_helper.blacklight_config.index_fields[caption_field] || null_display_field_class.new(caption_field))
end

#documentsObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 30

def documents
  @documents ||= begin
    doc_ids = items.pluck(:id)
    result = solr_helper.controller.send(:search_service).fetch(doc_ids)

    if result.first.is_a? Blacklight::Solr::Response
      result.last
    else
      result
    end
  end
end

#documents?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 43

def documents?
  each_document.any?
end

#each_documentObject



20
21
22
23
24
25
26
27
28
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 20

def each_document
  return to_enum(:each_document) unless block_given?

  items.each do |i|
    document = documents.detect { |doc| doc.id == i[:id] }
    i[:iiif_tilesource_base] = i.fetch(:iiif_tilesource, '').sub('/info.json', '')
    yield i, document if document
  end
end

#null_display_field_classObject



86
87
88
89
90
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 86

def null_display_field_class
  return Blacklight::Configuration::NullDisplayField if defined?(Blacklight::Configuration::NullDisplayField)

  Blacklight::Configuration::NullField
end

#primary_caption?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 47

def primary_caption?
  primary_caption_field.present? && show_primary_caption?
end

#primary_caption_fieldObject



76
77
78
79
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 76

def primary_caption_field
  val = send(:'primary-caption-field')
  val.presence
end

#secondary_caption?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 64

def secondary_caption?
  secondary_caption_field.present? && show_secondary_caption?
end

#secondary_caption_fieldObject



81
82
83
84
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 81

def secondary_caption_field
  val = send(:'secondary-caption-field')
  val.presence
end

#show_primary_caption?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 51

def show_primary_caption?
  ActiveModel::Type::Boolean.new.cast(send(:'show-primary-caption'))
end

#show_secondary_caption?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 68

def show_secondary_caption?
  ActiveModel::Type::Boolean.new.cast(send(:'show-secondary-caption'))
end

#with_solr_helper(solr_helper) ⇒ Object



12
13
14
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 12

def with_solr_helper(solr_helper)
  @solr_helper = solr_helper
end

#zpr_link?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 72

def zpr_link?
  zpr_link == 'true'
end