table_sortable 0.4.6 → 0.4.7
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/lib/table_sortable/column.rb +13 -6
- data/lib/table_sortable/controller.rb +1 -1
- data/lib/table_sortable/result.rb +2 -1
- data/lib/table_sortable/version.rb +1 -1
- data/lib/table_sortable/view_helpers.rb +14 -21
- 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: c8def2534bcfe05e1ab749a6853d1edd26a751ad
|
4
|
+
data.tar.gz: 91ad20906e10c0d9d4a49afaa198a88e9cf6e7f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0c532401296051648a7ec339a08ab7fcb4d970df8026177210c4e31f0bf1d054dbf129044c917d12a45137c1014822179f4413ca6eade55cef9093820fab08
|
7
|
+
data.tar.gz: 0731c3520684a99a85ad022bc30027f3f7aac04a8d6804856502013114af07f536736364e45c94c43c4bf408a4d9a17813bed72ac5c6917cbd1b9d9b91960596
|
@@ -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, :column_partial, :header_partial
|
5
5
|
|
6
6
|
def initialize(col_name, *options)
|
7
7
|
|
@@ -12,21 +12,28 @@ module TableSortable
|
|
12
12
|
template_path = options[:template_path]
|
13
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)
|
14
14
|
placeholder = options[:placeholder] || (options[:placeholder] == false ? nil : label)
|
15
|
-
# priority = options[:priority]
|
16
15
|
template = options[:template] || col_name
|
17
16
|
column_options = options[:options] || {}
|
18
|
-
|
19
|
-
# filter_defaultAttrib (data-value)
|
20
|
-
# data-sorter (=false?)
|
17
|
+
controller = options[:controller]
|
21
18
|
|
22
19
|
@name = col_name
|
23
20
|
@value = value.respond_to?(:call) ? value : -> (record) { record.send(value) }
|
24
21
|
@content = content.respond_to?(:call) ? content : -> (record) { record.send(content) }
|
25
22
|
@label = label
|
26
23
|
@placeholder = placeholder
|
27
|
-
# @sort_priority = sort_priority
|
28
24
|
@template = template
|
29
25
|
@template_path = template_path
|
26
|
+
|
27
|
+
view_path = @template_path || (defined?(Rails) ? File.join(Rails.root, 'app', 'views', "#{controller.controller_path}/table_sortable/") : '')
|
28
|
+
|
29
|
+
view_filename = "_#{@template}_column.html"
|
30
|
+
view = Dir.glob(File.join(view_path, "#{view_filename}.*"))
|
31
|
+
@column_partial = view.any? ? File.join(view_path, "#{view_filename}") : false
|
32
|
+
|
33
|
+
view_filename = "_#{@template}_header.html"
|
34
|
+
view = Dir.glob(File.join(view_path, "#{view_filename}.*"))
|
35
|
+
@header_partial = view.any? ? File.join(view_path, "#{view_filename}") : false
|
36
|
+
|
30
37
|
@options = column_options
|
31
38
|
@filter = TableSortable::Column::Filter.new(options.merge(:column => self) )
|
32
39
|
@sorter = TableSortable::Column::Sorter.new(options.merge(:column => self) )
|
@@ -65,7 +65,7 @@ module TableSortable
|
|
65
65
|
|
66
66
|
def define_column(col_name, *options)
|
67
67
|
options = default_column_options.merge(options.extract_options!)
|
68
|
-
@columns.add(col_name, options)
|
68
|
+
@columns.add(col_name, options.merge(controller: self))
|
69
69
|
end
|
70
70
|
|
71
71
|
def define_column_order(*order)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module TableSortable
|
2
2
|
class Result < Array
|
3
3
|
|
4
|
-
attr_reader :total_count
|
4
|
+
attr_reader :total_count, :unpaginated
|
5
5
|
|
6
6
|
def initialize(the_array, page, page_size)
|
7
|
+
@unpaginated = the_array
|
7
8
|
@total_count = the_array.length
|
8
9
|
super(the_array[(page)*page_size, page_size])
|
9
10
|
end
|
@@ -24,31 +24,25 @@ module TableSortable
|
|
24
24
|
|
25
25
|
def table_sortable_headers(html_options = {})
|
26
26
|
controller.columns.map.with_index do |col, index|
|
27
|
-
label = col.label
|
28
|
-
placeholder = col.placeholder
|
29
|
-
filter = col.filter
|
30
|
-
|
31
27
|
th_options = {}
|
32
|
-
th_options['data-placeholder'] = placeholder if placeholder
|
28
|
+
th_options['data-placeholder'] = col.placeholder if col.placeholder
|
33
29
|
# th_options['data-priority'] = col.sort_priority if col.sort_priority
|
34
|
-
th_options['data-filter'] = 'false' if filter.disabled?
|
30
|
+
th_options['data-filter'] = 'false' if col.filter.disabled?
|
35
31
|
th_options['data-sorter'] = 'false' if col.sorter.disabled?
|
36
|
-
unless filter.collection.blank?
|
37
|
-
th_options['filter-
|
38
|
-
th_options['data-filter-options'] = filter.collection
|
32
|
+
unless col.filter.collection.blank?
|
33
|
+
th_options['data-filter-options'] = col.filter.collection.to_json
|
39
34
|
end
|
40
|
-
th_options['data-value'] = filter.default_value if filter.default_value
|
35
|
+
th_options['data-value'] = col.filter.default_value if col.filter.default_value
|
41
36
|
th_options.merge!(html_options)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
locals: {label: label,
|
37
|
+
|
38
|
+
if col.header_partial
|
39
|
+
render file: col.header_partial,
|
40
|
+
locals: {label: col.label,
|
47
41
|
column: col,
|
48
42
|
index: index}
|
49
43
|
else
|
50
44
|
content_tag :th, th_options do
|
51
|
-
label
|
45
|
+
col.label
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end.join.html_safe
|
@@ -61,10 +55,9 @@ module TableSortable
|
|
61
55
|
td_options = {}
|
62
56
|
td_options['data-text'] = value if value != content
|
63
57
|
td_options.merge!(html_options)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
render file: File.join(view_path, view_filename),
|
58
|
+
|
59
|
+
if col.column_partial
|
60
|
+
render file: col.column_partial,
|
68
61
|
locals: {content: content,
|
69
62
|
value: value,
|
70
63
|
source: record,
|
@@ -72,7 +65,7 @@ module TableSortable
|
|
72
65
|
index: index}
|
73
66
|
else
|
74
67
|
content_tag :td, td_options do
|
75
|
-
|
68
|
+
content
|
76
69
|
end
|
77
70
|
end
|
78
71
|
end.join.html_safe
|
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.7
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|