Class: Umlaut::SectionHighlights

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/umlaut/section_highlights.rb

Overview

NOT Rails helper methods, but a helper class with logic to determine whether a given umlaut display section should be given the umlaut-section-highlighted class, used to mark recommended access methods. (For instance, fulltext if it’s available, or maybe document_delivery if it’s not, but it gets more complicated.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(umlaut_request, umlaut_config = UmlautController.umlaut_config) ⇒ SectionHighlights

  • First arg is the umlaut Request

  • Second optional is an UmlautConfiguration object, used for ‘section_highlights_filter` lambda – will default to UmlautController.umlaut_config



14
15
16
17
# File 'app/helpers/umlaut/section_highlights.rb', line 14

def initialize(umlaut_request, umlaut_config = UmlautController.umlaut_config)
  @umlaut_config  = umlaut_config
  @umlaut_request = umlaut_request
end

Instance Attribute Details

#umlaut_configObject (readonly)

Returns the value of attribute umlaut_config.



8
9
10
# File 'app/helpers/umlaut/section_highlights.rb', line 8

def umlaut_config
  @umlaut_config
end

#umlaut_requestObject (readonly)

Returns the value of attribute umlaut_request.



8
9
10
# File 'app/helpers/umlaut/section_highlights.rb', line 8

def umlaut_request
  @umlaut_request
end

Instance Method Details

#apply_filters!(sections) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/umlaut/section_highlights.rb', line 73

def apply_filters!(sections)
  sections = sections.dup

  (umlaut_config.section_highlights_filter || []).each do |filter|
    # filters are expected to mutate 'sections' if they want
    filter.call(umlaut_request, sections, self)
  end

  return sections
end

#calc_highlighted_sections!Object

Returns an array of zero or more sections to display with .umlaut-section-highlighted – usually the recommended section, fulltext if we have it, etc.

A bit hard to get exactly right for both technical and contextual policy issues, this is a basic starting point.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/umlaut/section_highlights.rb', line 36

def calc_highlighted_sections!
  sections = []

  if umlaut_request.get_service_type("fulltext").present?
    sections << "fulltext"
  end

  # Highlight holdings if it's present AND:
  #   no fulltext is present OR it's a book (non-serial) type
  # We think people want print for books more often. 
  if umlaut_request.get_service_type("holding").present? &&
     ( umlaut_request.get_service_type("fulltext").blank? ||  (! MetadataHelper.title_is_serial?(umlaut_request.referent)) )
    sections << "holding"
  end


  # Return document_delivery as highlighted only if 
  # fulltext and holdings are done being fetched. AND. 
  # If there's no fulltext or holdings, OR there's holdings, but
  # it's a journal type thing, where we probably don't know if the
  # particular volume/issue wanted is present. Ugh. 
  if ( umlaut_request.get_service_type("document_delivery").present? &&
       umlaut_request.get_service_type("fulltext").empty? && 
        (! umlaut_request.service_types_in_progress?(["fulltext", "holding"])) && (
          umlaut_request.get_service_type("holding").empty? || 
          umlaut_request.referent.format == "journal"
        )
      )
    sections << "document_delivery"
  end

  sections = apply_filters!(sections)

  return sections
end

#highlighted_sectionsObject

array of section div_id’s that should be highlighted for the current request in it’s current state. Calculated with calc_highlighted_sections!, then cached.



26
27
28
# File 'app/helpers/umlaut/section_highlights.rb', line 26

def highlighted_sections
  @highlighted_sections ||= calc_highlighted_sections!
end

#should_highlight_section?(section_id) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/helpers/umlaut/section_highlights.rb', line 19

def should_highlight_section?(section_id)
  highlighted_sections.include? section_id.to_s
end