Class: BorrowDirectPresenter

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

Overview

Rails helpers make it hard to isolate things, we wrap up the helpers for our BD resolve section in this helper presenter class.

Where ‘renderer’ is the SectionRenderer object probably available in view as ‘renderer’ bd_presenter = BorrowDirectPresenter.new(renderer)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer) ⇒ BorrowDirectPresenter

Returns a new instance of BorrowDirectPresenter.



9
10
11
12
13
# File 'app/helpers/borrow_direct_presenter.rb', line 9

def initialize(renderer)
  @renderer = renderer
  @request = renderer.request
  @responses = renderer.responses_list
end

Instance Attribute Details

#rendererObject (readonly)

Returns the value of attribute renderer.



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

def renderer
  @renderer
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#responsesObject (readonly)

Returns the value of attribute responses.



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

def responses
  @responses
end

Instance Method Details

#could_not_place_request?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/helpers/borrow_direct_presenter.rb', line 87

def could_not_place_request?
  self.status_response && self.status_response.view_data[:status] == BorrowDirectController::Error
end

#error_div_classesObject



108
109
110
111
112
113
114
# File 'app/helpers/borrow_direct_presenter.rb', line 108

def error_div_classes
  classes = ["borrow-direct-error"]
  if self.could_not_place_request?
    classes.concat ["alert", "alert-danger"]
  end
  return classes
end

#error_message_i18n_keyObject



116
117
118
119
120
121
122
# File 'app/helpers/borrow_direct_presenter.rb', line 116

def error_message_i18n_key
  if self.could_not_place_request?
    'umlaut.services.borrow_direct_adaptor.bd_request_status.error'
  else
    'umlaut.display_sections.borrow_direct.error'
  end
end

nil or a ServiceResponse of type bd_link_to_search



32
33
34
35
36
37
# File 'app/helpers/borrow_direct_presenter.rb', line 32

def link_response
  unless defined? @link_response
    @link_response = responses.find {|r| r.service_type_value_name == "bd_link_to_search"  }
  end
  return @link_response
end

#not_available_responseObject

nil or a ServiceResponse of type bd_not_available



40
41
42
43
44
45
# File 'app/helpers/borrow_direct_presenter.rb', line 40

def not_available_response
  unless defined? @not_available_response
    @not_available_response = responses.find {|r| r.service_type_value_name == "bd_not_available" }
  end
  return @not_available_response
end

#request_prompt_responseObject

nil or a ServiceResponse of type bd_request_prompt



24
25
26
27
28
29
# File 'app/helpers/borrow_direct_presenter.rb', line 24

def request_prompt_response
  unless defined? @request_prompt_response
    @request_prompt_response = responses.find {|r| r.service_type_value_name == "bd_request_prompt"}
  end
  return @request_prompt_response
end

#request_submission_in_progress?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/helpers/borrow_direct_presenter.rb', line 47

def request_submission_in_progress?
  self.status_response && (self.status_response.view_data[:status] == BorrowDirectController::InProgress)
end

#service_in_progress?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/helpers/borrow_direct_presenter.rb', line 51

def service_in_progress?
  request.service_types_in_progress?(renderer.service_type_values)
end

#show_confirmation?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/helpers/borrow_direct_presenter.rb', line 91

def show_confirmation?
  self.status_response && self.status_response.view_data[:status] == BorrowDirectController::Successful
end

Returns:

  • (Boolean)


83
84
85
# File 'app/helpers/borrow_direct_presenter.rb', line 83

def show_link_response?
  self.link_response && (! self.show_confirmation?) && (! self.show_request_form?)
end

#show_not_available?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/helpers/borrow_direct_presenter.rb', line 79

def show_not_available?
  (! self.status_response) && (! show_request_form? ) && self.not_available_response
end

#show_request_form?Boolean

We show the form if we have one, and we don’t have a bd_request_status with InProgress or Success

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/borrow_direct_presenter.rb', line 68

def show_request_form?    
  # have a request form, and do not have a status_response with a normal
  # code.  We show the form if validation error so they can try again. 
  # We do NOT show the form if submission error, it was too much stuff on screen,
  # too confusing. 
  self.request_prompt_response && (! self.could_not_place_request?) &&
  ! (  
      self.status_response && [BorrowDirectController::InProgress, BorrowDirectController::Successful].include?(self.status_response.view_data[:status])
    )
end

#spinner_render_hashObject

use our custom in progress messages, for checking API, vs placing request.



56
57
58
59
60
61
62
63
64
# File 'app/helpers/borrow_direct_presenter.rb', line 56

def spinner_render_hash
  render_hash = renderer.spinner_render_hash
  if self.request_submission_in_progress?
    render_hash[:locals][:progress_message] = I18n.t("umlaut.services.borrow_direct_adaptor.bd_request_status.progress") 
  else
    render_hash[:locals][:progress_message] = I18n.t("umlaut.services.borrow_direct_adaptor.bd_request_prompt.progress") 
  end        
  return render_hash
end

#status_responseObject

nil or a ServiceResponse with type bd_request_status



16
17
18
19
20
21
# File 'app/helpers/borrow_direct_presenter.rb', line 16

def status_response
  unless defined? @status_response
    @status_response = responses.find {|r| r.service_type_value_name == "bd_request_status"}
  end
  return @status_response
end

#user_reportable_errorObject



102
103
104
105
106
# File 'app/helpers/borrow_direct_presenter.rb', line 102

def user_reportable_error
  self.status_response &&
  self.status_response.view_data[:status] == BorrowDirectController::Error &&
  self.status_response.view_data[:error_user_message]
end

#validation_errorObject

nil or a string



96
97
98
99
100
# File 'app/helpers/borrow_direct_presenter.rb', line 96

def validation_error
  self.status_response && 
  self.status_response.view_data[:status] == BorrowDirectController::ValidationError &&
  self.status_response.view_data[:error_user_message]  
end