ransack_ui 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/app/views/ransack/_advanced_search.html.haml +2 -2
- data/app/views/ransack/_condition_fields.html.haml +2 -2
- data/app/views/ransack/_grouping_fields.html.haml +2 -2
- data/app/views/ransack/_search.html.haml +4 -4
- data/lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb +26 -1
- data/lib/ransack_ui/ransack_overrides/configuration.rb +11 -0
- data/lib/ransack_ui/ransack_overrides/helpers/form_builder.rb +20 -0
- data/lib/ransack_ui/version.rb +1 -1
- data/lib/ransack_ui/view_helpers.rb +4 -4
- metadata +5 -4
@@ -1,10 +1,10 @@
|
|
1
1
|
= search_form_for search, :url => url_for(:action => :index), :html => {:method => :get, :class => "advanced_search"}, :remote => true do |f|
|
2
2
|
|
3
3
|
= f.grouping_fields do |g|
|
4
|
-
= render 'ransack/grouping_fields', :f => g
|
4
|
+
= render 'ransack/grouping_fields', :f => g
|
5
5
|
|
6
6
|
%p
|
7
|
-
= link_to_add_fields t(:advanced_search_add_group), f, :grouping
|
7
|
+
= link_to_add_fields t(:advanced_search_add_group), f, :grouping
|
8
8
|
|
9
9
|
%p
|
10
10
|
= hidden_field_tag :distinct, '1'
|
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
= f.attribute_fields do |a|
|
6
6
|
%span.fields{ "data-object-name" => f.object_name }
|
7
|
-
= a.attribute_select({
|
7
|
+
= a.attribute_select({}, :class => 'ransack_attribute')
|
8
8
|
|
9
|
-
= f.predicate_select
|
9
|
+
= f.predicate_select({}, :class => 'ransack_predicate')
|
10
10
|
|
11
11
|
= f.value_fields do |v|
|
12
12
|
%span.fields.value{ 'data-object-name' => f.object_name }
|
@@ -6,7 +6,7 @@
|
|
6
6
|
.filters
|
7
7
|
- f.object.build_condition unless f.object.conditions.any?
|
8
8
|
= f.condition_fields do |c|
|
9
|
-
= render 'ransack/condition_fields', :f => c
|
9
|
+
= render 'ransack/condition_fields', :f => c
|
10
10
|
|
11
11
|
%p
|
12
|
-
= link_to_add_fields t(:advanced_search_add_condition), f, :condition
|
12
|
+
= link_to_add_fields t(:advanced_search_add_condition), f, :condition
|
@@ -6,8 +6,8 @@
|
|
6
6
|
%li
|
7
7
|
= link_to 'Advanced Search', '#', :"data-search-form" => "advanced_search", :class => (!params[:q] ? "" : " active")
|
8
8
|
|
9
|
-
.search_form#basic_search{
|
10
|
-
= render "ransack/basic_search"
|
9
|
+
.search_form#basic_search{ :style => (params[:q] ? 'display: none;' : '') }
|
10
|
+
= render "ransack/basic_search"
|
11
11
|
|
12
|
-
.search_form#advanced_search{
|
13
|
-
= render "ransack/advanced_search"
|
12
|
+
.search_form#advanced_search{ :style => (!params[:q] ? 'display: none;' : '') }
|
13
|
+
= render "ransack/advanced_search"
|
@@ -10,7 +10,32 @@ module Ransack
|
|
10
10
|
columns.map{|c| [c.name, c.type] } +
|
11
11
|
_ransackers.keys.map {|k| [k, :string] }
|
12
12
|
end
|
13
|
+
|
14
|
+
def self.extended(base)
|
15
|
+
alias :search :ransack unless base.method_defined? :search
|
16
|
+
base.class_eval do
|
17
|
+
class_attribute :_ransackers
|
18
|
+
class_attribute :_ransackable_associations
|
19
|
+
self._ransackers ||= {}
|
20
|
+
self._ransackable_associations ||= []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_ransackable_associations(associations)
|
25
|
+
self._ransackable_associations = associations
|
26
|
+
end
|
27
|
+
|
28
|
+
def ransackable_associations(auth_object = nil)
|
29
|
+
all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
|
30
|
+
if self._ransackable_associations.any?
|
31
|
+
# Return intersection of all associations, and associations defined on the model
|
32
|
+
all_associations & self._ransackable_associations
|
33
|
+
else
|
34
|
+
all_associations
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
13
38
|
end
|
14
39
|
end
|
15
40
|
end
|
16
|
-
end
|
41
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'ransack/configuration'
|
2
|
+
|
3
|
+
module Ransack
|
4
|
+
Configuration.class_eval do
|
5
|
+
# Set default predicate options for predicate_select in form builder
|
6
|
+
# This is ignored if any options are passed
|
7
|
+
def default_predicates=(options)
|
8
|
+
self.options[:default_predicates] = options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -6,6 +6,12 @@ module Ransack
|
|
6
6
|
def attribute_select(options = {}, html_options = {})
|
7
7
|
raise ArgumentError, "attribute_select must be called inside a search FormBuilder!" unless object.respond_to?(:context)
|
8
8
|
options[:include_blank] = true unless options.has_key?(:include_blank)
|
9
|
+
|
10
|
+
# Set default associations set on model with 'has_ransackable_associations'
|
11
|
+
if options[:associations].nil?
|
12
|
+
options[:associations] = object.context.klass.ransackable_associations
|
13
|
+
end
|
14
|
+
|
9
15
|
bases = [''] + association_array(options[:associations])
|
10
16
|
if bases.size > 1
|
11
17
|
@template.select(
|
@@ -27,6 +33,20 @@ module Ransack
|
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
36
|
+
def predicate_select(options = {}, html_options = {})
|
37
|
+
options = Ransack.options[:default_predicates] || {} if options.blank?
|
38
|
+
|
39
|
+
options[:compounds] = true if options[:compounds].nil?
|
40
|
+
keys = predicate_keys(options)
|
41
|
+
# If condition is newly built with build_condition(),
|
42
|
+
# then replace the default predicate with the first in the ordered list
|
43
|
+
@object.predicate_name = keys.first if @object.default?
|
44
|
+
@template.collection_select(
|
45
|
+
@object_name, :p, keys.map {|k| [k, Translate.predicate(k)]}, :first, :last,
|
46
|
+
objectify_options(options), @default_options.merge(html_options)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
30
50
|
def attribute_collection_for_bases(bases)
|
31
51
|
bases.map do |base|
|
32
52
|
begin
|
data/lib/ransack_ui/version.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module RansackUI
|
2
2
|
module ViewHelpers
|
3
|
-
def ransack_search_form
|
4
|
-
render 'ransack/search'
|
3
|
+
def ransack_search_form
|
4
|
+
render 'ransack/search'
|
5
5
|
end
|
6
6
|
|
7
|
-
def link_to_add_fields(name, f, type
|
7
|
+
def link_to_add_fields(name, f, type)
|
8
8
|
new_object = f.object.send "build_#{type}"
|
9
9
|
fields = f.send("#{type}_fields", new_object, :child_index => "new_#{type}") do |builder|
|
10
|
-
render "ransack/#{type.to_s}_fields", :f => builder
|
10
|
+
render "ransack/#{type.to_s}_fields", :f => builder
|
11
11
|
end
|
12
12
|
link_to name, nil, :class => "add_fields", "data-field-type" => type, "data-content" => "#{fields}"
|
13
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack_ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Framework for building a search UI with Ransack
|
15
15
|
email:
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/ransack_ui.rb
|
37
37
|
- lib/ransack_ui/rails/engine.rb
|
38
38
|
- lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb
|
39
|
+
- lib/ransack_ui/ransack_overrides/configuration.rb
|
39
40
|
- lib/ransack_ui/ransack_overrides/context.rb
|
40
41
|
- lib/ransack_ui/ransack_overrides/helpers/form_builder.rb
|
41
42
|
- lib/ransack_ui/version.rb
|
@@ -56,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
57
|
version: '0'
|
57
58
|
segments:
|
58
59
|
- 0
|
59
|
-
hash: -
|
60
|
+
hash: -2955605175423395892
|
60
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
62
|
none: false
|
62
63
|
requirements:
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
segments:
|
67
68
|
- 0
|
68
|
-
hash: -
|
69
|
+
hash: -2955605175423395892
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
72
|
rubygems_version: 1.8.24
|