administrate 0.11.0 → 0.12.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/stylesheets/administrate/base/_typography.scss +1 -1
  3. data/app/controllers/administrate/application_controller.rb +3 -3
  4. data/app/controllers/concerns/administrate/punditize.rb +3 -3
  5. data/app/helpers/administrate/application_helper.rb +9 -1
  6. data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +0 -0
  7. data/app/views/fields/select/_form.html.erb +1 -1
  8. data/app/views/fields/url/_form.html.erb +23 -0
  9. data/app/views/fields/url/_index.html.erb +20 -0
  10. data/app/views/fields/url/_show.html.erb +20 -0
  11. data/app/views/layouts/administrate/application.html.erb +1 -1
  12. data/config/locales/administrate.es.yml +1 -1
  13. data/config/locales/administrate.ko.yml +10 -10
  14. data/config/locales/administrate.zh-CN.yml +2 -2
  15. data/docs/customizing_attribute_partials.md +1 -1
  16. data/docs/customizing_controller_actions.md +2 -1
  17. data/docs/customizing_dashboards.md +29 -1
  18. data/docs/getting_started.md +14 -45
  19. data/docs/rails_api.md +43 -0
  20. data/lib/administrate/base_dashboard.rb +21 -8
  21. data/lib/administrate/engine.rb +1 -1
  22. data/lib/administrate/field/has_many.rb +1 -1
  23. data/lib/administrate/field/url.rb +21 -0
  24. data/lib/administrate/page/base.rb +6 -2
  25. data/lib/administrate/search.rb +83 -6
  26. data/lib/administrate/version.rb +1 -1
  27. data/lib/generators/administrate/dashboard/dashboard_generator.rb +3 -1
  28. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +22 -9
  29. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
  30. data/lib/generators/administrate/routes/routes_generator.rb +6 -1
  31. data/lib/generators/administrate/views/layout_generator.rb +1 -0
  32. metadata +26 -27
  33. data/config/secrets.yml +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11c705312ca68f68a80830fbe9088602b2d495fb4a4ee75ad86997a3ddb86c42
4
- data.tar.gz: 8f56b485d373c66777ef5d535916953a57b0d5416019504ddc45d4a0d5fc37fa
3
+ metadata.gz: 901108f5715bed268b4395d6edadf3738b127425910dc365390847710f19c98f
4
+ data.tar.gz: 6b61113c5c116250f2e46eaa5dbf77972473b16a6aae8042a6bcaef74f45308e
5
5
  SHA512:
6
- metadata.gz: 3eefe2c7ff3dd30bcf5f58ee2bdfe8ad86645f6e34f1b8d0a6fd74094bedaff76c96c0526b839dca435a4e1acda2f71c8687aaae27b62be301a1d087420bdcb2
7
- data.tar.gz: 5fb275186d046fd0daa165b994f84df4d4f944c56128e7c9309c9070e4d1e4a9ebecaf2d1c22b8d5677c8493bfcffda9414ecb819673ed8216bc9d74c745bd09
6
+ metadata.gz: ac4790d3bca102b4a27cc73f154e7167620f4589088b1207008f0915521735cfed483fbf085d24e7844e7b092f9f1a7d198ec6113cbc4be877758886c192f097
7
+ data.tar.gz: da2c64204adee3b43a566c67cf2aa42f37a0a38ea5f35b9988f704491f2b15dcd76210fb2f56f57de1576e77da71f429fe6572493e65933877b29f9eb9e5920f
@@ -23,7 +23,7 @@ p {
23
23
 
24
24
  a {
25
25
  color: $action-color;
26
- text-decoration-skip: ink;
26
+ text-decoration-skip-ink: auto;
27
27
  transition: color $base-duration $base-timing;
28
28
 
29
29
  &:hover {
@@ -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 = apply_resource_includes(resources)
10
+ resources = apply_collection_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)
@@ -125,8 +125,8 @@ module Administrate
125
125
  resource_class.default_scoped
126
126
  end
127
127
 
128
- def apply_resource_includes(relation)
129
- resource_includes = dashboard.association_includes
128
+ def apply_collection_includes(relation)
129
+ resource_includes = dashboard.collection_includes
130
130
  return relation if resource_includes.empty?
131
131
  relation.includes(*resource_includes)
132
132
  end
@@ -1,6 +1,6 @@
1
- if Object.const_defined?("Pundit")
2
- module Administrate
3
- module Punditize
1
+ module Administrate
2
+ module Punditize
3
+ if Object.const_defined?("Pundit")
4
4
  extend ActiveSupport::Concern
5
5
  include Pundit
6
6
 
@@ -2,6 +2,14 @@ module Administrate
2
2
  module ApplicationHelper
3
3
  PLURAL_MANY_COUNT = 2.1
4
4
 
5
+ def application_title
6
+ if Rails::VERSION::MAJOR <= 5
7
+ Rails.application.class.parent_name.titlecase
8
+ else
9
+ Rails.application.class.module_parent_name.titlecase
10
+ end
11
+ end
12
+
5
13
  def render_field(field, locals = {})
6
14
  locals.merge!(field: field)
7
15
  render locals: locals, partial: field.to_partial_path
@@ -33,7 +41,7 @@ module Administrate
33
41
  end
34
42
 
35
43
  def sanitized_order_params(page, current_field_name)
36
- collection_names = page.association_includes + [current_field_name]
44
+ collection_names = page.item_includes + [current_field_name]
37
45
  association_params = collection_names.map do |assoc_name|
38
46
  { assoc_name => %i[order direction page per_page] }
39
47
  end
@@ -1,5 +1,5 @@
1
1
  <%#
2
- # Select Index Partial
2
+ # Select Form Partial
3
3
 
4
4
  This partial renders a selectable text attribute,
5
5
  to be displayed on a resource's edit form page.
@@ -0,0 +1,23 @@
1
+ <%#
2
+ # Url Form Partial
3
+
4
+ This partial renders an input element for URL.
5
+ By default, the input is a text box.
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::Url][1].
13
+ A wrapper around the URL pulled from the database.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Url
16
+ %>
17
+
18
+ <div class="field-unit__label">
19
+ <%= f.label field.attribute %>
20
+ </div>
21
+ <div class="field-unit__field">
22
+ <%= f.url_field field.attribute %>
23
+ </div>
@@ -0,0 +1,20 @@
1
+ <%#
2
+ # Url Index Partial
3
+
4
+ This partial renders an email address,
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the value is rendered as an `a` element.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Url][1].
13
+ A wrapper around the email pulled from the database.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Url
16
+ %>
17
+
18
+ <%= content_tag :a, href: field.data do %>
19
+ <%= field.data %>
20
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <%#
2
+ # Url Show Partial
3
+
4
+ This partial renders an email address,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the value is rendered as an `a` element.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Url][1].
13
+ A wrapper around the email pulled from the database.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Url
16
+ %>
17
+
18
+ <%= content_tag :a, href: field.data do %>
19
+ <%= field.data %>
20
+ <% end %>
@@ -19,7 +19,7 @@ By default, it renders:
19
19
  <meta name="ROBOTS" content="NOODP">
20
20
  <meta name="viewport" content="initial-scale=1">
21
21
  <title>
22
- <%= content_for(:title) %> - <%= Rails.application.class.parent_name.titlecase %>
22
+ <%= content_for(:title) %> - <%= application_title %>
23
23
  </title>
24
24
  <%= render "stylesheet" %>
25
25
  <%= csrf_meta_tags %>
@@ -22,7 +22,7 @@ es:
22
22
  none: Ninguno
23
23
  form:
24
24
  error: error
25
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
25
+ errors: "%{pluralized_errors} no permitieron guardar este %{resource_name}:"
26
26
  search:
27
27
  clear: Borrar búsqueda
28
28
  label: Buscar %{resource}
@@ -4,25 +4,25 @@ ko:
4
4
  actions:
5
5
  confirm: 괜찮습니까?
6
6
  destroy: 삭제
7
- edit: 편집
8
- edit_resource: 편집 %{name}
9
- show_resource: 보여주기 %{name}
10
- new_resource: 새로운 %{name}
7
+ edit: 수정
8
+ edit_resource: 수정 %{name}
9
+ show_resource: "%{name}"
10
+ new_resource: %{name}
11
11
  back: 뒤로
12
12
  controller:
13
13
  create:
14
- success: "%{resource} 가 성공적으로 생성되었습니다."
14
+ success: "%{resource}가 성공적으로 생성되었습니다."
15
15
  destroy:
16
- success: "%{resource} 가 성공적으로 삭제되었습니다."
16
+ success: "%{resource}가 성공적으로 삭제되었습니다."
17
17
  update:
18
- success: "%{resource} 가 성공적으로 갱신되었습니다."
18
+ success: "%{resource}가 성공적으로 수정되었습니다."
19
19
  fields:
20
20
  has_many:
21
- more: "%{total_count} 개 중에서 %{count} 개"
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 @@ zh-CN:
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: "%{resource_name} 保存前出现了 %{pluralized_errors} 个错误:"
26
26
  search:
27
27
  clear: 清除搜索
28
28
  label: 搜索 %{resource}
@@ -10,7 +10,7 @@ across all dashboards. You can customize the following built in field types:
10
10
  - `has_many`
11
11
  - `has_one`
12
12
  - `number`
13
- - `polymporphic`
13
+ - `polymorphic`
14
14
  - `select`
15
15
  - `string`
16
16
  - `text`
@@ -28,9 +28,10 @@ class Admin::FoosController < Admin::ApplicationController
28
28
  # def find_resource(param)
29
29
  # Foo.find_by!(slug: param)
30
30
  # end
31
- #
31
+
32
32
  # Override this if you have certain roles that require a subset
33
33
  # this will be used to set the records shown on the `index` action.
34
+ #
34
35
  # def scoped_resource
35
36
  # if current_user.super_admin?
36
37
  # resource_class
@@ -98,7 +98,7 @@ For example:
98
98
  ```ruby
99
99
  country: Field::BelongsTo.with_options(
100
100
  searchable: true,
101
- seachable_field: 'name',
101
+ searchable_field: 'name',
102
102
  )
103
103
  ```
104
104
 
@@ -277,3 +277,31 @@ end
277
277
  ```
278
278
 
279
279
  Action is one of `new`, `edit`, `show`, `destroy`.
280
+
281
+ ## Collection Filters
282
+
283
+ Resources can be filtered with pre-set filters. For example if we added:
284
+
285
+ ```ruby
286
+ COLLECTION_FILTERS = {
287
+ inactive: ->(resources) { resources.where("login_at < ?", 1.week.ago) }
288
+ }
289
+ ```
290
+
291
+ …to a dashboard, we can query the resources of that dashboard with:
292
+
293
+ ```ruby
294
+ bob inactive:
295
+ ```
296
+
297
+ …to find users named "bob" who hasn't logged in the last week.
298
+
299
+ If you already had the `inactive` scope you could define the filter like so to
300
+ take advantage of existing ActiveRecord scopes (and other class methods on the
301
+ resource class).
302
+
303
+ ```ruby
304
+ COLLECTION_FILTERS = {
305
+ inactive: ->(resources) { resources.inactive }
306
+ }
307
+ ```
@@ -37,11 +37,11 @@ Rails.application.routes.draw do
37
37
  # Add dashboard for your models here
38
38
  resources :customers,
39
39
  resources :orders
40
-
40
+
41
41
  root to: "customers#index" # <--- Root route
42
42
  end
43
43
  end
44
- ```
44
+ ```
45
45
 
46
46
  The routes can be customized to show or hide
47
47
  different models on the dashboard.
@@ -73,6 +73,15 @@ namespace :admin do
73
73
  end
74
74
  ```
75
75
 
76
+ ## Using a Custom Namespace
77
+
78
+ Administrate supports using a namespace other than `Admin`, such as
79
+ `Supervisor`. This will also change the route it's using:
80
+
81
+ ```sh
82
+ rails generate administrate:install --namespace=supervisor
83
+ ```
84
+
76
85
  ## Keep Dashboards Updated as Model Attributes Change
77
86
 
78
87
  If you've installed Administrate and generated dashboards and _then_
@@ -112,46 +121,6 @@ Example:
112
121
  It's recommended that you make this change at the same time as you add the
113
122
  attribute to the model.
114
123
 
115
- The alternative way to handle this is to re-run `rails g administrate:install` and
116
- carefully pick through the diffs. This latter method is probably more cumbersome.
117
-
118
- ## Rails API
119
-
120
- Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
121
- we still want to have an admin.
122
-
123
- To get this working, we recommend updating this config:
124
-
125
- ```ruby
126
- # config/application.rb
127
- config.api_only = false
128
- ```
129
-
130
- That means, when your app _boots_, we'll have access to flashes and such. We
131
- also don't use your `ApplicationController`. Instead, Administrate provides its
132
- own. Meaning you're free to specify `ActionController::API` as your parent
133
- controller to make sure no flash, session, or cookie middleware is used by your
134
- API.
135
-
136
- Alternatively, if your application needs to have `config.api_only = true`, we recommend you add the following lines to your `config/application.rb`
137
-
138
- ```ruby
139
- # Enable Flash, Cookies, MethodOverride for Administrate Gem
140
- config.middleware.use ActionDispatch::Flash
141
- config.session_store :cookie_store
142
- config.middleware.use ActionDispatch::Cookies
143
- config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
144
- config.middleware.use ::Rack::MethodOverride
145
- ```
146
-
147
- You must also ensure that the all the required controller actions are available and accessible as routes since generators in API-only applications only generate some of the required actions. Here is an example:
148
-
149
- ```ruby
150
- # routes.rb
151
- namespace :admin do
152
- resources name, only: %i(index show new create edit update destroy)
153
- end
154
-
155
- # names_controller.rb
156
- # Ensure each of those methods are defined
157
- ```
124
+ The alternative way to handle this is to re-run `rails g administrate:install`
125
+ and carefully pick through the diffs. This latter method is probably more
126
+ cumbersome.
@@ -0,0 +1,43 @@
1
+ ## Rails API
2
+
3
+ Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
4
+ we still want to have an admin.
5
+
6
+ To get this working, we recommend updating this config:
7
+
8
+ ```ruby
9
+ # config/application.rb
10
+ config.api_only = false
11
+ ```
12
+
13
+ That means, when your app _boots_, we'll have access to flashes and such. We
14
+ also don't use your `ApplicationController`. Instead, Administrate provides its
15
+ own. Meaning you're free to specify `ActionController::API` as your parent
16
+ controller to make sure no flash, session, or cookie middleware is used by your
17
+ API.
18
+
19
+ Alternatively, if your application needs to have `config.api_only = true`, we
20
+ recommend you add the following lines to your `config/application.rb`
21
+
22
+ ```ruby
23
+ # Enable Flash, Cookies, MethodOverride for Administrate Gem
24
+ config.middleware.use ActionDispatch::Flash
25
+ config.session_store :cookie_store
26
+ config.middleware.use ActionDispatch::Cookies
27
+ config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
28
+ config.middleware.use ::Rack::MethodOverride
29
+ ```
30
+
31
+ You must also ensure that all the required controller actions are available
32
+ and accessible as routes since generators in API-only applications only
33
+ generate some of the required actions. Here is an example:
34
+
35
+ ```ruby
36
+ # routes.rb
37
+ namespace :admin do
38
+ resources :name, only: %i(index show new create edit update destroy)
39
+ end
40
+
41
+ # names_controller.rb
42
+ # Ensure each of those methods are defined
43
+ ```
@@ -10,6 +10,7 @@ require "administrate/field/select"
10
10
  require "administrate/field/string"
11
11
  require "administrate/field/text"
12
12
  require "administrate/field/time"
13
+ require "administrate/field/url"
13
14
  require "administrate/field/password"
14
15
 
15
16
  module Administrate
@@ -58,15 +59,12 @@ module Administrate
58
59
  "#{resource.class} ##{resource.id}"
59
60
  end
60
61
 
61
- def association_includes
62
- association_classes = [Field::HasMany, Field::HasOne, Field::BelongsTo]
63
-
64
- collection_attributes.map do |key|
65
- field = self.class::ATTRIBUTE_TYPES[key]
62
+ def collection_includes
63
+ attribute_includes(collection_attributes)
64
+ end
66
65
 
67
- next key if association_classes.include?(field)
68
- key if association_classes.include?(field.try(:deferred_class))
69
- end.compact
66
+ def item_includes
67
+ attribute_includes(show_page_attributes)
70
68
  end
71
69
 
72
70
  private
@@ -74,5 +72,20 @@ module Administrate
74
72
  def attribute_not_found_message(attr)
75
73
  "Attribute #{attr} could not be found in #{self.class}::ATTRIBUTE_TYPES"
76
74
  end
75
+
76
+ def association_classes
77
+ @association_classes ||=
78
+ ObjectSpace.each_object(Class).
79
+ select { |klass| klass < Administrate::Field::Associative }
80
+ end
81
+
82
+ def attribute_includes(attributes)
83
+ attributes.map do |key|
84
+ field = self.class::ATTRIBUTE_TYPES[key]
85
+
86
+ next key if association_classes.include?(field)
87
+ key if association_classes.include?(field.try(:deferred_class))
88
+ end.compact
89
+ end
77
90
  end
78
91
  end
@@ -2,7 +2,7 @@ require "datetime_picker_rails"
2
2
  require "jquery-rails"
3
3
  require "kaminari"
4
4
  require "momentjs-rails"
5
- require "sass-rails"
5
+ require "sassc-rails"
6
6
  require "selectize-rails"
7
7
  require "sprockets/railtie"
8
8
 
@@ -66,7 +66,7 @@ module Administrate
66
66
  private
67
67
 
68
68
  def includes
69
- associated_dashboard.association_includes
69
+ associated_dashboard.collection_includes
70
70
  end
71
71
 
72
72
  def candidate_resources
@@ -0,0 +1,21 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Url < Field::Base
6
+ def self.searchable?
7
+ true
8
+ end
9
+
10
+ def truncate
11
+ data.to_s[0...truncation_length]
12
+ end
13
+
14
+ private
15
+
16
+ def truncation_length
17
+ options.fetch(:truncate, 50)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -15,8 +15,12 @@ module Administrate
15
15
  @resource_path ||= resource_name.gsub("/", "_")
16
16
  end
17
17
 
18
- def association_includes
19
- dashboard.try(:association_includes) || []
18
+ def collection_includes
19
+ dashboard.try(:collection_includes) || []
20
+ end
21
+
22
+ def item_includes
23
+ dashboard.try(:item_includes) || []
20
24
  end
21
25
 
22
26
  protected
@@ -3,23 +3,82 @@ require "active_support/core_ext/object/blank"
3
3
 
4
4
  module Administrate
5
5
  class Search
6
+ class Query
7
+ attr_reader :filters
8
+
9
+ def blank?
10
+ terms.blank? && filters.empty?
11
+ end
12
+
13
+ def initialize(original_query)
14
+ @original_query = original_query
15
+ @filters, @terms = parse_query(original_query)
16
+ end
17
+
18
+ def original
19
+ @original_query
20
+ end
21
+
22
+ def terms
23
+ @terms.join(" ")
24
+ end
25
+
26
+ def to_s
27
+ original
28
+ end
29
+
30
+ private
31
+
32
+ def filter?(word)
33
+ word.match?(/^\w+:$/)
34
+ end
35
+
36
+ def parse_query(query)
37
+ filters = []
38
+ terms = []
39
+ query.to_s.split.each do |word|
40
+ if filter?(word)
41
+ filters << word.split(":").first
42
+ else
43
+ terms << word
44
+ end
45
+ end
46
+ [filters, terms]
47
+ end
48
+ end
49
+
6
50
  def initialize(scoped_resource, dashboard_class, term)
7
51
  @dashboard_class = dashboard_class
8
52
  @scoped_resource = scoped_resource
9
- @term = term
53
+ @query = Query.new(term)
10
54
  end
11
55
 
12
56
  def run
13
- if @term.blank?
57
+ if query.blank?
14
58
  @scoped_resource.all
15
59
  else
16
- @scoped_resource.joins(tables_to_join).where(query, *search_terms)
60
+ results = search_results(@scoped_resource)
61
+ results = filter_results(results)
62
+ results
17
63
  end
18
64
  end
19
65
 
20
66
  private
21
67
 
22
- def query
68
+ def apply_filter(filter, resources)
69
+ return resources unless filter
70
+ filter.call(resources)
71
+ end
72
+
73
+ def filter_results(resources)
74
+ query.filters.each do |filter_name|
75
+ filter = valid_filters[filter_name]
76
+ resources = apply_filter(filter, resources)
77
+ end
78
+ resources
79
+ end
80
+
81
+ def query_template
23
82
  search_attributes.map do |attr|
24
83
  table_name = query_table_name(attr)
25
84
  attr_name = column_to_query(attr)
@@ -28,7 +87,7 @@ module Administrate
28
87
  end.join(" OR ")
29
88
  end
30
89
 
31
- def search_terms
90
+ def query_values
32
91
  ["%#{term.mb_chars.downcase}%"] * search_attributes.count
33
92
  end
34
93
 
@@ -38,6 +97,20 @@ module Administrate
38
97
  end
39
98
  end
40
99
 
100
+ def search_results(resources)
101
+ resources.
102
+ joins(tables_to_join).
103
+ where(query_template, *query_values)
104
+ end
105
+
106
+ def valid_filters
107
+ if @dashboard_class.const_defined?(:COLLECTION_FILTERS)
108
+ @dashboard_class.const_get(:COLLECTION_FILTERS).stringify_keys
109
+ else
110
+ {}
111
+ end
112
+ end
113
+
41
114
  def attribute_types
42
115
  @dashboard_class::ATTRIBUTE_TYPES
43
116
  end
@@ -76,6 +149,10 @@ module Administrate
76
149
  ].include?(attribute_types[attribute].deferred_class)
77
150
  end
78
151
 
79
- attr_reader :resolver, :term
152
+ def term
153
+ query.terms
154
+ end
155
+
156
+ attr_reader :resolver, :query
80
157
  end
81
158
  end
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.11.0".freeze
2
+ VERSION = "0.12.0".freeze
3
3
  end
@@ -50,7 +50,9 @@ module Administrate
50
50
  end
51
51
 
52
52
  def attributes
53
- klass.reflections.keys + klass.attribute_names - redundant_attributes
53
+ klass.reflections.keys +
54
+ klass.columns.map(&:name) -
55
+ redundant_attributes
54
56
  end
55
57
 
56
58
  def form_attributes
@@ -1,18 +1,31 @@
1
1
  module <%= namespace.classify %>
2
2
  class <%= class_name.pluralize %>Controller < <%= namespace.classify %>::ApplicationController
3
- # To customize the behavior of this controller,
4
- # you can overwrite any of the RESTful actions. For example:
3
+ # Overwrite any of the RESTful controller actions to implement custom behavior
4
+ # For example, you may want to send an email after a foo is updated.
5
5
  #
6
- # def index
7
- # super
8
- # @resources = <%= class_name %>.
9
- # page(params[:page]).
10
- # per(10)
6
+ # def update
7
+ # foo = Foo.find(params[:id])
8
+ # foo.update(params[:foo])
9
+ # send_foo_updated_email
11
10
  # end
12
11
 
13
- # Define a custom finder by overriding the `find_resource` method:
12
+ # Override this method to specify custom lookup behavior.
13
+ # This will be used to set the resource for the `show`, `edit`, and `update`
14
+ # actions.
15
+ #
14
16
  # def find_resource(param)
15
- # <%= class_name %>.find_by!(slug: param)
17
+ # Foo.find_by!(slug: param)
18
+ # end
19
+
20
+ # Override this if you have certain roles that require a subset
21
+ # this will be used to set the records shown on the `index` action.
22
+ #
23
+ # def scoped_resource
24
+ # if current_user.super_admin?
25
+ # resource_class
26
+ # else
27
+ # resource_class.with_less_stuff
28
+ # end
16
29
  # end
17
30
 
18
31
  # See https://administrate-prototype.herokuapp.com/customizing_controller_actions
@@ -18,20 +18,20 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
18
18
  #
19
19
  # By default, it's limited to four items to reduce clutter on index pages.
20
20
  # Feel free to add, remove, or rearrange items.
21
- COLLECTION_ATTRIBUTES = [
21
+ COLLECTION_ATTRIBUTES = %i[
22
22
  <%=
23
23
  attributes.first(COLLECTION_ATTRIBUTE_LIMIT).map do |attr|
24
- " :#{attr},"
24
+ " #{attr}"
25
25
  end.join("\n")
26
26
  %>
27
27
  ].freeze
28
28
 
29
29
  # SHOW_PAGE_ATTRIBUTES
30
30
  # an array of attributes that will be displayed on the model's show page.
31
- SHOW_PAGE_ATTRIBUTES = [
31
+ SHOW_PAGE_ATTRIBUTES = %i[
32
32
  <%=
33
33
  attributes.map do |attr|
34
- " :#{attr},"
34
+ " #{attr}"
35
35
  end.join("\n")
36
36
  %>
37
37
  ].freeze
@@ -39,14 +39,26 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
39
39
  # FORM_ATTRIBUTES
40
40
  # an array of attributes that will be displayed
41
41
  # on the model's form (`new` and `edit`) pages.
42
- FORM_ATTRIBUTES = [
42
+ FORM_ATTRIBUTES = %i[
43
43
  <%=
44
44
  form_attributes.map do |attr|
45
- " :#{attr},"
45
+ " #{attr}"
46
46
  end.join("\n")
47
47
  %>
48
48
  ].freeze
49
49
 
50
+ # COLLECTION_FILTERS
51
+ # a hash that defines filters that can be used while searching via the search
52
+ # field of the dashboard.
53
+ #
54
+ # For example to add an option to search for open resources by typing "open:"
55
+ # in the search field:
56
+ #
57
+ # COLLECTION_FILTERS = {
58
+ # open: ->(resources) { where(open: true) }
59
+ # }.freeze
60
+ COLLECTION_FILTERS = {}.freeze
61
+
50
62
  # Overwrite this method to customize how <%= file_name.pluralize.humanize.downcase %> are displayed
51
63
  # across all pages of the admin dashboard.
52
64
  #
@@ -1,4 +1,9 @@
1
- Rails.application.eager_load!
1
+ if defined?(Zeitwerk)
2
+ Zeitwerk::Loader.eager_load_all
3
+ else
4
+ Rails.application.eager_load!
5
+ end
6
+
2
7
  require "rails/generators/base"
3
8
  require "administrate/namespace"
4
9
 
@@ -16,6 +16,7 @@ module Administrate
16
16
  copy_resource_template("_stylesheet")
17
17
  copy_resource_template("_javascript")
18
18
  copy_resource_template("_flashes")
19
+ copy_resource_template("_icons")
19
20
  end
20
21
  end
21
22
  end
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.11.0
4
+ version: 0.12.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-09-17 00:00:00.000000000 Z
12
+ date: 2019-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -18,9 +18,6 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '4.2'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '6.0'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +25,6 @@ dependencies:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: '4.2'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '6.0'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: actionview
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -38,9 +32,6 @@ dependencies:
38
32
  - - ">="
39
33
  - !ruby/object:Gem::Version
40
34
  version: '4.2'
41
- - - "<"
42
- - !ruby/object:Gem::Version
43
- version: '6.0'
44
35
  type: :runtime
45
36
  prerelease: false
46
37
  version_requirements: !ruby/object:Gem::Requirement
@@ -48,9 +39,6 @@ dependencies:
48
39
  - - ">="
49
40
  - !ruby/object:Gem::Version
50
41
  version: '4.2'
51
- - - "<"
52
- - !ruby/object:Gem::Version
53
- version: '6.0'
54
42
  - !ruby/object:Gem::Dependency
55
43
  name: activerecord
56
44
  requirement: !ruby/object:Gem::Requirement
@@ -58,9 +46,6 @@ dependencies:
58
46
  - - ">="
59
47
  - !ruby/object:Gem::Version
60
48
  version: '4.2'
61
- - - "<"
62
- - !ruby/object:Gem::Version
63
- version: '6.0'
64
49
  type: :runtime
65
50
  prerelease: false
66
51
  version_requirements: !ruby/object:Gem::Requirement
@@ -68,9 +53,6 @@ dependencies:
68
53
  - - ">="
69
54
  - !ruby/object:Gem::Version
70
55
  version: '4.2'
71
- - - "<"
72
- - !ruby/object:Gem::Version
73
- version: '6.0'
74
56
  - !ruby/object:Gem::Dependency
75
57
  name: autoprefixer-rails
76
58
  requirement: !ruby/object:Gem::Requirement
@@ -142,19 +124,19 @@ dependencies:
142
124
  - !ruby/object:Gem::Version
143
125
  version: '2.8'
144
126
  - !ruby/object:Gem::Dependency
145
- name: sass-rails
127
+ name: sassc-rails
146
128
  requirement: !ruby/object:Gem::Requirement
147
129
  requirements:
148
130
  - - "~>"
149
131
  - !ruby/object:Gem::Version
150
- version: '5.0'
132
+ version: '2.1'
151
133
  type: :runtime
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
136
  requirements:
155
137
  - - "~>"
156
138
  - !ruby/object:Gem::Version
157
- version: '5.0'
139
+ version: '2.1'
158
140
  - !ruby/object:Gem::Dependency
159
141
  name: selectize-rails
160
142
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +151,20 @@ dependencies:
169
151
  - - "~>"
170
152
  - !ruby/object:Gem::Version
171
153
  version: '0.6'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rspec-rails
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
172
168
  description: |
173
169
  Administrate is heavily inspired by projects like Rails Admin and ActiveAdmin,
174
170
  but aims to provide a better user experience for site admins,
@@ -223,7 +219,7 @@ files:
223
219
  - app/views/administrate/application/_collection.html.erb
224
220
  - app/views/administrate/application/_flashes.html.erb
225
221
  - app/views/administrate/application/_form.html.erb
226
- - app/views/administrate/application/_icons.erb
222
+ - app/views/administrate/application/_icons.html.erb
227
223
  - app/views/administrate/application/_javascript.html.erb
228
224
  - app/views/administrate/application/_navigation.html.erb
229
225
  - app/views/administrate/application/_search.html.erb
@@ -271,6 +267,9 @@ files:
271
267
  - app/views/fields/time/_form.html.erb
272
268
  - app/views/fields/time/_index.html.erb
273
269
  - app/views/fields/time/_show.html.erb
270
+ - app/views/fields/url/_form.html.erb
271
+ - app/views/fields/url/_index.html.erb
272
+ - app/views/fields/url/_show.html.erb
274
273
  - app/views/layouts/administrate/application.html.erb
275
274
  - config/i18n-tasks.yml
276
275
  - config/locales/administrate.al.yml
@@ -297,7 +296,6 @@ files:
297
296
  - config/locales/administrate.zh-CN.yml
298
297
  - config/locales/administrate.zh-TW.yml
299
298
  - config/routes.rb
300
- - config/secrets.yml
301
299
  - config/unicorn.rb
302
300
  - docs/adding_custom_field_types.md
303
301
  - docs/authentication.md
@@ -307,6 +305,7 @@ files:
307
305
  - docs/customizing_dashboards.md
308
306
  - docs/customizing_page_views.md
309
307
  - docs/getting_started.md
308
+ - docs/rails_api.md
310
309
  - lib/administrate.rb
311
310
  - lib/administrate/base_dashboard.rb
312
311
  - lib/administrate/engine.rb
@@ -326,6 +325,7 @@ files:
326
325
  - lib/administrate/field/string.rb
327
326
  - lib/administrate/field/text.rb
328
327
  - lib/administrate/field/time.rb
328
+ - lib/administrate/field/url.rb
329
329
  - lib/administrate/generator_helpers.rb
330
330
  - lib/administrate/namespace.rb
331
331
  - lib/administrate/namespace/resource.rb
@@ -384,8 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
384
  - !ruby/object:Gem::Version
385
385
  version: '0'
386
386
  requirements: []
387
- rubyforge_project:
388
- rubygems_version: 2.7.6
387
+ rubygems_version: 3.0.3
389
388
  signing_key:
390
389
  specification_version: 4
391
390
  summary: A Rails engine for creating super-flexible admin dashboards
@@ -1,14 +0,0 @@
1
- default: &default
2
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
3
-
4
- development:
5
- <<: *default
6
-
7
- test:
8
- <<: *default
9
-
10
- staging:
11
- <<: *default
12
-
13
- production:
14
- <<: *default