blacklight-maps 0.5.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +33 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +103 -0
  5. data/.solr_wrapper.yml +8 -0
  6. data/Gemfile +38 -8
  7. data/README.md +15 -13
  8. data/Rakefile +35 -32
  9. data/app/assets/images/blacklight/maps.svg +1 -0
  10. data/app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js +7 -8
  11. data/app/assets/javascripts/blacklight-maps.js +1 -4
  12. data/app/assets/stylesheets/blacklight_maps/blacklight-maps.scss +1 -2
  13. data/app/assets/stylesheets/blacklight_maps/default.scss +7 -10
  14. data/app/helpers/blacklight/blacklight_maps_helper_behavior.rb +81 -86
  15. data/app/helpers/blacklight_maps_helper.rb +2 -0
  16. data/app/views/catalog/_show_maplet_default.html.erb +8 -9
  17. data/app/views/catalog/map.html.erb +2 -2
  18. data/blacklight-maps.gemspec +27 -26
  19. data/config/locales/blacklight-maps-zh.yml +7 -7
  20. data/config/locales/blacklight-maps.ar.yml +21 -0
  21. data/config/locales/blacklight-maps.de.yml +21 -0
  22. data/config/locales/blacklight-maps.en.yml +1 -1
  23. data/config/locales/blacklight-maps.es.yml +21 -0
  24. data/config/locales/blacklight-maps.fr.yml +8 -8
  25. data/config/locales/blacklight-maps.hu.yml +21 -0
  26. data/config/locales/blacklight-maps.it.yml +8 -8
  27. data/config/locales/blacklight-maps.nl.yml +21 -0
  28. data/config/locales/blacklight-maps.pt-BR.yml +21 -0
  29. data/config/locales/blacklight-maps.sq.yml +21 -0
  30. data/config/routes.rb +3 -2
  31. data/lib/blacklight/maps/controller.rb +27 -0
  32. data/lib/blacklight/maps/engine.rb +15 -14
  33. data/lib/blacklight/maps/export.rb +114 -93
  34. data/lib/blacklight/maps/geometry.rb +30 -18
  35. data/lib/blacklight/maps/maps_search_builder.rb +4 -3
  36. data/lib/blacklight/maps/render_constraints_override.rb +63 -29
  37. data/lib/blacklight/maps/version.rb +3 -1
  38. data/lib/blacklight/maps.rb +8 -2
  39. data/lib/generators/blacklight_maps/install_generator.rb +38 -31
  40. data/lib/generators/blacklight_maps/templates/search_history_controller.rb +2 -0
  41. data/lib/railties/blacklight_maps.rake +10 -7
  42. data/spec/controllers/catalog_controller_spec.rb +20 -10
  43. data/spec/fixtures/sample_solr_documents.yml +909 -906
  44. data/spec/helpers/blacklight_maps_helper_spec.rb +60 -108
  45. data/spec/lib/blacklight/maps/export_spec.rb +109 -143
  46. data/spec/lib/blacklight/maps/geometry_spec.rb +34 -21
  47. data/spec/lib/blacklight/maps/maps_search_builder_spec.rb +17 -21
  48. data/spec/lib/blacklight/maps/render_constraints_override_spec.rb +42 -69
  49. data/spec/spec_helper.rb +18 -21
  50. data/spec/system/index_view_spec.rb +128 -0
  51. data/spec/system/initial_view_spec.rb +28 -0
  52. data/spec/system/map_view_spec.rb +50 -0
  53. data/spec/system/show_view_maplet_spec.rb +78 -0
  54. data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -21
  55. data/vendor/assets/images/layers-2x.png +0 -0
  56. data/vendor/assets/images/layers.png +0 -0
  57. data/vendor/assets/images/marker-icon-2x.png +0 -0
  58. data/vendor/assets/images/marker-icon.png +0 -0
  59. data/vendor/assets/images/marker-shadow.png +0 -0
  60. data/vendor/assets/javascripts/leaflet.js.erb +13922 -0
  61. data/vendor/assets/javascripts/leaflet.markercluster.js +3 -0
  62. data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  63. data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  64. data/vendor/assets/stylesheets/leaflet.css +635 -0
  65. metadata +85 -90
  66. data/.travis.yml +0 -25
  67. data/config/jetty.yml +0 -7
  68. data/lib/blacklight/maps/controller_override.rb +0 -20
  69. data/lib/generators/blacklight_maps/templates/saved_searches_controller.rb +0 -5
  70. data/spec/features/initial_view_spec.rb +0 -21
  71. data/spec/features/maps_spec.rb +0 -202
  72. data/spec/features/show_view_maplet_spec.rb +0 -93
  73. data/spec/test_app_templates/Gemfile.extra +0 -5
  74. /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/schema.xml +0 -0
  75. /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/solrconfig.xml +0 -0
@@ -1,5 +1,6 @@
1
- module BlacklightMaps
1
+ # frozen_string_literal: true
2
2
 
3
+ module BlacklightMaps
3
4
  # This class provides the ability to export a response document to GeoJSON.
4
5
  # The export is formated as a GeoJSON FeatureCollection, where the features
5
6
  # consist of an array of Point features. For more on the GeoJSON
@@ -8,146 +9,166 @@ module BlacklightMaps
8
9
  class GeojsonExport
9
10
  include BlacklightMaps
10
11
 
11
- # controller is a Blacklight CatalogController object passed by a helper
12
- # action is the controller action
13
- # response_docs is passed by a helper, and is either:
12
+ # @param controller [CatalogController]
13
+ # @param action [Symbol] the controller action
14
+ # @param response_docs [Array || SolrDocument] either:
14
15
  # - index view, map view: an array of facet values
15
16
  # - show view: the document object
16
- # options is an optional hash of possible configuration options
17
- def initialize(controller, action, response_docs, options={})
17
+ # @param options [Hash] optional hash of configuration options
18
+ def initialize(controller, action, response_docs, options = {})
18
19
  @controller = controller
19
20
  @action = action
20
21
  @response_docs = response_docs
21
22
  @options = options
23
+ @features = []
22
24
  end
23
25
 
24
- # build the GeoJSON FeatureCollection
26
+ # builds the GeoJSON FeatureCollection
25
27
  def to_geojson
26
- geojson_docs = { type: 'FeatureCollection',
27
- features: build_geojson_features }
28
- geojson_docs.to_json
28
+ { type: 'FeatureCollection', features: build_geojson_features }.to_json
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def blacklight_maps_config
33
+ def maps_config
34
34
  @controller.blacklight_config.view.maps
35
35
  end
36
36
 
37
37
  def geojson_field
38
- blacklight_maps_config.geojson_field
38
+ maps_config.geojson_field
39
39
  end
40
40
 
41
41
  def coordinates_field
42
- blacklight_maps_config.coordinates_field
42
+ maps_config.coordinates_field
43
43
  end
44
44
 
45
- def search_mode
46
- blacklight_maps_config.search_mode
45
+ def build_geojson_features
46
+ if @action == :index || @action == :map
47
+ build_index_features
48
+ elsif @action == :show
49
+ build_show_features
50
+ end
51
+ @features
47
52
  end
48
53
 
49
- def facet_mode
50
- blacklight_maps_config.facet_mode
54
+ # build GeoJSON features array for index and map views
55
+ def build_index_features
56
+ @response_docs.each do |geofacet|
57
+ @features << if maps_config.facet_mode == 'coordinates'
58
+ build_feature_from_coords(geofacet.value, geofacet.hits)
59
+ else
60
+ build_feature_from_geojson(geofacet.value, geofacet.hits)
61
+ end
62
+ end
51
63
  end
52
64
 
53
- def placename_property
54
- blacklight_maps_config.placename_property
65
+ # build GeoJSON features array for show view
66
+ def build_show_features
67
+ doc = @response_docs
68
+ return unless doc[geojson_field] || doc[coordinates_field]
69
+
70
+ if doc[geojson_field]
71
+ build_features_from_geojson(doc[geojson_field])
72
+ elsif doc[coordinates_field]
73
+ build_features_from_coords(doc[coordinates_field])
74
+ end
55
75
  end
56
76
 
57
- # build GeoJSON features array
58
- # determine how to build GeoJSON feature based on config and controller#action
59
- def build_geojson_features
60
- features = []
61
- case @action
62
- when "index", "map"
63
- @response_docs.each do |geofacet|
64
- if facet_mode == "coordinates"
65
- features.push(build_feature_from_coords(geofacet.value, geofacet.hits))
66
- else
67
- features.push(build_feature_from_geojson(geofacet.value, geofacet.hits))
68
- end
69
- end
70
- when "show"
71
- doc = @response_docs
72
- return unless doc[geojson_field] || doc[coordinates_field]
73
- if doc[geojson_field]
74
- doc[geojson_field].uniq.each do |loc|
75
- features.push(build_feature_from_geojson(loc))
76
- end
77
- elsif doc[coordinates_field]
78
- doc[coordinates_field].uniq.each do |coords|
79
- features.push(build_feature_from_coords(coords))
80
- end
81
- end
77
+ def build_features_from_geojson(geojson_field_values)
78
+ return unless geojson_field_values
79
+
80
+ geojson_field_values.uniq.each do |loc|
81
+ @features << build_feature_from_geojson(loc)
82
82
  end
83
- features
84
83
  end
85
84
 
86
- # build blacklight-maps GeoJSON feature from GeoJSON-formatted data
85
+ def build_features_from_coords(coordinates_field_values)
86
+ return unless coordinates_field_values
87
+
88
+ coordinates_field_values.uniq.each do |coords|
89
+ @features << build_feature_from_coords(coords)
90
+ end
91
+ end
92
+
93
+ # build GeoJSON feature from incoming GeoJSON data
87
94
  # turn bboxes into points for index view so we don't get weird mix of boxes and markers
95
+ # @param loc [Hash]
96
+ # @param hits [Integer]
97
+ # rubocop:disable Metrics/AbcSize
88
98
  def build_feature_from_geojson(loc, hits = nil)
89
- geojson_hash = JSON.parse(loc).deep_symbolize_keys
90
- if @action != "show" && geojson_hash[:bbox]
91
- geojson_hash[:geometry][:coordinates] = Geometry::Point.new(Geometry::BoundingBox.new(geojson_hash[:bbox]).find_center).normalize_for_search
92
- geojson_hash[:geometry][:type] = "Point"
93
- geojson_hash.delete(:bbox)
99
+ geojson = JSON.parse(loc).deep_symbolize_keys
100
+ if @action != :show && geojson[:bbox]
101
+ bbox = Geometry::BoundingBox.new(geojson[:bbox])
102
+ geojson[:geometry][:coordinates] = Geometry::Point.new(bbox.find_center).normalize_for_search
103
+ geojson[:geometry][:type] = 'Point'
104
+ geojson.delete(:bbox)
94
105
  end
95
- geojson_hash[:properties] ||= {}
96
- geojson_hash[:properties][:hits] = hits.to_i if hits
97
- geojson_hash[:properties][:popup] = render_leaflet_popup_content(geojson_hash, hits)
98
- geojson_hash
106
+ geojson[:properties] ||= {}
107
+ geojson[:properties][:hits] = hits.to_i if hits
108
+ geojson[:properties][:popup] = render_leaflet_popup_content(geojson, hits)
109
+ geojson
99
110
  end
111
+ # rubocop:enable Metrics/AbcSize
100
112
 
101
- # build blacklight-maps GeoJSON feature from coordinate data
113
+ # build GeoJSON feature from incoming raw coordinate data
102
114
  # turn bboxes into points for index view so we don't get weird mix of boxes and markers
115
+ # @param coords [String]
116
+ # @param hits [Integer]
103
117
  def build_feature_from_coords(coords, hits = nil)
104
- geojson_hash = {type: "Feature", geometry: {}, properties: {}}
105
- if coords.scan(/[\s]/).length == 3 # bbox
106
- if @action != "show"
107
- geojson_hash[:geometry][:type] = "Point"
108
- geojson_hash[:geometry][:coordinates] = Geometry::Point.new(Geometry::BoundingBox.from_lon_lat_string(coords).find_center).normalize_for_search
109
- else
110
- coords_array = coords.split(' ').map { |v| v.to_f }
111
- geojson_hash[:bbox] = coords_array
112
- geojson_hash[:geometry][:type] = "Polygon"
113
- geojson_hash[:geometry][:coordinates] = [[[coords_array[0],coords_array[1]],
114
- [coords_array[2],coords_array[1]],
115
- [coords_array[2],coords_array[3]],
116
- [coords_array[0],coords_array[3]],
117
- [coords_array[0],coords_array[1]]]]
118
- end
119
- elsif coords.match(/^[-]?[\d]*[\.]?[\d]*[ ,][-]?[\d]*[\.]?[\d]*$/) # point
120
- geojson_hash[:geometry][:type] = "Point"
121
- if coords.match(/,/)
122
- coords_array = coords.split(',').reverse
123
- else
124
- coords_array = coords.split(' ')
125
- end
126
- geojson_hash[:geometry][:coordinates] = coords_array.map { |v| v.to_f }
118
+ geojson = { type: 'Feature', properties: {} }
119
+ if coords =~ /ENVELOPE/ # bbox
120
+ geojson.merge!(build_bbox_feature_from_coords(coords))
121
+ elsif coords =~ /^-?\d*\.?\d*[ ,]-?\d*\.?\d*$/ # point
122
+ geojson[:geometry] = build_point_geometry(coords)
127
123
  else
128
124
  Rails.logger.error("This coordinate format is not yet supported: '#{coords}'")
129
125
  end
130
- geojson_hash[:properties] = { popup: render_leaflet_popup_content(geojson_hash, hits) } if geojson_hash[:geometry][:coordinates]
131
- geojson_hash[:properties][:hits] = hits.to_i if hits
132
- geojson_hash
126
+ geojson[:properties] = { popup: render_leaflet_popup_content(geojson, hits) } if geojson[:geometry][:coordinates]
127
+ geojson[:properties][:hits] = hits.to_i if hits
128
+ geojson
129
+ end
130
+
131
+ # @param coords [String]
132
+ def build_bbox_feature_from_coords(coords)
133
+ geojson = { geometry: {} }
134
+ bbox = Geometry::BoundingBox.from_wkt_envelope(coords)
135
+ if @action != :show
136
+ geojson[:geometry][:type] = 'Point'
137
+ geojson[:geometry][:coordinates] = Geometry::Point.new(bbox.find_center).normalize_for_search
138
+ else
139
+ coords_array = bbox.to_a
140
+ geojson[:bbox] = coords_array
141
+ geojson[:geometry][:type] = 'Polygon'
142
+ geojson[:geometry][:coordinates] = bbox.geojson_geometry_array
143
+ end
144
+ geojson
145
+ end
146
+
147
+ # @param coords [String]
148
+ def build_point_geometry(coords)
149
+ geometry = { type: 'Point' }
150
+ coords_array = coords =~ /,/ ? coords.split(',').reverse : coords.split(' ')
151
+ geometry[:coordinates] = coords_array.map(&:to_f)
152
+ geometry
133
153
  end
134
154
 
135
- # Render to string the partial for each individual doc.
155
+ # Render to string the partial for each individual feature.
136
156
  # For placename searching, render catalog/map_placename_search partial,
137
- # full geojson hash is passed to the partial for easier local customization
157
+ # pass the full geojson hash to the partial for easier local customization
138
158
  # For coordinate searches (or features with only coordinate data),
139
159
  # render catalog/map_coordinate_search partial
140
- def render_leaflet_popup_content(geojson_hash, hits=nil)
141
- if search_mode == 'placename' && geojson_hash[:properties][placename_property.to_sym]
142
- @controller.render_to_string partial: 'catalog/map_placename_search',
143
- locals: { geojson_hash: geojson_hash, hits: hits }
160
+ # @param geojson [Hash]
161
+ # @param hits [Integer]
162
+ def render_leaflet_popup_content(geojson, hits = nil)
163
+ if maps_config.search_mode == 'placename' &&
164
+ geojson[:properties][maps_config.placename_property.to_sym]
165
+ partial = 'catalog/map_placename_search'
166
+ locals = { geojson_hash: geojson, hits: hits }
144
167
  else
145
- @controller.render_to_string partial: 'catalog/map_spatial_search',
146
- locals: { coordinates: geojson_hash[:bbox].presence || geojson_hash[:geometry][:coordinates],
147
- hits: hits }
168
+ partial = 'catalog/map_spatial_search'
169
+ locals = { coordinates: geojson[:bbox].presence || geojson[:geometry][:coordinates], hits: hits }
148
170
  end
171
+ @controller.render_to_string(partial: partial, locals: locals)
149
172
  end
150
-
151
173
  end
152
-
153
174
  end
@@ -1,15 +1,14 @@
1
- module BlacklightMaps
1
+ # frozen_string_literal: true
2
2
 
3
+ module BlacklightMaps
3
4
  # Parent class of geospatial objects used in BlacklightMaps
4
5
  class Geometry
5
-
6
6
  # This class contains Bounding Box objects and methods for interacting with
7
7
  # them.
8
8
  class BoundingBox
9
-
10
9
  # points is an array containing longitude and latitude values which
11
10
  # relate to the southwest and northeast points of a bounding box
12
- # [west, south, east, north] ([swlng, swlat, nelng, nelat]).
11
+ # [west, south, east, north] ([minX, minY, maxX, maxY]).
13
12
  def initialize(points)
14
13
  @west = points[0].to_f
15
14
  @south = points[1].to_f
@@ -17,15 +16,24 @@ module BlacklightMaps
17
16
  @north = points[3].to_f
18
17
  end
19
18
 
19
+ def geojson_geometry_array
20
+ [
21
+ [
22
+ [@west, @south],
23
+ [@east, @south],
24
+ [@east, @north],
25
+ [@west, @north],
26
+ [@west, @south]
27
+ ]
28
+ ]
29
+ end
30
+
20
31
  # Returns an array [lng, lat] which is the centerpoint of a BoundingBox.
21
32
  def find_center
22
33
  center = []
23
34
  center[0] = (@west + @east) / 2
24
35
  center[1] = (@south + @north) / 2
25
-
26
- # Handle bounding boxes that cross the dateline
27
- center[0] -= 180 if @west > @east
28
-
36
+ center[0] -= 180 if @west > @east # handle bboxes that cross the dateline
29
37
  center
30
38
  end
31
39
 
@@ -34,11 +42,21 @@ module BlacklightMaps
34
42
  def self.from_lon_lat_string(points)
35
43
  new(points.split(' '))
36
44
  end
45
+
46
+ # Creates a new bounding box from from a Solr WKT Envelope string
47
+ # "ENVELOPE(34.26, 35.89, 33.33, 29.47)" (minX, maxX, maxY, minY)
48
+ def self.from_wkt_envelope(envelope)
49
+ coords = envelope.gsub(/[[A-Z]()]/, '')&.split(', ')
50
+ new([coords[0], coords[3], coords[1], coords[2]])
51
+ end
52
+
53
+ def to_a
54
+ [@west, @south, @east, @north]
55
+ end
37
56
  end
38
57
 
39
58
  # This class contains Point objects and methods for working with them
40
59
  class Point
41
-
42
60
  # points is an array corresponding to the longitude and latitude values
43
61
  # [long, lat]
44
62
  def initialize(points)
@@ -49,13 +67,9 @@ module BlacklightMaps
49
67
  # returns a string that can be used as the value of solr_parameters[:pt]
50
68
  # normalizes any long values >180 or <-180
51
69
  def normalize_for_search
52
- case
53
- when @long > 180
54
- @long -= 360
55
- when @long < -180
56
- @long += 360
57
- end
58
- [@long,@lat]
70
+ @long -= 360 if @long > 180
71
+ @long += 360 if @long < -180
72
+ [@long, @lat]
59
73
  end
60
74
 
61
75
  # Creates a new point from from a coordinate string
@@ -63,8 +77,6 @@ module BlacklightMaps
63
77
  def self.from_lat_lon_string(points)
64
78
  new(points.split(',').reverse)
65
79
  end
66
-
67
80
  end
68
-
69
81
  end
70
82
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BlacklightMaps
2
4
  module MapsSearchBuilderBehavior
3
5
  extend ActiveSupport::Concern
@@ -11,7 +13,7 @@ module BlacklightMaps
11
13
  if blacklight_params[:spatial_search_type] && blacklight_params[:coordinates]
12
14
  solr_parameters[:fq] ||= []
13
15
  if blacklight_params[:spatial_search_type] == 'bbox'
14
- solr_parameters[:fq] << blacklight_config.view.maps.coordinates_field + ":" + blacklight_params[:coordinates]
16
+ solr_parameters[:fq] << "#{blacklight_config.view.maps.coordinates_field}:#{blacklight_params[:coordinates]}"
15
17
  else
16
18
  solr_parameters[:fq] << "{!geofilt sfield=#{blacklight_config.view.maps.coordinates_field}}"
17
19
  solr_parameters[:pt] = blacklight_params[:coordinates]
@@ -20,6 +22,5 @@ module BlacklightMaps
20
22
  end
21
23
  solr_parameters
22
24
  end
23
-
24
25
  end
25
- end
26
+ end
@@ -1,61 +1,95 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Meant to be applied on top of Blacklight view helpers, to over-ride
2
4
  # certain methods from RenderConstraintsHelper (newish in BL),
3
5
  # to affect constraints rendering
4
6
  module BlacklightMaps
5
-
6
7
  module RenderConstraintsOverride
7
-
8
- # BlacklightMaps override: update to look for spatial query params
9
- def has_search_parameters?
10
- has_spatial_parameters? || super
11
- end
12
-
13
- def has_spatial_parameters?
14
- !params[:coordinates].blank?
8
+ # @param search_state [Blacklight::SearchState]
9
+ # @return [Boolean]
10
+ def has_spatial_parameters?(search_state)
11
+ search_state.params[:coordinates].present?
15
12
  end
16
13
 
17
14
  # BlacklightMaps override: check for coordinate parameters
18
- def query_has_constraints?(localized_params = params)
19
- has_search_parameters? || super
15
+ # @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
16
+ # @return [Boolean]
17
+ def query_has_constraints?(params_or_search_state = search_state)
18
+ search_state = convert_to_search_state(params_or_search_state)
19
+ has_spatial_parameters?(search_state) || super
20
20
  end
21
21
 
22
22
  # BlacklightMaps override: include render_spatial_query() in rendered constraints
23
- def render_constraints(localized_params = params)
24
- render_spatial_query(localized_params) + super
23
+ # @param localized_params [Hash] localized_params query parameters
24
+ # @param local_search_state [Blacklight::SearchState]
25
+ # @return [String]
26
+ def render_constraints(localized_params = params, local_search_state = search_state)
27
+ params_or_search_state = if localized_params != params
28
+ localized_params
29
+ else
30
+ local_search_state
31
+ end
32
+ render_spatial_query(params_or_search_state) + super
25
33
  end
26
34
 
27
35
  # BlacklightMaps override: include render_search_to_s_coord() in rendered constraints
28
36
  # Simpler textual version of constraints, used on Search History page.
37
+ # @param params [Hash]
38
+ # @return [String]
29
39
  def render_search_to_s(params)
30
40
  render_search_to_s_coord(params) + super
31
41
  end
32
42
 
33
43
  ##
34
44
  # Render the search query constraint
45
+ # @param params [Hash]
46
+ # @return [String]
35
47
  def render_search_to_s_coord(params)
36
- return "".html_safe if params[:coordinates].blank?
37
- render_search_to_s_element(spatial_constraint_label(params), render_filter_value(params[:coordinates]) )
48
+ return ''.html_safe if params[:coordinates].blank?
49
+
50
+ render_search_to_s_element(spatial_constraint_label(params),
51
+ render_filter_value(params[:coordinates]))
38
52
  end
39
53
 
40
54
  # Render the spatial query constraints
41
- def render_spatial_query(localized_params = params)
55
+ # @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
56
+ # @return [String]
57
+ def render_spatial_query(params_or_search_state = search_state)
58
+ search_state = convert_to_search_state(params_or_search_state)
59
+
42
60
  # So simple don't need a view template, we can just do it here.
43
- return ''.html_safe if localized_params[:coordinates].blank?
61
+ return ''.html_safe if search_state.params[:coordinates].blank?
44
62
 
45
- render_constraint_element(spatial_constraint_label(localized_params),
46
- localized_params[:coordinates],
47
- :classes => ['coordinates'],
48
- :remove => remove_constraint_url(localized_params.merge(:coordinates=>nil,
49
- :spatial_search_type=>nil,
50
- :action=>'index')))
63
+ render_constraint_element(spatial_constraint_label(search_state),
64
+ search_state.params[:coordinates],
65
+ classes: ['coordinates'],
66
+ remove: remove_spatial_params(search_state)) # _params.except!(:coordinates, :spatial_search_type)
51
67
  end
52
68
 
53
- def spatial_constraint_label(params)
54
- (params[:spatial_search_type] && params[:spatial_search_type] == 'bbox') ?
55
- t('blacklight.search.filters.coordinates.bbox') :
56
- t('blacklight.search.filters.coordinates.point')
69
+ ##
70
+ #
71
+ # @param search_state [Blacklight::SearchState]
72
+ # @return [String]
73
+ # remove the spatial params from params
74
+ def remove_spatial_params(search_state)
75
+ search_action_path(search_state.params.dup.except!(:coordinates, :spatial_search_type))
57
76
  end
58
77
 
78
+ ##
79
+ # render the label for the spatial constraint
80
+ # @param params_or_search_state [Blacklight::SearchState || ActionController::Parameters]
81
+ # @return [String]
82
+ def spatial_constraint_label(params_or_search_state)
83
+ search_params = if params_or_search_state.is_a?(Blacklight::SearchState)
84
+ params_or_search_state.params
85
+ else
86
+ params_or_search_state
87
+ end
88
+ if search_params[:spatial_search_type] && search_params[:spatial_search_type] == 'bbox'
89
+ t('blacklight.search.filters.coordinates.bbox')
90
+ else
91
+ t('blacklight.search.filters.coordinates.point')
92
+ end
93
+ end
59
94
  end
60
-
61
- end
95
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Maps
3
- VERSION = "0.5.2"
5
+ VERSION = '1.2.0'
4
6
  end
5
7
  end
@@ -1,13 +1,19 @@
1
- require "blacklight/maps/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'blacklight/maps/version'
2
4
 
3
5
  module Blacklight
4
6
  module Maps
5
- require 'blacklight/maps/controller_override'
7
+ require 'blacklight/maps/controller'
6
8
  require 'blacklight/maps/render_constraints_override'
7
9
  require 'blacklight/maps/engine'
8
10
  require 'blacklight/maps/export'
9
11
  require 'blacklight/maps/geometry'
10
12
  require 'blacklight/maps/maps_search_builder'
11
13
 
14
+ # returns the full path to the blacklight plugin installation
15
+ def self.root
16
+ @root ||= File.expand_path(File.dirname(File.dirname(File.dirname(__FILE__))))
17
+ end
12
18
  end
13
19
  end
@@ -1,61 +1,68 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
 
3
5
  module BlacklightMaps
4
6
  class Install < Rails::Generators::Base
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ desc 'Install Blacklight-Maps'
5
10
 
6
- source_root File.expand_path('../templates', __FILE__)
11
+ def verify_blacklight_installed
12
+ return if IO.read('app/controllers/application_controller.rb').include?('include Blacklight::Controller')
7
13
 
8
- desc "Install Blacklight-Maps"
14
+ say_status('info', 'BLACKLIGHT NOT INSTALLED; GENERATING BLACKLIGHT', :blue)
15
+ generate 'blacklight:install'
16
+ end
9
17
 
10
18
  def assets
11
- copy_file "blacklight_maps.css.scss", "app/assets/stylesheets/blacklight_maps.css.scss"
12
-
13
- unless IO.read("app/assets/javascripts/application.js").include?('blacklight-maps')
14
- marker = IO.read("app/assets/javascripts/application.js").include?('turbolinks') ?
15
- '//= require turbolinks' : "//= require jquery_ujs"
16
- insert_into_file "app/assets/javascripts/application.js", :after => marker do
17
- %q{
18
- //
19
- // Required by Blacklight-Maps
20
- //= require blacklight-maps}
21
- end
19
+ copy_file 'blacklight_maps.css.scss', 'app/assets/stylesheets/blacklight_maps.css.scss'
20
+ return if IO.read('app/assets/javascripts/application.js').include?('blacklight-maps')
21
+
22
+ marker = '//= require blacklight/blacklight'
23
+ insert_into_file 'app/assets/javascripts/application.js', after: marker do
24
+ "\n// Required by BlacklightMaps" \
25
+ "\n//= require blacklight-maps"
22
26
  end
27
+ append_to_file 'config/initializers/assets.rb',
28
+ "\nRails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'images')\n"
23
29
  end
24
30
 
25
31
  def inject_search_builder
26
- inject_into_file 'app/models/search_builder.rb', after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
32
+ inject_into_file 'app/models/search_builder.rb',
33
+ after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
27
34
  "\n include BlacklightMaps::MapsSearchBuilderBehavior\n"
28
35
  end
29
36
  end
30
37
 
31
38
  def install_catalog_controller_mixin
32
- inject_into_file "app/controllers/catalog_controller.rb", after: /include Blacklight::Catalog.*$/ do
33
- "\n include BlacklightMaps::ControllerOverride\n"
39
+ inject_into_file 'app/controllers/catalog_controller.rb',
40
+ after: /include Blacklight::Catalog.*$/ do
41
+ "\n include BlacklightMaps::Controller\n"
34
42
  end
35
43
  end
36
44
 
37
45
  def install_search_history_controller
38
- target_file = "app/controllers/search_history_controller.rb"
39
- if File.exists?(target_file)
40
- inject_into_file target_file, after: /include Blacklight::SearchHistory/ do
46
+ target_file = 'app/controllers/search_history_controller.rb'
47
+ if File.exist?(target_file)
48
+ inject_into_file target_file,
49
+ after: /include Blacklight::SearchHistory/ do
41
50
  "\n helper BlacklightMaps::RenderConstraintsOverride\n"
42
51
  end
43
52
  else
44
- copy_file "search_history_controller.rb", target_file
53
+ copy_file 'search_history_controller.rb', target_file
45
54
  end
46
55
  end
47
56
 
48
- def install_saved_searches_controller
49
- target_file = "app/controllers/saved_searches_controller.rb"
50
- if File.exists?(target_file)
51
- inject_into_file target_file, after: /include Blacklight::SavedSearches/ do
52
- "\n helper BlacklightMaps::RenderConstraintsOverride\n"
53
- end
54
- else
55
- copy_file "saved_searches_controller.rb", target_file
57
+ # TODO: inject Solr configuration (if needed)
58
+ def inject_solr_configuration
59
+ target_file = 'solr/conf/schema.xml'
60
+ return unless File.exist?(target_file)
61
+
62
+ inject_into_file target_file,
63
+ after: %r{<copyField source="title_tsim" dest="title_spell"/>} do
64
+ "\n <copyField source=\"coordinates_srpt\" dest=\"coordinates_ssim\" />\n"
56
65
  end
57
66
  end
58
-
59
-
60
67
  end
61
- end
68
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SearchHistoryController < ApplicationController
2
4
  include Blacklight::SearchHistory
3
5