table_sortable 0.4.2 → 0.4.3
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.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/table_sortable/column/filter.rb +2 -1
- data/lib/table_sortable/column.rb +5 -1
- data/lib/table_sortable/controller.rb +28 -11
- data/lib/table_sortable/version.rb +1 -1
- data/lib/table_sortable/view_helpers.rb +12 -6
- 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: b5653290ccc181f9313a45feae9d71810fd5987a
|
4
|
+
data.tar.gz: bbb838cf7f287f6c9fb8a6d8ed6e9283a2dccab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93af7674f241f73b8ca78bd9f41f7548f16930b994ce53cc339687b7e6b7e98ada4570f15d8e3ab98ca76493db11bd565e60e8e0a35126f8cb60a302078abee6
|
7
|
+
data.tar.gz: ce338d84b1087859d81ee6cd827926611e35a1a626eb8c550b7c3a2545336ad17ed120ea32fc4aa6273955993873ebafabb217c9d8b6c17e181d5729d54836b7
|
data/README.md
CHANGED
@@ -182,7 +182,7 @@ end
|
|
182
182
|
content: -> (user) {"#{user.last_name}, #{user.first_name}"}
|
183
183
|
```
|
184
184
|
- `label: (string)`
|
185
|
-
<sub>default: 'Titleized' version of the column name
|
185
|
+
<sub>default: 'Titleized' version of the column name. Supports I18n internationalization. see [translateion_key](#translation-key).</sub>
|
186
186
|
Allows specifying a string to be used as the column label, displayed at the table header.
|
187
187
|
- `placeholder: (string|false)`
|
188
188
|
<sub>default: same as label</sub>
|
@@ -331,6 +331,7 @@ Notice that in this case you need to manually specify the different data attribu
|
|
331
331
|
The view will be supplied with two locals:
|
332
332
|
- `label`: the column's label
|
333
333
|
- `column`: the TableSortable::Column object
|
334
|
+
- `index`: the column's index (useful for manually setting the `data-col` attribute)
|
334
335
|
|
335
336
|
Here is an example of a full name header partial, which includes a font-awesome icon:
|
336
337
|
```erb
|
@@ -368,6 +369,7 @@ The view will be supplied with four locals:
|
|
368
369
|
- `content`: the column's content to be displayed
|
369
370
|
- `value`: the column's value
|
370
371
|
- `column`: the TableSortable::Column object
|
372
|
+
- `index`: the column's index (useful for manually setting the `data-col` attribute)
|
371
373
|
|
372
374
|
Here is an example of a full name column partial, in which the name links to the edit_user_path:
|
373
375
|
```erb
|
@@ -3,11 +3,12 @@ module TableSortable
|
|
3
3
|
class Filter
|
4
4
|
include TableSortable::Concerns::Proc
|
5
5
|
|
6
|
-
attr_accessor :query, :default_value
|
6
|
+
attr_accessor :query, :default_value, :collection
|
7
7
|
|
8
8
|
def initialize(*args)
|
9
9
|
options = args.extract_options!
|
10
10
|
@default_value = options[:filter_initial_value]
|
11
|
+
@collection = options[:filter_collection]
|
11
12
|
super :filter, options
|
12
13
|
end
|
13
14
|
|
@@ -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
|
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
|
|
@@ -9,10 +9,12 @@ module TableSortable
|
|
9
9
|
value = options[:value] || col_name
|
10
10
|
content = options[:content] || value
|
11
11
|
translation_key = options[:translation_key]
|
12
|
+
template_path = options[:template_path]
|
12
13
|
label = options[:label] || (options[:label] == false ? '' : I18n.translate("table_sortable.#{"#{translation_key}." if translation_key }#{col_name.to_s}", :default => col_name.to_s).titleize)
|
13
14
|
placeholder = options[:placeholder] || (options[:placeholder] == false ? nil : label)
|
14
15
|
# priority = options[:priority]
|
15
16
|
template = options[:template] || col_name
|
17
|
+
column_options = options[:options] || {}
|
16
18
|
|
17
19
|
# filter_defaultAttrib (data-value)
|
18
20
|
# data-sorter (=false?)
|
@@ -24,6 +26,8 @@ module TableSortable
|
|
24
26
|
@placeholder = placeholder
|
25
27
|
# @sort_priority = sort_priority
|
26
28
|
@template = template
|
29
|
+
@template_path = template_path
|
30
|
+
@options = column_options
|
27
31
|
@filter = TableSortable::Column::Filter.new(options.merge(:column => self) )
|
28
32
|
@sorter = TableSortable::Column::Sorter.new(options.merge(:column => self) )
|
29
33
|
|
@@ -11,16 +11,9 @@ module TableSortable
|
|
11
11
|
|
12
12
|
module ClassMethods
|
13
13
|
def define_columns(*args)
|
14
|
-
|
15
|
-
column_offset = options[:offset] || 0
|
16
|
-
translation_key = options[:translation_key]
|
17
|
-
columns = args
|
14
|
+
|
18
15
|
before_action(options) do
|
19
|
-
|
20
|
-
define_column_offset column_offset
|
21
|
-
columns.each do |column|
|
22
|
-
define_column column, translation_key: translation_key
|
23
|
-
end
|
16
|
+
define_columns(args)
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
@@ -47,6 +40,26 @@ module TableSortable
|
|
47
40
|
define_translation_key key
|
48
41
|
end
|
49
42
|
end
|
43
|
+
|
44
|
+
def define_template_path(path)
|
45
|
+
before_action do
|
46
|
+
define_template_path path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def define_columns(*args)
|
52
|
+
options = args.extract_options!
|
53
|
+
column_offset = options[:offset] || 0
|
54
|
+
translation_key = options[:translation_key]
|
55
|
+
template_path = options[:template_path]
|
56
|
+
columns = args
|
57
|
+
define_translation_key translation_key
|
58
|
+
define_template_path template_path
|
59
|
+
define_column_offset column_offset
|
60
|
+
columns.each do |column|
|
61
|
+
define_column column, translation_key: translation_key
|
62
|
+
end
|
50
63
|
end
|
51
64
|
|
52
65
|
def define_column(col_name, *options)
|
@@ -66,6 +79,10 @@ module TableSortable
|
|
66
79
|
@translation_key = key
|
67
80
|
end
|
68
81
|
|
82
|
+
def define_template_path(path)
|
83
|
+
@template_path = path.blank? ? nil : File.join(path, "")
|
84
|
+
end
|
85
|
+
|
69
86
|
def columns
|
70
87
|
@columns.sort_by(column_order)
|
71
88
|
end
|
@@ -73,7 +90,7 @@ module TableSortable
|
|
73
90
|
private
|
74
91
|
|
75
92
|
def default_column_options
|
76
|
-
{translation_key: @translation_key}
|
93
|
+
{translation_key: @translation_key, template_path: @template_path}
|
77
94
|
end
|
78
95
|
|
79
96
|
def filter_and_sort(scope, params = nil)
|
@@ -108,7 +125,7 @@ module TableSortable
|
|
108
125
|
|
109
126
|
public
|
110
127
|
|
111
|
-
attr_reader :column_order, :column_offset, :translation_key
|
128
|
+
attr_reader :column_order, :column_offset, :translation_key, :template_path
|
112
129
|
|
113
130
|
end
|
114
131
|
end
|
@@ -23,19 +23,24 @@ module TableSortable
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def table_sortable_headers(html_options = {})
|
26
|
-
controller.columns.map do |col|
|
26
|
+
controller.columns.map.with_index do |col, index|
|
27
27
|
th_options = {}
|
28
28
|
th_options['data-placeholder'] = col.placeholder if col.placeholder
|
29
29
|
# th_options['data-priority'] = col.sort_priority if col.sort_priority
|
30
30
|
th_options['data-filter'] = 'false' if col.filter.disabled?
|
31
31
|
th_options['data-sorter'] = 'false' if col.sorter.disabled?
|
32
|
+
unless col.filter.collection.blank?
|
33
|
+
th_options['filter-select'] = true
|
34
|
+
th_options['data-filter-options'] = col.filter.collection
|
35
|
+
end
|
32
36
|
th_options['data-value'] = col.filter.default_value if col.filter.default_value
|
33
37
|
th_options.merge!(html_options)
|
34
38
|
|
35
39
|
begin
|
36
|
-
render partial: "#{controller_path}/table_sortable/#{col.template}_header.html",
|
40
|
+
render partial: "#{col.template_path || controller_path}/table_sortable/#{col.template}_header.html",
|
37
41
|
locals: {label: col.label,
|
38
|
-
column: col
|
42
|
+
column: col,
|
43
|
+
index: index}
|
39
44
|
rescue ActionView::MissingTemplate
|
40
45
|
content_tag :th, th_options do
|
41
46
|
col.label
|
@@ -45,17 +50,18 @@ module TableSortable
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def table_sortable_columns(record, html_options = {})
|
48
|
-
controller.columns.map do |col|
|
53
|
+
controller.columns.map.with_index do |col, index|
|
49
54
|
td_options = {}
|
50
55
|
td_options['data-text'] = col.value(record) if col.value(record) != col.content(record)
|
51
56
|
td_options.merge!(html_options)
|
52
57
|
|
53
58
|
begin
|
54
|
-
render partial: "#{controller_path}/table_sortable/#{col.template}_column.html",
|
59
|
+
render partial: "#{col.template_path || controller_path}/table_sortable/#{col.template}_column.html",
|
55
60
|
locals: {content: col.content(record),
|
56
61
|
value: col.value(record),
|
57
62
|
source: record,
|
58
|
-
column: col
|
63
|
+
column: col,
|
64
|
+
index: index}
|
59
65
|
rescue ActionView::MissingTemplate
|
60
66
|
content_tag :td, td_options do
|
61
67
|
col.value(record)
|
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: 0.4.
|
4
|
+
version: 0.4.3
|
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-06-
|
11
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|