datagrid 1.8.2 → 2.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/{Readme.markdown → README.md} +44 -27
  4. data/app/assets/stylesheets/datagrid.css +145 -0
  5. data/app/views/datagrid/_enum_checkboxes.html.erb +5 -3
  6. data/app/views/datagrid/_form.html.erb +4 -4
  7. data/app/views/datagrid/_head.html.erb +26 -3
  8. data/app/views/datagrid/_range_filter.html.erb +5 -3
  9. data/app/views/datagrid/_row.html.erb +12 -1
  10. data/app/views/datagrid/_table.html.erb +4 -4
  11. data/datagrid.gemspec +6 -6
  12. data/lib/datagrid/active_model.rb +9 -17
  13. data/lib/datagrid/base.rb +39 -0
  14. data/lib/datagrid/column_names_attribute.rb +9 -11
  15. data/lib/datagrid/columns/column.rb +155 -133
  16. data/lib/datagrid/columns.rb +254 -45
  17. data/lib/datagrid/configuration.rb +23 -10
  18. data/lib/datagrid/core.rb +89 -54
  19. data/lib/datagrid/deprecated_object.rb +20 -0
  20. data/lib/datagrid/drivers/abstract_driver.rb +12 -23
  21. data/lib/datagrid/drivers/active_record.rb +24 -26
  22. data/lib/datagrid/drivers/array.rb +22 -14
  23. data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
  24. data/lib/datagrid/drivers/mongoid.rb +15 -17
  25. data/lib/datagrid/drivers/sequel.rb +14 -19
  26. data/lib/datagrid/drivers.rb +2 -1
  27. data/lib/datagrid/engine.rb +11 -3
  28. data/lib/datagrid/filters/base_filter.rb +166 -142
  29. data/lib/datagrid/filters/boolean_filter.rb +19 -5
  30. data/lib/datagrid/filters/date_filter.rb +33 -35
  31. data/lib/datagrid/filters/date_time_filter.rb +24 -16
  32. data/lib/datagrid/filters/default_filter.rb +9 -3
  33. data/lib/datagrid/filters/dynamic_filter.rb +151 -105
  34. data/lib/datagrid/filters/enum_filter.rb +43 -19
  35. data/lib/datagrid/filters/extended_boolean_filter.rb +39 -30
  36. data/lib/datagrid/filters/float_filter.rb +16 -5
  37. data/lib/datagrid/filters/integer_filter.rb +21 -10
  38. data/lib/datagrid/filters/ranged_filter.rb +66 -45
  39. data/lib/datagrid/filters/select_options.rb +58 -49
  40. data/lib/datagrid/filters/string_filter.rb +9 -4
  41. data/lib/datagrid/filters.rb +190 -57
  42. data/lib/datagrid/form_builder.rb +116 -128
  43. data/lib/datagrid/generators/scaffold.rb +185 -0
  44. data/lib/datagrid/generators/views.rb +20 -0
  45. data/lib/datagrid/helper.rb +397 -22
  46. data/lib/datagrid/ordering.rb +26 -29
  47. data/lib/datagrid/rspec.rb +6 -10
  48. data/lib/datagrid/utils.rb +37 -30
  49. data/lib/datagrid/version.rb +3 -1
  50. data/lib/datagrid.rb +18 -28
  51. data/templates/base.rb.erb +6 -4
  52. data/templates/grid.rb.erb +1 -1
  53. metadata +15 -16
  54. data/app/assets/stylesheets/datagrid.sass +0 -134
  55. data/lib/datagrid/filters/composite_filters.rb +0 -49
  56. data/lib/datagrid/renderer.rb +0 -157
  57. data/lib/datagrid/scaffold.rb +0 -129
  58. data/lib/tasks/datagrid_tasks.rake +0 -15
  59. data/templates/controller.rb.erb +0 -6
  60. data/templates/index.html.erb +0 -5
@@ -1,164 +1,186 @@
1
- class Datagrid::Columns::Column
2
-
3
- # Datagrid class holding an information of
4
- # how a column should be rendered in data/console/csv format and HTML format
5
- class ResponseFormat
6
-
7
- attr_accessor :data_block, :html_block
8
-
9
- def initialize
10
- yield(self)
11
- end
12
-
13
- def data(&block)
14
- self.data_block = block
15
- end
16
-
17
- def html(&block)
18
- self.html_block = block
19
- end
20
-
21
- def call_data
22
- data_block.call
23
- end
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
- def to_s
26
- call_data.to_s
27
- end
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
- def call_html(context)
30
- context.instance_eval(&html_block)
31
- end
32
- end
61
+ def data_value(model, grid)
62
+ # backward compatibility method
63
+ grid.data_value(name, model)
64
+ end
33
65
 
34
- attr_accessor :grid_class, :options, :data_block, :name, :html_block, :query
66
+ def label
67
+ options[:label]
68
+ end
35
69
 
36
- def initialize(grid_class, name, query, options = {}, &block)
37
- self.grid_class = grid_class
38
- self.name = name.to_sym
39
- self.options = options
40
- if options[:html] == true
41
- self.html_block = block
42
- else
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
- if options[:html].is_a? Proc
46
- self.html_block = options[:html]
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
- def data_value(model, grid)
53
- # backward compatibility method
54
- grid.data_value(name, model)
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
- def label
59
- self.options[:label]
60
- end
98
+ def order_by_value?
99
+ !!options[:order_by_value]
100
+ end
61
101
 
62
- def header
63
- if header = options[:header]
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
- def order
71
- if options.has_key?(:order) && options[:order] != true
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
- def supports_order?
79
- order || order_by_value?
80
- end
108
+ def html?
109
+ options[:html] != false
110
+ end
81
111
 
82
- def order_by_value(model, grid)
83
- if options[:order_by_value] == true
84
- grid.data_value(self, model)
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
- def order_by_value?
91
- !! options[:order_by_value]
92
- end
116
+ def mandatory?
117
+ !!options[:mandatory]
118
+ end
93
119
 
94
- def order_desc
95
- return nil unless order
96
- self.options[:order_desc]
97
- end
120
+ def tag_options
121
+ options[:tag_options] || {}
122
+ end
98
123
 
99
- def html?
100
- options[:html] != false
101
- end
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
- def data?
104
- self.data_block != nil
105
- end
131
+ def mandatory_explicitly_set?
132
+ options.key?(:mandatory)
133
+ end
106
134
 
107
- def mandatory?
108
- !! options[:mandatory]
109
- end
135
+ def enabled?(grid)
136
+ ::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
137
+ end
110
138
 
111
- def mandatory_explicitly_set?
112
- options.key?(:mandatory)
113
- end
139
+ def inspect
140
+ "#<#{self.class} #{grid_class}##{name} #{options.inspect}>"
141
+ end
114
142
 
115
- def enabled?(grid)
116
- ::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
117
- end
143
+ def to_s
144
+ header
145
+ end
118
146
 
119
- def inspect
120
- "#<#{self.class} #{grid_class}##{name} #{options.inspect}>"
121
- end
147
+ def html_value(context, asset, grid)
148
+ grid.html_value(name, context, asset)
149
+ end
122
150
 
123
- def to_s
124
- header
125
- end
151
+ def generic_value(model, grid)
152
+ grid.generic_value(self, model)
153
+ end
126
154
 
127
- def html_value(context, asset, grid)
128
- grid.html_value(name, context, asset)
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
- def generic_value(model, grid)
133
- grid.generic_value(self, model)
134
- end
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
- def append_preload(relation)
137
- return relation unless preload
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
- def preload
151
- preload = options[:preload]
174
+ if preload == true && driver.can_preload?(grid_class.scope, name)
175
+ name
176
+ else
177
+ preload
178
+ end
179
+ end
152
180
 
153
- if preload == true && driver.can_preload?(grid_class.scope, name)
154
- name
155
- else
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