mighty_grid 1.0.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +20 -12
- data/features/support/env.rb +1 -0
- data/lib/generators/mighty_grid/install_generator.rb +1 -1
- data/lib/generators/mighty_grid/templates/{mighty_grid_config.rb → mighty_grid.rb} +1 -1
- data/lib/mighty_grid/base.rb +31 -111
- data/lib/mighty_grid/column.rb +1 -1
- data/lib/mighty_grid/engine.rb +11 -8
- data/lib/mighty_grid/exceptions.rb +9 -0
- data/lib/mighty_grid/filter_renderer.rb +18 -34
- data/lib/mighty_grid/filters/base.rb +27 -0
- data/lib/mighty_grid/filters/boolean_filter.rb +6 -0
- data/lib/mighty_grid/filters/custom_filter.rb +19 -0
- data/lib/mighty_grid/filters/enum_filter.rb +15 -0
- data/lib/mighty_grid/filters/string_filter.rb +6 -0
- data/lib/mighty_grid/filters/text_filter.rb +6 -0
- data/lib/mighty_grid/filters.rb +113 -0
- data/lib/mighty_grid/grid_renderer.rb +1 -1
- data/lib/mighty_grid/helpers/{mighty_grid_view_helpers.rb → view_helpers.rb} +13 -11
- data/lib/mighty_grid/map_type.rb +16 -0
- data/lib/mighty_grid/parameters.rb +58 -0
- data/lib/mighty_grid/version.rb +12 -1
- data/lib/mighty_grid.rb +64 -15
- data/spec/dummy/app/controllers/users_controller.rb +1 -1
- data/spec/dummy/app/grids/users_grid.rb +7 -0
- data/spec/dummy/app/views/users/index.html +1 -1
- data/spec/dummy/config/database.yml +29 -0
- data/spec/dummy/db/mg_test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +119680 -0
- data/spec/dummy/log/test.log +101833 -0
- data/spec/dummy/tmp/cache/assets/CCA/5E0/sprockets%2F48d34122dd1905305a6e63e3acb7c042 +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CF9/100/sprockets%2F3d8f5e96de4712db63b98083f75739c3 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D3C/EE0/sprockets%2Fccfd910338b6dcf575467d3009b46a0d +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D60/BE0/sprockets%2F37b5ab8193eccd1a29a0c61374c6b51e +0 -0
- data/spec/dummy/tmp/cache/assets/D82/820/sprockets%2Ff7c8a51f7f95d66a9d5112f898bc1fd0 +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/DF2/A80/sprockets%2F14a708b3bb2a924afdebae773e4ba5d8 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E0C/4E0/sprockets%2Fed4e3dbab857786229b1bdf7bbd289fe +0 -0
- data/spec/dummy/tmp/cache/assets/E14/600/sprockets%2F34cd0de2e0cd2c01e1c91b0ece565deb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e57c0129c0245eab3972d87efc6a9b9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/14a708b3bb2a924afdebae773e4ba5d8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1f8135a48e7ccbcb5361bb9e1f993929 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2479f30262de64213c228dc752440fd1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/34cd0de2e0cd2c01e1c91b0ece565deb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/37b5ab8193eccd1a29a0c61374c6b51e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3cbb6c28c7bbcc7c9b547346a59b4e7f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3d8f5e96de4712db63b98083f75739c3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/422d4d422d090c103e6b198600a90dac +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/48d34122dd1905305a6e63e3acb7c042 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a8c1ee1faf09397765710724fe3ee140 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bbd98f4797053ba2accbbca7b81cbbaf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cc03506b8188f839058f41aa8a4e19da +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cccf51971e81f175e527083a6ef4624d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ccfd910338b6dcf575467d3009b46a0d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d77d41650e5528f12146c728566cbf33 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ed4e3dbab857786229b1bdf7bbd289fe +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7c8a51f7f95d66a9d5112f898bc1fd0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/14a708b3bb2a924afdebae773e4ba5d8 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/34cd0de2e0cd2c01e1c91b0ece565deb +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/37b5ab8193eccd1a29a0c61374c6b51e +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/3d8f5e96de4712db63b98083f75739c3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/422d4d422d090c103e6b198600a90dac +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/48d34122dd1905305a6e63e3acb7c042 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a8c1ee1faf09397765710724fe3ee140 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cccf51971e81f175e527083a6ef4624d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/ccfd910338b6dcf575467d3009b46a0d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/ed4e3dbab857786229b1bdf7bbd289fe +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7c8a51f7f95d66a9d5112f898bc1fd0 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/lib/base_spec.rb +24 -15
- data/spec/lib/generators/install_generator_spec.rb +5 -3
- data/spec/lib/tmp/config/initializers/mighty_grid.rb +15 -0
- data/spec/lib/tmp/config/locales/mighty_grid.en.yml +6 -0
- data/spec/mighty_grid_spec.rb +17 -0
- data/spec/support/models.rb +1 -0
- metadata +154 -41
- data/.gitignore +0 -26
- data/.rspec +0 -2
- data/.travis.yml +0 -33
- data/Appraisals +0 -17
- data/gemfiles/rails_32.gemfile +0 -26
- data/gemfiles/rails_40.gemfile +0 -26
- data/gemfiles/rails_41.gemfile +0 -26
- data/lib/mighty_grid/config.rb +0 -49
- data/lib/mighty_grid/mighty_grid_controller.rb +0 -14
- data/lib/mighty_grid/mighty_grid_misc.rb +0 -11
- data/mighty_grid.gemspec +0 -27
- data/spec/config_spec.rb +0 -148
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
module MightyGrid
|
2
|
-
module
|
2
|
+
module ViewHelpers
|
3
3
|
def grid(grid, opts = {}, &block)
|
4
4
|
define_grid(grid, opts, &block)
|
5
5
|
render_grid(grid)
|
@@ -13,13 +13,13 @@ module MightyGrid
|
|
13
13
|
options = {
|
14
14
|
html: {},
|
15
15
|
header_tr_html: {},
|
16
|
-
order_type: MightyGrid.
|
17
|
-
order_asc: MightyGrid.
|
18
|
-
order_desc: MightyGrid.
|
19
|
-
order_asc_link_class: MightyGrid.
|
20
|
-
order_desc_link_class: MightyGrid.
|
21
|
-
order_active_link_class: MightyGrid.
|
22
|
-
order_wrapper_class: MightyGrid.
|
16
|
+
order_type: MightyGrid.order_type,
|
17
|
+
order_asc: MightyGrid.order_asc,
|
18
|
+
order_desc: MightyGrid.order_desc,
|
19
|
+
order_asc_link_class: MightyGrid.order_asc_link_class,
|
20
|
+
order_desc_link_class: MightyGrid.order_desc_link_class,
|
21
|
+
order_active_link_class: MightyGrid.order_active_link_class,
|
22
|
+
order_wrapper_class: MightyGrid.order_wrapper_class
|
23
23
|
}
|
24
24
|
|
25
25
|
opts.assert_valid_keys(options.keys)
|
@@ -28,7 +28,7 @@ module MightyGrid
|
|
28
28
|
|
29
29
|
options[:order_wrapper_class] = MightyGrid::MgHTML.join_html_classes({}, 'mg-order-wrapper', options[:order_wrapper_class])[:class]
|
30
30
|
|
31
|
-
table_html_attrs = MightyGrid::MgHTML.join_html_classes(options[:html], 'mighty-grid', MightyGrid.
|
31
|
+
table_html_attrs = MightyGrid::MgHTML.join_html_classes(options[:html], 'mighty-grid', MightyGrid.table_class)
|
32
32
|
|
33
33
|
grid.read
|
34
34
|
|
@@ -79,7 +79,7 @@ module MightyGrid
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def header_grid_html(rendering, grid, options)
|
82
|
-
header_tr_html = MightyGrid::MgHTML.join_html_classes(options[:header_tr_html], MightyGrid.
|
82
|
+
header_tr_html = MightyGrid::MgHTML.join_html_classes(options[:header_tr_html], MightyGrid.header_tr_class)
|
83
83
|
|
84
84
|
content_tag :thead do
|
85
85
|
content_tag :tr, header_tr_html do
|
@@ -150,7 +150,7 @@ module MightyGrid
|
|
150
150
|
content_tag :tfoot do
|
151
151
|
content_tag :tr do
|
152
152
|
content_tag :td, colspan: rendering.total_columns do
|
153
|
-
html_pag = paginate(grid.relation, theme: MightyGrid.
|
153
|
+
html_pag = paginate(grid.relation, theme: MightyGrid.pagination_theme, param_name: "#{grid.name}[page]")
|
154
154
|
html_pag += display_entries(grid)
|
155
155
|
html_pag.html_safe
|
156
156
|
end
|
@@ -166,3 +166,5 @@ module MightyGrid
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
|
+
|
170
|
+
ActionView::Base.send :include, MightyGrid::ViewHelpers
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute'
|
2
|
+
|
3
|
+
module MightyGrid
|
4
|
+
module MapType
|
5
|
+
def self.extended(base)
|
6
|
+
base.class_attribute :mappings
|
7
|
+
base.mappings = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def map_type(*types)
|
11
|
+
map_to = types.extract_options![:to]
|
12
|
+
raise ArgumentError, "You need to give :to as option to map_type" unless map_to
|
13
|
+
self.mappings.merge! types.each_with_object({}) { |t, m| m[t] = map_to }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module MightyGrid
|
2
|
+
module Parameters
|
3
|
+
def self.included(base)
|
4
|
+
base.send :include, InstanceMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
# Load grid parameters
|
9
|
+
def load_grid_params
|
10
|
+
@mg_params = {}
|
11
|
+
@mg_params[filter_param_name.to_sym] = {}
|
12
|
+
@mg_params.merge!(@options)
|
13
|
+
if current_grid_params
|
14
|
+
@mg_params.merge!(current_grid_params.symbolize_keys)
|
15
|
+
if @mg_params[:order].present? && !@mg_params[:order].to_s.include?('.')
|
16
|
+
@mg_params[:order] = "#{klass.table_name}.#{@mg_params[:order]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get current grid parameter by name
|
22
|
+
def get_current_grid_param(name)
|
23
|
+
current_grid_params.key?(name) ? current_grid_params[name] : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get current grid parameters
|
27
|
+
def current_grid_params
|
28
|
+
params[name] || {}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get order parameters
|
32
|
+
def order_params(attribute, model = nil, direction = nil)
|
33
|
+
order = model.present? ? "#{model.table_name}.#{attribute}" : attribute.to_s
|
34
|
+
direction ||= order == current_grid_params['order'] ? another_order_direction : 'asc'
|
35
|
+
{ @name => { order: order, order_direction: direction } }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get current order direction if current order parameter coincides with the received parameter
|
39
|
+
def get_active_order_direction(parameters)
|
40
|
+
parameters[@name]['order'] == current_grid_params['order'] ? current_order_direction : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get current order direction
|
44
|
+
def current_order_direction
|
45
|
+
direction = nil
|
46
|
+
if current_grid_params.key?('order_direction') && %w(asc desc).include?(current_grid_params['order_direction'].downcase)
|
47
|
+
direction = current_grid_params['order_direction'].downcase
|
48
|
+
end
|
49
|
+
direction
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get another order direction
|
53
|
+
def another_order_direction
|
54
|
+
current_grid_params.key?('order_direction') ? (%w(asc desc) - [current_grid_params['order_direction'].to_s]).first : MightyGrid.order_direction
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/mighty_grid/version.rb
CHANGED
data/lib/mighty_grid.rb
CHANGED
@@ -1,20 +1,69 @@
|
|
1
|
-
module MightyGrid; end
|
2
|
-
|
3
|
-
require 'action_view'
|
4
1
|
require 'kaminari'
|
2
|
+
require 'action_view'
|
3
|
+
require 'mighty_grid/helpers/view_helpers'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
module MightyGrid
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Base
|
9
|
+
autoload :Parameters
|
10
|
+
autoload :Filters
|
11
|
+
autoload :Column
|
12
|
+
autoload :GridRenderer
|
13
|
+
autoload :FilterRenderer
|
14
|
+
autoload :Exceptions
|
15
|
+
|
16
|
+
@@configured = false
|
17
|
+
|
18
|
+
def self.configured? #:nodoc:
|
19
|
+
@@configured
|
20
|
+
end
|
21
|
+
|
22
|
+
mattr_accessor :grid_name
|
23
|
+
@@grid_name = 'grid'
|
24
|
+
|
25
|
+
mattr_accessor :per_page
|
26
|
+
@@per_page = 15
|
27
|
+
|
28
|
+
mattr_accessor :order_direction
|
29
|
+
@@order_direction = 'asc'
|
30
|
+
|
31
|
+
mattr_accessor :order_type
|
32
|
+
@@order_type = 'single'
|
15
33
|
|
16
|
-
|
17
|
-
|
34
|
+
mattr_accessor :order_asc
|
35
|
+
@@order_asc = '↑'
|
36
|
+
|
37
|
+
mattr_accessor :order_desc
|
38
|
+
@@order_desc = '↓'
|
39
|
+
|
40
|
+
mattr_accessor :order_asc_link_class
|
41
|
+
@@order_asc_link_class = ''
|
42
|
+
|
43
|
+
mattr_accessor :order_desc_link_class
|
44
|
+
@@order_desc_link_class = ''
|
45
|
+
|
46
|
+
mattr_accessor :order_active_link_class
|
47
|
+
@@order_active_link_class = 'mg-order-active'
|
48
|
+
|
49
|
+
mattr_accessor :order_wrapper_class
|
50
|
+
@@order_wrapper_class = ''
|
51
|
+
|
52
|
+
mattr_accessor :table_class
|
53
|
+
@@table_class = ''
|
54
|
+
|
55
|
+
mattr_accessor :header_tr_class
|
56
|
+
@@header_tr_class = ''
|
57
|
+
|
58
|
+
mattr_accessor :pagination_theme
|
59
|
+
@@pagination_theme = 'mighty_grid'
|
60
|
+
|
61
|
+
def self.setup
|
62
|
+
@@configured = true
|
63
|
+
yield self
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
require 'mighty_grid/mighty_grid_ext'
|
18
68
|
|
19
69
|
require 'mighty_grid/engine'
|
20
|
-
require 'mighty_grid/base'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<%= filter.label :name %>
|
3
3
|
<%= filter.text_field :name %>
|
4
4
|
<%= filter.label :role %>
|
5
|
-
<%= filter.select :role,
|
5
|
+
<%= filter.select :role, prompt: 'Select role' %>
|
6
6
|
<label><%= filter.check_box :is_banned, 't' %> Banned</label>
|
7
7
|
<%= filter.submit %>
|
8
8
|
<%= filter.reset %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
sqlite: &sqlite
|
2
|
+
adapter: sqlite3
|
3
|
+
database: 'db/mg_test.sqlite3'
|
4
|
+
|
5
|
+
mysql: &mysql
|
6
|
+
adapter: mysql2
|
7
|
+
database: 'mg_test'
|
8
|
+
username: root
|
9
|
+
|
10
|
+
postgresql: &postgresql
|
11
|
+
adapter: postgresql
|
12
|
+
database: 'mg_test'
|
13
|
+
username: postgres
|
14
|
+
password: '4521'
|
15
|
+
|
16
|
+
defaults: &defaults
|
17
|
+
pool: 5
|
18
|
+
timeout: 5000
|
19
|
+
host: localhost
|
20
|
+
<<: *<%= ENV['DB'] || "sqlite" %>
|
21
|
+
|
22
|
+
development:
|
23
|
+
<<: *defaults
|
24
|
+
|
25
|
+
test:
|
26
|
+
<<: *defaults
|
27
|
+
|
28
|
+
production:
|
29
|
+
<<: *defaults
|
Binary file
|