Skip to content

Commit

Permalink
NEXT-1301 / NEXT-1305 - updates to location links & temp locations
Browse files Browse the repository at this point in the history
  • Loading branch information
marquis committed Apr 27, 2016
1 parent c609fd5 commit aa501ea
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 53 deletions.
54 changes: 36 additions & 18 deletions app/helpers/holdings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,10 @@ def create_dummy_entry(options = {})
def add_display_elements(entries)
entries.each do |entry|

# location links
location = Location.match_location_text(entry['location_name'])
entry['location'] = location
# location links, hours
location = Location.match_location_text( entry['location_name'] )

if location && location.category == 'physical'
# NEXT-1041 - Icon or other visual cue
# %span.glyphicon.glyphicon-map-marker.text-primary
map_marker = content_tag(:span, "".html_safe, class: 'glyphicon glyphicon-map-marker text-primary').html_safe

entry['location_link'] = link_to(map_marker + entry['location_name'], location_display_path(CGI.escape(entry['location_name'])), class: :location_display)
else
entry['location_link'] = entry['location_name']
end
entry['location_link'] = format_location_link( entry['location_name'] )

if location && location.library && (hours = location.library.hours.find_by_date(Date.today))
entry['hours'] = hours.to_opens_closes
Expand Down Expand Up @@ -399,13 +390,40 @@ def fetch_hathi_brief(id_type, id_value)
end
end

def format_temp_location_note(t)
# Here we're hard-coding a reliance on the exact text
# generated by voyager_api gem
what, shelved_in, where = t.match(/(.*)(Shelved in)(.*)/i).captures
label_text = "#{what.sub(/./, &:capitalize)}#{shelved_in.capitalize}:".html_safe
def format_temp_location_note(temp_location)
label_text = location = ''

# This is the old behavior of backend, being replaced soon with Hash, below.
if temp_location.is_a? String
# hard-coded reliance on exact text of voyager_api
what, shelved_in, location_name = temp_location.match(/(.*)(Shelved in)(.*)/i).captures
label_text = "#{what} shelved in:"
end

if temp_location.is_a? Hash
label_text = temp_location['itemLabel'] + " shelved in:"
location_name = temp_location['tempLocation']
end

label_text = label_text.strip.sub(/./, &:capitalize)
label = content_tag(:span, label_text, class: 'holdings_label')
return label + where
location = format_location_link( location_name )

return label + location
end


def format_location_link(location_name)
return '' unless location_name

location = Location.match_location_text(location_name)
return location_name unless location && location.category == 'physical'

map_marker = content_tag(:span, "".html_safe, class: 'glyphicon glyphicon-map-marker text-primary').html_safe
location_link = link_to(map_marker + location_name, location_display_path(CGI.escape(location.name)), class: :location_display, target: '_blank')

return location_link
end

end

3 changes: 3 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Location < ActiveRecord::Base
# library ? library.is_open?(check_at) : false
# end

# Given a string location, e.g., "Butler Mezzanine",
# query the Location table for a partial match (e.g., "Butler%"),
# return the Location object
def self.match_location_text(location = nil)
# move this out to the caller
# # location comes from URL, and so will be escaped (e.g., spaces will be '+')
Expand Down
4 changes: 2 additions & 2 deletions app/views/backend/holdings.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
.copy
-# If there are any temp locations for this item, print them out
- unless copy['temp_locations'].nil?
- copy['temp_locations'].each do |t|
.message= format_temp_location_note(t)
- copy['temp_locations'].each do |temp_location|
.temp_location= format_temp_location_note(temp_location)
-# If there are any special notes, print them out
- ['orders', 'summary_holdings', 'supplements', 'indexes', 'notes',
'reproduction_note', 'current_issues'].each do |type|
Expand Down
44 changes: 22 additions & 22 deletions spec/features/library_hours_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@

describe 'Item Locations should show correct library hours', :vcr, :skip_travis do

before(:all) do
Location.clear_and_load_fixtures!

Rake.application.rake_require 'tasks/solr_ingest'
Rake.application.rake_require 'tasks/sync_hours'
Rake::Task.define_task(:environment)
Rake.application.invoke_task 'hours:sync'

Location.clear_and_load_fixtures!

end

# I'm not sure... do I ever have to re-run the Rake tasks as part of the rspec?
# before :all do
# before(:all) do
# Location.clear_and_load_fixtures!
# Rake.application.rake_require "tasks/solr_ingest"
# Rake.application.rake_require "tasks/sync_hours"
#
# Rake.application.rake_require 'tasks/solr_ingest'
# Rake.application.rake_require 'tasks/sync_hours'
# Rake::Task.define_task(:environment)
# Rake.application.invoke_task "hours:sync"
# Rake.application.invoke_task 'hours:sync'
#
# Location.clear_and_load_fixtures!
# end

it 'for Avery Drawings & Archives', :js do
target = 'Avery Drawings & Archives - By appt. (Non-Circulating)'

visit catalog_path('8277276')
# page.save_and_open_page # debug
expect(find('.holdings-container')).to have_text('Avery Drawings & Archives')
click_link('Avery Drawings & Archives - By appt. (Non-Circulating)')
expect(find('.holdings-container')).to have_text(target)

# click_link('Avery Drawings & Archives - By appt. (Non-Circulating)')

# Can't use click_link(), because location pages open in new window
location_page_url = find('a', text: target)[:href]
visit location_page_url

# page.save_and_open_page # debug
expect(page).to have_text('Avery Drawings & Archives')
expect(page).to have_link('Full Hours Info', href: 'http://www.columbia.edu/cu/lweb/services/hours/index.html?library=avery-drawings-archives')
end

it 'for Avery Classics', :js do
target = 'Avery Classics'
# Pull up the item-detail page, follow link to Location page...
visit catalog_path('565036')
expect(find('.holdings-container')).to have_text('Avery Classics')
within('.location_box .location', text: 'Avery Classics') do
click_link('Avery Classics')
expect(find('.holdings-container')).to have_text(target)
within('.location_box .location', text: target) do
# Can't use click_link(), because location pages open in new window
location_page_url = find('a', text: target)[:href]
visit location_page_url
end

# Check out the Location page...
Expand Down
48 changes: 37 additions & 11 deletions vcr/cassettes/record_tests/special_collections_services.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa501ea

Please sign in to comment.