facet_for 0.0.7 → 0.0.8
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/version.rb +1 -1
- data/lib/facet_for.rb +49 -2
- metadata +6 -6
data/lib/facet_for/version.rb
CHANGED
data/lib/facet_for.rb
CHANGED
@@ -214,6 +214,11 @@ module FacetFor
|
|
214
214
|
facet_html << text_field
|
215
215
|
when :cont_any
|
216
216
|
collection_type = :array
|
217
|
+
|
218
|
+
if @facet[:collection].nil?
|
219
|
+
@facet[:collection] = unique_value_collection
|
220
|
+
end
|
221
|
+
|
217
222
|
if @facet[:collection].first.class == 'String'
|
218
223
|
collection_type = :string
|
219
224
|
end
|
@@ -277,14 +282,42 @@ module FacetFor
|
|
277
282
|
|
278
283
|
def check_box(value = "1")
|
279
284
|
name = "#{@facet[:column_name]}_#{@facet[:type]}"
|
280
|
-
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
if @facet[:type] == :cont_any
|
289
|
+
check_box_label = label_tag(self.name_for(name, true),
|
290
|
+
value.to_s.humanize)
|
291
|
+
check_box_name = self.name_for(name, true)
|
292
|
+
else
|
293
|
+
|
294
|
+
label_value = @facet[:column_name].to_s.humanize
|
295
|
+
|
296
|
+
case @facet[:type]
|
297
|
+
when :false
|
298
|
+
label_value = "Is Not #{label_value}"
|
299
|
+
when :null
|
300
|
+
label_value += "Is Null"
|
301
|
+
when :not_null
|
302
|
+
label_value += "Is Not Null"
|
303
|
+
end
|
304
|
+
|
305
|
+
check_box_label = label_tag(self.name_for(name, true), label_value)
|
306
|
+
check_box_name = self.name_for(name, false)
|
307
|
+
end
|
308
|
+
|
309
|
+
check_box_tag(check_box_name, value, check_box_checked(value)) + check_box_label
|
281
310
|
end
|
282
311
|
|
283
312
|
def check_box_checked(value = "1")
|
284
313
|
name = "#{@facet[:column_name]}_#{@facet[:type]}"
|
285
314
|
selected = @facet[:object].send(name)
|
286
315
|
|
287
|
-
|
316
|
+
if @facet[:type] == :cont_any
|
317
|
+
return (!selected.nil? and selected.include?(value))
|
318
|
+
else
|
319
|
+
return selected
|
320
|
+
end
|
288
321
|
|
289
322
|
end
|
290
323
|
|
@@ -292,6 +325,16 @@ module FacetFor
|
|
292
325
|
name = "#{@facet[:column_name]}_eq"
|
293
326
|
selected = @facet[:object].send(name)
|
294
327
|
|
328
|
+
# @facet[:collection] should be set if we've given it a valid
|
329
|
+
# association, or passed in a collection by hand.
|
330
|
+
#
|
331
|
+
# this assumes that we want to see all unique values from the database
|
332
|
+
# for the given column
|
333
|
+
|
334
|
+
if @facet[:collection].nil?
|
335
|
+
@facet[:collection] = unique_value_collection
|
336
|
+
end
|
337
|
+
|
295
338
|
if @facet[:collection].class == Array and
|
296
339
|
@facet[:collection].first.class == String
|
297
340
|
|
@@ -306,6 +349,10 @@ module FacetFor
|
|
306
349
|
|
307
350
|
end
|
308
351
|
|
352
|
+
def unique_value_collection
|
353
|
+
@facet[:collection] = @facet[:model].select("DISTINCT #{@facet[:column_name]}").where("#{@facet[:column_name]} IS NOT NULL").map { |m| m.send(@facet[:column_name]) }
|
354
|
+
end
|
355
|
+
|
309
356
|
def label(string_name, string_label = nil)
|
310
357
|
display_label = string_label || string_name.humanize
|
311
358
|
label_tag self.name_for(string_name), display_label
|
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.0.
|
4
|
+
version: 0.0.8
|
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-01-
|
12
|
+
date: 2012-01-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ransack
|
16
|
-
requirement: &
|
16
|
+
requirement: &78616160 !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: *78616160
|
25
25
|
description: Provides helpers for creating search forms with Ransack
|
26
26
|
email:
|
27
27
|
- jbarket@sleepunit.com
|
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
52
|
version: '0'
|
53
53
|
segments:
|
54
54
|
- 0
|
55
|
-
hash: -
|
55
|
+
hash: -507125603
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
segments:
|
63
63
|
- 0
|
64
|
-
hash: -
|
64
|
+
hash: -507125603
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project: facet_for
|
67
67
|
rubygems_version: 1.8.10
|