diff --git a/app/assets/stylesheets/modules/requests.scss b/app/assets/stylesheets/modules/requests.scss index 5983b599..f7012c72 100644 --- a/app/assets/stylesheets/modules/requests.scss +++ b/app/assets/stylesheets/modules/requests.scss @@ -3,3 +3,7 @@ width: auto; } } +.illiad-link { + padding: 6px 12px 6px 0px; + font-size: 1rem; +} diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index e8649422..a1f10382 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -6,7 +6,7 @@ class RequestsController < ApplicationController before_action :authorize_update!, except: :index rescue_from RequestException, with: :deny_access - # Renders user requests from FOLIO and/or BorrowDirect + # Renders user requests from FOLIO, BorrowDirect, and/or ILLIAD # # GET /requests # GET /requests.json diff --git a/app/models/borrow_direct_requests.rb b/app/models/borrow_direct_requests.rb index 89c7eaaf..f412fe59 100644 --- a/app/models/borrow_direct_requests.rb +++ b/app/models/borrow_direct_requests.rb @@ -66,5 +66,7 @@ def ready_for_pickup? def to_partial_path 'requests/borrow_direct_request' end + + def manage_request_link; end end end diff --git a/app/models/borrow_direct_reshare_requests.rb b/app/models/borrow_direct_reshare_requests.rb index 1dba98a3..78a1955c 100644 --- a/app/models/borrow_direct_reshare_requests.rb +++ b/app/models/borrow_direct_reshare_requests.rb @@ -112,5 +112,7 @@ def title def to_partial_path 'requests/borrow_direct_request' end + + def manage_request_link; end end end diff --git a/app/models/folio/patron.rb b/app/models/folio/patron.rb index 264f9b89..f024e6a4 100644 --- a/app/models/folio/patron.rb +++ b/app/models/folio/patron.rb @@ -166,9 +166,9 @@ def group_checkouts all_checkouts.select(&:proxy_checkout?) end - # Self requests + # Self requests: Combines data from FOLIO, borrow direct, and ILLIAD def requests - @requests ||= folio_requests.reject(&:proxy_request?) + borrow_direct_requests + @requests ||= folio_requests.reject(&:proxy_request?) + borrow_direct_requests + illiad_requests end # Requests from the proxy group @@ -176,6 +176,11 @@ def group_requests folio_requests.select(&:proxy_request?) if sponsor? end + # ILLIAD requests are retrieved separately + def illiad_requests + @illiad_requests ||= IlliadRequests.new(user_info['username']).requests + end + def to_partial_path return 'patron/expired' if expired? return 'patron/fee_borrower' if fee_borrower? diff --git a/app/models/folio/request.rb b/app/models/folio/request.rb index d679af60..50b5af64 100644 --- a/app/models/folio/request.rb +++ b/app/models/folio/request.rb @@ -138,6 +138,8 @@ def date_sort_key ] end + def manage_request_link; end + private def library_key diff --git a/app/models/illiad_requests.rb b/app/models/illiad_requests.rb new file mode 100644 index 00000000..85f99ea1 --- /dev/null +++ b/app/models/illiad_requests.rb @@ -0,0 +1,121 @@ +# frozen_string_literal: true + +### +# Class to handle creation of ILLiad OpenURL request +### +class IlliadRequests + def initialize(user_id) + @user_id = user_id + end + + def requests + request_user_transactions.map do |illiad_result| + IlliadRequests::Request.new(illiad_result) + end + rescue StandardError => e + Honeybadger.notify(e, error_message: "Unable to retrieve ILLIAD transactions with #{e}") + [] + end + + private + + def request_user_transactions + url = "#{Settings.sul_illiad}ILLiadWebPlatform/Transaction/UserRequests/#{@user_id}" + conn = Faraday.new(url: Settings.sul_illiad) do |req| + req.headers['ApiKey'] = Settings.illiad_api_key + req.headers['Accept'] = 'application/json; version=1' + req.adapter Faraday.default_adapter + end + + response = conn.get(url) + JSON.parse(response.body) + end + + class Request + # illiad_result is a hash with the results from the Illiad Request + def initialize(illiad_result) + @illiad_result = illiad_result + end + + def scan_type? + @illiad_result['PhotoJournalTitle'].present? + end + + def key + @illiad_result['TransactionNumber'].to_s + end + + # rubocop:disable Metrics/MethodLength + def sort_key(key) + sort_key = case key + when :library + [pickup_library, title, author, call_number] + when :date + [*date_sort_key, title, author, call_number] + when :title + [title, author, call_number] + when :author + [author, title, call_number] + when :call_number + [call_number] + end + sort_key.join('---') + end + # rubocop:enable Metrics/MethodLength + + def date_sort_key + (expiration_date || Folio::Request::END_OF_DAYS).strftime('%FT%T') + end + + def title + scan_type? ? @illiad_result['PhotoJournalTitle'] : @illiad_result['LoanTitle'] + end + + def call_number + @illiad_result['CallNumber'] + end + + def author + scan_type? ? @illiad_result['PhotoArticleAuthor'] : @illiad_result['LoanAuthor'] + end + + def placed_date + Time.zone.parse(@illiad_result['CreationDate']) + end + + def pickup_library + @illiad_result['ItemInfo4'] + end + + def expiration_date + scan_type? ? placed_date + 2.months : Time.zone.parse(@illiad_result['NotWantedAfter']) + end + + def fill_by_date; end + + def ready_for_pickup? + ready_for_pickup_status = ['Media Microtext Checkout to Customer', + 'Special Collections Checked Out to Customer', + 'Customer Notified via E-Mail'] + ready_for_pickup_status.include?(@illiad_result['TransactionStatus']) + end + + def from_ill? + true + end + + def service_point_name + Mylibrary::Application.config.library_map[pickup_library] || pickup_library + end + + def waitlist_position; end + + def to_partial_path + 'requests/request' + end + + def manage_request_link + "https://sulils.stanford.edu/illiad.dll?Action=10&Form=72&Value=#{key}" + end + end +end diff --git a/app/views/requests/_request.html.erb b/app/views/requests/_request.html.erb index 527595cf..31d2841c 100644 --- a/app/views/requests/_request.html.erb +++ b/app/views/requests/_request.html.erb @@ -10,7 +10,6 @@ <% else %> Deliver to <%= request.service_point_name %> <% end %> - <% if request.expiration_date %>