Class: Spotlight::Resources::Upload

Inherits:
Spotlight::Resource show all
Defined in:
app/models/spotlight/resources/upload.rb

Overview

Exhibit-specific resources, created using uploaded and custom fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spotlight::Resource

#document_model, #reindex_later, #save_and_index

Class Method Details

.fields(exhibit) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/spotlight/resources/upload.rb', line 13

def self.fields(exhibit)
  @fields ||= {}
  @fields[exhibit] ||= begin
    index_title_field = exhibit.blacklight_config.index.title_field
    title_field = Spotlight::Engine.config.upload_title_field ||
                  Spotlight::UploadFieldConfig.new(
                    field_name: index_title_field,
                    label: I18n.t(:"spotlight.search.fields.#{index_title_field}")
                  )
    [title_field] + exhibit.uploaded_resource_fields
  end
end

.indexing_pipelineObject



26
27
28
29
30
31
32
33
# File 'app/models/spotlight/resources/upload.rb', line 26

def self.indexing_pipeline
  @indexing_pipeline ||= super.dup.tap do |pipeline|
    pipeline.transforms = [
      ->(data, p) { data.merge({ p.context.document_model.unique_key.to_sym => p.source.compound_id }) },
      Spotlight::Etl::Transforms::SourceMethodTransform(:to_solr)
    ] + pipeline.transforms
  end
end

Instance Method Details

#compound_idObject



35
36
37
# File 'app/models/spotlight/resources/upload.rb', line 35

def compound_id
  "#{exhibit_id}-#{id}"
end

#sidecarObject



39
40
41
# File 'app/models/spotlight/resources/upload.rb', line 39

def sidecar
  @sidecar ||= document_model.new(id: compound_id).sidecar(exhibit)
end

#to_solrObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/spotlight/resources/upload.rb', line 43

def to_solr
  return {} unless upload&.file_present?

  spotlight_routes = Spotlight::Engine.routes.url_helpers
  riiif = Riiif::Engine.routes.url_helpers

  dimensions = Riiif::Image.new(upload_id).info

  {
    spotlight_full_image_width_ssm: dimensions.width,
    spotlight_full_image_height_ssm: dimensions.height,
    Spotlight::Engine.config.thumbnail_field => riiif.image_path(upload, size: '!400,400'),
    Spotlight::Engine.config.iiif_manifest_field => spotlight_routes.manifest_exhibit_solr_document_path(exhibit, compound_id)
  }
end