Module: UmlautBorrowDirect

Defined in:
app/controllers/umlaut_borrow_direct/controller_implementation.rb,
lib/umlaut_borrow_direct.rb,
lib/umlaut_borrow_direct/engine.rb,
lib/umlaut_borrow_direct/version.rb,
lib/umlaut_borrow_direct/route_set.rb,
lib/umlaut_borrow_direct/url_whitelister.rb

Overview

Superclass for actual BorrowDirectController, which will usually be implemented in local app, with an override of #current_user_barcode that provides some local auth system to figure out current barcode to make a request with.

Defined Under Namespace

Modules: RouteSet Classes: ControllerImplementation, Engine, UrlWhitelister

Constant Summary collapse

DefaultLocalAvailabilityCheck =
proc do |request, service|
  request.get_service_type(:holding).find do |sr| 
    UmlautController.umlaut_config.holdings.available_statuses.include?(sr.view_data[:status]) &&
    sr.view_data[:match_reliability] != ServiceResponse::MatchUnsure 
  end.present?
end
SectionVisibilityLogic =
proc do |section_renderer|
  (! MetadataHelper.title_is_serial?(section_renderer.request.referent)) &&
  (
    (! section_renderer.responses_empty?) || 
    section_renderer.services_in_progress? ||
    section_renderer.request.dispatch_objects_with(
      :service_type_values => UmlautBorrowDirect.service_type_values
    ).find_all {|ds| ds.failed? }.present?
  )
end
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.locally_available?(request) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/umlaut_borrow_direct.rb', line 94

def self.locally_available?(request)
  aProc = UmlautController.umlaut_config.lookup!("borrow_direct.local_availability_check") || DefaultLocalAvailabilityCheck
  return aProc.call(request, self)
end

.resolve_section_definitionObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/umlaut_borrow_direct.rb', line 24

def self.resolve_section_definition
  # A custom lambda for visibility of our section. 
  # We want it to be visible if the service is still in progress,
  # or if it's finished with ServiceResponses generated, OR
  # if it's finished in an error state. 
  # Another way to say this, the section will NOT be visible when
  # the service has finished, without generating responses, or errors. 
  #
  # Oh, and don't show it at all unless citation does not pass
  # MetadataHelper.title_is_serial?. If we don't think it's a serial,
  # it's not appropriate for BD and no results will be shown, don't show
  # spinner either. 
  #
  # We took the Umlaut SectionRenderer visibility logic for :in_progress,
  # and added a condition for error state
  {
    :div_id     => "borrow_direct",
    :html_area  => :main,
    :partial    => "borrow_direct/resolve_section",
    :visibility => SectionVisibilityLogic,
    :service_type_values => self.service_type_values,
    :show_spinner => false # we do our own
  }
end

.section_highlights_filterObject

In a local app UmlautController:

umlaut_config do
   add_section_highlights_filter! UmlautBorrowDirect.section_highlights_filter

Applies some default rules for white-background-highlighting of the borrow_direct section.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/umlaut_borrow_direct.rb', line 55

def self.section_highlights_filter
  proc {|umlaut_request, sections|
      # If it's not locally available, remove highlight from 'holding' --
      # will remove highlights for checked out material for instance. 
      # And add in document_delivery, although future lines may remove it again
      # if BD is available.
      if sections.include?("holding") && ! self.locally_available?(umlaut_request)
        sections.delete("holding")
        sections << "document_delivery"
      end


      if ( umlaut_request.get_service_type("bd_link_to_search").present? || 
           umlaut_request.get_service_type("bd_request_prompt").present? )
        # highlight BD section and NOT document_delivery if BD section is present
        sections.delete("document_delivery")
        sections << "borrow_direct"          
      end




      # If request is in progress or succesful, highlight it and not docdel. 
      if umlaut_request.get_service_type("bd_request_status").present?
        response = umlaut_request.get_service_type("bd_request_status").first
        if [ BorrowDirectController::InProgress, 
             BorrowDirectController::Successful].include? response.view_data[:status]
          sections.delete("document_delivery")
          sections << "borrow_direct" 
        elsif BorrowDirectController::Error == response.view_data[:status]
          sections.delete("document_delivery")
          sections << "borrow_direct" 
        end
      end
      
      sections.uniq!
    }
end

.service_type_valuesObject

Array of strings of all service type value names UmlautBorrowDirect does.



100
101
102
# File 'lib/umlaut_borrow_direct.rb', line 100

def self.service_type_values
  %w{bd_link_to_search bd_request_prompt bd_not_available bd_request_status}
end