Skip to content

Commit

Permalink
Refactor visit/pickup to use consistent routing for each library and …
Browse files Browse the repository at this point in the history
…then figure it out on the backend
  • Loading branch information
cbeer committed Mar 15, 2021
1 parent 22d8cf2 commit bc1b419
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 53 deletions.
7 changes: 7 additions & 0 deletions app/controllers/schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ class SchedulesController < ApplicationController
before_action :authenticate_user!

def show
@oncehub_id = Settings.oncehub.dig(params[:type], params[:id])

raise ActionController::RoutingError, 'Not Found' unless @oncehub_id

render layout: !request.xhr?
end

def libcal_pickup
@libcal_settings = Settings.libcal[params[:id]]
raise ActionController::RoutingError, 'Not Found' unless @libcal_settings

render layout: !request.xhr?
end
end
45 changes: 13 additions & 32 deletions app/helpers/summaries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def scheduler_data_param(user_attributes)
# rubocop:disable Layout/LineLength
def link_to_spec_visit
link = if patron_or_group.can_schedule_special_collections_visit?
link_to schedule_spec_path, role: 'button', class: 'btn btn-primary', data: { 'mylibrary-modal': 'trigger' } do
link_to schedule_visit_path('SPEC-COLL'), role: 'button', class: 'btn btn-primary', data: { 'mylibrary-modal': 'trigger' } do
safe_join([sul_icon(:'visit-spec', classes: 'lg mr-2'), 'Visit Reading Room'], ' ')
end
else
Expand Down Expand Up @@ -39,7 +39,7 @@ def spec_visit_note
def link_to_schedule_once_visit(library:, text:, css_class: nil)
link_to(
text,
enabled_schedule_libraries[library],
schedule_visit_path(library),
role: 'button',
class: css_class,
data: { 'mylibrary-modal': 'trigger' }
Expand All @@ -48,9 +48,9 @@ def link_to_schedule_once_visit(library:, text:, css_class: nil)

# rubocop:disable Layout/LineLength
def schedule_once_link_or_dropdown
return if enabled_schedule_libraries.blank?
schedulable_libraries = enabled_schedule_libraries

schedulable_libraries = enabled_schedule_libraries.keys
return if schedulable_libraries.blank?

if schedulable_libraries.one?
return link_to_schedule_once_visit(
Expand All @@ -74,11 +74,11 @@ def library_entry_note
end

def link_to_schedule_pickup(library:, text:, css_class: nil)
return unless enabled_pickup_libraries[library]
return unless enabled_pickup_libraries.include? library

link_to(
text,
enabled_pickup_libraries[library],
schedule_pickup_path(library),
role: 'button',
class: css_class,
data: { 'mylibrary-modal': 'trigger' }
Expand All @@ -87,9 +87,9 @@ def link_to_schedule_pickup(library:, text:, css_class: nil)

# rubocop:disable Layout/LineLength
def schedule_pickup_link_or_dropdown
return no_pickups_markup if enabled_pickup_libraries.blank?
pickup_libraries = enabled_pickup_libraries

pickup_libraries = enabled_pickup_libraries.keys
return no_pickups_markup if pickup_libraries.blank?

if pickup_libraries.one?
return link_to_schedule_pickup(
Expand Down Expand Up @@ -119,7 +119,7 @@ def request_pickup_note
return '' if controller_name == 'requests'

tag.span(class: 'ml-3') do
if enabled_pickup_libraries.keys.one?
if enabled_pickup_libraries.one?
link_to('You have items waiting.', requests_path)
else
safe_join(['You have items waiting at', link_to('multiple libraries.', requests_path)], ' ')
Expand All @@ -138,35 +138,16 @@ def link_to_pickup_requests
def enabled_schedule_libraries
configured_schedule_libraries = Settings.schedule_access.keys.map(&:to_s)

library_schedule_path_map.select do |library|
configured_schedule_libraries.include?(library) && patron_or_group.can_schedule_access?(library)
configured_schedule_libraries.select do |library|
patron_or_group.can_schedule_access?(library)
end
end

def library_schedule_path_map
{
'GREEN' => schedule_green_path,
'EAST-ASIA' => schedule_eal_path,
'MUSIC' => schedule_music_path,
'ARS' => schedule_ars_path
}
end

def enabled_pickup_libraries
configured_pickup_libraries = Settings.schedule_pickup.keys.map(&:to_s)

library_pickup_path_map.select do |library|
configured_pickup_libraries.include?(library) && patron_or_group.can_schedule_pickup?(library)
configured_pickup_libraries.select do |library|
patron_or_group.can_schedule_pickup?(library)
end
end

def library_pickup_path_map
{
'GREEN' => schedule_green_pickup_path,
'BUSINESS' => schedule_business_pickup_path,
'EAST-ASIA' => schedule_eal_pickup_path,
'HOPKINS' => schedule_miller_pickup_path,
'LAW' => schedule_law_pickup_path
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= sul_icon(:'request-pickup', classes: 'lg mr-2') %> Pick up requests
</button>
<div class="dropdown-menu" aria-labelledby="schedulePickupDropdown">
<% pickup_libraries.each do |library, path| %>
<% pickup_libraries.each do |library| %>
<%= link_to_schedule_pickup(library: library, text: library_name(library), css_class: 'dropdown-item') %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/schedules/libcal_pickup.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="modal-body">
<iframe src="https://api3.libcal.com/widget/appointments?<%= Settings.libcal[params[:libcal_library]].to_h.to_query %>" class="schedule-iframe" name="SchedulePickupIframe" scrolling="yes" frameborder="0" hspace="0" marginheight="0" marginwidth="0" height="900px" width="100%"></iframe>
<iframe src="https://api3.libcal.com/widget/appointments?<%= @libcal_settings.to_h.to_query %>" class="schedule-iframe" name="SchedulePickupIframe" scrolling="yes" frameborder="0" hspace="0" marginheight="0" marginwidth="0" height="900px" width="100%"></iframe>
</div>
<div class="modal-footer justify-content-start">
<%= link_to 'Close', :back, class: 'btn btn-link cancel-link', data: { dismiss: 'modal' } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/schedules/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="modal-body">
<iframe src="https://go.oncehub.com/<%= params[:oncehub_id] %>?brdr=1pxd8d8d8&amp;dt=&amp;em=1&amp;<%= scheduler_data_param({ name: patron_or_group.display_name, email: patron_or_group.email, sul_myaccount_name: patron_or_group.display_name, sul_myaccount_email: patron_or_group.email, sul_myaccount_sunet: current_user.username })%>&amp;Si=1" class="schedule-iframe" name="ScheduleOnceIframe" scrolling="yes" frameborder="0" hspace="0" marginheight="0" marginwidth="0" height="900px" width="100%" vspace="0" sotheme="light"></iframe>
<iframe src="https://go.oncehub.com/<%= @oncehub_id %>?brdr=1pxd8d8d8&amp;dt=&amp;em=1&amp;<%= scheduler_data_param({ name: patron_or_group.display_name, email: patron_or_group.email, sul_myaccount_name: patron_or_group.display_name, sul_myaccount_email: patron_or_group.email, sul_myaccount_sunet: current_user.username })%>&amp;Si=1" class="schedule-iframe" name="ScheduleOnceIframe" scrolling="yes" frameborder="0" hspace="0" marginheight="0" marginwidth="0" height="900px" width="100%" vspace="0" sotheme="light"></iframe>
</div>
<div class="modal-footer justify-content-start">
<%= link_to 'Close', :back, class: 'btn btn-link cancel-link', data: { dismiss: 'modal' } %>
Expand Down
19 changes: 7 additions & 12 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root to: 'sessions#index'
get 'schedule/eal' => 'schedules#show', oncehub_id: 'StanfordLibrariesEastAsiaLibraryEntry'
get 'schedule/green' => 'schedules#show', oncehub_id: 'StanfordLibrariesGreenEntry'
get 'schedule/spec' => 'schedules#show', oncehub_id: 'StanfordLibrariesVisitSpecialCollections'
get 'schedule/ars' => 'schedules#show', oncehub_id: 'StanfordLibrariesVisitArs'
get 'schedule/music' => 'schedules#show', oncehub_id: 'StanfordLibrariesVisitMusic'

get 'schedule/green_pickup' => 'schedules#show', oncehub_id: 'StanfordLibrariesPagingPickupGreenLibrary'
get 'schedule/eal_pickup' => 'schedules#show', oncehub_id: 'StanfordLibrariesPagingPickupEastAsiaLibrary'
get 'schedule/miller_pickup' => 'schedules#show', oncehub_id: 'StanfordLibrariesPagingPickupMillerLibrary'

get 'schedule/business_pickup' => 'schedules#libcal_pickup', libcal_library: 'BUSINESS'
get 'schedule/law_pickup' => 'schedules#libcal_pickup', libcal_library: 'LAW'

# business + law use libcal, not oncehub, so we override their routes:
get 'schedule/pickup/BUSINESS' => 'schedules#libcal_pickup', id: 'BUSINESS'
get 'schedule/pickup/LAW' => 'schedules#libcal_pickup', id: 'LAW'

get 'schedule/visit/:id' => 'schedules#show', as: 'schedule_visit', type: :visit
get 'schedule/pickup/:id' => 'schedules#show', as: 'schedule_pickup', type: :pickup

resources :summaries
resources :checkouts
Expand Down
13 changes: 13 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ schedule_access:
MUSIC: false
SPEC-COLL: false

oncehub:
visit:
EAST-ASIA: 'StanfordLibrariesEastAsiaLibraryEntry'
GREEN: 'StanfordLibrariesGreenEntry'
SPEC-COLL: 'StanfordLibrariesVisitSpecialCollections'
ARS: 'StanfordLibrariesVisitArs'
MUSIC: 'StanfordLibrariesMusicLibraryEntry'
pickup:
GREEN: 'StanfordLibrariesPagingPickupGreenLibrary'
EAST-ASIA: 'StanfordLibrariesPagingPickupEastAsiaLibrary'
MILLER: 'StanfordLibrariesPagingPickupMillerLibrary'


libcal:
BUSINESS:
u: 69353
Expand Down
12 changes: 6 additions & 6 deletions spec/helpers/summaries_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

it 'links to the appropriate href given the library' do
link = helper.link_to_schedule_once_visit(library: 'EAST-ASIA', text: 'East Asia Library')
expect(link).to include 'href="/schedule/eal"'
expect(link).to include 'href="/schedule/visit/EAST-ASIA"'
end

it 'uses the given text as the link text' do
link = Capybara.string(helper.link_to_schedule_once_visit(library: 'GREEN', text: 'Green Library'))
expect(link).to have_link('Green Library', href: '/schedule/green')
expect(link).to have_link('Green Library', href: '/schedule/visit/GREEN')
end
end

Expand Down Expand Up @@ -59,7 +59,7 @@
it 'renders a single button to schedule a visit' do
expect(
Capybara.string(helper.schedule_once_link_or_dropdown)
).to have_link('Enter Green Library for research', href: '/schedule/green')
).to have_link('Enter Green Library for research', href: '/schedule/visit/GREEN')
end
end

Expand Down Expand Up @@ -113,12 +113,12 @@

it 'uses the given text as the link text' do
link = Capybara.string(helper.link_to_schedule_pickup(library: 'GREEN', text: 'Green Library'))
expect(link).to have_link('Green Library', href: '/schedule/green_pickup')
expect(link).to have_link('Green Library', href: '/schedule/pickup/GREEN')
end

it 'links to the appropriate href given the library' do
link = helper.link_to_schedule_pickup(library: 'BUSINESS', text: 'Business Library')
expect(link).to include 'href="/schedule/business_pickup"'
expect(link).to include 'href="/schedule/pickup/BUSINESS"'
end
end

Expand All @@ -140,7 +140,7 @@

it 'links directly to that library' do
link = helper.schedule_pickup_link_or_dropdown
expect(link).to have_link('Pick up requests at Green Library', href: '/schedule/green_pickup')
expect(link).to have_link('Pick up requests at Green Library', href: '/schedule/pickup/GREEN')
end

it 'does not have a dropdown' do
Expand Down

0 comments on commit bc1b419

Please sign in to comment.