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

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

#as_json, block_class, block_class!, 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

Instance Method Details

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



51
52
53
54
55
56
57
58
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 51

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



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 26

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)


39
40
41
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 39

def documents?
  each_document.any?
end

#each_documentObject



16
17
18
19
20
21
22
23
24
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 16

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



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

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

  Blacklight::Configuration::NullField
end

#primary_caption?Boolean

Returns:

  • (Boolean)


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

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

#primary_caption_fieldObject



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

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

#secondary_caption?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/sir_trevor_rails/blocks/solr_documents_block.rb', line 60

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

#secondary_caption_fieldObject



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

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

#show_primary_caption?Boolean

Returns:

  • (Boolean)


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

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

#show_secondary_caption?Boolean

Returns:

  • (Boolean)


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

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)


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

def zpr_link?
  zpr_link == 'true'
end