facet_for 0.1.2 → 0.1.4
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.
- data/lib/facet_for.rb +10 -4
- data/lib/facet_for/form_builder.rb +5 -0
- data/lib/facet_for/version.rb +1 -1
- metadata +5 -11
data/lib/facet_for.rb
CHANGED
@@ -106,6 +106,7 @@ module FacetFor
|
|
106
106
|
@facet[:association_name] = "#{association.first.plural_name}"
|
107
107
|
@facet[:column_name] = "#{association.first.plural_name}_id"
|
108
108
|
@facet[:clean_column_name] = "#{association.first.name.to_s.singularize}_id"
|
109
|
+
@facet[:association_primary_key] = association.first.primary_key_column.name
|
109
110
|
|
110
111
|
elsif association.first.macro == :belongs_to
|
111
112
|
|
@@ -114,6 +115,7 @@ module FacetFor
|
|
114
115
|
@facet[:association_class] = association.first.klass
|
115
116
|
@facet[:association_name] = association.first.name
|
116
117
|
@facet[:column_name] = association.first.foreign_key
|
118
|
+
@facet[:association_primary_key] = association.first.primary_key_column.name
|
117
119
|
|
118
120
|
end
|
119
121
|
|
@@ -127,8 +129,11 @@ module FacetFor
|
|
127
129
|
# based on this association. We only want to use distinct values.
|
128
130
|
# This could probably be cleaner, but it works.
|
129
131
|
|
130
|
-
@facet[:collection]
|
132
|
+
unless @facet[:collection]
|
133
|
+
unique_objects = @facet[:model].unscoped.select("DISTINCT #{clean_column}").where("#{clean_column} IS NOT NULL").map { |x| x.send(clean_column) }.join(", ")
|
131
134
|
|
135
|
+
@facet[:collection] = @facet[:association_class].unscoped.where("#{@facet[:association_primary_key]} IN (#{unique_objects})")
|
136
|
+
end
|
132
137
|
end
|
133
138
|
else
|
134
139
|
|
@@ -343,11 +348,12 @@ module FacetFor
|
|
343
348
|
|
344
349
|
return select_tag self.name_for(name),
|
345
350
|
options_for_select(@facet[:collection], selected),
|
346
|
-
:include_blank => true
|
351
|
+
:include_blank => true, :class => @facet[:class]
|
347
352
|
else
|
348
353
|
return select_tag self.name_for(name),
|
349
354
|
options_from_collection_for_select(@facet[:collection], :id, :to_s,
|
350
|
-
selected), :include_blank => true
|
355
|
+
selected), :include_blank => true,
|
356
|
+
:class => @facet[:class]
|
351
357
|
end
|
352
358
|
|
353
359
|
end
|
@@ -357,7 +363,7 @@ module FacetFor
|
|
357
363
|
end
|
358
364
|
|
359
365
|
def unique_value_collection
|
360
|
-
@facet[:collection] = @facet[:model].unscoped.select("DISTINCT #{clean_column}").where("#{clean_column} IS NOT NULL").map { |
|
366
|
+
@facet[:collection] = @facet[:model].unscoped.select("DISTINCT #{clean_column}").where("#{clean_column} IS NOT NULL").map { |x| x.send(clean_column) }
|
361
367
|
end
|
362
368
|
|
363
369
|
def label(string_name, string_label = nil)
|
@@ -23,6 +23,8 @@ class ActionView::Helpers::FormBuilder
|
|
23
23
|
facet[:column_name] = column
|
24
24
|
facet[:column_type] = options[:column_type]
|
25
25
|
|
26
|
+
facet[:includes] = options[:includes]
|
27
|
+
|
26
28
|
# This is the type of field we will render. If this isn't provided, we'll
|
27
29
|
# determine this based on facet_column_type
|
28
30
|
|
@@ -41,6 +43,9 @@ class ActionView::Helpers::FormBuilder
|
|
41
43
|
# Are we labeling it differently?
|
42
44
|
facet[:label] = options[:label]
|
43
45
|
|
46
|
+
# How about adding a class?
|
47
|
+
facet[:class] = options[:class]
|
48
|
+
|
44
49
|
@facet = FacetFor::Facet.new(facet)
|
45
50
|
|
46
51
|
facet_html << @facet.render_facet
|
data/lib/facet_for/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facet_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ransack
|
16
|
-
requirement: &
|
16
|
+
requirement: &17945960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17945960
|
25
25
|
description: Provides helpers for creating search forms with Ransack
|
26
26
|
email:
|
27
27
|
- jbarket@sleepunit.com
|
@@ -50,21 +50,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- - ! '>='
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
|
-
segments:
|
54
|
-
- 0
|
55
|
-
hash: -544917759
|
56
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
54
|
none: false
|
58
55
|
requirements:
|
59
56
|
- - ! '>='
|
60
57
|
- !ruby/object:Gem::Version
|
61
58
|
version: '0'
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
hash: -544917759
|
65
59
|
requirements: []
|
66
60
|
rubyforge_project: facet_for
|
67
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.15
|
68
62
|
signing_key:
|
69
63
|
specification_version: 3
|
70
64
|
summary: Provides helpers for creating search forms with Ransack
|