ransack_ui 1.3.4 → 1.4.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.
- checksums.yaml +5 -5
- data/.rubocop_todo.yml +129 -0
- data/Gemfile +2 -1
- data/README.md +5 -4
- data/Rakefile +1 -1
- data/lib/ransack_ui.rb +5 -5
- data/lib/ransack_ui/adapters/active_record/base.rb +3 -4
- data/lib/ransack_ui/controller_helpers.rb +1 -1
- data/lib/ransack_ui/rails/engine.rb +5 -5
- data/lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb +4 -5
- data/lib/ransack_ui/ransack_overrides/configuration.rb +1 -1
- data/lib/ransack_ui/ransack_overrides/context.rb +1 -1
- data/lib/ransack_ui/ransack_overrides/helpers/form_builder.rb +67 -73
- data/lib/ransack_ui/ransack_overrides/nodes/attribute.rb +2 -2
- data/lib/ransack_ui/ransack_overrides/nodes/condition.rb +1 -1
- data/lib/ransack_ui/ransack_overrides/nodes/grouping.rb +1 -3
- data/lib/ransack_ui/version.rb +1 -1
- data/lib/ransack_ui/view_helpers.rb +7 -7
- data/ransack_ui.gemspec +11 -12
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ac84bded42933bf2a64def821e3698e5182047397d2e8bb6f0321d6b38051d21
|
|
4
|
+
data.tar.gz: abdc1d7d87b36deb0648b320b7e65e4511a046e35455b0f7887bb22c60a75b19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70fa91e7584802f51d68c0990e4a27acbfc928954cc48d6833258507287826b9b71a9c066f11c06c5b44449a72025367d61cf69f572f57d105ab4f55e86778b8
|
|
7
|
+
data.tar.gz: 7356459d70de3031278ec4ef61b1197d7c533b221ec1d2966e3e1e32072778f260f06e50970525fef732e6e6b0d8be8aa0a880af5e0472cc3e64bbce1bca5d00
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2019-11-08 16:20:08 +1030 using RuboCop version 0.76.0.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
# Cop supports --auto-correct.
|
|
11
|
+
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
|
|
12
|
+
# Include: **/*.gemspec
|
|
13
|
+
Gemspec/OrderedDependencies:
|
|
14
|
+
Exclude:
|
|
15
|
+
- 'ransack_ui.gemspec'
|
|
16
|
+
|
|
17
|
+
# Offense count: 5
|
|
18
|
+
# Cop supports --auto-correct.
|
|
19
|
+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
|
20
|
+
Lint/UnusedMethodArgument:
|
|
21
|
+
Exclude:
|
|
22
|
+
- 'lib/ransack_ui/adapters/active_record/base.rb'
|
|
23
|
+
- 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
|
|
24
|
+
- 'lib/ransack_ui/view_helpers.rb'
|
|
25
|
+
|
|
26
|
+
# Offense count: 6
|
|
27
|
+
Metrics/AbcSize:
|
|
28
|
+
Max: 53
|
|
29
|
+
|
|
30
|
+
# Offense count: 2
|
|
31
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
|
32
|
+
# ExcludedMethods: refine
|
|
33
|
+
Metrics/BlockLength:
|
|
34
|
+
Max: 200
|
|
35
|
+
|
|
36
|
+
# Offense count: 1
|
|
37
|
+
# Configuration parameters: CountBlocks.
|
|
38
|
+
Metrics/BlockNesting:
|
|
39
|
+
Max: 5
|
|
40
|
+
|
|
41
|
+
# Offense count: 3
|
|
42
|
+
Metrics/CyclomaticComplexity:
|
|
43
|
+
Max: 12
|
|
44
|
+
|
|
45
|
+
# Offense count: 7
|
|
46
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
|
47
|
+
Metrics/MethodLength:
|
|
48
|
+
Max: 46
|
|
49
|
+
|
|
50
|
+
# Offense count: 1
|
|
51
|
+
# Configuration parameters: CountComments.
|
|
52
|
+
Metrics/ModuleLength:
|
|
53
|
+
Max: 202
|
|
54
|
+
|
|
55
|
+
# Offense count: 3
|
|
56
|
+
Metrics/PerceivedComplexity:
|
|
57
|
+
Max: 13
|
|
58
|
+
|
|
59
|
+
# Offense count: 2
|
|
60
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
|
|
61
|
+
# NamePrefix: is_, has_, have_
|
|
62
|
+
# NamePrefixBlacklist: is_, has_, have_
|
|
63
|
+
# NameWhitelist: is_a?
|
|
64
|
+
# MethodDefinitionMacros: define_method, define_singleton_method
|
|
65
|
+
Naming/PredicateName:
|
|
66
|
+
Exclude:
|
|
67
|
+
- 'spec/**/*'
|
|
68
|
+
- 'lib/ransack_ui/adapters/active_record/base.rb'
|
|
69
|
+
- 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
|
|
70
|
+
|
|
71
|
+
# Offense count: 2
|
|
72
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
73
|
+
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
|
|
74
|
+
Naming/UncommunicativeMethodParamName:
|
|
75
|
+
Exclude:
|
|
76
|
+
- 'lib/ransack_ui/view_helpers.rb'
|
|
77
|
+
|
|
78
|
+
# Offense count: 1
|
|
79
|
+
# Cop supports --auto-correct.
|
|
80
|
+
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
|
|
81
|
+
# SupportedStyles: assign_to_condition, assign_inside_condition
|
|
82
|
+
Style/ConditionalAssignment:
|
|
83
|
+
Exclude:
|
|
84
|
+
- 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
|
|
85
|
+
|
|
86
|
+
# Offense count: 11
|
|
87
|
+
Style/Documentation:
|
|
88
|
+
Exclude:
|
|
89
|
+
- 'spec/**/*'
|
|
90
|
+
- 'test/**/*'
|
|
91
|
+
- 'lib/ransack_ui/adapters/active_record/base.rb'
|
|
92
|
+
- 'lib/ransack_ui/controller_helpers.rb'
|
|
93
|
+
- 'lib/ransack_ui/rails/engine.rb'
|
|
94
|
+
- 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
|
|
95
|
+
- 'lib/ransack_ui/ransack_overrides/configuration.rb'
|
|
96
|
+
- 'lib/ransack_ui/ransack_overrides/context.rb'
|
|
97
|
+
- 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
|
|
98
|
+
- 'lib/ransack_ui/ransack_overrides/nodes/attribute.rb'
|
|
99
|
+
- 'lib/ransack_ui/ransack_overrides/nodes/condition.rb'
|
|
100
|
+
- 'lib/ransack_ui/ransack_overrides/nodes/grouping.rb'
|
|
101
|
+
- 'lib/ransack_ui/view_helpers.rb'
|
|
102
|
+
|
|
103
|
+
# Offense count: 1
|
|
104
|
+
# Cop supports --auto-correct.
|
|
105
|
+
Style/EachWithObject:
|
|
106
|
+
Exclude:
|
|
107
|
+
- 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
|
|
108
|
+
|
|
109
|
+
# Offense count: 17
|
|
110
|
+
# Cop supports --auto-correct.
|
|
111
|
+
# Configuration parameters: EnforcedStyle.
|
|
112
|
+
# SupportedStyles: always, never
|
|
113
|
+
Style/FrozenStringLiteralComment:
|
|
114
|
+
Enabled: false
|
|
115
|
+
|
|
116
|
+
# Offense count: 1
|
|
117
|
+
# Cop supports --auto-correct.
|
|
118
|
+
# Configuration parameters: EnforcedStyle.
|
|
119
|
+
# SupportedStyles: use_perl_names, use_english_names
|
|
120
|
+
Style/SpecialGlobalVars:
|
|
121
|
+
Exclude:
|
|
122
|
+
- 'ransack_ui.gemspec'
|
|
123
|
+
|
|
124
|
+
# Offense count: 43
|
|
125
|
+
# Cop supports --auto-correct.
|
|
126
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
127
|
+
# URISchemes: http, https
|
|
128
|
+
Metrics/LineLength:
|
|
129
|
+
Max: 144
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
# Include rake in Gemfile so that `bundle exec rake` doesn't raise an error
|
|
4
|
-
gem 'rake', :
|
|
4
|
+
gem 'rake', group: :test
|
|
5
|
+
gem 'rubocop', '~> 0.76.0'
|
|
5
6
|
|
|
6
7
|
# Specify your gem's dependencies in ransack_ui.gemspec
|
|
7
8
|
gemspec
|
data/README.md
CHANGED
|
@@ -50,8 +50,9 @@ Now you can start playing with the results.
|
|
|
50
50
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
51
51
|
5. Create new Pull Request
|
|
52
52
|
|
|
53
|
-
##
|
|
53
|
+
## Acknowledgements
|
|
54
54
|
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Steve Kenworthy (steveyken)
|
|
55
|
+
* Ernie Miller (@ernie) - Creator of ransack (https://github.com/ernie/ransack)
|
|
56
|
+
* Nathan Broadbent (@ndbroadbent)
|
|
57
|
+
* Steve Kenworthy (@steveyken)
|
|
58
|
+
* Daniel O'Connor (@CloCkWeRX)
|
data/Rakefile
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/ransack_ui.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require 'ransack_ui/version'
|
|
2
|
+
require 'ransack_ui/rails/engine'
|
|
3
|
+
require 'ransack_chronic'
|
|
4
4
|
|
|
5
5
|
# Require ransack overrides
|
|
6
6
|
require 'ransack_ui/adapters/active_record'
|
|
7
|
-
Dir.glob(File.expand_path('
|
|
7
|
+
Dir.glob(File.expand_path('ransack_ui/ransack_overrides/**/*.rb', __dir__)) { |f| require f }
|
|
8
8
|
|
|
9
|
-
require
|
|
9
|
+
require 'ransack'
|
|
@@ -2,7 +2,6 @@ module RansackUI
|
|
|
2
2
|
module Adapters
|
|
3
3
|
module ActiveRecord
|
|
4
4
|
module Base
|
|
5
|
-
|
|
6
5
|
def self.extended(base)
|
|
7
6
|
base.class_eval do
|
|
8
7
|
class_attribute :_ransackable_associations
|
|
@@ -23,12 +22,12 @@ module RansackUI
|
|
|
23
22
|
# Return array of attributes with [name, type]
|
|
24
23
|
# (Default to :string type for ransackers)
|
|
25
24
|
def ransackable_attributes(auth_object = nil)
|
|
26
|
-
columns.map{|c| [c.name, c.type] } +
|
|
27
|
-
|
|
25
|
+
columns.map { |c| [c.name, c.type] } +
|
|
26
|
+
_ransackers.keys.map { |k, v| [k, v.type || :string] }
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def ransackable_associations(auth_object = nil)
|
|
31
|
-
all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
|
|
30
|
+
all_associations = reflect_on_all_associations.map { |a| a.name.to_s }
|
|
32
31
|
if self._ransackable_associations.any?
|
|
33
32
|
# Return intersection of all associations, and associations defined on the model
|
|
34
33
|
all_associations & self._ransackable_associations
|
|
@@ -10,7 +10,7 @@ module RansackUI
|
|
|
10
10
|
#
|
|
11
11
|
def load_ransack_search(klass = nil)
|
|
12
12
|
klass ||= controller_path.classify.constantize
|
|
13
|
-
@ransack_search = klass.
|
|
13
|
+
@ransack_search = klass.ransack(params[:q])
|
|
14
14
|
@ransack_search.build_grouping if @ransack_search.groupings.empty?
|
|
15
15
|
@ransack_search
|
|
16
16
|
end
|
|
@@ -4,17 +4,17 @@ require 'ransack_ui/controller_helpers'
|
|
|
4
4
|
module RansackUI
|
|
5
5
|
module Rails
|
|
6
6
|
class Engine < ::Rails::Engine
|
|
7
|
-
initializer
|
|
8
|
-
ActionView::Base.
|
|
7
|
+
initializer 'ransack_ui.view_helpers' do
|
|
8
|
+
ActionView::Base.include ViewHelpers
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
initializer
|
|
12
|
-
ActionController::Base.
|
|
11
|
+
initializer 'ransack_ui.controller_helpers' do
|
|
12
|
+
ActionController::Base.include ControllerHelpers
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
config.before_configuration do
|
|
16
16
|
# Add images to be precompiled
|
|
17
|
-
::Rails.application.config.assets.precompile += %w
|
|
17
|
+
::Rails.application.config.assets.precompile += %w[ransack_ui/delete.png ransack_ui/calendar.png]
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -7,12 +7,12 @@ module Ransack
|
|
|
7
7
|
# Return array of attributes with [name, type]
|
|
8
8
|
# (Default to :string type for ransackers)
|
|
9
9
|
def ransackable_attributes(auth_object = nil)
|
|
10
|
-
columns.map{|c| [c.name, c.type] } +
|
|
11
|
-
|
|
10
|
+
columns.map { |c| [c.name, c.type] } +
|
|
11
|
+
_ransackers.map { |k, v| [k, v.type || :string] }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def self.extended(base)
|
|
15
|
-
|
|
15
|
+
alias_method :search, :ransack unless base.method_defined? :search
|
|
16
16
|
base.class_eval do
|
|
17
17
|
class_attribute :_ransackers
|
|
18
18
|
class_attribute :_ransackable_associations
|
|
@@ -32,7 +32,7 @@ module Ransack
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def ransackable_associations(auth_object = nil)
|
|
35
|
-
all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
|
|
35
|
+
all_associations = reflect_on_all_associations.map { |a| a.name.to_s }
|
|
36
36
|
if self._ransackable_associations.any?
|
|
37
37
|
# Return intersection of all associations, and associations defined on the model
|
|
38
38
|
all_associations & self._ransackable_associations
|
|
@@ -40,7 +40,6 @@ module Ransack
|
|
|
40
40
|
all_associations
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
|
-
|
|
44
43
|
end
|
|
45
44
|
end
|
|
46
45
|
end
|
|
@@ -7,13 +7,12 @@ module Ransack
|
|
|
7
7
|
self.cached_searchable_attributes_for_base = {}
|
|
8
8
|
|
|
9
9
|
def attribute_select(options = {}, html_options = {})
|
|
10
|
-
raise ArgumentError,
|
|
11
|
-
|
|
10
|
+
raise ArgumentError, 'attribute_select must be called inside a search FormBuilder!' unless object.respond_to?(:context)
|
|
11
|
+
|
|
12
|
+
options[:include_blank] = true unless options.key?(:include_blank)
|
|
12
13
|
|
|
13
14
|
# Set default associations set on model with 'has_ransackable_associations'
|
|
14
|
-
if options[:associations].nil?
|
|
15
|
-
options[:associations] = object.context.klass.ransackable_associations
|
|
16
|
-
end
|
|
15
|
+
options[:associations] = object.context.klass.ransackable_associations if options[:associations].nil?
|
|
17
16
|
|
|
18
17
|
bases = [''] + association_array(options[:associations])
|
|
19
18
|
if bases.size > 1
|
|
@@ -31,32 +30,33 @@ module Ransack
|
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
def sort_select(options = {}, html_options = {})
|
|
34
|
-
raise ArgumentError,
|
|
35
|
-
|
|
33
|
+
raise ArgumentError, 'sort_select must be called inside a search FormBuilder!' unless object.respond_to?(:context)
|
|
34
|
+
|
|
35
|
+
options[:include_blank] = true unless options.key?(:include_blank)
|
|
36
36
|
bases = [''] + association_array(options[:associations])
|
|
37
37
|
if bases.size > 1
|
|
38
38
|
@template.select(
|
|
39
39
|
@object_name, :name,
|
|
40
40
|
@template.grouped_options_for_select(attribute_collection_for_bases(bases), object.name),
|
|
41
|
-
objectify_options(options), @default_options.merge(
|
|
41
|
+
objectify_options(options), @default_options.merge(class: 'ransack_sort').merge(html_options)
|
|
42
42
|
) + @template.collection_select(
|
|
43
43
|
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
|
|
44
|
-
objectify_options(options.except(:include_blank)), @default_options.merge(
|
|
44
|
+
objectify_options(options.except(:include_blank)), @default_options.merge(class: 'ransack_sort_order').merge(html_options)
|
|
45
45
|
)
|
|
46
46
|
else
|
|
47
47
|
# searchable_attributes now returns [c, type]
|
|
48
|
-
collection = object.context.searchable_attributes(bases.first).map do |c,
|
|
48
|
+
collection = object.context.searchable_attributes(bases.first).map do |c, _type|
|
|
49
49
|
[
|
|
50
50
|
attr_from_base_and_column(bases.first, c),
|
|
51
|
-
Translate.attribute(attr_from_base_and_column(bases.first, c), :
|
|
51
|
+
Translate.attribute(attr_from_base_and_column(bases.first, c), context: object.context)
|
|
52
52
|
]
|
|
53
53
|
end
|
|
54
54
|
@template.collection_select(
|
|
55
55
|
@object_name, :name, collection, :first, :last,
|
|
56
|
-
objectify_options(options), @default_options.merge(
|
|
56
|
+
objectify_options(options), @default_options.merge(class: 'ransack_sort').merge(html_options)
|
|
57
57
|
) + @template.collection_select(
|
|
58
58
|
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
|
|
59
|
-
objectify_options(options.except(:include_blank)), @default_options.merge(
|
|
59
|
+
objectify_options(options.except(:include_blank)), @default_options.merge(class: 'ransack_sort_order').merge(html_options)
|
|
60
60
|
)
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -69,27 +69,27 @@ module Ransack
|
|
|
69
69
|
condition.values.each do |value|
|
|
70
70
|
# If value is present, and the attribute is an association,
|
|
71
71
|
# load the selected record and include the record name as a data attribute
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
next unless value.value.present?
|
|
73
|
+
|
|
74
|
+
condition_attributes = condition.attributes
|
|
75
|
+
next unless condition_attributes.any?
|
|
76
|
+
|
|
77
|
+
attribute = condition_attributes.first.name
|
|
78
|
+
klass_name = foreign_klass_for_attribute(attribute)
|
|
79
|
+
|
|
80
|
+
next unless klass_name
|
|
81
|
+
|
|
82
|
+
klass = klass_name.constantize
|
|
83
|
+
|
|
84
|
+
value_object = klass.find_by_id(value.value)
|
|
85
|
+
next unless value_object
|
|
86
|
+
|
|
87
|
+
labels[attribute] ||= {}
|
|
88
|
+
|
|
89
|
+
if value_object.respond_to? :full_name
|
|
90
|
+
labels[attribute][value.value] = value_object.full_name
|
|
91
|
+
elsif value_object.respond_to? :name
|
|
92
|
+
labels[attribute][value.value] = value_object.name
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
end
|
|
@@ -98,18 +98,17 @@ module Ransack
|
|
|
98
98
|
labels
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
|
|
102
101
|
def predicate_keys(options)
|
|
103
|
-
keys = options[:compounds] ? Predicate.names : Predicate.names.reject {|k| k.match(/_(any|all)$/)}
|
|
104
|
-
if only = options[:only]
|
|
102
|
+
keys = options[:compounds] ? Predicate.names : Predicate.names.reject { |k| k.match(/_(any|all)$/) }
|
|
103
|
+
if (only = options[:only])
|
|
105
104
|
if only.respond_to? :call
|
|
106
|
-
keys = keys.select {|k| only.call(k)}
|
|
105
|
+
keys = keys.select { |k| only.call(k) }
|
|
107
106
|
else
|
|
108
107
|
only = Array.wrap(only).map(&:to_s)
|
|
109
108
|
# Create compounds hash, e.g. {"eq" => ["eq", "eq_any", "eq_all"], "blank" => ["blank"]}
|
|
110
|
-
key_groups = keys.inject(Hash.new([])){ |h,k| h[k.sub(/_(any|all)$/, '')] += [k]; h }
|
|
109
|
+
key_groups = keys.inject(Hash.new([])) { |h, k| h[k.sub(/_(any|all)$/, '')] += [k]; h }
|
|
111
110
|
# Order compounds hash by 'only' keys
|
|
112
|
-
keys = only.map {|k| key_groups[k] }.flatten.compact
|
|
111
|
+
keys = only.map { |k| key_groups[k] }.flatten.compact
|
|
113
112
|
end
|
|
114
113
|
end
|
|
115
114
|
keys
|
|
@@ -124,19 +123,19 @@ module Ransack
|
|
|
124
123
|
# then replace the default predicate with the first in the ordered list
|
|
125
124
|
@object.predicate_name = keys.first if @object.default?
|
|
126
125
|
@template.collection_select(
|
|
127
|
-
@object_name, :p, keys.map {|k| [k, Translate.predicate(k)]}, :first, :last,
|
|
126
|
+
@object_name, :p, keys.map { |k| [k, Translate.predicate(k)] }, :first, :last,
|
|
128
127
|
objectify_options(options), @default_options.merge(html_options)
|
|
129
128
|
)
|
|
130
129
|
end
|
|
131
130
|
|
|
132
131
|
def attribute_collection_for_bases(bases)
|
|
133
132
|
bases.map do |base|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
next unless (collection = attribute_collection_for_base(base))
|
|
134
|
+
|
|
135
|
+
[
|
|
136
|
+
Translate.association(base, context: object.context),
|
|
137
|
+
collection
|
|
138
|
+
]
|
|
140
139
|
end.compact
|
|
141
140
|
end
|
|
142
141
|
|
|
@@ -146,21 +145,19 @@ module Ransack
|
|
|
146
145
|
|
|
147
146
|
# Detect any inclusion validators to build list of options for a column
|
|
148
147
|
column_select_options = klass.validators.each_with_object({}) do |v, hash|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
next unless v.is_a? ActiveModel::Validations::InclusionValidator
|
|
149
|
+
|
|
150
|
+
v.attributes.each do |a|
|
|
151
|
+
# Try to translate options from activerecord.attribute_options.<model>.<attribute>
|
|
152
|
+
inclusions = v.send(:delimiter)
|
|
153
|
+
inclusions = inclusions.call if inclusions.respond_to?(:call) # handle lambda
|
|
154
|
+
hash[a.to_s] = inclusions.each_with_object({}) do |o, options|
|
|
155
|
+
options[o.to_s] = I18n.translate("activerecord.attribute_options.#{klass.to_s.downcase}.#{a}.#{o}", default: o.to_s.titleize)
|
|
157
156
|
end
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
161
|
-
if klass.respond_to?(:ransack_column_select_options)
|
|
162
|
-
column_select_options.merge!(klass.ransack_column_select_options)
|
|
163
|
-
end
|
|
160
|
+
column_select_options.merge!(klass.ransack_column_select_options) if klass.respond_to?(:ransack_column_select_options)
|
|
164
161
|
|
|
165
162
|
searchable_attributes_for_base(base).map do |attribute_data|
|
|
166
163
|
column = attribute_data[:column]
|
|
@@ -175,17 +172,17 @@ module Ransack
|
|
|
175
172
|
# Set column options if detected from inclusion validator
|
|
176
173
|
if column_select_options[column]
|
|
177
174
|
# Format options as an array of hashes with id and text columns, for Select2
|
|
178
|
-
html_options[:'data-select-options'] = column_select_options[column].map
|
|
179
|
-
{:
|
|
180
|
-
|
|
175
|
+
html_options[:'data-select-options'] = column_select_options[column].map do |id, text|
|
|
176
|
+
{ id: id, text: text }
|
|
177
|
+
end.to_json
|
|
181
178
|
end
|
|
182
179
|
|
|
183
180
|
foreign_klass = attribute_data[:foreign_klass]
|
|
184
181
|
|
|
185
182
|
if foreign_klass
|
|
186
183
|
# If field is a foreign key, set up 'data-ajax-*' attributes for auto-complete
|
|
187
|
-
controller = ActiveSupport::Inflector
|
|
188
|
-
html_options[:'data-ajax-entity'] = I18n.translate(controller, :
|
|
184
|
+
controller = ActiveSupport::Inflector.tableize(foreign_klass.to_s)
|
|
185
|
+
html_options[:'data-ajax-entity'] = I18n.translate(controller, default: controller)
|
|
189
186
|
if ajax_options[:url]
|
|
190
187
|
html_options[:'data-ajax-url'] = ajax_options[:url].sub(':controller', controller)
|
|
191
188
|
else
|
|
@@ -201,11 +198,10 @@ module Ransack
|
|
|
201
198
|
html_options
|
|
202
199
|
]
|
|
203
200
|
end
|
|
204
|
-
rescue UntraversableAssociationError
|
|
201
|
+
rescue UntraversableAssociationError
|
|
205
202
|
nil
|
|
206
203
|
end
|
|
207
204
|
|
|
208
|
-
|
|
209
205
|
private
|
|
210
206
|
|
|
211
207
|
def searchable_attributes_for_base(base)
|
|
@@ -214,22 +210,22 @@ module Ransack
|
|
|
214
210
|
|
|
215
211
|
self.class.cached_searchable_attributes_for_base[cache_key] ||= object.context.searchable_attributes(base).map do |column, type|
|
|
216
212
|
klass = object.context.traverse(base)
|
|
217
|
-
foreign_keys = klass.reflect_on_all_associations.select(&:belongs_to?)
|
|
218
|
-
|
|
213
|
+
foreign_keys = klass.reflect_on_all_associations.select(&:belongs_to?)
|
|
214
|
+
.each_with_object({}) { |r, h| h[r.foreign_key.to_sym] = r.class_name }
|
|
219
215
|
|
|
220
216
|
# Don't show 'id' column for base model
|
|
221
217
|
next nil if base.blank? && column == 'id'
|
|
222
218
|
|
|
223
219
|
attribute = attr_from_base_and_column(base, column)
|
|
224
|
-
attribute_label = Translate.attribute(attribute, :
|
|
220
|
+
attribute_label = Translate.attribute(attribute, context: object.context)
|
|
225
221
|
|
|
226
222
|
# Set model name as label for 'id' column on that model's table.
|
|
227
223
|
if column == 'id'
|
|
228
224
|
foreign_klass = object.context.traverse(base).model_name
|
|
229
225
|
# Check that model can autocomplete. If not, skip this id column.
|
|
230
|
-
next nil unless ActiveSupport::Inflector
|
|
226
|
+
next nil unless ActiveSupport::Inflector.constantize(foreign_klass.to_s)._ransack_can_autocomplete
|
|
231
227
|
|
|
232
|
-
attribute_label = I18n.translate(foreign_klass, :
|
|
228
|
+
attribute_label = I18n.translate(foreign_klass, default: foreign_klass)
|
|
233
229
|
else
|
|
234
230
|
foreign_klass = foreign_keys[column.to_sym]
|
|
235
231
|
end
|
|
@@ -251,9 +247,7 @@ module Ransack
|
|
|
251
247
|
|
|
252
248
|
bases.each do |base|
|
|
253
249
|
searchable_attributes_for_base(base).each do |attribute_data|
|
|
254
|
-
if attribute == attribute_data[:attribute]
|
|
255
|
-
return attribute_data[:foreign_klass]
|
|
256
|
-
end
|
|
250
|
+
return attribute_data[:foreign_klass] if attribute == attribute_data[:attribute]
|
|
257
251
|
end
|
|
258
252
|
end
|
|
259
253
|
end
|
|
@@ -5,8 +5,8 @@ module Ransack
|
|
|
5
5
|
Attribute.class_eval do
|
|
6
6
|
def valid?
|
|
7
7
|
bound? && attr &&
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
context.klassify(parent).ransackable_attributes(context.auth_object)
|
|
9
|
+
.map(&:first).include?(attr_name)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -3,7 +3,6 @@ require 'ransack/nodes/grouping'
|
|
|
3
3
|
module Ransack
|
|
4
4
|
module Nodes
|
|
5
5
|
Grouping.class_eval do
|
|
6
|
-
|
|
7
6
|
def new_condition(opts = {})
|
|
8
7
|
attrs = opts[:attributes] || 1
|
|
9
8
|
vals = opts[:values] || 1
|
|
@@ -14,7 +13,6 @@ module Ransack
|
|
|
14
13
|
vals.times { condition.build_value }
|
|
15
14
|
condition
|
|
16
15
|
end
|
|
17
|
-
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
|
-
end
|
|
18
|
+
end
|
data/lib/ransack_ui/version.rb
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
module RansackUI
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
def ransack_ui_search(options = {})
|
|
4
|
-
render 'ransack_ui/search', :
|
|
4
|
+
render 'ransack_ui/search', options: options
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def link_to_add_fields(name, f, type, options)
|
|
8
8
|
new_object = f.object.send "build_#{type}"
|
|
9
|
-
fields = f.send("#{type}_fields", new_object, :
|
|
10
|
-
render "ransack_ui/#{type
|
|
9
|
+
fields = f.send("#{type}_fields", new_object, child_index: "new_#{type}") do |builder|
|
|
10
|
+
render "ransack_ui/#{type}_fields", f: builder, options: options
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
if options[:theme].to_s == 'bootstrap'
|
|
14
|
-
link_to nil, :class =>
|
|
14
|
+
link_to nil, :class => 'add_fields btn btn-small btn-primary', 'data-field-type' => type, 'data-content' => fields.to_s do
|
|
15
15
|
"<i class=\"icon-plus icon-white\"></i><span>#{name}</span>".html_safe
|
|
16
16
|
end
|
|
17
17
|
else
|
|
18
|
-
link_to name, nil, :class =>
|
|
18
|
+
link_to name, nil, :class => 'add_fields', 'data-field-type' => type, 'data-content' => fields.to_s
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def link_to_remove_fields(name, f, options)
|
|
23
23
|
if options[:theme].to_s == 'bootstrap'
|
|
24
|
-
link_to '<i class="icon-remove icon-white"></i>'.html_safe, nil, :
|
|
24
|
+
link_to '<i class="icon-remove icon-white"></i>'.html_safe, nil, class: 'remove_fields btn btn-mini btn-danger'
|
|
25
25
|
else
|
|
26
|
-
link_to image_tag('ransack_ui/delete.png', :
|
|
26
|
+
link_to image_tag('ransack_ui/delete.png', size: '16x16', alt: name), nil, class: 'remove_fields'
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
data/ransack_ui.gemspec
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
3
|
require 'ransack_ui/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |gem|
|
|
7
|
-
gem.name =
|
|
6
|
+
gem.name = 'ransack_ui'
|
|
8
7
|
gem.version = RansackUI::VERSION
|
|
9
|
-
gem.authors = [
|
|
10
|
-
gem.email = [
|
|
11
|
-
gem.description =
|
|
12
|
-
gem.summary =
|
|
13
|
-
gem.homepage =
|
|
14
|
-
gem.license =
|
|
8
|
+
gem.authors = ['Nathan Broadbent']
|
|
9
|
+
gem.email = ['nathan.f77@gmail.com']
|
|
10
|
+
gem.description = 'Framework for building a search UI with Ransack'
|
|
11
|
+
gem.summary = 'UI Builder for Ransack'
|
|
12
|
+
gem.homepage = 'https://github.com/ndbroadbent/ransack_ui'
|
|
13
|
+
gem.license = 'MIT'
|
|
15
14
|
|
|
16
15
|
gem.files = `git ls-files`.split($/)
|
|
17
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
gem.require_paths = [
|
|
18
|
+
gem.require_paths = ['lib']
|
|
20
19
|
|
|
21
20
|
gem.add_dependency 'ransack_chronic', '>= 1.1.0'
|
|
22
|
-
gem.add_dependency 'ransack'
|
|
21
|
+
gem.add_dependency 'ransack', '~> 2.0'
|
|
23
22
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ransack_ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Broadbent
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ransack_chronic
|
|
@@ -28,16 +28,16 @@ dependencies:
|
|
|
28
28
|
name: ransack
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
33
|
+
version: '2.0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
40
|
+
version: '2.0'
|
|
41
41
|
description: Framework for building a search UI with Ransack
|
|
42
42
|
email:
|
|
43
43
|
- nathan.f77@gmail.com
|
|
@@ -46,6 +46,7 @@ extensions: []
|
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
48
|
- ".gitignore"
|
|
49
|
+
- ".rubocop_todo.yml"
|
|
49
50
|
- Gemfile
|
|
50
51
|
- LICENSE.txt
|
|
51
52
|
- README.md
|
|
@@ -98,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
99
|
- !ruby/object:Gem::Version
|
|
99
100
|
version: '0'
|
|
100
101
|
requirements: []
|
|
101
|
-
|
|
102
|
-
rubygems_version: 2.4.3
|
|
102
|
+
rubygems_version: 3.1.2
|
|
103
103
|
signing_key:
|
|
104
104
|
specification_version: 4
|
|
105
105
|
summary: UI Builder for Ransack
|