Module: GeoblacklightHelper
- Defined in:
- app/helpers/geoblacklight_helper.rb
Instance Method Summary collapse
- #document_available? ⇒ Boolean
- #document_downloadable? ⇒ Boolean deprecated Deprecated.
- #download_link_file(label, id, url) ⇒ Object deprecated Deprecated.
- #download_link_generated(download_type, document) ⇒ Object deprecated Deprecated.
- #download_link_hgl(text, document) ⇒ Object deprecated Deprecated.
- #download_link_iiif ⇒ String deprecated Deprecated.
- #download_text(format) ⇒ Object deprecated Deprecated.
- #export_format_label(format) ⇒ Object deprecated Deprecated.
-
#first_metadata?(document, metadata) ⇒ Boolean
Determines whether or not the metadata is the first within the array of References.
-
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references.
-
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays.
-
#geoblacklight_icon(name, **args) ⇒ SVG or HTML tag
Returns an SVG icon or empty HTML span element standard:disable Style/ArgumentsForwarding TODO: Remove linter disable after lowest supported Ruby version >= 3.2.
- #iiif_jpg_url ⇒ Object deprecated Deprecated.
- #iiif_manifest_container? ⇒ Boolean deprecated Deprecated.
- #iiif_manifest_viewer ⇒ Object deprecated Deprecated.
-
#leaflet_options ⇒ Object
Returns a hash of the leaflet plugin settings to pass to the viewer.
- #leaflet_viewer ⇒ Object deprecated Deprecated.
- #ol_viewer ⇒ Object deprecated Deprecated.
- #openlayers_container? ⇒ Boolean deprecated Deprecated.
- #proper_case_format(format) ⇒ Object deprecated Deprecated.
-
#relations_icon(document, icon) ⇒ Object
Returns the icon used based off a Settings strategy.
- #render_help_text_entry(feature, key) ⇒ HTML tag deprecated Deprecated.
-
#render_references_url(args) ⇒ Object
Renders a reference url for a document.
- #render_sidebar_map?(document) ⇒ Boolean deprecated Deprecated.
-
#render_transformed_metadata(metadata) ⇒ String
Renders the transformed metadata (Renders a partial when the metadata isn't available).
-
#render_value_as_truncate_abstract(args) ⇒ Object
Render value for a document's field as a truncate abstract div.
- #render_web_services(reference) ⇒ Object deprecated Deprecated.
-
#results_js_map_selector(controller_name) ⇒ Object
Returns the data-map attribute value used as the JS map selector.
- #show_attribute_table? ⇒ Boolean deprecated Deprecated.
- #show_help_text?(feature, key) ⇒ Boolean deprecated Deprecated.
-
#snippit(args) ⇒ String
Blacklight catalog controller helper method to truncate field value to 150 chars.
- #viewer_container ⇒ Object deprecated Deprecated.
Instance Method Details
#document_available? ⇒ Boolean
4 5 6 |
# File 'app/helpers/geoblacklight_helper.rb', line 4 def document_available? @document.public? || (@document.same_institution? && user_signed_in?) end |
#document_downloadable? ⇒ Boolean
9 10 11 |
# File 'app/helpers/geoblacklight_helper.rb', line 9 def document_downloadable? document_available? && @document.downloadable? end |
#download_link_file(label, id, url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/geoblacklight_helper.rb', line 22 def download_link_file(label, id, url) link_to( label, url, "contentUrl" => url, :data => { download: "trigger", download_type: "direct", download_id: id } ) end |
#download_link_generated(download_type, document) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/geoblacklight_helper.rb', line 66 def download_link_generated(download_type, document) link_to( t("geoblacklight.download.export_link", download_format: Geoblacklight.deprecation.silence { export_format_label(download_type) }), "", data: { download_path: download_path(document.id, type: download_type), download: "trigger", download_type: download_type, download_id: document.id } ) end |
#download_link_hgl(text, document) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/geoblacklight_helper.rb', line 36 def download_link_hgl(text, document) link_to( text, download_hgl_path(id: document), data: { blacklight_modal: "trigger", download: "trigger", download_type: "harvard-hgl", download_id: document.id } ) end |
#download_link_iiif ⇒ String
Generates the link markup for the IIIF JPEG download
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/geoblacklight_helper.rb', line 52 def download_link_iiif Geoblacklight.deprecation.silence do link_to( download_text("JPG"), iiif_jpg_url, "contentUrl" => iiif_jpg_url, :data => { download: "trigger" } ) end end |
#download_text(format) ⇒ Object
Wraps download text with proper_case_format
136 137 138 139 140 |
# File 'app/helpers/geoblacklight_helper.rb', line 136 def download_text(format) download_format = Geoblacklight.deprecation.silence { proper_case_format(format) } value = t("geoblacklight.download.download_link", download_format: download_format) value.html_safe end |
#export_format_label(format) ⇒ Object
Format labels are customized for exports - look up the appropriate key.
117 118 119 |
# File 'app/helpers/geoblacklight_helper.rb', line 117 def export_format_label(format) t("geoblacklight.download.export_#{format.to_s.parameterize(separator: "_")}_link") end |
#first_metadata?(document, metadata) ⇒ Boolean
Determines whether or not the metadata is the first within the array of References
253 254 255 |
# File 'app/helpers/geoblacklight_helper.rb', line 253 def (document, ) document.references..first.type == .type end |
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references
128 129 130 |
# File 'app/helpers/geoblacklight_helper.rb', line 128 def formatted_name_reference(reference) t "geoblacklight.references.#{reference}" end |
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays
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 standard:disable Style/ArgumentsForwarding TODO: Remove linter disable after lowest supported Ruby version >= 3.2
97 98 99 100 101 102 103 104 |
# File 'app/helpers/geoblacklight_helper.rb', line 97 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_url ⇒ Object
14 15 16 |
# File 'app/helpers/geoblacklight_helper.rb', line 14 def iiif_jpg_url @document.references.iiif.endpoint.sub! "info.json", "full/full/0/default.jpg" end |
#iiif_manifest_container? ⇒ Boolean
339 340 341 342 |
# File 'app/helpers/geoblacklight_helper.rb', line 339 def iiif_manifest_container? return false unless @document @document&.item_viewer&.viewer_preference&.key?(:iiif_manifest) end |
#iiif_manifest_viewer ⇒ Object
345 346 347 |
# File 'app/helpers/geoblacklight_helper.rb', line 345 def iiif_manifest_viewer tag.div(nil, id: "clover-viewer", iiif_content: @document.viewer_endpoint) end |
#leaflet_options ⇒ Object
Returns a hash of the leaflet plugin settings to pass to the viewer. @return
229 230 231 |
# File 'app/helpers/geoblacklight_helper.rb', line 229 def Settings.LEAFLET end |
#leaflet_viewer ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'app/helpers/geoblacklight_helper.rb', line 307 def leaflet_viewer tag.div(nil, id: "map", data: { :map => "item", :protocol => Geoblacklight.deprecation.silence { @document.viewer_protocol }.camelize, :url => @document.viewer_endpoint, "layer-id" => Geoblacklight.deprecation.silence { @document.wxs_identifier }, "map-geom" => @document.geometry.geojson, "catalog-path" => search_catalog_path, :available => document_available?, :basemap => geoblacklight_basemap, :leaflet_options => }) end |
#ol_viewer ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'app/helpers/geoblacklight_helper.rb', line 323 def ol_viewer tag.div(nil, id: "ol-map", data: { :map => "item", :protocol => Geoblacklight.deprecation.silence { @document.viewer_protocol }.camelize, :url => @document.viewer_endpoint, "layer-id" => Geoblacklight.deprecation.silence { @document.wxs_identifier }, "map-geom" => @document.geometry.geojson, "catalog-path" => search_catalog_path, :available => document_available?, :basemap => geoblacklight_basemap, :leaflet_options => }) end |
#openlayers_container? ⇒ Boolean
301 302 303 304 |
# File 'app/helpers/geoblacklight_helper.rb', line 301 def openlayers_container? return false unless @document @document.item_viewer.pmtiles || @document.item_viewer.cog end |
#proper_case_format(format) ⇒ Object
Looks up properly formatted names for formats
111 112 113 |
# File 'app/helpers/geoblacklight_helper.rb', line 111 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
269 270 271 272 273 274 275 |
# File 'app/helpers/geoblacklight_helper.rb', line 269 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? = {} = {classes: "svg_tooltip"} if Settings.USE_GEOM_FOR_RELATIONS_ICON geoblacklight_icon(icon_name, **) end |
#render_help_text_entry(feature, key) ⇒ HTML tag
Render help text popover for a given feature and translation key
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/helpers/geoblacklight_helper.rb', line 156 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
260 261 262 263 264 265 266 |
# File 'app/helpers/geoblacklight_helper.rb', line 260 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_sidebar_map?(document) ⇒ Boolean
Determines if item view should render the sidebar static map
176 177 178 |
# File 'app/helpers/geoblacklight_helper.rb', line 176 def (document) Geoblacklight.deprecation.silence { Settings.SIDEBAR_STATIC_MAP&.any? { |vp| document.viewer_protocol == vp } } end |
#render_transformed_metadata(metadata) ⇒ String
Renders the transformed metadata (Renders a partial when the metadata isn't available)
238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/geoblacklight_helper.rb', line 238 def () render partial: "catalog/metadata/content", locals: {content: .transform.html_safe} rescue Geoblacklight::MetadataTransformer::TransformError => transform_err Geoblacklight.logger.warn transform_err. render partial: "catalog/metadata/markup", locals: {content: .to_xml} rescue => err Geoblacklight.logger.warn err. 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
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
215 216 217 218 219 220 221 222 |
# File 'app/helpers/geoblacklight_helper.rb', line 215 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
278 279 280 281 282 283 284 285 |
# File 'app/helpers/geoblacklight_helper.rb', line 278 def results_js_map_selector(controller_name) case controller_name when "bookmarks" "bookmarks" else "index" end end |
#show_attribute_table? ⇒ Boolean
Deteremines if item view should include attribute table
186 187 188 |
# File 'app/helpers/geoblacklight_helper.rb', line 186 def show_attribute_table? document_available? && @document.inspectable? end |
#show_help_text?(feature, key) ⇒ Boolean
Deteremines if a feature should include help text popover
148 149 150 |
# File 'app/helpers/geoblacklight_helper.rb', line 148 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
88 89 90 |
# File 'app/helpers/geoblacklight_helper.rb', line 88 def snippit(args) truncate(Array(args[:value]).flatten.join(" "), length: 150) end |
#viewer_container ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 |
# File 'app/helpers/geoblacklight_helper.rb', line 288 def viewer_container Geoblacklight.deprecation.silence do if openlayers_container? ol_viewer elsif iiif_manifest_container? iiif_manifest_viewer else leaflet_viewer end end end |