Module: GeoblacklightHelper

Defined in:
app/helpers/geoblacklight_helper.rb

Instance Method Summary collapse

Instance Method Details

#document_available?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/helpers/geoblacklight_helper.rb', line 3

def document_available?
  @document.public? || (@document.same_institution? && user_signed_in?)
end

#document_downloadable?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/helpers/geoblacklight_helper.rb', line 7

def document_downloadable?
  document_available? && @document.downloadable?
end

#download_generated_body(format) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/helpers/geoblacklight_helper.rb', line 146

def download_generated_body(format)
  value = proper_case_format(format)
  value = case value
          when t('geoblacklight.formats.shapefile')
            t('geoblacklight.download.export_shapefile_link')
          when t('geoblacklight.formats.kmz')
            t('geoblacklight.download.export_kmz_link')
          when t('geoblacklight.formats.geojson')
            t('geoblacklight.download.export_geojson_link')
          else
            value
          end

  value.html_safe
end


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/geoblacklight_helper.rb', line 29

def download_link_direct(text, document)
  link_to(
    text,
    document.direct_download[:download],
    'contentUrl' => document.direct_download[:download],
    class: ['btn', 'btn-default', 'download', 'download-original'],
    data: {
      download: 'trigger',
      download_type: 'direct',
      download_id: document.id
    }
  )
end


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/geoblacklight_helper.rb', line 15

def download_link_file(label, id, url)
  link_to(
    label,
    url,
    'contentUrl' => url,
    class: ['btn', 'btn-default', 'download', 'download-original'],
    data: {
      download: 'trigger',
      download_type: 'direct',
      download_id: id
    }
  )
end


72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/geoblacklight_helper.rb', line 72

def download_link_generated(download_type, document)
  link_to(
    t('geoblacklight.download.export_link', download_format: proper_case_format(download_type)),
    '',
    class: ['btn', 'btn-default', 'download', 'download-generated'],
    data: {
      download_path: download_path(document.id, type: download_type),
      download: 'trigger',
      download_type: download_type,
      download_id: document.id
    }
  )
end


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/geoblacklight_helper.rb', line 44

def download_link_hgl(text, document)
  link_to(
    text,
    download_hgl_path(id: document),
    class: ['btn', 'btn-default', 'download', 'download-original'],
    data: {
      blacklight_modal: 'trigger',
      download: 'trigger',
      download_type: 'harvard-hgl',
      download_id: document.id
    }
  )
end

Generates the link markup for the IIIF JPEG download

Returns:

  • (String)


60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/geoblacklight_helper.rb', line 60

def download_link_iiif
  link_to(
    download_text('JPG'),
    iiif_jpg_url,
    'contentUrl' => iiif_jpg_url,
    class: ['btn', 'btn-default', 'download', 'download-generated'],
    data: {
      download: 'trigger'
    }
  )
end

#download_text(format) ⇒ Object

Wraps download text with proper_case_format



140
141
142
143
144
# File 'app/helpers/geoblacklight_helper.rb', line 140

def download_text(format)
  download_format = proper_case_format(format)
  value = t('geoblacklight.download.download_link', download_format: download_format)
  value.html_safe
end

#first_metadata?(document, metadata) ⇒ Boolean

Determines whether or not the metadata is the first within the array of References

Parameters:

Returns:

  • (Boolean)


262
263
264
# File 'app/helpers/geoblacklight_helper.rb', line 262

def first_metadata?(document, )
  document.references..first.type == .type
end

#formatted_name_reference(reference) ⇒ String

Looks up formatted names for references

Parameters:

  • reference (String, Symbol)

Returns:

  • (String)


133
134
135
# File 'app/helpers/geoblacklight_helper.rb', line 133

def formatted_name_reference(reference)
  t "geoblacklight.references.#{reference}"
end

#geoblacklight_basemapString

Selects the basemap used for map displays

Returns:

  • (String)


206
207
208
# File 'app/helpers/geoblacklight_helper.rb', line 206

def geoblacklight_basemap
  blacklight_config.basemap_provider || 'positron'
end

#geoblacklight_icon(name, **args) ⇒ SVG or HTML tag

Returns an SVG icon or empty HTML span element

Returns:

  • (SVG or HTML tag)


103
104
105
106
107
108
109
110
# File 'app/helpers/geoblacklight_helper.rb', line 103

def geoblacklight_icon(name, **args)
  icon_name = name ? name.to_s.parameterize : 'none'
  begin
    blacklight_icon(icon_name, **args)
  rescue Blacklight::Exceptions::IconNotFound
    tag.span class: 'icon-missing geoblacklight-none'
  end
end

#iiif_jpg_urlObject



11
12
13
# File 'app/helpers/geoblacklight_helper.rb', line 11

def iiif_jpg_url
  @document.references.iiif.endpoint.sub! 'info.json', 'full/full/0/default.jpg'
end

#leaflet_optionsObject

Returns a hash of the leaflet plugin settings to pass to the viewer. @return



226
227
228
# File 'app/helpers/geoblacklight_helper.rb', line 226

def leaflet_options
  Settings.LEAFLET
end

#proper_case_format(format) ⇒ Object

Looks up properly formatted names for formats



125
126
127
# File 'app/helpers/geoblacklight_helper.rb', line 125

def proper_case_format(format)
  t("geoblacklight.formats.#{format.to_s.parameterize(separator: '_')}")
end

#relations_icon(document, icon) ⇒ Object

Returns the icon used based off a Settings strategy



278
279
280
281
282
283
284
# File 'app/helpers/geoblacklight_helper.rb', line 278

def relations_icon(document, icon)
  icon_name = document[Settings.FIELDS.GEOM_TYPE] if Settings.USE_GEOM_FOR_RELATIONS_ICON
  icon_name = icon if icon_name.blank?
  icon_options = {}
  icon_options = { classes: 'svg_tooltip' } if Settings.USE_GEOM_FOR_RELATIONS_ICON
  geoblacklight_icon(icon_name, icon_options)
end

#render_facet_item_with_icon(field_name, item) ⇒ Object

Renders a facet item with an icon placed as the first child of ‘.facet-label`. This works with `render_facet_value` and `render_selected_facet_value`

Returns:

  • String



235
236
237
238
239
240
# File 'app/helpers/geoblacklight_helper.rb', line 235

def render_facet_item_with_icon(field_name, item)
  doc = Nokogiri::HTML.fragment(render_facet_item(field_name, item))
  doc.at_css('.facet-label').children.first
     .add_previous_sibling(geoblacklight_icon(item.value, aria_hidden: true, classes: 'svg_tooltip'))
  doc.to_html.html_safe
end

Renders an unique array of search links based off of terms passed in using the facet parameter



116
117
118
119
120
# File 'app/helpers/geoblacklight_helper.rb', line 116

def render_facet_links(facet, items)
  items.uniq.map do |item|
    link_to item, search_catalog_path(f: { facet => [item] })
  end.join(', ').html_safe
end

#render_facet_tags(facet) ⇒ Object



94
95
96
97
98
# File 'app/helpers/geoblacklight_helper.rb', line 94

def render_facet_tags(facet)
  render_facet_limit(facets_from_request(facet).first,
                     partial: 'facet_tag_item',
                     layout: 'facet_tag_layout')
end

#render_help_text_entry(feature, key) ⇒ HTML tag

Render help text popover for a given feature and translation key

Returns:

  • (HTML tag)


172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/helpers/geoblacklight_helper.rb', line 172

def render_help_text_entry(feature, key)
  if I18n.exists?("geoblacklight.help_text.#{feature}.#{key}", locale)
    help_text = I18n.t("geoblacklight.help_text.#{feature}.#{key}")
    tag.h3 class: 'help-text viewer_protocol h6' do
      tag.a data: { toggle: 'popover', title: help_text[:title], content: help_text[:content] } do
        help_text[:title]
      end
    end
  else
    tag.span class: 'help-text translation-missing'
  end
end

#render_references_url(args) ⇒ Object

Renders a reference url for a document

Parameters:

  • document, (Hash)

    field_name



269
270
271
272
273
274
275
# File 'app/helpers/geoblacklight_helper.rb', line 269

def render_references_url(args)
  return unless args[:document]&.references&.url
  link_to(
    args[:document].references.url.endpoint,
    args[:document].references.url.endpoint
  )
end

#render_transformed_metadata(metadata) ⇒ String

Renders the transformed metadata (Renders a partial when the metadata isn’t available)

Parameters:

Returns:

  • (String)


247
248
249
250
251
252
253
254
255
# File 'app/helpers/geoblacklight_helper.rb', line 247

def ()
  render partial: 'catalog/metadata/content', locals: { content: .transform.html_safe }
rescue Geoblacklight::MetadataTransformer::TransformError => transform_err
  Geoblacklight.logger.warn transform_err.message
  render partial: 'catalog/metadata/markup', locals: { content: .to_xml }
rescue => err
  Geoblacklight.logger.warn err.message
  render partial: 'catalog/metadata/missing'
end

#render_value_as_truncate_abstract(args) ⇒ Object

Render value for a document’s field as a truncate abstract div. Arguments come from Blacklight::DocumentPresenter’s get_field_values method

Parameters:

  • args (Hash)

    from get_field_values



197
198
199
200
201
# File 'app/helpers/geoblacklight_helper.rb', line 197

def render_value_as_truncate_abstract(args)
  tag.div class: 'truncate-abstract' do
    Array(args[:value]).flatten.join(' ')
  end
end

#render_web_services(reference) ⇒ Object

Renders the partials for a Geoblacklight::Reference in the web services modal

Parameters:



214
215
216
217
218
219
220
221
# File 'app/helpers/geoblacklight_helper.rb', line 214

def render_web_services(reference)
  render(
    partial: "web_services_#{reference.type}",
    locals: { reference: reference }
  )
rescue ActionView::MissingTemplate
  render partial: 'web_services_default', locals: { reference: reference }
end

#results_js_map_selector(controller_name) ⇒ Object

Returns the data-map attribute value used as the JS map selector



287
288
289
290
291
292
293
294
295
296
# File 'app/helpers/geoblacklight_helper.rb', line 287

def results_js_map_selector(controller_name)
  case controller_name
  when 'bookmarks'
    'bookmarks'
  when 'catalog'
    'index'
  else
    'index'
  end
end

#show_attribute_table?Boolean

Deteremines if item view should include attribute table

Returns:

  • (Boolean)


188
189
190
# File 'app/helpers/geoblacklight_helper.rb', line 188

def show_attribute_table?
  document_available? && @document.inspectable?
end

#show_help_text?(feature, key) ⇒ Boolean

Deteremines if a feature should include help text popover

Returns:

  • (Boolean)


165
166
167
# File 'app/helpers/geoblacklight_helper.rb', line 165

def show_help_text?(feature, key)
  Settings&.HELP_TEXT&.send(feature)&.include?(key)
end

#snippit(args) ⇒ String

Blacklight catalog controller helper method to truncate field value to 150 chars

Parameters:

  • args (SolrDocument)

Returns:

  • (String)


90
91
92
# File 'app/helpers/geoblacklight_helper.rb', line 90

def snippit(args)
  truncate(Array(args[:value]).flatten.join(' '), length: 150)
end