From 5ad4f4e2b4578fb3462538d53939ebfafa21037e Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Fri, 21 Aug 2015 12:21:32 -0500 Subject: [PATCH 01/10] add functionality to hide all search indicator arrows via config --- lib/ransack/configuration.rb | 7 +++++- lib/ransack/helpers/form_helper.rb | 2 +- spec/ransack/helpers/form_helper_spec.rb | 28 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/ransack/configuration.rb b/lib/ransack/configuration.rb index 9568c83ea..6446e24c6 100644 --- a/lib/ransack/configuration.rb +++ b/lib/ransack/configuration.rb @@ -8,7 +8,8 @@ module Configuration self.predicates = {} self.options = { :search_key => :q, - :ignore_unknown_conditions => true + :ignore_unknown_conditions => true, + :remove_search_order_indicators => false } def configure @@ -75,5 +76,9 @@ def arel_predicate_with_suffix(arel_predicate, suffix) end end + def remove_search_order_indicators=(boolean) + self.options[:remove_search_order_indicators] = boolean + end + end end diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 562a23471..0e4fdee25 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -198,7 +198,7 @@ def default_sort_order(attr_name) end def order_indicator - if @hide_indicator || no_sort_direction_specified? + if @hide_indicator || no_sort_direction_specified? || Ransack.options[:remove_search_order_indicators] nil else direction_arrow diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index 261b95fb5..f383e7ced 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -399,6 +399,34 @@ module Helpers it { should match /example_name_eq/ } end + describe '#search_form_for with config set to remove search order indicators' do + before do + Ransack.configure { |c| c.remove_search_order_indicators = true } + end + subject { @controller.view_context + .sort_link( + [:main_app, Person.search(sorts: ['name desc'])], + :name, + controller: 'people' + ) + } + it { should match /Full Name/ } + end + + describe '#search_form_for with config set to remove search order indicators' do + before do + Ransack.configure { |c| c.remove_search_order_indicators = false } + end + subject { @controller.view_context + .sort_link( + [:main_app, Person.search(sorts: ['name desc'])], + :name, + controller: 'people' + ) + } + it { should match /Full Name ▼/ } + end + end end end From 57499405a8e38e986efe433ac1f880345d30b561 Mon Sep 17 00:00:00 2001 From: kalami Date: Fri, 21 Aug 2015 12:31:58 -0500 Subject: [PATCH 02/10] Update form_helper_spec.rb Changed the description of the 'false' case spec to be more accurate. --- spec/ransack/helpers/form_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index f383e7ced..661fd172c 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -413,7 +413,7 @@ module Helpers it { should match /Full Name/ } end - describe '#search_form_for with config set to remove search order indicators' do + describe '#search_form_for with config set to not remove search order indicators' do before do Ransack.configure { |c| c.remove_search_order_indicators = false } end From 3e6ee0305e3147c0c692108d6a711b6c503cb02e Mon Sep 17 00:00:00 2001 From: kalami Date: Fri, 21 Aug 2015 14:01:54 -0500 Subject: [PATCH 03/10] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index e448a5562..3171f5b24 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,13 @@ The sort link may be displayed without the order indicator arrow by passing <%= sort_link(@q, :name, hide_indicator: true) %> ``` +Alternatively, all sort links may be displayed without the order indicator arrow by adding this to an initializer like config/initializers/ransack.rb: + +Ransack.configure do |c| + c.remove_search_order_indicators = true +end + + ### Advanced Mode "Advanced" searches (ab)use Rails' nested attributes functionality in order to From aad81baf6130f0fa13cfabdb4dedcd25f0297b8c Mon Sep 17 00:00:00 2001 From: kalami Date: Fri, 21 Aug 2015 14:08:53 -0500 Subject: [PATCH 04/10] Update README.md fixed formatting of code portion of description --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3171f5b24..067f3e9ce 100644 --- a/README.md +++ b/README.md @@ -215,9 +215,9 @@ The sort link may be displayed without the order indicator arrow by passing Alternatively, all sort links may be displayed without the order indicator arrow by adding this to an initializer like config/initializers/ransack.rb: -Ransack.configure do |c| - c.remove_search_order_indicators = true -end + Ransack.configure do |c| + c.remove_search_order_indicators = true + end ### Advanced Mode From 354827aeb6ca9d89405fce7635f259303a27180f Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Mon, 24 Aug 2015 10:57:40 -0500 Subject: [PATCH 05/10] moved logic for setting @hide_indicator into a seperate method, improved config option name and readme --- README.md | 8 ++++++++ lib/ransack/configuration.rb | 4 ++-- lib/ransack/helpers/form_helper.rb | 8 ++++++-- spec/ransack/helpers/form_helper_spec.rb | 8 ++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e448a5562..1ea030ed0 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,14 @@ The sort link may be displayed without the order indicator arrow by passing <%= sort_link(@q, :name, hide_indicator: true) %> ``` +Alternatively, all sort links may be displayed without the order indicator arrow by adding this to an initializer like config/initializers/ransack.rb: + +```ruby +Ransack.configure do |c| + c.remove_search_order_indicators = true +end +``` + ### Advanced Mode "Advanced" searches (ab)use Rails' nested attributes functionality in order to diff --git a/lib/ransack/configuration.rb b/lib/ransack/configuration.rb index 6446e24c6..19a9e5ed3 100644 --- a/lib/ransack/configuration.rb +++ b/lib/ransack/configuration.rb @@ -9,7 +9,7 @@ module Configuration self.options = { :search_key => :q, :ignore_unknown_conditions => true, - :remove_search_order_indicators => false + :hide_sort_order_indicators => false } def configure @@ -76,7 +76,7 @@ def arel_predicate_with_suffix(arel_predicate, suffix) end end - def remove_search_order_indicators=(boolean) + def hide_sort_order_indicators=(boolean) self.options[:remove_search_order_indicators] = boolean end diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 0e4fdee25..340869f1f 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -94,7 +94,7 @@ def initialize(search, attribute, args, params) @current_dir = existing_sort_direction @label_text = extract_label_and_mutate_args!(args) @options = extract_options_and_mutate_args!(args) - @hide_indicator = @options.delete :hide_indicator + @hide_indicator = indicator? @default_order = @options.delete :default_order end @@ -197,8 +197,12 @@ def default_sort_order(attr_name) end end + def indicator? + @options.delete :hide_indicator unless Ransack.options[:hide_sort_order_indicators] + end + def order_indicator - if @hide_indicator || no_sort_direction_specified? || Ransack.options[:remove_search_order_indicators] + if @hide_indicator || no_sort_direction_specified? nil else direction_arrow diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index f383e7ced..1c1a59172 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -399,9 +399,9 @@ module Helpers it { should match /example_name_eq/ } end - describe '#search_form_for with config set to remove search order indicators' do + describe '#search_form_for with config set to remove sort order indicators' do before do - Ransack.configure { |c| c.remove_search_order_indicators = true } + Ransack.configure { |c| c.hide_sort_order_indicators = true } end subject { @controller.view_context .sort_link( @@ -413,9 +413,9 @@ module Helpers it { should match /Full Name/ } end - describe '#search_form_for with config set to remove search order indicators' do + describe '#search_form_for with config set to remove sort order indicators' do before do - Ransack.configure { |c| c.remove_search_order_indicators = false } + Ransack.configure { |c| c.hide_sort_order_indicators = false } end subject { @controller.view_context .sort_link( From 237fc6486c01a9912762935e704ef1f1d98c5df5 Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Mon, 24 Aug 2015 11:48:28 -0500 Subject: [PATCH 06/10] removed merge comments from form_helper_spec.rb --- spec/ransack/helpers/form_helper_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index 6255e1426..1c1a59172 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -413,11 +413,7 @@ module Helpers it { should match /Full Name/ } end -<<<<<<< HEAD describe '#search_form_for with config set to remove sort order indicators' do -======= - describe '#search_form_for with config set to not remove search order indicators' do ->>>>>>> aad81baf6130f0fa13cfabdb4dedcd25f0297b8c before do Ransack.configure { |c| c.hide_sort_order_indicators = false } end From 0c742418666257fe32f0f4edc550f412d75a2916 Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Tue, 25 Aug 2015 10:39:57 -0500 Subject: [PATCH 07/10] [skip ci] set line to 80 characters and added backticks to identify initializer --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ea030ed0..7fc98b296 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,8 @@ The sort link may be displayed without the order indicator arrow by passing <%= sort_link(@q, :name, hide_indicator: true) %> ``` -Alternatively, all sort links may be displayed without the order indicator arrow by adding this to an initializer like config/initializers/ransack.rb: +Alternatively, all sort links may be displayed without the order indicator arrow +by adding this to an initializer like `config/initializers/ransack.rb`: ```ruby Ransack.configure do |c| From e0c8eba2118708c5e88c00224137f0ebeeec89f0 Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Wed, 26 Aug 2015 17:53:09 -0500 Subject: [PATCH 08/10] removed indicator? method and updated readme.md --- README.md | 2 +- lib/ransack/helpers/form_helper.rb | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7fc98b296..e83ee3e26 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ by adding this to an initializer like `config/initializers/ransack.rb`: ```ruby Ransack.configure do |c| - c.remove_search_order_indicators = true + c.hide_sort_order_indicators = true end ``` diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 340869f1f..a40e287c2 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -94,7 +94,7 @@ def initialize(search, attribute, args, params) @current_dir = existing_sort_direction @label_text = extract_label_and_mutate_args!(args) @options = extract_options_and_mutate_args!(args) - @hide_indicator = indicator? + @hide_indicator = @options.delete :hide_indicator || Ransack.options[:hide_sort_order_indicators] @default_order = @options.delete :default_order end @@ -197,16 +197,9 @@ def default_sort_order(attr_name) end end - def indicator? - @options.delete :hide_indicator unless Ransack.options[:hide_sort_order_indicators] - end - def order_indicator - if @hide_indicator || no_sort_direction_specified? - nil - else - direction_arrow - end + return if @hide_indicator || no_sort_direction_specified? + direction_arrow end def no_sort_direction_specified?(dir = @current_dir) From aebfead33f9a3dd508453682927d3436edf88a5c Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Thu, 27 Aug 2015 14:12:58 -0500 Subject: [PATCH 09/10] added parens for @hide_indicator in SortLink#initialize; corrected the regex in the hide_indicator spec and hide_sort_order_indicator spec; corrected option name in hide_sort_orders setter in configuration.rb --- lib/ransack/configuration.rb | 2 +- lib/ransack/helpers/form_helper.rb | 2 +- spec/ransack/helpers/form_helper_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ransack/configuration.rb b/lib/ransack/configuration.rb index 19a9e5ed3..c35898c69 100644 --- a/lib/ransack/configuration.rb +++ b/lib/ransack/configuration.rb @@ -77,7 +77,7 @@ def arel_predicate_with_suffix(arel_predicate, suffix) end def hide_sort_order_indicators=(boolean) - self.options[:remove_search_order_indicators] = boolean + self.options[:hide_sort_order_indicators] = boolean end end diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index a40e287c2..e289562a1 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -94,7 +94,7 @@ def initialize(search, attribute, args, params) @current_dir = existing_sort_direction @label_text = extract_label_and_mutate_args!(args) @options = extract_options_and_mutate_args!(args) - @hide_indicator = @options.delete :hide_indicator || Ransack.options[:hide_sort_order_indicators] + @hide_indicator = @options.delete(:hide_indicator) || Ransack.options[:hide_sort_order_indicators] @default_order = @options.delete :default_order end diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index 1c1a59172..d2fb3df71 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -343,7 +343,7 @@ module Helpers hide_indicator: true ) } - it { should match /Full Name/ } + it { should_not match /▼|▲/ } end describe '#sort_link with hide order indicator set to false' do @@ -410,10 +410,10 @@ module Helpers controller: 'people' ) } - it { should match /Full Name/ } + it { should_not match /▼|▲/ } end - describe '#search_form_for with config set to remove sort order indicators' do + describe '#search_form_for with config set to not remove sort order indicators' do before do Ransack.configure { |c| c.hide_sort_order_indicators = false } end From d99a6de0bc06900b137d4d57456ce1ae2f76823f Mon Sep 17 00:00:00 2001 From: Josh Hunter Date: Thu, 27 Aug 2015 14:57:34 -0500 Subject: [PATCH 10/10] moved sort_link hide_sort_order_indicator specs up with the other sort_link specs and corrected their description --- spec/ransack/helpers/form_helper_spec.rb | 57 ++++++++++++------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index d2fb3df71..b1526963c 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -358,6 +358,34 @@ module Helpers it { should match /Full Name ▼/ } end + describe '#sort_link with config set to remove sort order indicators' do + before do + Ransack.configure { |c| c.hide_sort_order_indicators = true } + end + subject { @controller.view_context + .sort_link( + [:main_app, Person.search(sorts: ['name desc'])], + :name, + controller: 'people' + ) + } + it { should_not match /▼|▲/ } + end + + describe '#sort_link with config set to not remove sort order indicators' do + before do + Ransack.configure { |c| c.hide_sort_order_indicators = false } + end + subject { @controller.view_context + .sort_link( + [:main_app, Person.search(sorts: ['name desc'])], + :name, + controller: 'people' + ) + } + it { should match /Full Name ▼/ } + end + describe '#search_form_for with default format' do subject { @controller.view_context .search_form_for(Person.search) {} } @@ -398,35 +426,6 @@ module Helpers } it { should match /example_name_eq/ } end - - describe '#search_form_for with config set to remove sort order indicators' do - before do - Ransack.configure { |c| c.hide_sort_order_indicators = true } - end - subject { @controller.view_context - .sort_link( - [:main_app, Person.search(sorts: ['name desc'])], - :name, - controller: 'people' - ) - } - it { should_not match /▼|▲/ } - end - - describe '#search_form_for with config set to not remove sort order indicators' do - before do - Ransack.configure { |c| c.hide_sort_order_indicators = false } - end - subject { @controller.view_context - .sort_link( - [:main_app, Person.search(sorts: ['name desc'])], - :name, - controller: 'people' - ) - } - it { should match /Full Name ▼/ } - end - end end end