Class: BorrowDirectPresenter
- Inherits:
-
Object
- Object
- BorrowDirectPresenter
- 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
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #could_not_place_request? ⇒ Boolean
- #error_div_classes ⇒ Object
- #error_message_i18n_key ⇒ Object
-
#initialize(renderer) ⇒ BorrowDirectPresenter
constructor
A new instance of BorrowDirectPresenter.
-
#link_response ⇒ Object
nil or a ServiceResponse of type bd_link_to_search.
-
#not_available_response ⇒ Object
nil or a ServiceResponse of type bd_not_available.
-
#request_prompt_response ⇒ Object
nil or a ServiceResponse of type bd_request_prompt.
- #request_submission_in_progress? ⇒ Boolean
- #service_in_progress? ⇒ Boolean
- #show_confirmation? ⇒ Boolean
- #show_link_response? ⇒ Boolean
- #show_not_available? ⇒ Boolean
-
#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.
-
#spinner_render_hash ⇒ Object
use our custom in progress messages, for checking API, vs placing request.
-
#status_response ⇒ Object
nil or a ServiceResponse with type bd_request_status.
- #user_reportable_error ⇒ Object
-
#validation_error ⇒ Object
nil or a string.
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
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
8 9 10 |
# File 'app/helpers/borrow_direct_presenter.rb', line 8 def renderer @renderer end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'app/helpers/borrow_direct_presenter.rb', line 8 def request @request end |
#responses ⇒ Object (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
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_classes ⇒ Object
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_key ⇒ Object
116 117 118 119 120 121 122 |
# File 'app/helpers/borrow_direct_presenter.rb', line 116 def if self.could_not_place_request? 'umlaut.services.borrow_direct_adaptor.bd_request_status.error' else 'umlaut.display_sections.borrow_direct.error' end end |
#link_response ⇒ Object
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_response ⇒ Object
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_response ⇒ Object
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
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
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
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 |
#show_link_response? ⇒ 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
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
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_hash ⇒ Object
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_response ⇒ Object
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_error ⇒ Object
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_error ⇒ Object
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 |