tableficate 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -48
- data/app/views/tableficate/{_column_header.html.erb → _header.html.erb} +0 -0
- data/app/views/tableficate/_table.html.erb +4 -4
- data/app/views/tableficate/filters/_check_box.html.erb +4 -0
- data/app/views/tableficate/{_input_filter.html.erb → filters/_input.html.erb} +0 -0
- data/app/views/tableficate/{_input_range_filter.html.erb → filters/_input_range.html.erb} +0 -0
- data/app/views/tableficate/filters/_radio.html.erb +4 -0
- data/app/views/tableficate/{_select_filter.html.erb → filters/_select.html.erb} +0 -0
- data/app/views/tableficate/filters/_select_range.html.erb +6 -0
- data/changelog.markdown +8 -0
- data/lib/tableficate/action_column.rb +2 -2
- data/lib/tableficate/base.rb +2 -2
- data/lib/tableficate/column.rb +6 -2
- data/lib/tableficate/exceptions.rb +4 -0
- data/lib/tableficate/filters/base.rb +21 -0
- data/lib/tableficate/filters/check_box.rb +6 -0
- data/lib/tableficate/filters/choice.rb +23 -0
- data/lib/tableficate/filters/collection.rb +30 -0
- data/lib/tableficate/filters/input.rb +12 -0
- data/lib/tableficate/filters/input_range.rb +57 -0
- data/lib/tableficate/filters/radio.rb +6 -0
- data/lib/tableficate/filters/select.rb +6 -0
- data/lib/tableficate/filters/select_range.rb +54 -0
- data/lib/tableficate/helper.rb +69 -4
- data/lib/tableficate/table.rb +56 -10
- data/lib/tableficate/version.rb +1 -1
- data/lib/tableficate.rb +9 -3
- data/spec/action_column_spec.rb +1 -1
- data/spec/column_spec.rb +8 -0
- data/spec/filters/base_spec.rb +30 -0
- data/spec/filters/choice_spec.rb +13 -0
- data/spec/filters/collection_spec.rb +94 -0
- data/spec/filters/input_range_spec.rb +91 -0
- data/spec/filters/input_spec.rb +24 -0
- data/spec/generators/tableficate_table_spec.rb +20 -0
- data/spec/generators/tableficate_theme_spec.rb +11 -0
- data/spec/helper_spec.rb +164 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/table_spec.rb +38 -13
- data/spec/test_app/Gemfile +1 -1
- data/spec/test_app/app/controllers/filters_controller.rb +7 -0
- data/spec/test_app/app/views/filters/check_box_tags.html.erb +14 -0
- data/spec/test_app/app/views/filters/multi_select_from_string.html.erb +11 -0
- data/spec/test_app/app/views/filters/multi_select_tag.html.erb +11 -0
- data/spec/test_app/app/views/filters/radio_tags.html.erb +14 -0
- data/spec/test_app/app/views/filters/select_from_string.html.erb +11 -0
- data/spec/test_app/app/views/filters/select_tag.html.erb +11 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_data.html.erb +1 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_header.html.erb +8 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_row.html.erb +5 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_table.html.erb +36 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box.html.erb +7 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input_range.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_radio.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select_range_filter.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_data.html.erb +1 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_header.html.erb +8 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_row.html.erb +5 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/_table.html.erb +36 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_check_box.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input_range.html.erb +6 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio.html.erb +7 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select.html.erb +4 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select_range_filter.html.erb +6 -0
- data/spec/test_app/config/routes.rb +1 -56
- data/tableficate.gemspec +4 -2
- metadata +122 -27
- data/lib/tableficate/filters/filter.rb +0 -19
- data/lib/tableficate/filters/input_filters.rb +0 -64
- data/lib/tableficate/filters/select_filter.rb +0 -11
- data/spec/filter_spec.rb +0 -30
- data/spec/input_filter_spec.rb +0 -90
- data/spec/select_filter_spec.rb +0 -10
data/README.markdown
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Tableficate
|
2
|
-
A DSL for easy table creation with sorting and filtering. It tries to do to tables what simple_form and formtastic have done for forms. Below you'll find basic documentation with more compelete docs
|
2
|
+
A DSL for easy table creation with sorting and filtering. It tries to do to tables what simple_form and formtastic have done for forms. Below you'll find basic documentation with more compelete docs in the [wiki](https://github.com/sei-mi/tableficate/wiki).
|
3
|
+
|
4
|
+
This project follows [Semantic Versioning](http://semver.org/).
|
3
5
|
|
4
6
|
## Installation
|
5
7
|
|
@@ -7,7 +9,7 @@ A DSL for easy table creation with sorting and filtering. It tries to do to tabl
|
|
7
9
|
|
8
10
|
If you're using Bundler, add this to your Gemfile:
|
9
11
|
|
10
|
-
gem 'tableficate'
|
12
|
+
gem 'tableficate', '~0.2.0'
|
11
13
|
|
12
14
|
## Support
|
13
15
|
|
@@ -33,45 +35,43 @@ Our controller:
|
|
33
35
|
|
34
36
|
@accounts = Accounts.active.tableficate(params[:accounts]).page(params.try(:[], :accounts_page) || 1)
|
35
37
|
|
36
|
-
Here we're getting active accounts, calling tableficate and then paginating with Kaminari. Tableficate works on Arel objects and passes out an Arel so you can add things like pagination. We pass in the params for the table we'll create in the view. By default
|
38
|
+
Here we're getting active accounts, calling tableficate and then paginating with Kaminari. Tableficate works on Arel objects and passes out an Arel so you can add things like pagination. We pass in the params for the table we'll create in the view. By default `:accounts` is derived from the database table name of the primary table in the query.
|
37
39
|
|
38
40
|
Our View:
|
39
41
|
|
40
|
-
<%= table_for @accounts, show_sorts: true do |t|
|
41
|
-
t.column :id, header: 'Account Number'
|
42
|
-
t.column :created_at do |account|
|
43
|
-
account.created_at.strftime('%m/%d/%Y')
|
44
|
-
end
|
45
|
-
t.column :first_name
|
46
|
-
t.column :last_name
|
47
|
-
t.actions do |account|
|
48
|
-
link_to('View', account_path(account))
|
49
|
-
end
|
42
|
+
<%= table_for @accounts, show_sorts: true do |t| %>
|
43
|
+
<% t.column :id, header: 'Account Number' %>
|
44
|
+
<% t.column :created_at do |account| %>
|
45
|
+
<%= account.created_at.strftime('%m/%d/%Y') %>
|
46
|
+
<% end %>
|
47
|
+
<% t.column :first_name %>
|
48
|
+
<% t.column :last_name %>
|
49
|
+
<% t.actions do |account| %>
|
50
|
+
<%= link_to('View', account_path(account)) %>
|
51
|
+
<% end %>
|
50
52
|
|
51
|
-
t.
|
52
|
-
t.
|
53
|
-
%>
|
53
|
+
<% t.filter :first_name %>
|
54
|
+
<% t.filter :last_name %>
|
55
|
+
<% end %>
|
54
56
|
|
55
|
-
This creates a sortable table with
|
57
|
+
This creates a sortable table with 2 filters, 4 data columns and a column for actions. Column headers are automatically generated but can be overridden as seen on `:id`. The column output can also be overridden by passing a block to the call. This setup only covers basic functionality. Some of the more advanced functionality requires you to wrap your scope in a special table model.
|
56
58
|
|
57
|
-
Having created the basic table we now want to default the sorting to show newest accounts first and we want
|
59
|
+
Having created the basic table we now want to default the sorting to show newest accounts first and we want `:first_name` and `:last_name` to be merged into one column. First, create a table model.
|
58
60
|
|
59
|
-
In "app/tables/" we'll create a new table model.
|
61
|
+
In "app/tables/" we'll create a new table model using the generator. Provide the name of the new table model and then the model being wrapped.
|
60
62
|
|
61
|
-
$ rails generate tableficate:table AccountReport
|
63
|
+
$ rails generate tableficate:table AccountReport Account
|
62
64
|
|
63
65
|
Our table model:
|
64
66
|
|
65
67
|
class AccountReport < Tableficate::Base
|
66
|
-
scope
|
67
|
-
Accounts.active
|
68
|
-
end
|
68
|
+
scope :accounts
|
69
69
|
|
70
|
-
default_sort
|
70
|
+
default_sort :created_at, 'DESC'
|
71
71
|
|
72
|
-
column
|
72
|
+
column :full_name, sort: 'first_name ASC, last_name ASC'
|
73
73
|
|
74
|
-
filter
|
74
|
+
filter :full_name do |value, scope|
|
75
75
|
first_name, last_name = value.split(/\s+/)
|
76
76
|
|
77
77
|
if last_name.nil?
|
@@ -82,39 +82,44 @@ Our table model:
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
We've defined a scope that we're wrapping. Then we provide a default sorting and explain how to sort and filter a new column called
|
85
|
+
We've defined a scope that we're wrapping. Then we provide a default sorting and explain how to sort and filter a new column called `:full_name`.
|
86
86
|
|
87
|
-
Our new controller
|
87
|
+
Our new controller using `AccountReport`:
|
88
88
|
|
89
|
-
@accounts = AccountReport.tableficate(params[:accounts]).page(params.try(:[], :accounts_page) || 1)
|
89
|
+
@accounts = AccountReport.active.tableficate(params[:accounts]).page(params.try(:[], :accounts_page) || 1)
|
90
90
|
|
91
|
-
|
91
|
+
Our new view using `:full_name`:
|
92
92
|
|
93
|
-
|
93
|
+
<%= table_for @accounts, show_sorts: true do |t| %>
|
94
|
+
<% t.column :id, header: 'Account Number' %>
|
95
|
+
<% t.column :created_at do |account| %>
|
96
|
+
<%= account.created_at.strftime('%m/%d/%Y') %>
|
97
|
+
<% end %>
|
98
|
+
<% t.column :full_name do |account| %>
|
99
|
+
<%= "#{account.first_name} #{account.last_name}" %>
|
100
|
+
<% end %>
|
101
|
+
<% t.actions do |account| %>
|
102
|
+
<%= link_to('View', account_path(account)) %>
|
103
|
+
<% end %>
|
94
104
|
|
95
|
-
|
96
|
-
|
97
|
-
t.column :created_at do |account|
|
98
|
-
account.created_at.strftime('%m/%d/%Y')
|
99
|
-
end
|
100
|
-
t.column :full_name
|
101
|
-
t.actions do |account|
|
102
|
-
link_to('View', account_path(account))
|
103
|
-
end
|
104
|
-
|
105
|
-
t.input_filter :full_name
|
106
|
-
%>
|
105
|
+
<% t.filter :full_name %>
|
106
|
+
<% end %>
|
107
107
|
|
108
|
-
|
108
|
+
Now we have default sorting, sortable columns and a full name filter.
|
109
109
|
|
110
110
|
## Themes
|
111
111
|
|
112
112
|
New themes can be created using the theme generator.
|
113
113
|
|
114
|
-
$ rails generate tableficate:theme
|
114
|
+
$ rails generate tableficate:theme foo
|
115
115
|
|
116
|
-
The theme can then be applied to a table
|
116
|
+
The theme can then be applied to a table.
|
117
117
|
|
118
|
-
<%= table_for @
|
118
|
+
<%= table_for @records, theme: 'foo' do |t| %>
|
119
119
|
...
|
120
|
-
%>
|
120
|
+
<% end %>
|
121
|
+
|
122
|
+
## Changes Needed to Upgrade From 0.1
|
123
|
+
|
124
|
+
1. The filter functions used in the `table_for` call have been completely changed. They will need to be rewritten in all of your calls.
|
125
|
+
2. New filter partials have been added to accomodate the new filter types that are available. If you have custom themes they will need to be updated. This can be done by first moving "_column_header.html.erb" to "_header.html.erb", "filters/_input_field.html.erb" to "filters/_input.html.erb" and "filters/_input_field_range.html.erb" to "filters/_input_range.html.erb". Then rerun `rails generate tableficate:theme NAME`. This will not overwrite files you have altered for your new theme.
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if table.filters.any? %>
|
2
|
-
<%= form_tag
|
2
|
+
<%= form_tag('', method: :get, novalidate: 'novalidate') do %>
|
3
3
|
<% if params[table.as] and params[table.as][:sort] %>
|
4
4
|
<%= hidden_field_tag("#{table.as}[sort]", params[table.as][:sort]) %>
|
5
5
|
<% end %>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%= hidden_field_tag("#{table.as}[dir]", params[table.as][:dir]) %>
|
8
8
|
<% end %>
|
9
9
|
<% table.filters.each do |filter| %>
|
10
|
-
<%= tableficate_filter_tag
|
10
|
+
<%= tableficate_filter_tag(filter) %>
|
11
11
|
<% end %>
|
12
12
|
|
13
13
|
<%= submit_tag('Filter') %>
|
@@ -24,13 +24,13 @@
|
|
24
24
|
<thead>
|
25
25
|
<tr>
|
26
26
|
<% table.columns.each do |column| %>
|
27
|
-
<%= tableficate_header_tag
|
27
|
+
<%= tableficate_header_tag(column) %>
|
28
28
|
<% end %>
|
29
29
|
</tr>
|
30
30
|
</thead>
|
31
31
|
<tbody>
|
32
32
|
<% table.rows.each do |row| %>
|
33
|
-
<%= tableficate_row_tag
|
33
|
+
<%= tableficate_row_tag(row, table.columns) %>
|
34
34
|
<% end %>
|
35
35
|
</tbody>
|
36
36
|
<% end %>
|
File without changes
|
File without changes
|
File without changes
|
data/changelog.markdown
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
* complete filter rewrite
|
3
|
+
* replaced existing filter functions in table_for calls
|
4
|
+
* added select based range filter
|
5
|
+
* added radio button filter
|
6
|
+
* added check box filter
|
7
|
+
* `column` and `actions` calls in `table_for` now accept template blocks
|
8
|
+
|
1
9
|
## 0.1.3
|
2
10
|
* fixing html_safe break in 0.1.2
|
3
11
|
|
data/lib/tableficate/base.rb
CHANGED
data/lib/tableficate/column.rb
CHANGED
@@ -14,8 +14,12 @@ module Tableficate
|
|
14
14
|
def value(row)
|
15
15
|
if @block
|
16
16
|
output = @block.call(row)
|
17
|
-
|
18
|
-
|
17
|
+
if output.is_a?(ActionView::OutputBuffer)
|
18
|
+
''
|
19
|
+
else
|
20
|
+
output = output.html_safe if output.respond_to? :html_safe
|
21
|
+
output
|
22
|
+
end
|
19
23
|
else
|
20
24
|
row.send(@name)
|
21
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class Base
|
4
|
+
attr_reader :name, :label, :options, :template, :table, :field_name
|
5
|
+
|
6
|
+
def initialize(table, name, options = {})
|
7
|
+
@table = table
|
8
|
+
@name = name
|
9
|
+
@options = options
|
10
|
+
|
11
|
+
@template = 'filters/' + self.class.name.demodulize.underscore
|
12
|
+
@label = @options.delete(:label) || table.columns.detect{|column| column.name == @name}.try(:header) || name.to_s.titleize
|
13
|
+
@field_name = "#{table.as}[filter][#{@name}]"
|
14
|
+
end
|
15
|
+
|
16
|
+
def field_value(params)
|
17
|
+
params[:filter][@name] rescue ''
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class Choice
|
4
|
+
attr_reader :name, :value, :options
|
5
|
+
|
6
|
+
def initialize(name, value, options = {})
|
7
|
+
@name = name
|
8
|
+
@value = value
|
9
|
+
|
10
|
+
@selected = !!(options.has_key?(:selected) || options.has_key?(:checked))
|
11
|
+
options.delete(:selected)
|
12
|
+
options.delete(:checked)
|
13
|
+
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def selected?
|
18
|
+
@selected
|
19
|
+
end
|
20
|
+
alias_method :checked?, :selected?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class Collection < Array
|
4
|
+
def initialize(container, options = {})
|
5
|
+
container = container.to_a if container.is_a?(Range)
|
6
|
+
|
7
|
+
selected = Array.wrap(options[:selected]).map{|item| item.to_s}
|
8
|
+
disabled = Array.wrap(options[:disabled]).map{|item| item.to_s}
|
9
|
+
|
10
|
+
container.map do |element|
|
11
|
+
text, value, choice_options = case
|
12
|
+
when Array === element
|
13
|
+
html_attrs = element.detect {|e| Hash === e} || {}
|
14
|
+
element = element.reject {|e| Hash === e}
|
15
|
+
[element.first, element.last, html_attrs]
|
16
|
+
when !element.is_a?(String) && element.respond_to?(:first) && element.respond_to?(:last)
|
17
|
+
[element.first, element.last, {}]
|
18
|
+
else
|
19
|
+
[element, element, {}]
|
20
|
+
end
|
21
|
+
|
22
|
+
choice_options[:selected] = 'selected' if selected.include?(value.to_s)
|
23
|
+
choice_options[:disabled] = 'disabled' if disabled.include?(value.to_s)
|
24
|
+
|
25
|
+
self.push(Choice.new(text, value, choice_options))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class Input < Base
|
4
|
+
def initialize(table, name, options = {})
|
5
|
+
super(table, name, options)
|
6
|
+
|
7
|
+
new_template = "filters/input_#{options[:type]}"
|
8
|
+
@template = new_template if table.template.lookup_context.exists?(Tableficate::Utils::template_path(new_template, table.options[:theme]), [], true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class InputStart < Input
|
4
|
+
def initialize(table, name, options = {})
|
5
|
+
super(table, name, options)
|
6
|
+
|
7
|
+
@field_name += '[start]'
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
"#{@name}_start".to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def field_value(params)
|
15
|
+
params[:filter][@name][:start] rescue ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class InputStop < Input
|
20
|
+
def initialize(table, name, options = {})
|
21
|
+
super(table, name, options)
|
22
|
+
|
23
|
+
@field_name += '[stop]'
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
"#{@name}_stop".to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
def field_value(params)
|
31
|
+
params[:filter][@name][:stop] rescue ''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class InputRange < Base
|
36
|
+
attr_reader :start, :stop
|
37
|
+
|
38
|
+
def initialize(table, name, options = {})
|
39
|
+
start_options = options.delete(:start) || {}
|
40
|
+
stop_options = options.delete(:stop) || {}
|
41
|
+
|
42
|
+
super(table, name, options)
|
43
|
+
|
44
|
+
start_options.reverse_merge!(@options)
|
45
|
+
start_options.reverse_merge!(label: self.label)
|
46
|
+
stop_options.reverse_merge!(@options)
|
47
|
+
stop_options.reverse_merge!(label: self.label)
|
48
|
+
|
49
|
+
@start = InputStart.new(table, name, start_options)
|
50
|
+
@stop = InputStop.new(table, name, stop_options)
|
51
|
+
|
52
|
+
new_template = "filters/input_range_#{options[:type]}"
|
53
|
+
@template = new_template if table.template.lookup_context.exists?(Tableficate::Utils::template_path(new_template, table.options[:theme]), [], true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Tableficate
|
2
|
+
module Filter
|
3
|
+
class SelectStart < Select
|
4
|
+
def initialize(table, name, options = {})
|
5
|
+
super(table, name, options)
|
6
|
+
|
7
|
+
@field_name += '[start]'
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
"#{@name}_start".to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def field_value(params)
|
15
|
+
params[:filter][@name][:start] rescue ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class SelectStop < Select
|
20
|
+
def initialize(table, name, options = {})
|
21
|
+
super(table, name, options)
|
22
|
+
|
23
|
+
@field_name += '[stop]'
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
"#{@name}_stop".to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
def field_value(params)
|
31
|
+
params[:filter][@name][:stop] rescue ''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class SelectRange < Base
|
36
|
+
attr_reader :start, :stop
|
37
|
+
|
38
|
+
def initialize(table, name, options = {})
|
39
|
+
start_options = options.delete(:start) || {}
|
40
|
+
stop_options = options.delete(:stop) || {}
|
41
|
+
|
42
|
+
super(table, name, options)
|
43
|
+
|
44
|
+
start_options.reverse_merge!(@options)
|
45
|
+
start_options.reverse_merge!(label: self.label)
|
46
|
+
stop_options.reverse_merge!(@options)
|
47
|
+
stop_options.reverse_merge!(label: self.label)
|
48
|
+
|
49
|
+
@start = SelectStart.new(table, name, start_options)
|
50
|
+
@stop = SelectStop.new(table, name, stop_options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/tableficate/helper.rb
CHANGED
@@ -7,7 +7,7 @@ module Tableficate
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def tableficate_header_tag(column)
|
10
|
-
render partial: Tableficate::Utils::template_path('
|
10
|
+
render partial: Tableficate::Utils::template_path('header', column.table.options[:theme]), locals: {column: column}
|
11
11
|
end
|
12
12
|
|
13
13
|
def tableficate_data_tag(row, column)
|
@@ -23,15 +23,80 @@ module Tableficate
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def tableficate_label_tag(filter)
|
26
|
-
label_tag(filter.field_name, filter.label, filter.options[:label_options]
|
26
|
+
label_tag(filter.field_name, filter.label, filter.options[:label_options])
|
27
27
|
end
|
28
28
|
|
29
29
|
def tableficate_text_field_tag(filter)
|
30
|
-
text_field_tag(filter.field_name, filter.field_value(params[filter.table.as]), filter.options
|
30
|
+
text_field_tag(filter.field_name, filter.field_value(params[filter.table.as]), filter.options)
|
31
31
|
end
|
32
32
|
|
33
33
|
def tableficate_select_tag(filter)
|
34
|
-
|
34
|
+
field_value = filter.field_value(params[filter.table.as])
|
35
|
+
|
36
|
+
if field_value.present? and filter.options[:collection].is_a?(String)
|
37
|
+
Array.wrap(field_value).each do |fv|
|
38
|
+
if filter.options[:collection].match(/<option[^>]*value\s*=/)
|
39
|
+
filter.options[:collection].gsub!(/(<option[^>]*value\s*=\s*['"]?#{fv}[^>]*)/, '\1 selected="selected"')
|
40
|
+
else
|
41
|
+
filter.options[:collection].gsub!(/>#{fv}</, " selected=\"selected\">#{fv}<")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
elsif not filter.options[:collection].is_a?(String)
|
45
|
+
filter.options[:collection] = Tableficate::Filter::Collection.new(filter.options[:collection], selected: field_value).map {|choice|
|
46
|
+
html_attributes = choice.options.length > 0 ? ' ' + choice.options.map {|k, v| %(#{k.to_s}="#{v}")}.join(' ') : ''
|
47
|
+
selected_attribute = choice.selected? ? ' selected="selected"' : ''
|
48
|
+
|
49
|
+
%(<option value="#{ERB::Util.html_escape(choice.value)}"#{selected_attribute}#{html_attributes}>#{ERB::Util.html_escape(choice.name)}</option>)
|
50
|
+
}.join("\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
filter.options[:collection] = filter.options[:collection].html_safe
|
54
|
+
|
55
|
+
select_tag(filter.field_name, filter.options.delete(:collection), filter.options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def tableficate_radio_tags(filter, &block)
|
59
|
+
field_value = filter.field_value(params[filter.table.as])
|
60
|
+
|
61
|
+
collection = Tableficate::Filter::Collection.new(filter.options[:collection], selected: filter.field_value(params[filter.table.as]))
|
62
|
+
|
63
|
+
html = []
|
64
|
+
if block_given?
|
65
|
+
html = collection.map {|choice| capture(choice, &block)}
|
66
|
+
else
|
67
|
+
collection.each do |choice|
|
68
|
+
html.push(
|
69
|
+
radio_button_tag(filter.field_name, choice.value, choice.checked?, choice.options),
|
70
|
+
label_tag("#{filter.field_name}[#{choice.value}]", choice.name),
|
71
|
+
'<br/>'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
html.join("\n").html_safe
|
77
|
+
end
|
78
|
+
|
79
|
+
def tableficate_check_box_tags(filter, &block)
|
80
|
+
field_value = filter.field_value(params[filter.table.as])
|
81
|
+
|
82
|
+
collection = Tableficate::Filter::Collection.new(filter.options[:collection], selected: filter.field_value(params[filter.table.as]))
|
83
|
+
|
84
|
+
html = []
|
85
|
+
if block_given?
|
86
|
+
html = collection.map {|choice| capture(choice, &block)}
|
87
|
+
else
|
88
|
+
collection.each do |choice|
|
89
|
+
html.push(
|
90
|
+
check_box_tag(
|
91
|
+
"#{filter.field_name}[#{choice.value}]", choice.value, choice.checked?, choice.options.reverse_merge(name: "#{filter.field_name}[]")
|
92
|
+
),
|
93
|
+
label_tag("#{filter.field_name}[#{choice.value}]", choice.name),
|
94
|
+
'<br/>'
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
html.join("\n").html_safe
|
35
100
|
end
|
36
101
|
end
|
37
102
|
end
|