Skip to content

Commit

Permalink
update engine for Blacklight 6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenenglish committed Jun 9, 2016
1 parent ddbfe0a commit 7f70627
Show file tree
Hide file tree
Showing 24 changed files with 143 additions and 116 deletions.
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ notifications:
language: ruby
sudo: false
rvm:
- 2.2.3
- 2.3.0

matrix:
include:
- rvm: 2.2.2
env: "RAILS_VERSION=4.1.13"
- rvm: 2.1.6
env: "RAILS_VERSION=4.2.4"
allow_failures:
- rvm: jruby
env: "RAILS_VERSION=4.2.4 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
- rvm: 1.9.3
- rvm: 2.2.4
env: "RAILS_VERSION=4.1.14"

before_install:
- gem install bundler

env:
- "RAILS_VERSION=4.2.4"
- "RAILS_VERSION=4.2.6"

notifications:
irc: "irc.freenode.org#blacklight"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ The table below indicates which versions of Blacklight Maps are compatible with
Blacklight Maps version | works with Blacklight version
----------------------- | ---------------------
>= 0.4.0 | >= 5.12.0 to < 6.*
0.5.0 | >= 6.1.0
0.4.0 | >= 5.12.0 to < 6.*
<= 0.3.3 | >= 5.1 to <= 5.11.2
## Contributing
Expand Down
12 changes: 6 additions & 6 deletions app/helpers/blacklight/blacklight_maps_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def placename_value(geojson_hash)
def link_to_bbox_search bbox_coordinates
coords_for_search = bbox_coordinates.map { |v| v.to_s }
link_to(t('blacklight.maps.interactions.bbox_search'),
catalog_index_path(spatial_search_type: "bbox",
search_catalog_path(spatial_search_type: "bbox",
coordinates: "[#{coords_for_search[1]},#{coords_for_search[0]} TO #{coords_for_search[3]},#{coords_for_search[2]}]",
view: default_document_index_view_type))
end
Expand All @@ -36,11 +36,11 @@ def link_to_placename_field field_value, field, displayvalue = nil
if params[:f] && params[:f][field] && params[:f][field].include?(field_value)
new_params = params
else
new_params = add_facet_params(field, field_value)
new_params = search_state.add_facet_params(field, field_value)
end
new_params[:view] = default_document_index_view_type
link_to(displayvalue.presence || field_value,
catalog_index_path(new_params.except(:id, :spatial_search_type, :coordinates)))
search_catalog_path(new_params.except(:id, :spatial_search_type, :coordinates)))
end

# create a link to a spatial search for a set of point coordinates
Expand All @@ -49,7 +49,7 @@ def link_to_point_search point_coordinates
new_params[:spatial_search_type] = "point"
new_params[:coordinates] = "#{point_coordinates[1]},#{point_coordinates[0]}"
new_params[:view] = default_document_index_view_type
link_to(t('blacklight.maps.interactions.point_search'), catalog_index_path(new_params))
link_to(t('blacklight.maps.interactions.point_search'), search_catalog_path(new_params))
end

# return the facet field containing geographic data
Expand All @@ -76,8 +76,8 @@ def render_placename_heading(geojson_hash)
end

# render the map for #index and #map views
def render_index_map
render :partial => 'catalog/index_map',
def render_index_mapview
render :partial => 'catalog/index_mapview',
:locals => {:geojson_features => serialize_geojson(map_facet_values)}
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_document_maps.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% # container for all documents in map view -%>
<div id="documents" class="map">
<%= render_index_map %>
<%= render_index_mapview %>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= blacklight_map_tag('blacklight-index-map',
{data:{searchcontrol: true,
catalogpath: catalog_index_path,
catalogpath: search_catalog_path,
placenamefield: blacklight_config.view.maps.placename_field,
clustercount:'hits',
searchresultsview: default_document_index_view_type
Expand Down
2 changes: 1 addition & 1 deletion blacklight-maps.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "rails"
spec.add_dependency "blacklight", ">= 5.12.0"
spec.add_dependency "blacklight", ">= 6.1.0"
spec.add_dependency "bootstrap-sass", "~> 3.2"
spec.add_dependency "leaflet-rails"
spec.add_dependency "leaflet-markercluster-rails"
Expand Down
2 changes: 1 addition & 1 deletion config/jetty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ development:
jetty_port: 8983
test:
startup_wait: 60
jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
<%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
13 changes: 0 additions & 13 deletions lib/blacklight/maps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,5 @@ module Maps
require 'blacklight/maps/geometry'
require 'blacklight/maps/maps_search_builder'

def self.inject!
CatalogController.send(:include, BlacklightMaps::ControllerOverride)
CatalogController.send(:include, BlacklightMaps::RenderConstraintsOverride)
CatalogController.send(:helper, BlacklightMaps::RenderConstraintsOverride) unless
CatalogController.helpers.is_a?(BlacklightMaps::RenderConstraintsOverride)

# inject into SearchHistory and SavedSearches so spatial queries display properly
SearchHistoryController.send(:helper, BlacklightMaps::RenderConstraintsOverride) unless
SearchHistoryController.helpers.is_a?(BlacklightMaps::RenderConstraintsOverride)
SavedSearchesController.send(:helper, BlacklightMaps::RenderConstraintsOverride) unless
SavedSearchesController.helpers.is_a?(BlacklightMaps::RenderConstraintsOverride)
end

end
end
19 changes: 4 additions & 15 deletions lib/blacklight/maps/controller_override.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
module BlacklightMaps
module ControllerOverride
extend ActiveSupport::Concern
included do

if self.respond_to? :search_params_logic
search_params_logic << :add_spatial_search_to_solr
end

if self.blacklight_config.search_builder_class
self.blacklight_config.search_builder_class.send(:include,
BlacklightMaps::MapsSearchBuilder
) unless
self.blacklight_config.search_builder_class.include?(
BlacklightMaps::MapsSearchBuilder
)
end

included do
self.send(:include, BlacklightMaps::RenderConstraintsOverride)
self.send(:helper, BlacklightMaps::RenderConstraintsOverride)
end

def map
(@response, @document_list) = search_results(params, search_params_logic)
(@response, @document_list) = search_results(params)
params[:view] = 'maps'
respond_to do |format|
format.html
Expand Down
31 changes: 15 additions & 16 deletions lib/blacklight/maps/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
module Blacklight
module Maps
class Engine < Rails::Engine

# Set some default configurations
Blacklight::Configuration.default_values[:view].maps.geojson_field = "geojson"
Blacklight::Configuration.default_values[:view].maps.placename_property = "placename"
Blacklight::Configuration.default_values[:view].maps.coordinates_field = "coordinates"
Blacklight::Configuration.default_values[:view].maps.search_mode = "placename" # or 'coordinates'
Blacklight::Configuration.default_values[:view].maps.spatial_query_dist = 0.5
Blacklight::Configuration.default_values[:view].maps.placename_field = "placename_field"
Blacklight::Configuration.default_values[:view].maps.coordinates_facet_field = "coordinates_facet_field"
Blacklight::Configuration.default_values[:view].maps.facet_mode = "geojson" # or 'coordinates'
Blacklight::Configuration.default_values[:view].maps.tileurl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
Blacklight::Configuration.default_values[:view].maps.mapattribution = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
Blacklight::Configuration.default_values[:view].maps.maxzoom = 18
Blacklight::Configuration.default_values[:view].maps.show_initial_zoom = 5
initializer 'blacklight-maps.default_config' do |app|
Blacklight::Configuration.default_values[:view].maps.geojson_field = "geojson"
Blacklight::Configuration.default_values[:view].maps.placename_property = "placename"
Blacklight::Configuration.default_values[:view].maps.coordinates_field = "coordinates"
Blacklight::Configuration.default_values[:view].maps.search_mode = "placename" # or 'coordinates'
Blacklight::Configuration.default_values[:view].maps.spatial_query_dist = 0.5
Blacklight::Configuration.default_values[:view].maps.placename_field = "placename_field"
Blacklight::Configuration.default_values[:view].maps.coordinates_facet_field = "coordinates_facet_field"
Blacklight::Configuration.default_values[:view].maps.facet_mode = "geojson" # or 'coordinates'
Blacklight::Configuration.default_values[:view].maps.tileurl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
Blacklight::Configuration.default_values[:view].maps.mapattribution = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
Blacklight::Configuration.default_values[:view].maps.maxzoom = 18
Blacklight::Configuration.default_values[:view].maps.show_initial_zoom = 5
end

# Add our helpers
initializer 'blacklight-maps.helpers' do |app|
ActionView::Base.send :include, BlacklightMapsHelper
end

config.to_prepare do
Blacklight::Maps.inject!
end

# This makes our rake tasks visible.
rake_tasks do
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))) do
Expand Down
7 changes: 6 additions & 1 deletion lib/blacklight/maps/maps_search_builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module BlacklightMaps
module MapsSearchBuilder
module MapsSearchBuilderBehavior
extend ActiveSupport::Concern

included do
self.default_processor_chain += [:add_spatial_search_to_solr]
end

# add spatial search params to solr
def add_spatial_search_to_solr(solr_parameters = {})
Expand Down
7 changes: 3 additions & 4 deletions lib/blacklight/maps/render_constraints_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ def render_search_to_s_coord(params)
# Render the spatial query constraints
def render_spatial_query(localized_params = params)
# So simple don't need a view template, we can just do it here.
scope = localized_params.delete(:route_set) || self
return ''.html_safe if localized_params[:coordinates].blank?

render_constraint_element(spatial_constraint_label(localized_params),
localized_params[:coordinates],
:classes => ['coordinates'],
:remove => scope.url_for(localized_params.merge(:coordinates=>nil,
:spatial_search_type=>nil,
:action=>'index')))
:remove => remove_constraint_url(localized_params.merge(:coordinates=>nil,
:spatial_search_type=>nil,
:action=>'index')))
end

def spatial_constraint_label(params)
Expand Down
36 changes: 36 additions & 0 deletions lib/generators/blacklight_maps/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,41 @@ def assets
end
end
end

def inject_search_builder
inject_into_file 'app/models/search_builder.rb', after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
"\n include BlacklightMaps::MapsSearchBuilderBehavior\n"
end
end

def install_catalog_controller_mixin
inject_into_file "app/controllers/catalog_controller.rb", after: /include Blacklight::Catalog.*$/ do
"\n include BlacklightMaps::ControllerOverride\n"
end
end

def install_search_history_controller
target_file = "app/controllers/search_history_controller.rb"
if File.exists?(target_file)
inject_into_file target_file, after: /include Blacklight::SearchHistory/ do
"\n helper BlacklightMaps::RenderConstraintsOverride\n"
end
else
copy_file "search_history_controller.rb", target_file
end
end

def install_saved_searches_controller
target_file = "app/controllers/saved_searches_controller.rb"
if File.exists?(target_file)
inject_into_file target_file, after: /include Blacklight::SavedSearches/ do
"\n helper BlacklightMaps::RenderConstraintsOverride\n"
end
else
copy_file "saved_searches_controller.rb", target_file
end
end


end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SavedSearchesController < ApplicationController
include Blacklight::SavedSearches

helper BlacklightMaps::RenderConstraintsOverride
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SearchHistoryController < ApplicationController
include Blacklight::SearchHistory

helper BlacklightMaps::RenderConstraintsOverride
end
5 changes: 3 additions & 2 deletions lib/railties/blacklight_maps.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace :blacklight_maps do
desc "Put sample data into solr"
task :seed => :environment do
docs = YAML::load(File.open(File.expand_path(File.join('..', '..', '..', 'spec', 'fixtures', 'sample_solr_documents.yml'), __FILE__)))
Blacklight.solr.add docs
Blacklight.solr.commit
conn = Blacklight.default_index.connection
conn.add docs
conn.commit
end
end
end
4 changes: 2 additions & 2 deletions spec/features/initial_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
end
end
scenario 'defaults to zoom area of markers' do
visit catalog_index_path f: { format: ['Book'] }, view: 'maps'
visit search_catalog_path f: { format: ['Book'] }, view: 'maps'
expect(page).to have_css '.leaflet-marker-icon.marker-cluster', count: 8
end
scenario 'when provided sets map to its view' do
map_tag = '<div id="blacklight-index-map" data-initialview="[[37.65, -122.56],[37.89, -122.27]]" data-maxzoom="18" data-tileurl="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" data-mapattribution="Map data &amp;copy; &lt;a href=&quot;http://openstreetmap.org&quot;&gt;OpenStreetMap&lt;/a&gt; contributors, &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/&quot;&gt;CC-BY-SA&lt;/a&gt;" data-searchcontrol="true" data-catalogpath="/catalog" data-placenamefield="placename_field" data-clustercount="hits" />'.html_safe
expect_any_instance_of(Blacklight::BlacklightMapsHelperBehavior).to receive(:blacklight_map_tag).and_return(map_tag)
visit catalog_index_path f: { format: ['Book'] }, view: 'maps'
visit search_catalog_path f: { format: ['Book'] }, view: 'maps'
expect(page).to_not have_css '.leaflet-marker-icon.marker-cluster'
end
end
4 changes: 2 additions & 2 deletions spec/features/maps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
config.add_facet_field 'geojson', :limit => -2, :label => 'GeoJSON', :show => false
config.add_facet_fields_to_solr_request!
end
visit catalog_index_path :q => 'korea', :view => 'maps'
visit search_catalog_path :q => 'korea', :view => 'maps'
end

it "should display map elements" do
Expand Down Expand Up @@ -158,7 +158,7 @@
config.add_facet_fields_to_solr_request!
end
visit map_path
#print page.html # debugging
# print page.html # debugging
end

it "should display map elements" do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/show_view_maplet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
describe "item with point feature" do

before :each do
visit catalog_path("00314247")
visit solr_document_path("00314247")
end

it "should display the maplet" do
Expand All @@ -40,7 +40,7 @@
describe "item with point and bbox features" do

before :each do
visit catalog_path("2008308175")
visit solr_document_path("2008308175")
end

it "should show the correct mapped item count" do
Expand Down Expand Up @@ -75,7 +75,7 @@
# set maxzoom so we can test whether initial zoom is correct
config.view.maps.maxzoom = 8
end
visit catalog_path("2009373514")
visit solr_document_path("2009373514")
end

it "should display a bounding box" do
Expand Down

0 comments on commit 7f70627

Please sign in to comment.