Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from pulibrary/callno-param
Browse files Browse the repository at this point in the history
Allow locator to accept call number parameter, rails 5.1
  • Loading branch information
escowles committed Nov 22, 2017
2 parents 08c3be4 + cc8f79d commit 38f9484
Show file tree
Hide file tree
Showing 39 changed files with 235 additions and 221 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby
rvm:
- 2.1.5
- 2.2.0
- 2.3.5

script: bundle exec rake ci

Expand All @@ -17,4 +16,4 @@ notifications:
on_success: "change"
on_failure: "always"
template:
- "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
- "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
2 changes: 1 addition & 1 deletion app/assets/javascripts/locations/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require bootstrap-sprockets
//= require jquery-tablesorter
//= require jquery-tablesorter/widgets/widget-editable
Expand Down
18 changes: 8 additions & 10 deletions app/controllers/locations/map_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ module Locations
class MapController < ApplicationController

def index
@map = Map.new(id: map_params[:id],loc: map_params[:loc])

if @map.valid?
unless @map.on_reserve?
redirect_to @map.url
end
else
render plain: "Invalid parameters.", status: 400
@map = Map.new(id: map_params[:id],loc: map_params[:loc], callno: map_params[:callno])
if @map.valid?
unless @map.on_reserve?
redirect_to @map.url
end

else
render plain: "Invalid parameters.", status: 400
end
end

# Only allow a trusted parameter "white list" through.
def map_params
params.permit(:id, :loc)
params.permit(:id, :loc, :callno)
end

end
Expand Down
2 changes: 1 addition & 1 deletion app/models/locations/delivery_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DeliveryLocation < ActiveRecord::Base
include Locations::Labeled
include Locations::WithLibrary

has_and_belongs_to_many :holding_locations, -> { uniq },
has_and_belongs_to_many :holding_locations, -> { distinct },
class_name: 'Locations::HoldingLocation',
join_table: 'locations_holdings_delivery',
foreign_key: 'locations_holding_location_id',
Expand Down
6 changes: 3 additions & 3 deletions app/models/locations/holding_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class HoldingLocation < ActiveRecord::Base
include Locations::Coded
include Locations::WithLibrary

belongs_to :hours_location, class_name: 'Locations::HoursLocation', foreign_key: :locations_hours_location_id
belongs_to :holding_library, class_name: 'Locations::Library', foreign_key: :holding_library_id
belongs_to :hours_location, class_name: 'Locations::HoursLocation', foreign_key: :locations_hours_location_id, optional: true
belongs_to :holding_library, class_name: 'Locations::Library', foreign_key: :holding_library_id, optional: true

has_and_belongs_to_many :delivery_locations, -> { uniq },
has_and_belongs_to_many :delivery_locations, -> { distinct },
class_name: 'Locations::DeliveryLocation',
join_table: 'locations_holdings_delivery',
foreign_key: 'locations_delivery_location_id',
Expand Down
36 changes: 20 additions & 16 deletions app/models/locations/map.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
module Locations
class Map
attr_reader :id, :loc
attr_reader :id, :loc, :cn

def initialize(id: nil, loc: nil)
def initialize(id: nil, loc: nil, callno: nil)
@id = id
@loc = loc
@cn = callno
end

def url
return locator_url if locator_url
return stackmap_url if stackmap_url
"https://pulsearch.princeton.edu/requests/#{id}"
if locator_libs.include? lib.code
locator_url
elsif stackmap_libs.include? lib.code
stackmap_url
else
"https://pulsearch.princeton.edu/requests/#{id}"
end
end

def locator_url
return false unless locator_libs.include? lib.code
"http://library.princeton.edu/locator/index.php?loc=#{loc}&id=#{id}"
"https://library.princeton.edu/locator/index.php?loc=#{loc}&id=#{id}"
end

def stackmap_url
return false unless stackmap_libs.include? lib.code
stackmap_url = 'http://princeton.stackmap.com'
stackmap_url = 'https://princeton.stackmap.com'
URI.encode("#{stackmap_url}/view/?callno=#{callno}&location=#{loc}&library=#{lib.label}")
end

def callno
return bibrec['title_sort'].first if by_title_locations.include? loc
bibrec['call_number_browse_s'].first
if by_title_locations.include? loc
bibrec['title_sort'].first
else
cn || bibrec['call_number_browse_s'].first
end
end

# Need to include all non-stackmap libraries here to support the Main Catalog
# that displays the locator link on EVERY record.
# that displays the locator link on EVERY record.
def locator_libs
%w(firestone hrc annexa annexb mudd online rare recap)
end
Expand Down Expand Up @@ -64,13 +70,11 @@ def hours_location
end

def valid?
return true if !holding_location.nil? && !bibrec.nil?
false
!holding_location.nil?
end

def on_reserve?
return true if closed_stack_reserves.include? loc
false
closed_stack_reserves.include? loc
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateLocationsDeliveryLocations < ActiveRecord::Migration
class CreateLocationsDeliveryLocations < ActiveRecord::Migration[4.2]
def change
create_table :locations_delivery_locations do |t|
t.string :label
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20150520130710_create_locations_libraries.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateLocationsLibraries < ActiveRecord::Migration
class CreateLocationsLibraries < ActiveRecord::Migration[4.2]
def change
create_table :locations_libraries do |t|
t.string :label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLocationsLibraryToLocationsDeliveryLocation < ActiveRecord::Migration
class AddLocationsLibraryToLocationsDeliveryLocation < ActiveRecord::Migration[4.2]
def change
add_reference :locations_delivery_locations, :locations_library, index: true, foreign_key: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateLocationsHoldingLocations < ActiveRecord::Migration
class CreateLocationsHoldingLocations < ActiveRecord::Migration[4.2]
def change
create_table :locations_holding_locations do |t|
t.string :label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLocationsLibraryToLocationsHoldingLocation < ActiveRecord::Migration
class AddLocationsLibraryToLocationsHoldingLocation < ActiveRecord::Migration[4.2]
def change
add_reference :locations_holding_locations, :locations_library, index: true, foreign_key: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLocationsHoldingsDeliveryJoin < ActiveRecord::Migration
class AddLocationsHoldingsDeliveryJoin < ActiveRecord::Migration[4.2]
def change
create_table :locations_holdings_delivery, id: false do |t|
t.integer :locations_delivery_location_id, index: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddAdditionalFieldsToHoldingLocation < ActiveRecord::Migration
class AddAdditionalFieldsToHoldingLocation < ActiveRecord::Migration[4.2]
def change
add_column :locations_holding_locations, :aeon_location, :boolean, default: false
add_column :locations_holding_locations, :recap_electronic_delivery_location, :boolean, default: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddPickupAttrToDeliveryLocation < ActiveRecord::Migration
class AddPickupAttrToDeliveryLocation < ActiveRecord::Migration[4.2]
def change
add_column :locations_delivery_locations, :gfa_pickup, :string
add_column :locations_delivery_locations, :pickup_location, :boolean, default: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateLocationsHoursLocations < ActiveRecord::Migration
class CreateLocationsHoursLocations < ActiveRecord::Migration[4.2]
def change
create_table :locations_hours_locations do |t|
t.string :code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddHoursLocToLocationsHoldingLocations < ActiveRecord::Migration
class AddHoursLocToLocationsHoldingLocations < ActiveRecord::Migration[4.2]
def change
add_reference :locations_holding_locations, :locations_hours_location, foreign_key: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddDigitalLocationToDeliveryLocation < ActiveRecord::Migration
class AddDigitalLocationToDeliveryLocation < ActiveRecord::Migration[4.2]
def change
add_column :locations_delivery_locations, :digital_location, :boolean
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160127155209_set_digital_location.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SetDigitalLocation < ActiveRecord::Migration
class SetDigitalLocation < ActiveRecord::Migration[4.2]
def change
Locations::DeliveryLocation.update_all("digital_location=pickup_location")
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddCirculatesToLocationsHoldingLocations < ActiveRecord::Migration
class AddCirculatesToLocationsHoldingLocations < ActiveRecord::Migration[4.2]
def change
add_column :locations_holding_locations, :circulates, :boolean, default: true
reversible do |direction|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddHoldingLibraryToLocationsHoldingLibrary < ActiveRecord::Migration
class AddHoldingLibraryToLocationsHoldingLibrary < ActiveRecord::Migration[4.2]
def change
add_column :locations_holding_locations, :holding_library_id, :integer, index: true
add_foreign_key :locations_holding_locations, :locations_libraries, column: :holding_library_id
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160610203622_create_locations_floors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateLocationsFloors < ActiveRecord::Migration
class CreateLocationsFloors < ActiveRecord::Migration[4.2]
def change
create_table :locations_floors do |t|
t.string :label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLocationsLibraryToLocationsFloors < ActiveRecord::Migration
class AddLocationsLibraryToLocationsFloors < ActiveRecord::Migration[4.2]
def change
add_reference :locations_floors, :locations_library, index: true, foreign_key: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddOrderToLocationsLibraries < ActiveRecord::Migration
class AddOrderToLocationsLibraries < ActiveRecord::Migration[4.2]
def change
add_column :locations_libraries, :order, :integer, default: 0
end
Expand Down
7 changes: 6 additions & 1 deletion lib/generators/locations/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class InstallGenerator < Rails::Generators::Base

def add_gems
gem 'bootstrap-sass'
gem 'yaml_db', '~> 0.3.0'
gem 'yaml_db', '~> 0.6'
gem 'jquery-rails'
Bundler.with_clean_env do
run "bundle install"
end
Expand All @@ -15,6 +16,10 @@ def add_gems
def friendly_id
gem 'friendly_id', '~> 5.1.0'
generate 'friendly_id'
migration_file = Dir['db/migrate/*_create_friendly_id_slugs.rb'].first
inject_into_file migration_file, after: 'ActiveRecord::Migration' do
'[4.2]'
end
gsub_file 'config/initializers/friendly_id.rb', 'new edit', 'create edit'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/locations/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Locations
VERSION = "0.5.0"
VERSION = "1.0.0"
end
9 changes: 5 additions & 4 deletions locations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ Gem::Specification.new do |s|

s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']

s.add_dependency 'rails', '~> 4.2'
s.add_dependency 'rails', '~> 5.1'
s.add_dependency 'bootstrap-sass', '~> 3.3'
s.add_dependency 'friendly_id', '~> 5.1.0'
s.add_dependency 'yaml_db', '~> 0.3.0'
s.add_dependency 'yaml_db', '~> 0.6'
s.add_dependency 'jquery-tablesorter', '~> 1.21'
s.add_dependency 'rmagick'
s.add_dependency 'carrierwave'

s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec-rails', '~> 3.1'
s.add_development_dependency 'engine_cart', '~> 1.0'
s.add_development_dependency 'engine_cart', '~> 1.2'
s.add_development_dependency 'factory_girl_rails', '~> 4.5.0'
s.add_development_dependency 'faker', '~> 1.4.3'
s.add_development_dependency 'database_cleaner', '~> 1.3'
s.add_development_dependency 'capybara', '~> 2.4.4'
s.add_development_dependency 'capybara', '~> 2.13'
s.add_development_dependency 'poltergeist'
s.add_development_dependency 'coveralls'
s.add_development_dependency 'webmock'
s.add_development_dependency 'rails-controller-testing'
end
Loading

0 comments on commit 38f9484

Please sign in to comment.