datagrid 1.8.1 → 2.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -7
- data/{Readme.markdown → README.md} +46 -29
- data/app/assets/stylesheets/datagrid.css +145 -0
- data/app/views/datagrid/_enum_checkboxes.html.erb +5 -3
- data/app/views/datagrid/_form.html.erb +4 -5
- data/app/views/datagrid/_head.html.erb +26 -3
- data/app/views/datagrid/_range_filter.html.erb +5 -3
- data/app/views/datagrid/_row.html.erb +12 -1
- data/app/views/datagrid/_table.html.erb +4 -4
- data/datagrid.gemspec +8 -8
- data/lib/datagrid/active_model.rb +9 -17
- data/lib/datagrid/base.rb +39 -0
- data/lib/datagrid/column_names_attribute.rb +12 -12
- data/lib/datagrid/columns/column.rb +155 -133
- data/lib/datagrid/columns.rb +495 -282
- data/lib/datagrid/configuration.rb +23 -10
- data/lib/datagrid/core.rb +184 -150
- data/lib/datagrid/deprecated_object.rb +20 -0
- data/lib/datagrid/drivers/abstract_driver.rb +13 -25
- data/lib/datagrid/drivers/active_record.rb +24 -26
- data/lib/datagrid/drivers/array.rb +26 -17
- data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
- data/lib/datagrid/drivers/mongoid.rb +16 -18
- data/lib/datagrid/drivers/sequel.rb +14 -19
- data/lib/datagrid/drivers.rb +2 -1
- data/lib/datagrid/engine.rb +11 -3
- data/lib/datagrid/filters/base_filter.rb +166 -142
- data/lib/datagrid/filters/boolean_filter.rb +19 -5
- data/lib/datagrid/filters/date_filter.rb +33 -35
- data/lib/datagrid/filters/date_time_filter.rb +24 -16
- data/lib/datagrid/filters/default_filter.rb +9 -3
- data/lib/datagrid/filters/dynamic_filter.rb +151 -105
- data/lib/datagrid/filters/enum_filter.rb +43 -19
- data/lib/datagrid/filters/extended_boolean_filter.rb +39 -27
- data/lib/datagrid/filters/float_filter.rb +16 -5
- data/lib/datagrid/filters/integer_filter.rb +21 -10
- data/lib/datagrid/filters/ranged_filter.rb +66 -45
- data/lib/datagrid/filters/select_options.rb +58 -49
- data/lib/datagrid/filters/string_filter.rb +9 -4
- data/lib/datagrid/filters.rb +234 -106
- data/lib/datagrid/form_builder.rb +116 -128
- data/lib/datagrid/generators/scaffold.rb +185 -0
- data/lib/datagrid/generators/views.rb +20 -0
- data/lib/datagrid/helper.rb +397 -22
- data/lib/datagrid/ordering.rb +81 -87
- data/lib/datagrid/rspec.rb +8 -12
- data/lib/datagrid/utils.rb +42 -38
- data/lib/datagrid/version.rb +3 -1
- data/lib/datagrid.rb +18 -28
- data/templates/base.rb.erb +33 -7
- data/templates/grid.rb.erb +1 -1
- metadata +18 -19
- data/app/assets/stylesheets/datagrid.sass +0 -134
- data/lib/datagrid/filters/composite_filters.rb +0 -49
- data/lib/datagrid/renderer.rb +0 -157
- data/lib/datagrid/scaffold.rb +0 -129
- data/lib/tasks/datagrid_tasks.rake +0 -15
- data/templates/controller.rb.erb +0 -6
- data/templates/index.html.erb +0 -5
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Datagrid
|
2
4
|
module ColumnNamesAttribute
|
3
5
|
extend ActiveSupport::Concern
|
@@ -21,6 +23,7 @@ module Datagrid
|
|
21
23
|
# will always present in the grid table and won't be listed
|
22
24
|
# in column names selection
|
23
25
|
# Accepts same options as <tt>:enum</tt> filter
|
26
|
+
# @return [Datagrid::Filters::BaseFilter] Defined filter object
|
24
27
|
# @example
|
25
28
|
# column_names_filter(header: "Choose columns")
|
26
29
|
# @see Datagrid::Filters::ClassMethods#filter
|
@@ -44,7 +47,7 @@ module Datagrid
|
|
44
47
|
# If no mandatory columns specified than all of them considered mandatory
|
45
48
|
# @return [Array<Datagrid::Columns::Column>]
|
46
49
|
def mandatory_columns
|
47
|
-
available_columns.select
|
50
|
+
available_columns.select(&:mandatory?)
|
48
51
|
end
|
49
52
|
|
50
53
|
# Returns a list of enabled columns without <tt>mandatory: true</tt> option
|
@@ -57,27 +60,25 @@ module Datagrid
|
|
57
60
|
protected
|
58
61
|
|
59
62
|
def optional_columns_select
|
60
|
-
optional_columns.map {|c| [c.header, c.name] }
|
63
|
+
optional_columns.map { |c| [c.header, c.name] }
|
61
64
|
end
|
62
65
|
|
63
66
|
def selected_column_names(*args)
|
64
67
|
if args.any?
|
65
68
|
args.compact!
|
66
|
-
args.map!
|
69
|
+
args.map! do |column|
|
70
|
+
column.is_a?(Datagrid::Columns::Column) ? column.name : column.to_sym
|
71
|
+
end
|
67
72
|
args
|
73
|
+
elsif column_names&.any?
|
74
|
+
column_names + mandatory_columns.map(&:name)
|
68
75
|
else
|
69
|
-
|
70
|
-
column_names + mandatory_columns.map(&:name)
|
71
|
-
else
|
72
|
-
columns_enabled_by_default.map(&:name)
|
73
|
-
end
|
76
|
+
columns_enabled_by_default.map(&:name)
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
80
|
def columns_visibility_enabled?
|
78
|
-
columns_array.any?
|
79
|
-
column.mandatory_explicitly_set?
|
80
|
-
end
|
81
|
+
columns_array.any?(&:mandatory_explicitly_set?)
|
81
82
|
end
|
82
83
|
|
83
84
|
def columns_enabled_by_default
|
@@ -85,4 +86,3 @@ module Datagrid
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
88
|
-
|
@@ -1,164 +1,186 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagrid
|
4
|
+
module Columns
|
5
|
+
class Column
|
6
|
+
# Datagrid class holding an information of
|
7
|
+
# how a column should be rendered in data/console/csv format and HTML format
|
8
|
+
class ResponseFormat
|
9
|
+
attr_accessor :data_block, :html_block
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
yield(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def data(&block)
|
16
|
+
self.data_block = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def html(&block)
|
20
|
+
self.html_block = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def call_data
|
24
|
+
data_block.call
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
call_data.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def call_html(context)
|
32
|
+
context.instance_eval(&html_block)
|
33
|
+
end
|
34
|
+
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
attr_accessor :grid_class, :options, :data_block, :name, :html_block, :query
|
37
|
+
|
38
|
+
def initialize(grid_class, name, query, options = {}, &block)
|
39
|
+
self.grid_class = grid_class
|
40
|
+
self.name = name.to_sym
|
41
|
+
self.options = options
|
42
|
+
if options[:class]
|
43
|
+
Datagrid::Utils.warn_once(
|
44
|
+
"column[class] option is deprecated. Use {tag_options: {class: ...}} instead.",
|
45
|
+
)
|
46
|
+
self.options[:tag_options] = {
|
47
|
+
**self.options.fetch(:tag_options, {}),
|
48
|
+
class: options[:class],
|
49
|
+
}
|
50
|
+
end
|
51
|
+
if options[:html] == true
|
52
|
+
self.html_block = block
|
53
|
+
else
|
54
|
+
self.data_block = block
|
55
|
+
|
56
|
+
self.html_block = options[:html] if options[:html].is_a? Proc
|
57
|
+
end
|
58
|
+
self.query = query
|
59
|
+
end
|
28
60
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
61
|
+
def data_value(model, grid)
|
62
|
+
# backward compatibility method
|
63
|
+
grid.data_value(name, model)
|
64
|
+
end
|
33
65
|
|
34
|
-
|
66
|
+
def label
|
67
|
+
options[:label]
|
68
|
+
end
|
35
69
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
self.data_block = block
|
70
|
+
def header
|
71
|
+
if (header = options[:header])
|
72
|
+
Datagrid::Utils.callable(header)
|
73
|
+
else
|
74
|
+
Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
|
75
|
+
end
|
76
|
+
end
|
44
77
|
|
45
|
-
|
46
|
-
|
78
|
+
def order
|
79
|
+
if options.key?(:order) && options[:order] != true
|
80
|
+
options[:order]
|
81
|
+
else
|
82
|
+
driver.default_order(grid_class.scope, name)
|
83
|
+
end
|
47
84
|
end
|
48
|
-
end
|
49
|
-
self.query = query
|
50
|
-
end
|
51
85
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
86
|
+
def supports_order?
|
87
|
+
order || order_by_value?
|
88
|
+
end
|
56
89
|
|
90
|
+
def order_by_value(model, grid)
|
91
|
+
if options[:order_by_value] == true
|
92
|
+
grid.data_value(self, model)
|
93
|
+
else
|
94
|
+
Datagrid::Utils.apply_args(model, grid, &options[:order_by_value])
|
95
|
+
end
|
96
|
+
end
|
57
97
|
|
58
|
-
|
59
|
-
|
60
|
-
|
98
|
+
def order_by_value?
|
99
|
+
!!options[:order_by_value]
|
100
|
+
end
|
61
101
|
|
62
|
-
|
63
|
-
|
64
|
-
Datagrid::Utils.callable(header)
|
65
|
-
else
|
66
|
-
Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
|
67
|
-
end
|
68
|
-
end
|
102
|
+
def order_desc
|
103
|
+
return nil unless order
|
69
104
|
|
70
|
-
|
71
|
-
|
72
|
-
self.options[:order]
|
73
|
-
else
|
74
|
-
driver.default_order(grid_class.scope, name)
|
75
|
-
end
|
76
|
-
end
|
105
|
+
options[:order_desc]
|
106
|
+
end
|
77
107
|
|
78
|
-
|
79
|
-
|
80
|
-
|
108
|
+
def html?
|
109
|
+
options[:html] != false
|
110
|
+
end
|
81
111
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
else
|
86
|
-
Datagrid::Utils.apply_args(model, grid, &options[:order_by_value])
|
87
|
-
end
|
88
|
-
end
|
112
|
+
def data?
|
113
|
+
data_block != nil
|
114
|
+
end
|
89
115
|
|
90
|
-
|
91
|
-
|
92
|
-
|
116
|
+
def mandatory?
|
117
|
+
!!options[:mandatory]
|
118
|
+
end
|
93
119
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
120
|
+
def tag_options
|
121
|
+
options[:tag_options] || {}
|
122
|
+
end
|
98
123
|
|
99
|
-
|
100
|
-
|
101
|
-
|
124
|
+
def html_class
|
125
|
+
Datagrid::Utils.warn_once(
|
126
|
+
"Column#html_class is deprecated. Use Column#tag_options instead.",
|
127
|
+
)
|
128
|
+
options[:class]
|
129
|
+
end
|
102
130
|
|
103
|
-
|
104
|
-
|
105
|
-
|
131
|
+
def mandatory_explicitly_set?
|
132
|
+
options.key?(:mandatory)
|
133
|
+
end
|
106
134
|
|
107
|
-
|
108
|
-
|
109
|
-
|
135
|
+
def enabled?(grid)
|
136
|
+
::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
|
137
|
+
end
|
110
138
|
|
111
|
-
|
112
|
-
|
113
|
-
|
139
|
+
def inspect
|
140
|
+
"#<#{self.class} #{grid_class}##{name} #{options.inspect}>"
|
141
|
+
end
|
114
142
|
|
115
|
-
|
116
|
-
|
117
|
-
|
143
|
+
def to_s
|
144
|
+
header
|
145
|
+
end
|
118
146
|
|
119
|
-
|
120
|
-
|
121
|
-
|
147
|
+
def html_value(context, asset, grid)
|
148
|
+
grid.html_value(name, context, asset)
|
149
|
+
end
|
122
150
|
|
123
|
-
|
124
|
-
|
125
|
-
|
151
|
+
def generic_value(model, grid)
|
152
|
+
grid.generic_value(self, model)
|
153
|
+
end
|
126
154
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
155
|
+
def append_preload(relation)
|
156
|
+
return relation unless preload
|
130
157
|
|
158
|
+
if preload.respond_to?(:call)
|
159
|
+
return relation unless preload
|
131
160
|
|
132
|
-
|
133
|
-
|
134
|
-
|
161
|
+
if preload.arity == 1
|
162
|
+
preload.call(relation)
|
163
|
+
else
|
164
|
+
relation.instance_exec(&preload)
|
165
|
+
end
|
166
|
+
else
|
167
|
+
driver.default_preload(relation, preload)
|
168
|
+
end
|
169
|
+
end
|
135
170
|
|
136
|
-
|
137
|
-
|
138
|
-
if preload.respond_to?(:call)
|
139
|
-
return relation unless preload
|
140
|
-
if preload.arity == 1
|
141
|
-
preload.call(relation)
|
142
|
-
else
|
143
|
-
relation.instance_exec(&preload)
|
144
|
-
end
|
145
|
-
else
|
146
|
-
driver.default_preload(relation, preload)
|
147
|
-
end
|
148
|
-
end
|
171
|
+
def preload
|
172
|
+
preload = options[:preload]
|
149
173
|
|
150
|
-
|
151
|
-
|
174
|
+
if preload == true && driver.can_preload?(grid_class.scope, name)
|
175
|
+
name
|
176
|
+
else
|
177
|
+
preload
|
178
|
+
end
|
179
|
+
end
|
152
180
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
preload
|
181
|
+
def driver
|
182
|
+
grid_class.driver
|
183
|
+
end
|
157
184
|
end
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
def driver
|
162
|
-
grid_class.driver
|
163
185
|
end
|
164
186
|
end
|