administrate 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of administrate might be problematic. Click here for more details.

Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/date_time_picker.js +5 -1
  3. data/app/controllers/administrate/application_controller.rb +17 -12
  4. data/app/views/administrate/application/_flashes.html.erb +1 -1
  5. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  6. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  7. data/app/views/fields/date_time/_form.html.erb +1 -1
  8. data/app/views/fields/date_time/_index.html.erb +1 -1
  9. data/app/views/fields/password/_form.html.erb +23 -0
  10. data/app/views/fields/password/_index.html.erb +18 -0
  11. data/app/views/fields/password/_show.html.erb +18 -0
  12. data/app/views/fields/time/_form.html.erb +22 -0
  13. data/app/views/fields/time/_index.html.erb +17 -0
  14. data/app/views/fields/time/_show.html.erb +17 -0
  15. data/config/locales/administrate.al.yml +28 -0
  16. data/config/locales/administrate.ja.yml +2 -2
  17. data/config/locales/administrate.ru.yml +2 -2
  18. data/docs/customizing_dashboards.md +67 -1
  19. data/docs/customizing_page_views.md +5 -1
  20. data/lib/administrate/base_dashboard.rb +2 -0
  21. data/lib/administrate/field/associative.rb +4 -4
  22. data/lib/administrate/field/belongs_to.rb +3 -1
  23. data/lib/administrate/field/date_time.rb +1 -1
  24. data/lib/administrate/field/deferred.rb +4 -0
  25. data/lib/administrate/field/password.rb +25 -0
  26. data/lib/administrate/field/polymorphic.rb +1 -1
  27. data/lib/administrate/field/time.rb +8 -0
  28. data/lib/administrate/namespace.rb +1 -1
  29. data/lib/administrate/order.rb +3 -1
  30. data/lib/administrate/search.rb +39 -5
  31. data/lib/administrate/version.rb +1 -1
  32. data/lib/generators/administrate/dashboard/dashboard_generator.rb +1 -1
  33. metadata +17 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 200650aa4703202324342f17c6e1bce7642309664b28149e3aa5763d708af7cf
4
- data.tar.gz: 2b49177bd91bc20d1c5ffcb15fb33497339163e5058e24c39d82ef7fba6bdae9
3
+ metadata.gz: 9d7d418391f23f99dc9c37e3ce7dc127a6cff9eb45f6994d9604f3771f4f51b4
4
+ data.tar.gz: cc2badcba457d79690e1ae05e2f03069ed1e13522a1a0f58ff2ad9b38ebc071d
5
5
  SHA512:
6
- metadata.gz: 56aa3cfb03420e71ee5ce158e3ce2d98b04a2038d8322b84dcddf4ebca67e27c599806d58d61d8f7c2d39f1bec4a723ac47f2157e73ae54df0e7249e6d37a9fd
7
- data.tar.gz: 6856dcf40b1cabea4b46e580f1379e07a79fca813040c39ae7e5018e1fb2a0c55e62ed4940872f5a28b983f762a276808b47d3954593660fd81a170f01ddf749
6
+ metadata.gz: a7e684f116a9d44b54d32fcf6c12865f61dcae3749366c253fdb4d9003c2930c18303d034f16c0273c174c035bc05b4524042e6d09124051a68af40eac8a6dc1
7
+ data.tar.gz: 4045bcd18584e285373a860c0f634f952aff238063a58862750fc5ad9988d8dac9e5bba18ce684be6d6b3a0a72ae3647f863d134cb756038fae7c5f5bd65e88c
@@ -1,5 +1,9 @@
1
1
  $(function () {
2
- $(".datetimepicker").datetimepicker({
2
+ $('[data-type="time"]').datetimepicker({
3
+ debug: false,
4
+ format: "HH:mm:ss",
5
+ });
6
+ $('[data-type="datetime"]').datetimepicker({
3
7
  debug: false,
4
8
  format: "YYYY-MM-DD HH:mm:ss",
5
9
  });
@@ -7,7 +7,7 @@ module Administrate
7
7
  resources = Administrate::Search.new(scoped_resource,
8
8
  dashboard_class,
9
9
  search_term).run
10
- resources = resources.includes(*resource_includes) if resource_includes.any?
10
+ resources = apply_resource_includes(resources)
11
11
  resources = order.apply(resources)
12
12
  resources = resources.page(params[:page]).per(records_per_page)
13
13
  page = Administrate::Page::Collection.new(dashboard, order: order)
@@ -16,7 +16,7 @@ module Administrate
16
16
  resources: resources,
17
17
  search_term: search_term,
18
18
  page: page,
19
- show_search_bar: show_search_bar?
19
+ show_search_bar: show_search_bar?,
20
20
  }
21
21
  end
22
22
 
@@ -70,8 +70,11 @@ module Administrate
70
70
  end
71
71
 
72
72
  def destroy
73
- requested_resource.destroy
74
- flash[:notice] = translate_with_resource("destroy.success")
73
+ if requested_resource.destroy
74
+ flash[:notice] = translate_with_resource("destroy.success")
75
+ else
76
+ flash[:error] = requested_resource.errors.full_messages.join("<br/>")
77
+ end
75
78
  redirect_to action: :index
76
79
  end
77
80
 
@@ -98,15 +101,15 @@ module Administrate
98
101
  end
99
102
 
100
103
  def order
101
- @_order ||= Administrate::Order.new(params[:order], params[:direction])
104
+ @order ||= Administrate::Order.new(params[:order], params[:direction])
102
105
  end
103
106
 
104
107
  def dashboard
105
- @_dashboard ||= dashboard_class.new
108
+ @dashboard ||= dashboard_class.new
106
109
  end
107
110
 
108
111
  def requested_resource
109
- @_requested_resource ||= find_resource(params[:id]).tap do |resource|
112
+ @requested_resource ||= find_resource(params[:id]).tap do |resource|
110
113
  authorize_resource(resource)
111
114
  end
112
115
  end
@@ -119,8 +122,10 @@ module Administrate
119
122
  resource_class.default_scoped
120
123
  end
121
124
 
122
- def resource_includes
123
- dashboard.association_includes
125
+ def apply_resource_includes(relation)
126
+ resource_includes = dashboard.association_includes
127
+ return relation if resource_includes.empty?
128
+ relation.includes(*resource_includes)
124
129
  end
125
130
 
126
131
  def resource_params
@@ -147,7 +152,7 @@ module Administrate
147
152
  helper_method :resource_name
148
153
 
149
154
  def resource_resolver
150
- @_resource_resolver ||=
155
+ @resource_resolver ||=
151
156
  Administrate::ResourceResolver.new(controller_path)
152
157
  end
153
158
 
@@ -160,11 +165,11 @@ module Administrate
160
165
 
161
166
  def show_search_bar?
162
167
  dashboard.attribute_types_for(
163
- dashboard.collection_attributes
168
+ dashboard.collection_attributes,
164
169
  ).any? { |_name, attribute| attribute.searchable? }
165
170
  end
166
171
 
167
- def show_action?(action, resource)
172
+ def show_action?(_action, _resource)
168
173
  true
169
174
  end
170
175
  helper_method :show_action?
@@ -14,7 +14,7 @@ This partial renders flash messages on every page.
14
14
  <% if flash.any? %>
15
15
  <div class="flashes">
16
16
  <% flash.each do |key, value| -%>
17
- <div class="flash flash-<%= key %>"><%= value %></div>
17
+ <div class="flash flash-<%= key %>"><%= value.html_safe %></div>
18
18
  <% end -%>
19
19
  </div>
20
20
  <% end %>
@@ -16,7 +16,7 @@ By default, the relationship is rendered as a link to the associated object.
16
16
  %>
17
17
 
18
18
  <% if field.data %>
19
- <% if valid_action?(:show, field.attribute) %>
19
+ <% if valid_action?(:show, field.associated_class) %>
20
20
  <%= link_to(
21
21
  field.display_associated_resource,
22
22
  [namespace, field.data],
@@ -16,7 +16,7 @@ By default, the relationship is rendered as a link to the associated object.
16
16
  %>
17
17
 
18
18
  <% if field.data %>
19
- <% if valid_action?(:show, field.attribute) %>
19
+ <% if valid_action?(:show, field.associated_class) %>
20
20
  <%= link_to(
21
21
  field.display_associated_resource,
22
22
  [namespace, field.data],
@@ -20,5 +20,5 @@ By default, the input is a text field that is augmented with [DateTimePicker].
20
20
  <%= f.label field.attribute %>
21
21
  </div>
22
22
  <div class="field-unit__field">
23
- <%= f.text_field field.attribute, class: "datetimepicker" %>
23
+ <%= f.text_field field.attribute, data: { type: 'datetime' } %>
24
24
  </div>
@@ -17,5 +17,5 @@ as a localized date & time string.
17
17
  %>
18
18
 
19
19
  <% if field.data %>
20
- <%= field.date %>
20
+ <%= field.datetime %>
21
21
  <% end %>
@@ -0,0 +1,23 @@
1
+ <%#
2
+ # Password Form Partial
3
+
4
+ This partial renders an input element for a password attribute.
5
+ By default, the input is a password field.
6
+
7
+ ## Local variables:
8
+
9
+ - `f`:
10
+ A Rails form generator, used to help create the appropriate input fields.
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <div class="field-unit__label">
19
+ <%= f.label field.attribute %>
20
+ </div>
21
+ <div class="field-unit__field">
22
+ <%= f.password_field field.attribute, value: field.data %>
23
+ </div>
@@ -0,0 +1,18 @@
1
+ <%#
2
+ # Password Index Partial
3
+
4
+ This partial renders a password attribute
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the attribute is rendered as a truncated string.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <%= field.truncate %>
@@ -0,0 +1,18 @@
1
+ <%#
2
+ # Password Show Partial
3
+
4
+ This partial renders a password attribute,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the attribute is rendered as an truncate string.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <%= field.truncate %>
@@ -0,0 +1,22 @@
1
+ <%#
2
+ # Time Form Partial
3
+
4
+ This partial renders an input element for time attributes.
5
+ By default, the input is a select field for the time attributes.
6
+
7
+ ## Local variables:
8
+
9
+ - `f`:
10
+ A Rails form generator, used to help create the appropriate input fields.
11
+ - `field`:
12
+ An instance of [Administrate::Field::Time][1].
13
+ A wrapper around the tmie attributes pulled from the model.
14
+
15
+ %>
16
+
17
+ <div class="field-unit__label">
18
+ <%= f.label field.attribute %>
19
+ </div>
20
+ <div class="field-unit__field">
21
+ <%= f.text_field field.attribute, data: { type: 'time' } %>
22
+ </div>
@@ -0,0 +1,17 @@
1
+ <%#
2
+ # Time Index Partial
3
+
4
+ This partial renders an time attribute
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the attribute is rendered as a text tag.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Time][1].
13
+ A wrapper around the time attributes pulled from the model.
14
+
15
+ %>
16
+
17
+ <%= field.data.strftime("%I:%M%p").to_s %>
@@ -0,0 +1,17 @@
1
+ <%#
2
+ # Time Show Partial
3
+
4
+ This partial renders an time attribute,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the attribute is rendered as a text tag.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Time][1].
13
+ A wrapper around the time attributes pulled from the model.
14
+
15
+ %>
16
+
17
+ <%= field.data.strftime("%I:%M%p").to_s %>
@@ -0,0 +1,28 @@
1
+ ---
2
+ al:
3
+ administrate:
4
+ actions:
5
+ confirm: A jeni te sigurtë?
6
+ destroy: Fshij
7
+ edit: Ndrysho
8
+ edit_resource: Ndrysho %{name}
9
+ show_resource: Trego %{name}
10
+ new_resource: Të re %{name}
11
+ back: Prapa
12
+ controller:
13
+ create:
14
+ success: "%{resource} është krijuar me sukses."
15
+ destroy:
16
+ success: "%{resource} është fshirë me sukses."
17
+ update:
18
+ success: "%{resource} është azhurnuar me sukses."
19
+ fields:
20
+ has_many:
21
+ more: Duke treguar %{count} nga %{total_count}
22
+ none: Asnjë
23
+ form:
24
+ error: gabim
25
+ errors: "%{pluralized_errors} nuk e lejoj %{resource_name} të ruhet:"
26
+ search:
27
+ clear: Pastro kërkimin
28
+ label: Kërko %{resource}
@@ -21,8 +21,8 @@ ja:
21
21
  more: "%{total_count} 件中 %{count} 件表示"
22
22
  none: データがありません
23
23
  form:
24
- error: error
25
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
24
+ error: エラー
25
+ errors: "%{pluralized_errors}のため%{resource_name}を保存できません。"
26
26
  search:
27
27
  clear: 検索をクリアする
28
28
  label: サーチ %{resource}
@@ -21,8 +21,8 @@ ru:
21
21
  more: "%{count} из %{total_count}"
22
22
  none: Нет
23
23
  form:
24
- error: error
25
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
24
+ error: Ошибка
25
+ errors: "При сохранении %{resource_name} произошли ошибки:"
26
26
  search:
27
27
  clear: Очистить поиск
28
28
  label: Поиск %{resource}
@@ -10,7 +10,7 @@ require "administrate/dashboard/base"
10
10
 
11
11
  class CustomerDashboard < Administrate::Dashboard::Base
12
12
  ATTRIBUTE_TYPES = {
13
- id: Field::Integer,
13
+ id: Field::Number,
14
14
  name: Field::String,
15
15
  email: Field::String,
16
16
  created_at: Field::DateTime,
@@ -62,6 +62,7 @@ specify, including:
62
62
  - `Field::Select`
63
63
  - `Field::String`
64
64
  - `Field::Text`
65
+ - `Field::Password`
65
66
 
66
67
  ## Customizing Fields
67
68
 
@@ -80,6 +81,30 @@ than one column. e.g.: `"name, email DESC"`.
80
81
  `:foreign_key` - Specifies the name of the foreign key directly.
81
82
  Defaults to `:#{attribute}_id`.
82
83
 
84
+ `:scope` - Specifies a custom scope inside a callable. Useful for preloading.
85
+ Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
86
+
87
+ `:class_name` - Specifies the name of the associated class.
88
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
89
+
90
+ `:searchable` - Specify if the attribute should be considered when searching.
91
+ Default is `false`.
92
+
93
+ `searchable_field` - Specify which column to use on the search, only applies
94
+ if `searchable` is `true`
95
+
96
+ For example:
97
+
98
+ ```ruby
99
+ country: Field::BelongsTo(
100
+ searchable: true,
101
+ seachable_field: 'name',
102
+ )
103
+ ```
104
+
105
+ with this, you will be able to search through the column `name` from the
106
+ association `belongs_to :country`, from your model.
107
+
83
108
  **Field::HasMany**
84
109
 
85
110
  `:limit` - Set the number of resources to display in the show view. Default is
@@ -93,8 +118,38 @@ Defaults to `:#{attribute}_id`.
93
118
 
94
119
  `:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
95
120
 
121
+ `:class_name` - Specifies the name of the associated class.
122
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
123
+
124
+ **Field::HasOne**
125
+
126
+ `:class_name` - Specifies the name of the associated class.
127
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
128
+
129
+ `:searchable` - Specify if the attribute should be considered when searching.
130
+ Default is `false`.
131
+
132
+ `searchable_field` - Specify which column to use on the search, only applies if
133
+ `searchable` is `true`
134
+
135
+ For example:
136
+
137
+ ```ruby
138
+ cities: Field::HasMany(
139
+ searchable: true,
140
+ seachable_field: 'name',
141
+ )
142
+ ```
143
+
144
+ with this, you will be able to search through the column `name` from the
145
+ association `has_many :cities`, from your model.
146
+
96
147
  **Field::Number**
97
148
 
149
+ `:searchable` - Specify if the attribute should be considered when searching.
150
+ Note that currently number fields are searched like text, which may yield
151
+ more results than expected. Default is `false`.
152
+
98
153
  `:decimals` - Set the number of decimals to display. Defaults to `0`.
99
154
 
100
155
  `:prefix` - Prefixes the number with a string. Defaults to `""`.
@@ -158,6 +213,17 @@ Default is `false`.
158
213
  `:truncate` - Set the number of characters to display in the index view.
159
214
  Defaults to `50`.
160
215
 
216
+ **Field::Password**
217
+
218
+ `:searchable` - Specify if the attribute should be considered when searching.
219
+ Default is `false`.
220
+
221
+ `:truncate` - Set the number of characters to display in the views.
222
+ Defaults to `50`.
223
+
224
+ `:character` - Set the replace character.
225
+ Defaults to `•`.
226
+
161
227
  ### Defining Labels
162
228
 
163
229
  To change the user-facing label for an attribute,
@@ -67,7 +67,7 @@ and will leave the show pages for other resources unchanged.
67
67
  ## Customizing layouts
68
68
 
69
69
  Many developers need to customize the layouts of their admin dashboard.
70
- It's so easy that pass in the "layout" key word to the view generators.
70
+ It's as easy as passing in the "layout" keyword to the view generators.
71
71
 
72
72
  ```bash
73
73
  rails generate administrate:views:layout
@@ -75,4 +75,8 @@ rails generate administrate:views:layout
75
75
  # -> app/views/admin/application/_navigation.html.erb
76
76
  # -> app/views/admin/application/_javascript.html.erb
77
77
  # -> app/views/admin/application/_flashes.html.erb
78
+
79
+ rails generate administrate:views:navigation
80
+ # It only generates the sidebar partial
81
+ # -> app/views/admin/application/_navigation.html.erb
78
82
  ```
@@ -9,6 +9,8 @@ require "administrate/field/polymorphic"
9
9
  require "administrate/field/select"
10
10
  require "administrate/field/string"
11
11
  require "administrate/field/text"
12
+ require "administrate/field/time"
13
+ require "administrate/field/password"
12
14
 
13
15
  module Administrate
14
16
  class BaseDashboard
@@ -7,16 +7,16 @@ module Administrate
7
7
  associated_dashboard.display_resource(data)
8
8
  end
9
9
 
10
+ def associated_class
11
+ associated_class_name.constantize
12
+ end
13
+
10
14
  protected
11
15
 
12
16
  def associated_dashboard
13
17
  "#{associated_class_name}Dashboard".constantize.new
14
18
  end
15
19
 
16
- def associated_class
17
- associated_class_name.constantize
18
- end
19
-
20
20
  def associated_class_name
21
21
  options.fetch(:class_name, attribute.to_s.singularize.camelcase)
22
22
  end
@@ -24,8 +24,10 @@ module Administrate
24
24
  private
25
25
 
26
26
  def candidate_resources
27
+ scope = options[:scope] ? options[:scope].call : associated_class.all
28
+
27
29
  order = options.delete(:order)
28
- order ? associated_class.order(order) : associated_class.all
30
+ order ? scope.reorder(order) : scope
29
31
  end
30
32
 
31
33
  def display_candidate_resource(resource)
@@ -25,7 +25,7 @@ module Administrate
25
25
  end
26
26
 
27
27
  def timezone
28
- options.fetch(:timezone, "UTC")
28
+ options.fetch(:timezone, ::Time.zone.name || "UTC")
29
29
  end
30
30
  end
31
31
  end
@@ -25,6 +25,10 @@ module Administrate
25
25
  options.fetch(:searchable, deferred_class.searchable?)
26
26
  end
27
27
 
28
+ def searchable_field
29
+ options.fetch(:searchable_field)
30
+ end
31
+
28
32
  def permitted_attribute(attr, _options = nil)
29
33
  options.fetch(:foreign_key,
30
34
  deferred_class.permitted_attribute(attr, options))
@@ -0,0 +1,25 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Password < Field::Base
6
+ def self.searchable?
7
+ false
8
+ end
9
+
10
+ def truncate
11
+ data.to_s.gsub(/./, character)[0...truncation_length]
12
+ end
13
+
14
+ private
15
+
16
+ def truncation_length
17
+ options.fetch(:truncate, 50)
18
+ end
19
+
20
+ def character
21
+ options.fetch(:character, "•")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -30,7 +30,7 @@ module Administrate
30
30
  end
31
31
 
32
32
  def classes
33
- options.fetch(:classes) || []
33
+ options.fetch(:classes, [])
34
34
  end
35
35
 
36
36
  private
@@ -0,0 +1,8 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Time < Base
6
+ end
7
+ end
8
+ end
@@ -12,7 +12,7 @@ module Administrate
12
12
 
13
13
  def routes
14
14
  @routes ||= all_routes.select do |controller, _action|
15
- controller.starts_with?(namespace.to_s)
15
+ controller.starts_with?("#{namespace}/")
16
16
  end.map do |controller, action|
17
17
  [controller.gsub(/^#{namespace}\//, ""), action]
18
18
  end
@@ -9,7 +9,9 @@ module Administrate
9
9
  return order_by_association(relation) unless
10
10
  reflect_association(relation).nil?
11
11
 
12
- return relation.reorder("#{attribute} #{direction}") if
12
+ order = "#{relation.table_name}.#{attribute} #{direction}"
13
+
14
+ return relation.reorder(order) if
13
15
  relation.columns_hash.keys.include?(attribute.to_s)
14
16
 
15
17
  relation
@@ -13,7 +13,7 @@ module Administrate
13
13
  if @term.blank?
14
14
  @scoped_resource.all
15
15
  else
16
- @scoped_resource.where(query, *search_terms)
16
+ @scoped_resource.joins(tables_to_join).where(query, *search_terms)
17
17
  end
18
18
  end
19
19
 
@@ -21,10 +21,10 @@ module Administrate
21
21
 
22
22
  def query
23
23
  search_attributes.map do |attr|
24
- table_name = ActiveRecord::Base.connection.
25
- quote_table_name(@scoped_resource.table_name)
26
- attr_name = ActiveRecord::Base.connection.quote_column_name(attr)
27
- "LOWER(TEXT(#{table_name}.#{attr_name})) LIKE ?"
24
+ table_name = query_table_name(attr)
25
+ attr_name = column_to_query(attr)
26
+
27
+ "LOWER(CAST(#{table_name}.#{attr_name} AS CHAR(256))) LIKE ?"
28
28
  end.join(" OR ")
29
29
  end
30
30
 
@@ -42,6 +42,40 @@ module Administrate
42
42
  @dashboard_class::ATTRIBUTE_TYPES
43
43
  end
44
44
 
45
+ def query_table_name(attr)
46
+ if association_search?(attr)
47
+ ActiveRecord::Base.connection.quote_table_name(attr.to_s.pluralize)
48
+ else
49
+ ActiveRecord::Base.connection.
50
+ quote_table_name(@scoped_resource.table_name)
51
+ end
52
+ end
53
+
54
+ def column_to_query(attr)
55
+ if association_search?(attr)
56
+ ActiveRecord::Base.connection.
57
+ quote_column_name(attribute_types[attr].searchable_field)
58
+ else
59
+ ActiveRecord::Base.connection.quote_column_name(attr)
60
+ end
61
+ end
62
+
63
+ def tables_to_join
64
+ attribute_types.keys.select do |attribute|
65
+ attribute_types[attribute].searchable? && association_search?(attribute)
66
+ end
67
+ end
68
+
69
+ def association_search?(attribute)
70
+ return unless attribute_types[attribute].respond_to?(:deferred_class)
71
+
72
+ [
73
+ Administrate::Field::BelongsTo,
74
+ Administrate::Field::HasMany,
75
+ Administrate::Field::HasOne,
76
+ ].include?(attribute_types[attribute].deferred_class)
77
+ end
78
+
45
79
  attr_reader :resolver, :term
46
80
  end
47
81
  end
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "0.10.0".freeze
3
3
  end
@@ -10,7 +10,7 @@ module Administrate
10
10
  enum: "Field::String",
11
11
  float: "Field::Number",
12
12
  integer: "Field::Number",
13
- time: "Field::DateTime",
13
+ time: "Field::Time",
14
14
  text: "Field::Text",
15
15
  string: "Field::String",
16
16
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Charlton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-17 00:00:00.000000000 Z
12
+ date: 2018-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '4.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.2'
23
+ version: '6.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '4.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '6.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: actionview
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '4.2'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '5.2'
43
+ version: '6.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: '4.2'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '5.2'
53
+ version: '6.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: activerecord
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ dependencies:
60
60
  version: '4.2'
61
61
  - - "<"
62
62
  - !ruby/object:Gem::Version
63
- version: '5.2'
63
+ version: '6.0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ dependencies:
70
70
  version: '4.2'
71
71
  - - "<"
72
72
  - !ruby/object:Gem::Version
73
- version: '5.2'
73
+ version: '6.0'
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: autoprefixer-rails
76
76
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,9 @@ files:
253
253
  - app/views/fields/number/_form.html.erb
254
254
  - app/views/fields/number/_index.html.erb
255
255
  - app/views/fields/number/_show.html.erb
256
+ - app/views/fields/password/_form.html.erb
257
+ - app/views/fields/password/_index.html.erb
258
+ - app/views/fields/password/_show.html.erb
256
259
  - app/views/fields/polymorphic/_form.html.erb
257
260
  - app/views/fields/polymorphic/_index.html.erb
258
261
  - app/views/fields/polymorphic/_show.html.erb
@@ -265,8 +268,12 @@ files:
265
268
  - app/views/fields/text/_form.html.erb
266
269
  - app/views/fields/text/_index.html.erb
267
270
  - app/views/fields/text/_show.html.erb
271
+ - app/views/fields/time/_form.html.erb
272
+ - app/views/fields/time/_index.html.erb
273
+ - app/views/fields/time/_show.html.erb
268
274
  - app/views/layouts/administrate/application.html.erb
269
275
  - config/i18n-tasks.yml
276
+ - config/locales/administrate.al.yml
270
277
  - config/locales/administrate.ar.yml
271
278
  - config/locales/administrate.bs.yml
272
279
  - config/locales/administrate.ca.yml
@@ -312,10 +319,12 @@ files:
312
319
  - lib/administrate/field/has_many.rb
313
320
  - lib/administrate/field/has_one.rb
314
321
  - lib/administrate/field/number.rb
322
+ - lib/administrate/field/password.rb
315
323
  - lib/administrate/field/polymorphic.rb
316
324
  - lib/administrate/field/select.rb
317
325
  - lib/administrate/field/string.rb
318
326
  - lib/administrate/field/text.rb
327
+ - lib/administrate/field/time.rb
319
328
  - lib/administrate/generator_helpers.rb
320
329
  - lib/administrate/namespace.rb
321
330
  - lib/administrate/namespace/resource.rb