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.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/administrate/base/_typography.scss +1 -1
- data/app/controllers/administrate/application_controller.rb +3 -3
- data/app/controllers/concerns/administrate/punditize.rb +3 -3
- data/app/helpers/administrate/application_helper.rb +9 -1
- data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +0 -0
- data/app/views/fields/select/_form.html.erb +1 -1
- data/app/views/fields/url/_form.html.erb +23 -0
- data/app/views/fields/url/_index.html.erb +20 -0
- data/app/views/fields/url/_show.html.erb +20 -0
- data/app/views/layouts/administrate/application.html.erb +1 -1
- data/config/locales/administrate.es.yml +1 -1
- data/config/locales/administrate.ko.yml +10 -10
- data/config/locales/administrate.zh-CN.yml +2 -2
- data/docs/customizing_attribute_partials.md +1 -1
- data/docs/customizing_controller_actions.md +2 -1
- data/docs/customizing_dashboards.md +29 -1
- data/docs/getting_started.md +14 -45
- data/docs/rails_api.md +43 -0
- data/lib/administrate/base_dashboard.rb +21 -8
- data/lib/administrate/engine.rb +1 -1
- data/lib/administrate/field/has_many.rb +1 -1
- data/lib/administrate/field/url.rb +21 -0
- data/lib/administrate/page/base.rb +6 -2
- data/lib/administrate/search.rb +83 -6
- data/lib/administrate/version.rb +1 -1
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +3 -1
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +22 -9
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
- data/lib/generators/administrate/routes/routes_generator.rb +6 -1
- data/lib/generators/administrate/views/layout_generator.rb +1 -0
- metadata +26 -27
- data/config/secrets.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 901108f5715bed268b4395d6edadf3738b127425910dc365390847710f19c98f
|
4
|
+
data.tar.gz: 6b61113c5c116250f2e46eaa5dbf77972473b16a6aae8042a6bcaef74f45308e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac4790d3bca102b4a27cc73f154e7167620f4589088b1207008f0915521735cfed483fbf085d24e7844e7b092f9f1a7d198ec6113cbc4be877758886c192f097
|
7
|
+
data.tar.gz: da2c64204adee3b43a566c67cf2aa42f37a0a38ea5f35b9988f704491f2b15dcd76210fb2f56f57de1576e77da71f429fe6572493e65933877b29f9eb9e5920f
|
@@ -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 =
|
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
|
129
|
-
resource_includes = dashboard.
|
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
|
@@ -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.
|
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
|
File without changes
|
@@ -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) %> - <%=
|
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}
|
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:
|
9
|
-
show_resource:
|
10
|
-
new_resource:
|
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}
|
21
|
+
more: "%{total_count}개 중에서 %{count}개"
|
22
22
|
none: 없음
|
23
23
|
form:
|
24
|
-
error:
|
25
|
-
errors: "%{pluralized_errors}
|
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:
|
25
|
-
errors: "%{
|
24
|
+
error: 错误
|
25
|
+
errors: "%{resource_name} 保存前出现了 %{pluralized_errors} 个错误:"
|
26
26
|
search:
|
27
27
|
clear: 清除搜索
|
28
28
|
label: 搜索 %{resource}
|
@@ -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
|
-
|
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
|
+
```
|
data/docs/getting_started.md
CHANGED
@@ -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`
|
116
|
-
carefully pick through the diffs. This latter method is probably more
|
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.
|
data/docs/rails_api.md
ADDED
@@ -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
|
62
|
-
|
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
|
-
|
68
|
-
|
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
|
data/lib/administrate/engine.rb
CHANGED
@@ -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
|
19
|
-
dashboard.try(:
|
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
|
data/lib/administrate/search.rb
CHANGED
@@ -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
|
-
@
|
53
|
+
@query = Query.new(term)
|
10
54
|
end
|
11
55
|
|
12
56
|
def run
|
13
|
-
if
|
57
|
+
if query.blank?
|
14
58
|
@scoped_resource.all
|
15
59
|
else
|
16
|
-
@scoped_resource
|
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
|
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
|
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
|
-
|
152
|
+
def term
|
153
|
+
query.terms
|
154
|
+
end
|
155
|
+
|
156
|
+
attr_reader :resolver, :query
|
80
157
|
end
|
81
158
|
end
|
data/lib/administrate/version.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
1
|
module <%= namespace.classify %>
|
2
2
|
class <%= class_name.pluralize %>Controller < <%= namespace.classify %>::ApplicationController
|
3
|
-
#
|
4
|
-
# you
|
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
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
"
|
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
|
-
"
|
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
|
-
"
|
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
|
#
|
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.
|
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:
|
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:
|
127
|
+
name: sassc-rails
|
146
128
|
requirement: !ruby/object:Gem::Requirement
|
147
129
|
requirements:
|
148
130
|
- - "~>"
|
149
131
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
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: '
|
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
|
-
|
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
|