table_sortable 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -4
- data/lib/table_sortable/column.rb +2 -10
- data/lib/table_sortable/version.rb +1 -1
- data/lib/table_sortable/view_helpers.rb +23 -7
- 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: ef99429a8e38ac1b35cca7c1132ac37dd1010e90
|
4
|
+
data.tar.gz: 990f9be300de2361525306f8441b9403295df3ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4476c99e0fcb47487687ae2b423e31e7b4eb13279853cd08525c77bbde688905d6a20ebb94f1c6e18c6715a11046f56f3be66f6569d4efee4187f9ae35bb58b5
|
7
|
+
data.tar.gz: ff9103a5e53aeaa7b3c14db4d3b30b1096072d06a044b995837e0bc894579d8c3735c2ab61d186ca8d8bf294a0d6da95c44af536fb367467671df6d8777ba28e
|
data/README.md
CHANGED
@@ -365,11 +365,8 @@ you may create a partial inside a `table_sortable` folder nested inside the cont
|
|
365
365
|
Notice that in this case you need to manually specify the different data attributes that correspond to the behaviour you wish this column to have.
|
366
366
|
|
367
367
|
The view will be supplied with four locals:
|
368
|
-
- `
|
369
|
-
- `content`: the column's content to be displayed
|
370
|
-
- `value`: the column's value
|
368
|
+
- `record`: the source ActiveRecord object
|
371
369
|
- `column`: the TableSortable::Column object
|
372
|
-
- `index`: the column's index (useful for manually setting the `data-col` attribute)
|
373
370
|
|
374
371
|
Here is an example of a full name column partial, in which the name links to the edit_user_path:
|
375
372
|
```erb
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module TableSortable
|
2
2
|
class Column
|
3
3
|
|
4
|
-
attr_reader :name, :label, :filter, :sorter, :template, :placeholder, :content, :translation_key, :options, :template_path
|
4
|
+
attr_reader :name, :label, :filter, :sorter, :template, :placeholder, :content, :translation_key, :options, :template_path
|
5
5
|
|
6
6
|
def initialize(col_name, *options)
|
7
7
|
|
@@ -14,7 +14,6 @@ module TableSortable
|
|
14
14
|
placeholder = options[:placeholder] || (options[:placeholder] == false ? nil : label)
|
15
15
|
template = options[:template] || col_name
|
16
16
|
column_options = options[:options] || {}
|
17
|
-
controller = options[:controller]
|
18
17
|
|
19
18
|
@name = col_name
|
20
19
|
@value = value.respond_to?(:call) ? value : -> (record) { record.send(value) }
|
@@ -23,14 +22,7 @@ module TableSortable
|
|
23
22
|
@placeholder = placeholder
|
24
23
|
@template = template
|
25
24
|
@template_path = template_path
|
26
|
-
|
27
|
-
view_path = @template_path || (defined?(Rails) ? File.join("#{controller.controller_path}/table_sortable/") : '')
|
28
|
-
|
29
|
-
view_filename = "#{@template}_column.html"
|
30
|
-
@column_partial = controller.lookup_context.find_all(File.join(view_path, "_#{view_filename}")).any? ? File.join(view_path, "#{view_filename}") : false
|
31
|
-
|
32
|
-
view_filename = "#{@template}_header.html"
|
33
|
-
@header_partial = controller.lookup_context.find_all(File.join(view_path, "_#{view_filename}")).any? ? File.join(view_path, "#{view_filename}") : false
|
25
|
+
@translation_key = translation_key
|
34
26
|
|
35
27
|
@options = column_options
|
36
28
|
@filter = TableSortable::Column::Filter.new(options.merge(:column => self) )
|
@@ -35,8 +35,11 @@ module TableSortable
|
|
35
35
|
th_options['data-value'] = col.filter.default_value if col.filter.default_value
|
36
36
|
th_options.merge!(html_options)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
view_path = col.template_path || (defined?(Rails) ? File.join("#{controller.controller_path}/table_sortable/") : '')
|
39
|
+
view_filename = "#{col.template}_header.html"
|
40
|
+
if controller.lookup_context.find_all(File.join(view_path, "_#{view_filename}")).any?
|
41
|
+
|
42
|
+
render partial: File.join(view_path, "#{view_filename}"),
|
40
43
|
locals: {label: col.label,
|
41
44
|
column: col,
|
42
45
|
index: index}
|
@@ -48,7 +51,7 @@ module TableSortable
|
|
48
51
|
end.join.html_safe
|
49
52
|
end
|
50
53
|
|
51
|
-
def table_sortable_columns(record, row_number, html_options = {})
|
54
|
+
def table_sortable_columns(record, row_number = nil, html_options = {})
|
52
55
|
controller.columns.map.with_index do |col, index|
|
53
56
|
value = col.value(record)
|
54
57
|
content = col.content(record)
|
@@ -56,8 +59,10 @@ module TableSortable
|
|
56
59
|
td_options['data-text'] = value if value != content
|
57
60
|
td_options.merge!(html_options)
|
58
61
|
|
59
|
-
if col.
|
62
|
+
if row_number && @column_html[col.name]
|
60
63
|
@column_html[col.name][row_number]
|
64
|
+
elsif row_number.nil? && (col_partial = partial_for(col))
|
65
|
+
render partial: col_partial, locals: {column: col, record: record}
|
61
66
|
else
|
62
67
|
content_tag :td, td_options do
|
63
68
|
content
|
@@ -68,11 +73,22 @@ module TableSortable
|
|
68
73
|
|
69
74
|
def table_sortable_rows(layout, collection, html_options = {})
|
70
75
|
@column_html = {}
|
71
|
-
controller.columns.
|
72
|
-
|
73
|
-
|
76
|
+
controller.columns.each do |col|
|
77
|
+
col_partial = partial_for(col)
|
78
|
+
if col_partial
|
79
|
+
@column_html[col.name] = []
|
80
|
+
render partial: col_partial, collection: collection, as: :record, layout: '/table_sortable/capture_column.html.erb', locals: {column: col}
|
81
|
+
end
|
74
82
|
end
|
75
83
|
render partial: '/table_sortable/row.html.erb', layout: layout, collection: collection, as: :record, locals: {html_options: html_options}
|
76
84
|
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def partial_for(col)
|
89
|
+
view_path = col.template_path || (defined?(Rails) ? File.join("#{controller.controller_path}/table_sortable/") : '')
|
90
|
+
view_filename = "#{col.template}_column.html"
|
91
|
+
File.join(view_path, "#{view_filename}") if controller.lookup_context.find_all(File.join(view_path, "_#{view_filename}")).any?
|
92
|
+
end
|
77
93
|
end
|
78
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_sortable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.alpha.
|
4
|
+
version: 1.0.0.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Davidov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|