Class: Geoblacklight::HeaderIconsComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, fields: [Geoblacklight.configuration.fields.resource_class, Geoblacklight.configuration.fields.access_rights]) ⇒ HeaderIconsComponent

Returns a new instance of HeaderIconsComponent.



7
8
9
10
11
12
13
# File 'app/components/geoblacklight/header_icons_component.rb', line 7

def initialize(document:,
  fields: [Geoblacklight.configuration.fields.resource_class,
    Geoblacklight.configuration.fields.access_rights])
  @document = document
  @fields = fields
  super()
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'app/components/geoblacklight/header_icons_component.rb', line 5

def document
  @document
end

#fieldsObject (readonly)

Returns the value of attribute fields.



5
6
7
# File 'app/components/geoblacklight/header_icons_component.rb', line 5

def fields
  @fields
end

Instance Method Details

#icon(field) ⇒ Object



15
16
17
18
19
# File 'app/components/geoblacklight/header_icons_component.rb', line 15

def icon(field)
  return resource_icon if field == Geoblacklight.configuration.fields.resource_class

  helpers.geoblacklight_icon(@document[field], classes: "svg_tooltip")
end

#resource_iconObject

If the item has a resource type of “X data” where “X” is an existing icon, use that icon Otherwise just use the resource class icon



23
24
25
26
27
28
29
# File 'app/components/geoblacklight/header_icons_component.rb', line 23

def resource_icon
  dataset_type = @document.resource_type.find { |type| type.include?(" data") }&.gsub(" data", "")
  resource_type_icon = helpers.geoblacklight_icon(dataset_type, classes: "svg_tooltip")
  return resource_type_icon unless resource_type_icon.include?("icon-missing")

  helpers.geoblacklight_icon(@document.resource_class.first, classes: "svg_tooltip")
end