Class: Geoblacklight::Document::DownloadLinksComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/geoblacklight/document/download_links_component.rb

Overview

Display expandable file download links in sidebar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:) ⇒ DownloadLinksComponent

Returns a new instance of DownloadLinksComponent.



9
10
11
12
# File 'app/components/geoblacklight/document/download_links_component.rb', line 9

def initialize(document:)
  @document = document
  super()
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'app/components/geoblacklight/document/download_links_component.rb', line 7

def document
  @document
end

Instance Method Details

#child_componentObject



22
23
24
# File 'app/components/geoblacklight/document/download_links_component.rb', line 22

def child_component
  Geoblacklight::Document::DownloadLinkComponent
end

Direct download links to files



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/geoblacklight/document/download_links_component.rb', line 27

def direct_download_links
  direct_downloads = Array(document.direct_download&.dig(:download))
  return [] unless direct_downloads.present?

  # Use label and url for multiple downloads; use format to label otherwise
  direct_downloads.map do |entry|
    if entry.is_a?(Hash)
      child_component.new(
        title: entry["label"],
        url: entry["url"]
      )
    else
      child_component.new(
        url: entry,
        data_file_type: document.file_format
      )
    end
  end
end


18
19
20
# File 'app/components/geoblacklight/document/download_links_component.rb', line 18

def download_links
  (direct_download_links + iiif_download_links).compact
end

Links to IIIF image and manifest downloads



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/components/geoblacklight/document/download_links_component.rb', line 48

def iiif_download_links
  [
    document.iiif_download.present? && child_component.new(
      title: t("geoblacklight.download.iiif_image_link"),
      url: document.iiif_download[:iiif].sub(/\/info\.json$/, "/full/full/0/default.jpg")
    ),
    document.references.iiif_manifest.present? && child_component.new(
      title: t("geoblacklight.download.iiif_manifest_link"),
      url: document.references.iiif_manifest.endpoint,
      file_type: "JSON"
    )
  ].compact_blank
end

#render?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/components/geoblacklight/document/download_links_component.rb', line 14

def render?
  download_links.any? && helpers.document_available?(document)
end