administrate 1.0.0.beta3 → 1.0.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/administrate/application.css +91 -19
  3. data/app/assets/builds/administrate/application.css.map +1 -1
  4. data/app/assets/builds/administrate/application.js +12576 -3114
  5. data/app/assets/builds/administrate/application.js.map +4 -4
  6. data/app/assets/builds/administrate-internal/docs.css +25 -12
  7. data/app/assets/builds/administrate-internal/docs.css.map +1 -1
  8. data/app/assets/javascripts/administrate/application.js +1 -0
  9. data/app/assets/javascripts/administrate/controllers/index.js +2 -0
  10. data/app/assets/javascripts/administrate/controllers/select_controller.js +18 -1
  11. data/app/assets/javascripts/administrate/controllers/tooltip_controller.js +24 -0
  12. data/app/assets/javascripts/administrate/vendor/css-anchor-positioning.js +9310 -0
  13. data/app/assets/stylesheets/administrate/base/_typography.scss +8 -5
  14. data/app/assets/stylesheets/administrate/components/_buttons.scss +26 -1
  15. data/app/assets/stylesheets/administrate/components/_cells.scss +8 -1
  16. data/app/assets/stylesheets/administrate/components/_search.scss +44 -3
  17. data/app/assets/stylesheets/administrate-internal/docs.scss +25 -23
  18. data/app/controllers/administrate/application_controller.rb +9 -22
  19. data/app/controllers/concerns/administrate/punditize.rb +1 -9
  20. data/app/helpers/administrate/application_helper.rb +9 -1
  21. data/app/views/administrate/application/_collection.html.erb +29 -19
  22. data/app/views/administrate/application/_collection_header_actions.html.erb +1 -1
  23. data/app/views/administrate/application/_collection_item_actions.html.erb +2 -2
  24. data/app/views/administrate/application/_form.html.erb +1 -1
  25. data/app/views/administrate/application/_icons.html.erb +14 -6
  26. data/app/views/administrate/application/_index_header.html.erb +19 -0
  27. data/app/views/administrate/application/index.html.erb +1 -0
  28. data/app/views/fields/has_many/_form.html.erb +1 -1
  29. data/app/views/fields/has_one/_form.html.erb +6 -0
  30. data/app/views/fields/polymorphic/_form.html.erb +1 -1
  31. data/docs/customizing_dashboards.md +75 -6
  32. data/docs/guides/switching_templates_with_view_variants.md +45 -0
  33. data/docs/guides.md +1 -0
  34. data/docs/migrating-to-v1.md +34 -0
  35. data/lib/administrate/base_dashboard.rb +0 -6
  36. data/lib/administrate/field/associative.rb +2 -21
  37. data/lib/administrate/field/base.rb +19 -2
  38. data/lib/administrate/field/belongs_to.rb +1 -6
  39. data/lib/administrate/field/date.rb +5 -1
  40. data/lib/administrate/field/date_time.rb +2 -3
  41. data/lib/administrate/field/deferred.rb +5 -17
  42. data/lib/administrate/field/has_many.rb +22 -3
  43. data/lib/administrate/field/has_one.rb +1 -9
  44. data/lib/administrate/field/password.rb +4 -0
  45. data/lib/administrate/field/polymorphic.rb +1 -1
  46. data/lib/administrate/field/time.rb +5 -4
  47. data/lib/administrate/namespace.rb +10 -10
  48. data/lib/administrate/order.rb +8 -8
  49. data/lib/administrate/search.rb +8 -9
  50. data/lib/administrate/version.rb +1 -1
  51. data/lib/administrate/view_generator.rb +1 -0
  52. data/lib/administrate.rb +0 -38
  53. data/lib/generators/administrate/install/install_generator.rb +1 -0
  54. data/lib/generators/administrate/routes/routes_generator.rb +1 -0
  55. metadata +12 -20
@@ -106,11 +106,14 @@ For example:
106
106
  with this, you will be able to search through the column `name` from the
107
107
  association `belongs_to :country`, from your model.
108
108
 
109
- `:class_name` - Specifies the name of the associated class.
109
+ `:sortable` - Specifies if sorting should be enabled in the table views.
110
+ Default is `true`.
110
111
 
111
- `:primary_key` (deprecated) - Specifies the association's primary_key.
112
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the table views and dropdown menu.
113
+ If `sorting_column` is omitted and `order` is specified, the value of `order` will be used.
114
+ If neither is specified, sorting will be done using the foreign key.
112
115
 
113
- `:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
116
+ `:class_name` - Specifies the name of the associated class.
114
117
 
115
118
  **Field::HasMany**
116
119
 
@@ -124,11 +127,15 @@ set this to `0` or `false`. Default is `5`.
124
127
 
125
128
  `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
126
129
 
127
- `:class_name` - Specifies the name of the associated class.
130
+ `:sortable` - Specifies if sorting should be enabled in the table views.
131
+ Default is `true`.
128
132
 
129
- `:primary_key` (deprecated) - Specifies object's primary_key.
133
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the dropdown menu.
134
+ If `sorting_column` is omitted and `sort_by` is specified, the value of `sort_by` will be used.
135
+ If neither is specified, sorting will be done using the foreign key.
136
+ For `HasMany` associations, sorting is based on the count, so this option is not referenced in the table views.
130
137
 
131
- `:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
138
+ `:class_name` - Specifies the name of the associated class.
132
139
 
133
140
  **Field::HasOne**
134
141
 
@@ -154,6 +161,13 @@ For example:
154
161
  with this, you will be able to search through the column `name` from the
155
162
  association `has_one :city`, from your model.
156
163
 
164
+ `:sortable` - Specifies if sorting should be enabled in the table views.
165
+ Default is `true`.
166
+
167
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the table views and dropdown menu.
168
+ If `sorting_column` is omitted and `order` is specified, the value of `order` will be used.
169
+ If neither is specified, sorting will be done using the foreign key.
170
+
157
171
  `:class_name` - Specifies the name of the associated class.
158
172
 
159
173
  **Field::Number**
@@ -162,6 +176,13 @@ association `has_one :city`, from your model.
162
176
  Note that currently number fields are searched like text, which may yield
163
177
  more results than expected. Default is `false`.
164
178
 
179
+ `:sortable` - Specifies if sorting should be enabled in the table views.
180
+ Default is `true`.
181
+
182
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
183
+ By default, the column itself is used, but when used as a virtual column,
184
+ a custom sorting column can be specified.
185
+
165
186
  `:decimals` - Set the number of decimals to display. Defaults to `0`.
166
187
 
167
188
  `:prefix` - Prefixes the number with a string. Defaults to `""`.
@@ -210,8 +231,18 @@ Default is `[]`.
210
231
  `:order` - What to sort the association by in the form select.
211
232
  Default is `nil`.
212
233
 
234
+ `:sortable` - Specifies if sorting should be enabled in the table views.
235
+ Default is `true`.
236
+
213
237
  **Field::DateTime**
214
238
 
239
+ `:sortable` - Specifies if sorting should be enabled in the table views.
240
+ Default is `true`.
241
+
242
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
243
+ By default, the column itself is used, but when used as a virtual column,
244
+ a custom sorting column can be specified.
245
+
215
246
  `:format` - Specify what format, using `strftime` you would like `DateTime`
216
247
  objects to display as.
217
248
 
@@ -220,6 +251,13 @@ in.
220
251
 
221
252
  **Field::Date**
222
253
 
254
+ `:sortable` - Specifies if sorting should be enabled in the table views.
255
+ Default is `true`.
256
+
257
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
258
+ By default, the column itself is used, but when used as a virtual column,
259
+ a custom sorting column can be specified.
260
+
223
261
  `:format` - Specify what format, using `strftime` you would like `Date`
224
262
  objects to display as.
225
263
 
@@ -249,6 +287,13 @@ If no collection is provided and no enum can be detected, the list of options wi
249
287
  `:searchable` - Specify if the attribute should be considered when searching.
250
288
  Default is `true`.
251
289
 
290
+ `:sortable` - Specifies if sorting should be enabled in the table views.
291
+ Default is `true`.
292
+
293
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
294
+ By default, the column itself is used, but when used as a virtual column,
295
+ a custom sorting column can be specified.
296
+
252
297
  `:include_blank` - Similar to [the option of the same name accepted by Rails helpers](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html). If provided, a "blank" option will be added first to the list of options, with the value of `include_blank` as label.
253
298
 
254
299
  **Field::String**
@@ -256,6 +301,13 @@ Default is `true`.
256
301
  `:searchable` - Specify if the attribute should be considered when searching.
257
302
  Default is `true`.
258
303
 
304
+ `:sortable` - Specifies if sorting should be enabled in the table views.
305
+ Default is `true`.
306
+
307
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
308
+ By default, the column itself is used, but when used as a virtual column,
309
+ a custom sorting column can be specified.
310
+
259
311
  `:truncate` - Set the number of characters to display in the index view.
260
312
  Defaults to `50`.
261
313
 
@@ -264,6 +316,13 @@ Defaults to `50`.
264
316
  `:searchable` - Specify if the attribute should be considered when searching.
265
317
  Default is `false`.
266
318
 
319
+ `:sortable` - Specifies if sorting should be enabled in the table views.
320
+ Default is `true`.
321
+
322
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
323
+ By default, the column itself is used, but when used as a virtual column,
324
+ a custom sorting column can be specified.
325
+
267
326
  `:truncate` - Set the number of characters to display in the index view.
268
327
  Defaults to `50`.
269
328
 
@@ -275,6 +334,13 @@ Example: `.with_options(input_options: { rows: 20 })`
275
334
  `:searchable` - Specify if the attribute should be considered when searching.
276
335
  Default is `true`.
277
336
 
337
+ `:sortable` - Specifies if sorting should be enabled in the table views.
338
+ Default is `true`.
339
+
340
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
341
+ By default, the column itself is used, but when used as a virtual column,
342
+ a custom sorting column can be specified.
343
+
278
344
  `:truncate` - Set the number of characters to display in the index view.
279
345
  Defaults to `50`.
280
346
 
@@ -286,6 +352,9 @@ Defaults is `{}`.
286
352
  `:searchable` - Specify if the attribute should be considered when searching.
287
353
  Default is `false`.
288
354
 
355
+ `:sortable` - Specifies if sorting should be enabled in the table views.
356
+ Default is `false`.
357
+
289
358
  `:truncate` - Set the number of characters to display in the views.
290
359
  Defaults to `50`.
291
360
 
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Switching templates with view variants
3
+ ---
4
+
5
+ You can switch to different templates using Rails' support for [view
6
+ variants][], which can be used to override the template used inside the
7
+ controller.
8
+
9
+ By setting the `request.variant` option to any value (in this case, `:admin`)
10
+ at any point in any controller, you can add a new variant to Rails' template
11
+ lookup tree (in this case, `.html+admin.erb`).
12
+
13
+ For example, to add a button to become the admin to view certain functionality:
14
+
15
+ ```ruby
16
+ class CustomersController < Admin::ApplicationController
17
+ before_action :with_variant, only: %i[index]
18
+
19
+ private
20
+
21
+ def with_variant
22
+ if @current_user.admin?
23
+ request.variant = :admin
24
+ end
25
+ end
26
+ end
27
+ ```
28
+
29
+ ```erb
30
+ <!-- app/views/admin/customers/_index_header.html.erb -->
31
+ <p class="identity__banner">
32
+ You are logged in as <em><%= pundit_user.name %></em>.
33
+ <%= link_to("Become the Admin", become_admin_customer_path("admin"),
34
+ class: "identity__become-action")%>
35
+ </p>
36
+ ```
37
+
38
+ ```erb
39
+ <!-- app/views/admin/customers/_index_header.html+admin.erb -->
40
+ <p class="identity__banner identity__banner--admin">
41
+ You are logged in as <em><%= pundit_user.name %></em>.
42
+ </p>
43
+ ```
44
+
45
+ [view variants]: https://guides.rubyonrails.org/layouts_and_rendering.html#the-variants-option
data/docs/guides.md CHANGED
@@ -5,3 +5,4 @@ title: Guides
5
5
  - [Hiding Dashboards from the Sidebar](./guides/hiding_dashboards_from_sidebar)
6
6
  - [Customising the search](./guides/customising_search)
7
7
  - [Scoping HasMany Relations](./guides/scoping_has_many_relations.md)
8
+ - [Switching templates with view variants](./guides/switching_templates_with_view_variants.md)
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: Migrating to v1
3
+ ---
4
+
5
+ In the release of v1.0.0, we [began bundling assets in the gem itself][2397].
6
+ In the future, this should mean that any changes made to assets (coming
7
+ from you or from Administrate updates) should not have an effect on you.
8
+ However, this is quite a big change and so you might find some problems.
9
+
10
+ As with most upgrades, if you're upgrading between versions with changes to the
11
+ templates, and if you've customised them, you may need to apply recent changes.
12
+ You can see those which changed in the [CHANGELOG][].
13
+
14
+ This applies to both modified files in `app/views/admin` and `app/views/fields`
15
+ if you have your own Field classes defined. A good way is to use the same
16
+ command to generate the view as for the earlier version:
17
+ `rails generate administrate:views:ACTION MyModel`
18
+ noting the changes and re-applying the modifications
19
+
20
+ [2397]: https://github.com/thoughtbot/administrate/pull/2397
21
+ [CHANGELOG]: https://github.com/thoughtbot/administrate/blob/main/CHANGELOG.md
22
+
23
+ ## Reported issues
24
+
25
+ ### Removal of the `sprockets-rails` transitive dependency
26
+
27
+ [Issue][2514]
28
+
29
+ Previously, Administrate depended on [`sprockets-rails`][], if you have a
30
+ dependency which requires this, you may now need to add a direct dependency on
31
+ your application.
32
+
33
+ [2514]: https://github.com/thoughtbot/administrate/issues/2514
34
+ [`sprockets-rails`]: https://rubygems.org/gems/sprockets-rails
@@ -111,12 +111,6 @@ module Administrate
111
111
  attribute_includes(collection_attributes)
112
112
  end
113
113
 
114
- def item_includes
115
- # Deprecated, internal usage has moved to #item_associations
116
- Administrate.warn_of_deprecated_method(self.class, :item_includes)
117
- attribute_includes(show_page_attributes)
118
- end
119
-
120
114
  def item_associations
121
115
  attributes = if show_page_attributes.is_a?(Hash)
122
116
  show_page_attributes.values.flatten
@@ -56,36 +56,17 @@ module Administrate
56
56
  "#{associated_class_name}Dashboard".constantize.new
57
57
  end
58
58
 
59
- def primary_key
60
- # Deprecated, renamed `association_primary_key`
61
- Administrate.warn_of_deprecated_method(self.class, :primary_key)
62
- association_primary_key
63
- end
64
-
65
59
  def association_primary_key
66
- if option_given?(:primary_key)
67
- deprecated_option(:primary_key)
68
- else
69
- self.class.association_primary_key_for(resource.class, attribute)
70
- end
60
+ self.class.association_primary_key_for(resource.class, attribute)
71
61
  end
72
62
 
73
63
  def foreign_key
74
- if option_given?(:foreign_key)
75
- deprecated_option(:foreign_key)
76
- else
77
- self.class.foreign_key_for(resource.class, attribute)
78
- end
64
+ self.class.foreign_key_for(resource.class, attribute)
79
65
  end
80
66
 
81
67
  def option_given?(name)
82
68
  options.key?(name)
83
69
  end
84
-
85
- def deprecated_option(name)
86
- Administrate.warn_of_deprecated_option(name)
87
- options.fetch(name)
88
- end
89
70
  end
90
71
  end
91
72
  end
@@ -24,6 +24,10 @@ module Administrate
24
24
  false
25
25
  end
26
26
 
27
+ def self.sortable?
28
+ true
29
+ end
30
+
27
31
  def self.field_type
28
32
  to_s.split("::").last.underscore
29
33
  end
@@ -32,6 +36,19 @@ module Administrate
32
36
  attr
33
37
  end
34
38
 
39
+ def self.partial_prefixes
40
+ @partial_prefixes ||=
41
+ if superclass.respond_to?(:partial_prefixes)
42
+ local_partial_prefixes + superclass.partial_prefixes
43
+ else
44
+ local_partial_prefixes
45
+ end
46
+ end
47
+
48
+ def self.local_partial_prefixes
49
+ ["fields/#{field_type}"]
50
+ end
51
+
35
52
  def initialize(attribute, data, page, options = {})
36
53
  @attribute = attribute
37
54
  @page = page
@@ -66,8 +83,8 @@ module Administrate
66
83
  end
67
84
  end
68
85
 
69
- def to_partial_path
70
- "/fields/#{self.class.field_type}/#{page}"
86
+ def partial_prefixes
87
+ self.class.partial_prefixes
71
88
  end
72
89
 
73
90
  def required?
@@ -5,12 +5,7 @@ module Administrate
5
5
  class BelongsTo < Associative
6
6
  def self.permitted_attribute(attr, options = {})
7
7
  resource_class = options[:resource_class]
8
- if resource_class
9
- foreign_key_for(resource_class, attr)
10
- else
11
- Administrate.warn_of_missing_resource_class
12
- :"#{attr}_id"
13
- end
8
+ foreign_key_for(resource_class, attr)
14
9
  end
15
10
 
16
11
  def self.eager_load?
@@ -5,7 +5,7 @@ module Administrate
5
5
  class Date < Base
6
6
  def date
7
7
  I18n.localize(
8
- data.to_date,
8
+ data.in_time_zone(timezone).to_date,
9
9
  format: format
10
10
  )
11
11
  end
@@ -15,6 +15,10 @@ module Administrate
15
15
  def format
16
16
  options.fetch(:format, :default)
17
17
  end
18
+
19
+ def timezone
20
+ options.fetch(:timezone, ::Time.zone)
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -13,8 +13,7 @@ module Administrate
13
13
  def datetime
14
14
  I18n.localize(
15
15
  data.in_time_zone(timezone),
16
- format: format,
17
- default: data
16
+ format: format
18
17
  )
19
18
  end
20
19
 
@@ -25,7 +24,7 @@ module Administrate
25
24
  end
26
25
 
27
26
  def timezone
28
- options.fetch(:timezone, ::Time.zone.name || "UTC")
27
+ options.fetch(:timezone, ::Time.zone)
29
28
  end
30
29
  end
31
30
  end
@@ -41,28 +41,16 @@ module Administrate
41
41
  end
42
42
  end
43
43
 
44
- def searchable_field
45
- Administrate.deprecator.warn(
46
- "searchable_field is deprecated, use searchable_fields instead"
47
- )
48
- options.fetch(:searchable_field)
44
+ def searchable_fields
45
+ options.fetch(:searchable_fields)
49
46
  end
50
47
 
51
- def searchable_fields
52
- if options.key?(:searchable_field)
53
- [searchable_field]
54
- else
55
- options.fetch(:searchable_fields)
56
- end
48
+ def sortable?
49
+ options.fetch(:sortable, deferred_class.sortable?)
57
50
  end
58
51
 
59
52
  def permitted_attribute(attr, opts = {})
60
- if options.key?(:foreign_key)
61
- Administrate.warn_of_deprecated_option(:foreign_key)
62
- options.fetch(:foreign_key)
63
- else
64
- deferred_class.permitted_attribute(attr, options.merge(opts))
65
- end
53
+ deferred_class.permitted_attribute(attr, options.merge(opts))
66
54
  end
67
55
 
68
56
  delegate :html_class, to: :deferred_class
@@ -72,7 +72,7 @@ module Administrate
72
72
  end
73
73
 
74
74
  def more_than_limit?
75
- paginate? && data.count(:all) > limit
75
+ paginate? && data.size > limit
76
76
  end
77
77
 
78
78
  def data
@@ -82,12 +82,21 @@ module Administrate
82
82
  def order_from_params(params)
83
83
  Administrate::Order.new(
84
84
  params.fetch(:order, sort_by),
85
- params.fetch(:direction, direction)
85
+ params.fetch(:direction, direction),
86
+ sorting_column: sorting_column(
87
+ associated_dashboard_attribute(params.fetch(:order, sort_by))
88
+ )
86
89
  )
87
90
  end
88
91
 
89
92
  def order
90
- @order ||= Administrate::Order.new(sort_by, direction)
93
+ @order ||= Administrate::Order.new(
94
+ sort_by,
95
+ direction,
96
+ sorting_column: sorting_column(
97
+ associated_dashboard_attribute(sort_by)
98
+ )
99
+ )
91
100
  end
92
101
 
93
102
  private
@@ -109,6 +118,16 @@ module Administrate
109
118
  associated_dashboard.display_resource(resource)
110
119
  end
111
120
 
121
+ def sorting_column(dashboard_attribute)
122
+ return unless dashboard_attribute.try(:options)
123
+
124
+ dashboard_attribute.options.fetch(:sorting_column, nil)
125
+ end
126
+
127
+ def associated_dashboard_attribute(attribute)
128
+ associated_dashboard.attribute_types[attribute.to_sym] if attribute
129
+ end
130
+
112
131
  def sort_by
113
132
  options[:sort_by]
114
133
  end
@@ -7,17 +7,9 @@ module Administrate
7
7
  resource_class = options[:resource_class]
8
8
  final_associated_class_name =
9
9
  if options.key?(:class_name)
10
- Administrate.warn_of_deprecated_option(:class_name)
11
10
  options.fetch(:class_name)
12
- elsif resource_class
13
- associated_class_name(resource_class, attr)
14
11
  else
15
- Administrate.warn_of_missing_resource_class
16
- if options
17
- attr.to_s.singularize.camelcase
18
- else
19
- attr
20
- end
12
+ associated_class_name(resource_class, attr)
21
13
  end
22
14
  related_dashboard_attributes =
23
15
  Administrate::ResourceResolver
@@ -7,6 +7,10 @@ module Administrate
7
7
  false
8
8
  end
9
9
 
10
+ def self.sortable?
11
+ false
12
+ end
13
+
10
14
  def truncate
11
15
  data.to_s.gsub(/./, character)[0...truncation_length]
12
16
  end
@@ -9,7 +9,7 @@ module Administrate
9
9
 
10
10
  def associated_resource_grouped_options
11
11
  classes.map do |klass|
12
- [klass.to_s, candidate_resources_for(klass).map do |resource|
12
+ [klass.model_name.human, candidate_resources_for(klass).map do |resource|
13
13
  [display_candidate_resource(resource), resource.to_global_id]
14
14
  end]
15
15
  end
@@ -4,15 +4,16 @@ module Administrate
4
4
  module Field
5
5
  class Time < Base
6
6
  def time
7
- return I18n.localize(data, format: format) if options[:format]
8
-
9
- data.strftime("%I:%M%p")
7
+ I18n.localize(
8
+ data,
9
+ format: format
10
+ )
10
11
  end
11
12
 
12
13
  private
13
14
 
14
15
  def format
15
- options[:format]
16
+ options.fetch(:format, "%I:%M%p")
16
17
  end
17
18
  end
18
19
  end
@@ -11,10 +11,16 @@ module Administrate
11
11
  end
12
12
 
13
13
  def routes
14
- @routes ||= all_routes.select do |controller, _action|
15
- controller.starts_with?("#{namespace}/")
16
- end.map do |controller, action|
17
- [controller.gsub(/^#{namespace}\//, ""), action]
14
+ @routes ||= begin
15
+ prefix = "#{namespace}/".freeze
16
+ Rails.application.routes.routes.filter_map do |route|
17
+ next unless route.defaults[:controller]&.start_with?(prefix)
18
+
19
+ [
20
+ route.defaults[:controller].delete_prefix(prefix),
21
+ route.defaults[:action]
22
+ ]
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -25,11 +31,5 @@ module Administrate
25
31
  private
26
32
 
27
33
  attr_reader :namespace
28
-
29
- def all_routes
30
- Rails.application.routes.routes.map do |route|
31
- route.defaults.values_at(:controller, :action).map(&:to_s)
32
- end
33
- end
34
34
  end
35
35
  end
@@ -1,19 +1,19 @@
1
1
  module Administrate
2
2
  class Order
3
- def initialize(attribute = nil, direction = nil, association_attribute: nil)
3
+ def initialize(attribute = nil, direction = nil, sorting_column: nil)
4
4
  @attribute = attribute
5
5
  @direction = sanitize_direction(direction)
6
- @association_attribute = association_attribute
6
+ @sorting_column = sorting_column || attribute
7
7
  end
8
8
 
9
9
  def apply(relation)
10
10
  return order_by_association(relation) unless
11
11
  reflect_association(relation).nil?
12
12
 
13
- order = relation.arel_table[attribute].public_send(direction)
13
+ order = relation.arel_table[sorting_column].public_send(direction)
14
14
 
15
15
  return relation.reorder(order) if
16
- column_exist?(relation, attribute)
16
+ column_exist?(relation, sorting_column)
17
17
 
18
18
  relation
19
19
  end
@@ -33,7 +33,7 @@ module Administrate
33
33
 
34
34
  private
35
35
 
36
- attr_reader :attribute, :association_attribute
36
+ attr_reader :attribute, :sorting_column
37
37
 
38
38
  def sanitize_direction(direction)
39
39
  %w[asc desc].include?(direction.to_s) ? direction.to_sym : :asc
@@ -94,9 +94,9 @@ module Administrate
94
94
  end
95
95
 
96
96
  def ordering_by_association_column?(relation)
97
- association_attribute &&
97
+ (attribute != sorting_column) &&
98
98
  column_exist?(
99
- reflect_association(relation).klass, association_attribute.to_sym
99
+ reflect_association(relation).klass, sorting_column.to_sym
100
100
  )
101
101
  end
102
102
 
@@ -113,7 +113,7 @@ module Administrate
113
113
  end
114
114
 
115
115
  def order_by_association_attribute(relation)
116
- order_by_association_column(relation, association_attribute)
116
+ order_by_association_column(relation, sorting_column)
117
117
  end
118
118
 
119
119
  def order_by_association_column(relation, column_name)
@@ -63,6 +63,14 @@ module Administrate
63
63
  end
64
64
  end
65
65
 
66
+ def valid_filters
67
+ if @dashboard.class.const_defined?(:COLLECTION_FILTERS)
68
+ @dashboard.class.const_get(:COLLECTION_FILTERS).stringify_keys
69
+ else
70
+ {}
71
+ end
72
+ end
73
+
66
74
  private
67
75
 
68
76
  def apply_filter(filter, filter_param, resources)
@@ -116,14 +124,6 @@ module Administrate
116
124
  .where(query_template, *query_values)
117
125
  end
118
126
 
119
- def valid_filters
120
- if @dashboard.class.const_defined?(:COLLECTION_FILTERS)
121
- @dashboard.class.const_get(:COLLECTION_FILTERS).stringify_keys
122
- else
123
- {}
124
- end
125
- end
126
-
127
127
  def attribute_types
128
128
  @dashboard.class.const_get(:ATTRIBUTE_TYPES)
129
129
  end
@@ -133,7 +133,6 @@ module Administrate
133
133
  provided_class_name = attribute_types[attr].options[:class_name]
134
134
  unquoted_table_name =
135
135
  if provided_class_name
136
- Administrate.warn_of_deprecated_option(:class_name)
137
136
  provided_class_name.constantize.table_name
138
137
  else
139
138
  @scoped_resource.reflect_on_association(attr).klass.table_name
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "1.0.0.beta3".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end