iquest-simple_table 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iquest/simple_table/table_builder.rb +37 -14
- data/lib/iquest/simple_table/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22a88ebc15153bfbddfa1b076b799834eef673c
|
4
|
+
data.tar.gz: 14f4ac09b39995cfb23a0336d4b6edffc57280c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7356d83577cf0749b74a32d2dd247c89272943297a89365eb4c0362115e23842b26359350ddcc74fe62df5fd7f19dc1e72fb7d1134b9ddef0be0ae730e8e9791
|
7
|
+
data.tar.gz: deffa5e1599cae4b17533e848962ce8b4a0d4a593ea8a1c6f419e41ac0540213c4c16a62a18c28ea487a6d989522d69c8896a3f2f0a025f14c6ec57f86a2bed3
|
@@ -25,9 +25,12 @@ module Iquest
|
|
25
25
|
options[:search_url] ||= polymorphic_path(collection_or_search.map {|o| o.is_a?(Ransack::Search) ? o.klass : o})
|
26
26
|
elsif collection_or_search.is_a?(Array) && (collection = collection_or_search.detect {|o| o.is_a?(ActiveRecord::Relation) || o.is_a?(ActiveRecord::AssociationRelation)})
|
27
27
|
@collection = collection
|
28
|
-
@klass = @collection.klass
|
29
|
-
|
30
|
-
|
28
|
+
@klass = @collection.klass
|
29
|
+
elsif collection_or_search.is_a?(Array) && (collection_or_search.any? || options[:class])
|
30
|
+
@collection = collection_or_search
|
31
|
+
@klass = options[:class] || collection_or_search.first.class
|
32
|
+
else
|
33
|
+
raise TypeError, 'ActiveRecord::Relation, ActiveRecord::AssociationRelation, Ransack::Search or Array of ActiveModel like objects expected'
|
31
34
|
end
|
32
35
|
apply_pagination
|
33
36
|
#draper
|
@@ -46,11 +49,7 @@ module Iquest
|
|
46
49
|
options = args.extract_options!
|
47
50
|
search = options.delete(:search)
|
48
51
|
@columns[attr] = options
|
49
|
-
|
50
|
-
@columns[attr][:label] ||= Ransack::Translate.attribute(attr.to_s.tr('.','_'), context: @search.context)
|
51
|
-
else
|
52
|
-
@columns[attr][:label] ||= @klass.human_attribute_name(attr)
|
53
|
-
end
|
52
|
+
@columns[attr][:label] ||= column_label(attr)
|
54
53
|
#iniciaizce search options
|
55
54
|
if search.is_a?(Symbol) || search.is_a?(String)
|
56
55
|
@columns[attr][:search] = {search.to_sym => {}}
|
@@ -61,6 +60,7 @@ module Iquest
|
|
61
60
|
end
|
62
61
|
@columns[attr][:formatter] ||= block if block_given?
|
63
62
|
@columns[attr][:sort] ||= attr.to_s.tr('.','_') unless @columns[attr][:sort] == false #sort link attr
|
63
|
+
@columns[attr][:html] ||= {}
|
64
64
|
end
|
65
65
|
|
66
66
|
def action(*args, &block)
|
@@ -213,12 +213,21 @@ module Iquest
|
|
213
213
|
end
|
214
214
|
|
215
215
|
def render_label(column)
|
216
|
-
attr = column
|
216
|
+
attr = column
|
217
217
|
options = @columns[attr]
|
218
218
|
label = options[:label] || attr.to_s
|
219
|
-
sort = options[:sort]
|
219
|
+
sort = options[:sort]
|
220
220
|
if @search && sort
|
221
|
-
|
221
|
+
sort_attr = attr
|
222
|
+
sort_options = {}
|
223
|
+
if sort.is_a?(Hash)
|
224
|
+
sort_attr = sort.keys.first
|
225
|
+
sort_options = sort[sort_attr]
|
226
|
+
elsif sort.is_a?(Symbol) || sort.is_a?(String)
|
227
|
+
sort_attr = sort
|
228
|
+
end
|
229
|
+
sort_options.reverse_merge!(method: search_action)
|
230
|
+
sort_link(@search, sort_attr, label, sort_options)
|
222
231
|
else
|
223
232
|
label
|
224
233
|
end
|
@@ -234,9 +243,9 @@ module Iquest
|
|
234
243
|
cell_value = render_value(obj, value, &formatter)
|
235
244
|
cell_classes = []
|
236
245
|
cell_classes << "rowlink-skip" if include_link?(cell_value)
|
237
|
-
cell_classes << "#{options[:class]}"
|
238
|
-
content_tag :td, class: cell_classes
|
239
|
-
cell_value
|
246
|
+
cell_classes << "#{options[:html][:class]}"
|
247
|
+
content_tag :td, class: cell_classes do
|
248
|
+
"#{cell_value}".html_safe
|
240
249
|
end
|
241
250
|
end
|
242
251
|
|
@@ -324,6 +333,20 @@ module Iquest
|
|
324
333
|
col.to_s.split('.').inject(obj, :try)
|
325
334
|
end
|
326
335
|
|
336
|
+
def column_label(attr)
|
337
|
+
if attr_class(attr).respond_to?(:human_attribute_name)
|
338
|
+
attr_class(attr).try(:human_attribute_name, attr)
|
339
|
+
elsif @search
|
340
|
+
Ransack::Translate.attribute(attr.to_s.tr('.','_'), context: @search.context)
|
341
|
+
else
|
342
|
+
attr.to_s.humanize
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def attr_class(attr)
|
347
|
+
attr.to_s.split('.')[0..-2].inject(@klass) {|klass, assoc| klass.try(:reflect_on_association, assoc).try(:klass)}
|
348
|
+
end
|
349
|
+
|
327
350
|
def column_count
|
328
351
|
@columns.count
|
329
352
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iquest-simple_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Dusanek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ransack_simple_form
|