blacklight_advanced_search 2.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/Gemfile +8 -0
  2. data/{README.rdoc → README.md} +85 -59
  3. data/Rakefile +2 -2
  4. data/VERSION +1 -1
  5. data/app/assets/javascripts/blacklight_advanced_search.js +4 -4
  6. data/app/assets/stylesheets/blacklight_advanced_search/advanced_results.css +11 -31
  7. data/app/assets/stylesheets/blacklight_advanced_search/blacklight_advanced_search_styles.css.scss +42 -7
  8. data/app/controllers/blacklight_advanced_search/advanced_controller.rb +1 -3
  9. data/app/helpers/advanced_helper.rb +13 -9
  10. data/app/views/advanced/_advanced_search_facets.html.erb +15 -2
  11. data/app/views/advanced/_advanced_search_facets_as_select.html.erb +30 -0
  12. data/app/views/advanced/_advanced_search_fields.html.erb +5 -3
  13. data/app/views/advanced/_advanced_search_form.html.erb +26 -25
  14. data/app/views/advanced/_advanced_search_help.html.erb +19 -17
  15. data/app/views/advanced/_advanced_search_submit_btns.html.erb +12 -0
  16. data/app/views/advanced/_facet_limit.html.erb +11 -3
  17. data/app/views/advanced/index.html.erb +19 -6
  18. data/app/views/blacklight_advanced_search/_facet_limit.html.erb +8 -3
  19. data/blacklight_advanced_search.gemspec +7 -3
  20. data/config/locales/blacklight_advanced_search.en.yml +12 -0
  21. data/lib/blacklight_advanced_search.rb +28 -17
  22. data/lib/blacklight_advanced_search/advanced_query_parser.rb +26 -15
  23. data/lib/blacklight_advanced_search/redirect_legacy_params_filter.rb +32 -0
  24. data/lib/blacklight_advanced_search/render_constraints_override.rb +33 -7
  25. data/spec/features/blacklight_advanced_search_form_spec.rb +5 -5
  26. data/spec/lib/deep_merge_spec.rb +45 -0
  27. data/spec/test_app_templates/Gemfile.extra +2 -0
  28. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  29. metadata +41 -15
  30. data/app/assets/javascripts/blacklight_advanced_search/blacklight_advanced_search_javascript.js +0 -48
  31. data/app/views/advanced/_facet_layout.html.erb +0 -5
@@ -18,7 +18,7 @@ module BlacklightAdvancedSearch::RenderConstraintsOverride
18
18
  if (@advanced_query.nil? || @advanced_query.keyword_queries.empty? )
19
19
  return super(my_params)
20
20
  else
21
- content = ""
21
+ content = []
22
22
  @advanced_query.keyword_queries.each_pair do |field, query|
23
23
  label = search_field_def_for_key(field)[:label]
24
24
  content << render_constraint_element(
@@ -29,10 +29,13 @@ module BlacklightAdvancedSearch::RenderConstraintsOverride
29
29
  end
30
30
  if (@advanced_query.keyword_op == "OR" &&
31
31
  @advanced_query.keyword_queries.length > 1)
32
- content = '<span class="inclusive_or appliedFilter">' + '<span class="operator">Any of:</span>' + content + '</span>'
32
+ content.unshift content_tag(:span, "Any of:", class:'operator')
33
+ content_tag :span, class: "inclusive_or appliedFilter well" do
34
+ safe_join(content.flatten, "\n")
35
+ end
36
+ else
37
+ safe_join(content.flatten, "\n")
33
38
  end
34
-
35
- return content
36
39
  end
37
40
  end
38
41
 
@@ -44,9 +47,9 @@ module BlacklightAdvancedSearch::RenderConstraintsOverride
44
47
 
45
48
  if (@advanced_query)
46
49
  @advanced_query.filters.each_pair do |field, value_list|
47
- label = facet_field_labels[field]
50
+ label = facet_field_label(field)
48
51
  content << render_constraint_element(label,
49
- value_list.join(" OR "),
52
+ safe_join(value_list, " <strong class='text-muted constraint-connector'>OR</strong> ".html_safe),
50
53
  :remove => catalog_index_path( remove_advanced_filter_group(field, my_params) )
51
54
  )
52
55
  end
@@ -55,6 +58,26 @@ module BlacklightAdvancedSearch::RenderConstraintsOverride
55
58
  return content
56
59
  end
57
60
 
61
+ # override of BL method, so our inclusive facet selections
62
+ # are still recgonized for eg highlighting facet with selected
63
+ # values.
64
+ def facet_field_in_params?(field)
65
+ return true if super
66
+
67
+ # otherwise use our own logic. And work around a weird bug
68
+ # in BL that assumes params[:f][field] will exist if facet_field_in_params?
69
+ # hacky insistence on params[:f] etc won't be neccesary if after:
70
+ # https://github.com/projectblacklight/blacklight/pull/790
71
+ query = BlacklightAdvancedSearch::QueryParser.new(params, self.blacklight_config )
72
+ if query.filters.keys.include?( field )
73
+ params[:f] ||= {}
74
+ params[:f][field] ||= []
75
+ return true
76
+ end
77
+
78
+ return false
79
+ end
80
+
58
81
  def render_search_to_s_filters(my_params)
59
82
  content = super(my_params)
60
83
 
@@ -62,7 +85,10 @@ module BlacklightAdvancedSearch::RenderConstraintsOverride
62
85
 
63
86
  if (advanced_query.filters.length > 0)
64
87
  advanced_query.filters.each_pair do |field, values|
65
- label = facet_field_labels[field]
88
+ # old-style, may still be in history
89
+ values = values.keys if values.kind_of? Hash
90
+
91
+ label = facet_field_label(field)
66
92
 
67
93
  content << render_search_to_s_element(
68
94
  label,
@@ -11,8 +11,8 @@ describe "Blacklight Advanced Search Form" do
11
11
  end
12
12
 
13
13
  it "should have field and facet blocks" do
14
- page.should have_selector('.query_column')
15
- page.should have_selector('.limit_column')
14
+ page.should have_selector('.query-criteria')
15
+ page.should have_selector('.limit-criteria')
16
16
  end
17
17
 
18
18
  describe "query column" do
@@ -25,8 +25,8 @@ describe "Blacklight Advanced Search Form" do
25
25
  end
26
26
 
27
27
  it "should list the configured search fields" do
28
- page.should have_selector '.advanced_search_field #title'
29
- page.should have_selector '.advanced_search_field #author'
28
+ page.should have_selector '.advanced-search-field #title'
29
+ page.should have_selector '.advanced-search-field #author'
30
30
  end
31
31
 
32
32
  it "should not list the search fields listed as not to be included in adv search" do
@@ -46,7 +46,7 @@ describe "Blacklight Advanced Search Form" do
46
46
 
47
47
  it "scope searches to fields" do
48
48
  fill_in "title", :with => "Medicine"
49
- click_on "advanced_search"
49
+ click_on "advanced-search-submit"
50
50
  puts page.current_url
51
51
  page.should have_content "Remove constraint Title: Medicine"
52
52
  page.should have_content "2007020969"
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe "BlacklightAdvancedSearch#deep_merge!" do
4
+ before do
5
+ @ahash = {"a" => "a", "b" => "b",
6
+ "array1" => [1,2], "array2" => [3,4],
7
+ "hash1" => {"a" => "a", "array" => [1], "b" => "b"},
8
+ "hash2" => {"a2" => "a2", "array2" => [12], "b2" => "b2"}
9
+ }
10
+
11
+ BlacklightAdvancedSearch.deep_merge!(@ahash, {
12
+ "a" => "NEW A",
13
+ "array1" => [3, 4],
14
+ "hash1" => {
15
+ "array" => [2],
16
+ "b" => "NEW B"
17
+ },
18
+ "c" => "NEW C"
19
+ })
20
+ end
21
+
22
+
23
+ it "leaves un-collided content alone" do
24
+ expect(@ahash["b"]).to eq("b")
25
+ expect(@ahash["array2"]).to eq([3,4])
26
+ expect(@ahash["hash2"]).to eq({"a2" => "a2", "array2" => [12], "b2" => "b2"})
27
+ end
28
+
29
+ it "adds new content" do
30
+ expect(@ahash["c"]).to eq("NEW C")
31
+ end
32
+
33
+ it "merges an array" do
34
+ expect(@ahash["array1"]).to eq([1,2,3,4])
35
+ end
36
+
37
+ it "merges a hash, recursive like" do
38
+ expect(@ahash["hash1"]).to eq({
39
+ "a" => "a",
40
+ "array" => [1,2],
41
+ "b" => "NEW B"
42
+ })
43
+ end
44
+
45
+ end
@@ -3,6 +3,8 @@ platforms :jruby do
3
3
  gem 'therubyrhino'
4
4
  end
5
5
 
6
+ gem 'blacklight', github: 'projectblacklight/blacklight', branch: 'master'
7
+
6
8
  group :test do
7
9
  gem 'rspec-rails', '~> 2.13'
8
10
  gem 'generator_spec'
@@ -15,7 +15,7 @@ class TestAppGenerator < Rails::Generators::Base
15
15
  def run_blacklight_generator
16
16
  say_status("warning", "GENERATING BL", :yellow)
17
17
 
18
- generate 'blacklight', '--marc'
18
+ generate 'blacklight:install'
19
19
  end
20
20
 
21
21
  def run_blacklight_advanced_search
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_advanced_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 5.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,30 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-05 00:00:00.000000000 Z
13
+ date: 2014-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: blacklight
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ~>
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: '4.0'
22
+ version: '5.1'
23
+ - - <
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
23
26
  type: :runtime
24
27
  prerelease: false
25
28
  version_requirements: !ruby/object:Gem::Requirement
26
29
  none: false
27
30
  requirements:
28
- - - ~>
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ - - <
29
35
  - !ruby/object:Gem::Version
30
- version: '4.0'
36
+ version: '6.0'
31
37
  - !ruby/object:Gem::Dependency
32
38
  name: parslet
33
39
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +50,22 @@ dependencies:
44
50
  - - ! '>='
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: blacklight_marc
55
+ requirement: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: rails
49
71
  requirement: !ruby/object:Gem::Requirement
@@ -97,17 +119,17 @@ dependencies:
97
119
  requirement: !ruby/object:Gem::Requirement
98
120
  none: false
99
121
  requirements:
100
- - - ! '>='
122
+ - - ~>
101
123
  - !ruby/object:Gem::Version
102
- version: '0'
124
+ version: 0.2.2
103
125
  type: :development
104
126
  prerelease: false
105
127
  version_requirements: !ruby/object:Gem::Requirement
106
128
  none: false
107
129
  requirements:
108
- - - ! '>='
130
+ - - ~>
109
131
  - !ruby/object:Gem::Version
110
- version: '0'
132
+ version: 0.2.2
111
133
  description:
112
134
  email:
113
135
  - blacklight-development@googlegroups.com
@@ -119,11 +141,10 @@ files:
119
141
  - .travis.yml
120
142
  - Gemfile
121
143
  - LICENSE
122
- - README.rdoc
144
+ - README.md
123
145
  - Rakefile
124
146
  - VERSION
125
147
  - app/assets/javascripts/blacklight_advanced_search.js
126
- - app/assets/javascripts/blacklight_advanced_search/blacklight_advanced_search_javascript.js
127
148
  - app/assets/stylesheets/blacklight_advanced_search.css
128
149
  - app/assets/stylesheets/blacklight_advanced_search/advanced_results.css
129
150
  - app/assets/stylesheets/blacklight_advanced_search/blacklight_advanced_search_styles.css.scss
@@ -131,15 +152,17 @@ files:
131
152
  - app/controllers/blacklight_advanced_search/advanced_controller.rb
132
153
  - app/helpers/advanced_helper.rb
133
154
  - app/views/advanced/_advanced_search_facets.html.erb
155
+ - app/views/advanced/_advanced_search_facets_as_select.html.erb
134
156
  - app/views/advanced/_advanced_search_fields.html.erb
135
157
  - app/views/advanced/_advanced_search_form.html.erb
136
158
  - app/views/advanced/_advanced_search_help.html.erb
137
- - app/views/advanced/_facet_layout.html.erb
159
+ - app/views/advanced/_advanced_search_submit_btns.html.erb
138
160
  - app/views/advanced/_facet_limit.html.erb
139
161
  - app/views/advanced/index.html.erb
140
162
  - app/views/blacklight_advanced_search/_facet_limit.html.erb
141
163
  - blacklight_advanced_search.gemspec
142
164
  - config/jetty.yml
165
+ - config/locales/blacklight_advanced_search.en.yml
143
166
  - config/routes.rb
144
167
  - lib/blacklight_advanced_search.rb
145
168
  - lib/blacklight_advanced_search/advanced_query_parser.rb
@@ -149,6 +172,7 @@ files:
149
172
  - lib/blacklight_advanced_search/filter_parser.rb
150
173
  - lib/blacklight_advanced_search/parse_basic_q.rb
151
174
  - lib/blacklight_advanced_search/parsing_nesting_parser.rb
175
+ - lib/blacklight_advanced_search/redirect_legacy_params_filter.rb
152
176
  - lib/blacklight_advanced_search/render_constraints_override.rb
153
177
  - lib/blacklight_advanced_search/version.rb
154
178
  - lib/generators/blacklight_advanced_search/assets_generator.rb
@@ -159,6 +183,7 @@ files:
159
183
  - lib/parsing_nesting/tree.rb
160
184
  - spec/features/blacklight_advanced_search_form_spec.rb
161
185
  - spec/integration/blacklight_stub_spec.rb
186
+ - spec/lib/deep_merge_spec.rb
162
187
  - spec/lib/filter_parser_spec.rb
163
188
  - spec/parsing_nesting/build_tree_spec.rb
164
189
  - spec/parsing_nesting/consuming_spec.rb
@@ -184,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
209
  version: '0'
185
210
  segments:
186
211
  - 0
187
- hash: 4211602717521532640
212
+ hash: -3234438610145730217
188
213
  required_rubygems_version: !ruby/object:Gem::Requirement
189
214
  none: false
190
215
  requirements:
@@ -193,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
218
  version: '0'
194
219
  segments:
195
220
  - 0
196
- hash: 4211602717521532640
221
+ hash: -3234438610145730217
197
222
  requirements: []
198
223
  rubyforge_project: blacklight
199
224
  rubygems_version: 1.8.23
@@ -203,6 +228,7 @@ summary: Blacklight Advanced Search plugin
203
228
  test_files:
204
229
  - spec/features/blacklight_advanced_search_form_spec.rb
205
230
  - spec/integration/blacklight_stub_spec.rb
231
+ - spec/lib/deep_merge_spec.rb
206
232
  - spec/lib/filter_parser_spec.rb
207
233
  - spec/parsing_nesting/build_tree_spec.rb
208
234
  - spec/parsing_nesting/consuming_spec.rb
@@ -1,48 +0,0 @@
1
- $(document).ready(function() {
2
-
3
- /* Stuff for handling the checkboxes */
4
- /* When you click a checkbox, update readout */
5
-
6
-
7
- /* Pass in a jquery obj holding the "selected facet element" spans, get back
8
- a string for display representing currently checked things. */
9
- function checkboxesToString(checkbox_elements) {
10
- var selectedLabels = new Array();
11
- checkbox_elements.each(function() {
12
- if ($(this).is(":checked")) {
13
- selectedLabels.push( $(this).next('.facet-value').text());
14
- }
15
- });
16
- return selectedLabels.join(" OR ");
17
- }
18
-
19
- //Pass in JQuery object of zero or more <div class="facet_item"> blocks,
20
- //that contain an h3, some checkboxes, and a span.adv_facet_selections for
21
- //display of current selections. Will update the span.
22
- function updateSelectedDisplay(facet_item) {
23
- var checkboxes = $(facet_item).find("input:checkbox");
24
- var displaySpan = $(facet_item).find("span.adv_facet_selections");
25
- var displayStr = checkboxesToString( checkboxes );
26
-
27
- displaySpan.text( displayStr );
28
- if (displayStr == "") {
29
- displaySpan.hide();
30
- } else {
31
- displaySpan.show();
32
- }
33
-
34
-
35
- }
36
-
37
- // on page load, set initial properly
38
- $(".facet_item").each(function() {
39
- updateSelectedDisplay(this);
40
- });
41
-
42
- //change on checkbox change
43
- $(".facet_item input:checkbox").change( function() {
44
- updateSelectedDisplay( $(this).closest(".facet_item"));
45
- });
46
-
47
-
48
- });
@@ -1,5 +0,0 @@
1
- <div class="facet_item blacklight-<%= facet_field.field.parameterize %>">
2
- <h5 class="twiddle"><%= facet_field.label -%> <i class="icon-chevron"></i><span class="adv_facet_selections" style="display:none;"></span></h5>
3
-
4
- <%= yield %>
5
- </div>