administrate 0.16.0 → 0.17.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.
- checksums.yaml +4 -4
- data/app/controllers/administrate/application_controller.rb +18 -5
- data/app/views/administrate/application/_collection.html.erb +18 -22
- data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
- data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
- data/app/views/administrate/application/_flashes.html.erb +1 -0
- data/app/views/administrate/application/_form.html.erb +1 -1
- data/app/views/administrate/application/_icons.html.erb +1 -1
- data/app/views/administrate/application/_index_header.html.erb +28 -0
- data/app/views/administrate/application/index.html.erb +8 -28
- data/app/views/fields/belongs_to/_index.html.erb +1 -1
- data/app/views/fields/belongs_to/_show.html.erb +1 -1
- data/app/views/fields/select/_form.html.erb +4 -2
- data/app/views/fields/time/_index.html.erb +1 -1
- data/app/views/fields/time/_show.html.erb +1 -1
- data/config/locales/administrate.zh-TW.yml +1 -1
- data/docs/customizing_controller_actions.md +19 -1
- data/docs/customizing_dashboards.md +36 -4
- data/docs/extending_administrate.md +5 -5
- data/docs/getting_started.md +1 -1
- data/lib/administrate/base_dashboard.rb +16 -2
- data/lib/administrate/field/select.rb +4 -0
- data/lib/administrate/field/time.rb +11 -0
- data/lib/administrate/page/form.rb +9 -2
- data/lib/administrate/search.rb +21 -17
- data/lib/administrate/version.rb +1 -1
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +2 -2
- data/lib/generators/administrate/install/templates/application_controller.rb.erb +1 -1
- metadata +6 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a099c28c8a74491759229e6fe82de763f25b9ff59473d5c70b00d38675e3498
|
|
4
|
+
data.tar.gz: c24140b9e1bc63eb9ecd5f38cd0cfd3d3c0f125a81370df1dd6663af66121baa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ada94532afa210a359eece24f042fdb7de549cdb6bb94507c044f85df7b26cfbd5855202de2016255d635d2448dcba303d91eac4dc41c896f30e52f95073345
|
|
7
|
+
data.tar.gz: 98e115c8c3acfe7dc5cab3a3055b5f06dfa5661f9d2eb135c528b474cbe36e6fb51b36a8c88489860a9fda200758ce37f4d60375705f0e0234af4dc2805e75ff
|
|
@@ -6,7 +6,7 @@ module Administrate
|
|
|
6
6
|
authorize_resource(resource_class)
|
|
7
7
|
search_term = params[:search].to_s.strip
|
|
8
8
|
resources = Administrate::Search.new(scoped_resource,
|
|
9
|
-
|
|
9
|
+
dashboard,
|
|
10
10
|
search_term).run
|
|
11
11
|
resources = apply_collection_includes(resources)
|
|
12
12
|
resources = order.apply(resources)
|
|
@@ -47,7 +47,7 @@ module Administrate
|
|
|
47
47
|
|
|
48
48
|
if resource.save
|
|
49
49
|
redirect_to(
|
|
50
|
-
|
|
50
|
+
after_resource_created_path(resource),
|
|
51
51
|
notice: translate_with_resource("create.success"),
|
|
52
52
|
)
|
|
53
53
|
else
|
|
@@ -60,7 +60,7 @@ module Administrate
|
|
|
60
60
|
def update
|
|
61
61
|
if requested_resource.update(resource_params)
|
|
62
62
|
redirect_to(
|
|
63
|
-
|
|
63
|
+
after_resource_updated_path(requested_resource),
|
|
64
64
|
notice: translate_with_resource("update.success"),
|
|
65
65
|
)
|
|
66
66
|
else
|
|
@@ -76,14 +76,27 @@ module Administrate
|
|
|
76
76
|
else
|
|
77
77
|
flash[:error] = requested_resource.errors.full_messages.join("<br/>")
|
|
78
78
|
end
|
|
79
|
-
redirect_to
|
|
79
|
+
redirect_to after_resource_destroyed_path(requested_resource)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
private
|
|
83
83
|
|
|
84
|
+
def after_resource_destroyed_path(_requested_resource)
|
|
85
|
+
{ action: :index }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def after_resource_created_path(requested_resource)
|
|
89
|
+
[namespace, requested_resource]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def after_resource_updated_path(requested_resource)
|
|
93
|
+
[namespace, requested_resource]
|
|
94
|
+
end
|
|
95
|
+
|
|
84
96
|
helper_method :nav_link_state
|
|
85
97
|
def nav_link_state(resource)
|
|
86
|
-
|
|
98
|
+
underscore_resource = resource.to_s.split("/").join("__")
|
|
99
|
+
resource_name.to_s.pluralize == underscore_resource ? :active : :inactive
|
|
87
100
|
end
|
|
88
101
|
|
|
89
102
|
helper_method :valid_action?
|
|
@@ -24,7 +24,8 @@ to display a collection of resources in an HTML table.
|
|
|
24
24
|
<% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
|
|
25
25
|
<th class="cell-label
|
|
26
26
|
cell-label--<%= attr_type.html_class %>
|
|
27
|
-
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
|
|
27
|
+
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
|
|
28
|
+
cell-label--<%= "#{resource_name}_#{attr_name}" %>"
|
|
28
29
|
scope="col"
|
|
29
30
|
role="columnheader"
|
|
30
31
|
aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
|
|
@@ -45,10 +46,13 @@ to display a collection of resources in an HTML table.
|
|
|
45
46
|
<% end %>
|
|
46
47
|
</th>
|
|
47
48
|
<% end %>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
<%= render(
|
|
50
|
+
"collection_header_actions",
|
|
51
|
+
collection_presenter: collection_presenter,
|
|
52
|
+
page: page,
|
|
53
|
+
resources: resources,
|
|
54
|
+
table_title: "page-title"
|
|
55
|
+
) %>
|
|
52
56
|
</tr>
|
|
53
57
|
</thead>
|
|
54
58
|
|
|
@@ -74,23 +78,15 @@ to display a collection of resources in an HTML table.
|
|
|
74
78
|
</td>
|
|
75
79
|
<% end %>
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<td><%= link_to(
|
|
87
|
-
t("administrate.actions.destroy"),
|
|
88
|
-
[namespace, resource],
|
|
89
|
-
class: "text-color-red",
|
|
90
|
-
method: :delete,
|
|
91
|
-
data: { confirm: t("administrate.actions.confirm") }
|
|
92
|
-
) if show_action? :destroy, resource %></td>
|
|
93
|
-
<% end %>
|
|
81
|
+
<%= render(
|
|
82
|
+
"collection_item_actions",
|
|
83
|
+
collection_presenter: collection_presenter,
|
|
84
|
+
collection_field_name: collection_field_name,
|
|
85
|
+
page: page,
|
|
86
|
+
namespace: namespace,
|
|
87
|
+
resource: resource,
|
|
88
|
+
table_title: "page-title"
|
|
89
|
+
) %>
|
|
94
90
|
</tr>
|
|
95
91
|
<% end %>
|
|
96
92
|
</tbody>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<% if valid_action?(:edit, collection_presenter.resource_name) %>
|
|
2
|
+
<td><%= link_to(
|
|
3
|
+
t("administrate.actions.edit"),
|
|
4
|
+
[:edit, namespace, resource],
|
|
5
|
+
class: "action-edit",
|
|
6
|
+
) if show_action?(:edit, resource) %></td>
|
|
7
|
+
<% end %>
|
|
8
|
+
|
|
9
|
+
<% if valid_action?(:destroy, collection_presenter.resource_name) %>
|
|
10
|
+
<td><%= link_to(
|
|
11
|
+
t("administrate.actions.destroy"),
|
|
12
|
+
[namespace, resource],
|
|
13
|
+
class: "text-color-red",
|
|
14
|
+
method: :delete,
|
|
15
|
+
data: { confirm: t("administrate.actions.confirm") }
|
|
16
|
+
) if show_action?(:destroy, resource) %></td>
|
|
17
|
+
<% end %>
|
|
@@ -14,6 +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
|
+
<% next unless value.respond_to?(:html_safe) %>
|
|
17
18
|
<div class="flash flash-<%= key %>"><%= value.html_safe %></div>
|
|
18
19
|
<% end -%>
|
|
19
20
|
</div>
|
|
@@ -33,7 +33,7 @@ and renders all form fields for a resource's editable attributes.
|
|
|
33
33
|
</div>
|
|
34
34
|
<% end %>
|
|
35
35
|
|
|
36
|
-
<% page.attributes.each do |attribute| -%>
|
|
36
|
+
<% page.attributes(controller.action_name).each do |attribute| -%>
|
|
37
37
|
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
|
|
38
38
|
<%= render_field attribute, f: f %>
|
|
39
39
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
1
|
+
<svg hidden xmlns="http://www.w3.org/2000/svg">
|
|
2
2
|
<symbol id="icon-cancel" viewBox="0 0 48 48">
|
|
3
3
|
<path fill-rule="evenodd" d="M24 19.757l-8.485-8.485c-.784-.783-2.047-.782-2.827 0l-1.417 1.416c-.777.777-.78 2.046.002 2.827L19.757 24l-8.485 8.485c-.783.784-.782 2.047 0 2.827l1.416 1.417c.777.777 2.046.78 2.827-.002L24 28.243l8.485 8.485c.784.783 2.047.782 2.827 0l1.417-1.416c.777-.777.78-2.046-.002-2.827L28.243 24l8.485-8.485c.783-.784.782-2.047 0-2.827l-1.416-1.417c-.777-.777-2.046-.78-2.827.002L24 19.757zM24 47c12.703 0 23-10.297 23-23S36.703 1 24 1 1 11.297 1 24s10.297 23 23 23z" />
|
|
4
4
|
</symbol>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<% content_for(:title) do %>
|
|
2
|
+
<%= display_resource_name(page.resource_name) %>
|
|
3
|
+
<% end %>
|
|
4
|
+
|
|
5
|
+
<header class="main-content__header" role="banner">
|
|
6
|
+
<h1 class="main-content__page-title" id="page-title">
|
|
7
|
+
<%= content_for(:title) %>
|
|
8
|
+
</h1>
|
|
9
|
+
|
|
10
|
+
<% if show_search_bar %>
|
|
11
|
+
<%= render(
|
|
12
|
+
"search",
|
|
13
|
+
search_term: search_term,
|
|
14
|
+
resource_name: display_resource_name(page.resource_name)
|
|
15
|
+
) %>
|
|
16
|
+
<% end %>
|
|
17
|
+
|
|
18
|
+
<div>
|
|
19
|
+
<%= link_to(
|
|
20
|
+
t(
|
|
21
|
+
"administrate.actions.new_resource",
|
|
22
|
+
name: display_resource_name(page.resource_name, singular: true).downcase
|
|
23
|
+
),
|
|
24
|
+
[:new, namespace, page.resource_path.to_sym],
|
|
25
|
+
class: "button",
|
|
26
|
+
) if valid_action?(:new) && show_action?(:new, new_resource) %>
|
|
27
|
+
</div>
|
|
28
|
+
</header>
|
|
@@ -23,34 +23,14 @@ It renders the `_table` partial to display details about the resources.
|
|
|
23
23
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
|
|
24
24
|
%>
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<% if show_search_bar %>
|
|
36
|
-
<%= render(
|
|
37
|
-
"search",
|
|
38
|
-
search_term: search_term,
|
|
39
|
-
resource_name: display_resource_name(page.resource_name)
|
|
40
|
-
) %>
|
|
41
|
-
<% end %>
|
|
42
|
-
|
|
43
|
-
<div>
|
|
44
|
-
<%= link_to(
|
|
45
|
-
t(
|
|
46
|
-
"administrate.actions.new_resource",
|
|
47
|
-
name: display_resource_name(page.resource_name, singular: true).downcase
|
|
48
|
-
),
|
|
49
|
-
[:new, namespace, page.resource_path.to_sym],
|
|
50
|
-
class: "button",
|
|
51
|
-
) if valid_action?(:new) && show_action?(:new, new_resource) %>
|
|
52
|
-
</div>
|
|
53
|
-
</header>
|
|
26
|
+
<%=
|
|
27
|
+
render("index_header",
|
|
28
|
+
resources: resources,
|
|
29
|
+
search_term: search_term,
|
|
30
|
+
page: page,
|
|
31
|
+
show_search_bar: show_search_bar,
|
|
32
|
+
)
|
|
33
|
+
%>
|
|
54
34
|
|
|
55
35
|
<section class="main-content__body main-content__body--flush">
|
|
56
36
|
<%= render(
|
|
@@ -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.associated_class) %>
|
|
19
|
+
<% if valid_action?(:show, field.associated_class) && show_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.associated_class) %>
|
|
19
|
+
<% if valid_action?(:show, field.associated_class) && show_action?(:show, field.associated_class) %>
|
|
20
20
|
<%= link_to(
|
|
21
21
|
field.display_associated_resource,
|
|
22
22
|
[namespace, field.data],
|
|
@@ -27,7 +27,8 @@ to be displayed on a resource's edit form page.
|
|
|
27
27
|
:last,
|
|
28
28
|
:first,
|
|
29
29
|
field.data,
|
|
30
|
-
)
|
|
30
|
+
),
|
|
31
|
+
include_blank: field.include_blank_option
|
|
31
32
|
) %>
|
|
32
33
|
<% else %>
|
|
33
34
|
<%= f.select(
|
|
@@ -37,7 +38,8 @@ to be displayed on a resource's edit form page.
|
|
|
37
38
|
:to_s,
|
|
38
39
|
:to_s,
|
|
39
40
|
field.data,
|
|
40
|
-
)
|
|
41
|
+
),
|
|
42
|
+
include_blank: field.include_blank_option
|
|
41
43
|
) %>
|
|
42
44
|
<% end %>
|
|
43
45
|
</div>
|
|
@@ -69,4 +69,22 @@ end
|
|
|
69
69
|
def default_sorting_direction
|
|
70
70
|
:desc
|
|
71
71
|
end
|
|
72
|
-
```
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Customizing Redirects after actions
|
|
75
|
+
|
|
76
|
+
To set custom redirects after the actions `create`, `update` and `destroy` you can override `after_resource_created_path`, `after_resource_updated_path` or `after_resource_destroyed_path` like this:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
def after_resource_destroyed_path(_requested_resource)
|
|
80
|
+
{ action: :index, controller: :some_other_resource }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def after_resource_created_path(requested_resource)
|
|
84
|
+
[namespace, requested_resource.some_other_resource]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def after_resource_updated_path(requested_resource)
|
|
88
|
+
[namespace, requested_resource.some_other_resource]
|
|
89
|
+
end
|
|
90
|
+
```
|
|
@@ -8,9 +8,9 @@ edit the dashboard file generated by the installation generator.
|
|
|
8
8
|
By default, the file will look something like this:
|
|
9
9
|
|
|
10
10
|
```ruby
|
|
11
|
-
require "administrate/
|
|
11
|
+
require "administrate/base_dashboard"
|
|
12
12
|
|
|
13
|
-
class CustomerDashboard < Administrate::
|
|
13
|
+
class CustomerDashboard < Administrate::BaseDashboard
|
|
14
14
|
ATTRIBUTE_TYPES = {
|
|
15
15
|
id: Field::Number,
|
|
16
16
|
name: Field::String,
|
|
@@ -183,9 +183,9 @@ Or, to display a distance in kilometers, using a space as the delimiter:
|
|
|
183
183
|
distance: Field::Number.with_options(
|
|
184
184
|
suffix: " km",
|
|
185
185
|
decimals: 2,
|
|
186
|
-
format: {
|
|
186
|
+
format: {
|
|
187
187
|
formatter: :number_to_delimited,
|
|
188
|
-
formatter_options: {
|
|
188
|
+
formatter_options: {
|
|
189
189
|
delimiter: ' ',
|
|
190
190
|
},
|
|
191
191
|
},
|
|
@@ -223,6 +223,9 @@ an array or an object responding to `:call`. Defaults to `[]`.
|
|
|
223
223
|
`:searchable` - Specify if the attribute should be considered when searching.
|
|
224
224
|
Default is `true`.
|
|
225
225
|
|
|
226
|
+
`:include_blank` - Specifies if the select element to be rendered should include
|
|
227
|
+
blank option. Default is `false`.
|
|
228
|
+
|
|
226
229
|
**Field::String**
|
|
227
230
|
|
|
228
231
|
`:searchable` - Specify if the attribute should be considered when searching.
|
|
@@ -326,3 +329,32 @@ COLLECTION_FILTERS = {
|
|
|
326
329
|
inactive: ->(resources) { resources.inactive }
|
|
327
330
|
}
|
|
328
331
|
```
|
|
332
|
+
|
|
333
|
+
You can also define a filter with parameters:
|
|
334
|
+
|
|
335
|
+
```ruby
|
|
336
|
+
COLLECTION_FILTERS = {
|
|
337
|
+
state: ->(resources, attr) { resources.where(state: attr) }
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
You can now search your resource with 'state:open' and your
|
|
342
|
+
collection filter Proc will be called with with attr = open.
|
|
343
|
+
|
|
344
|
+
## Form Attributes
|
|
345
|
+
|
|
346
|
+
You can define different attributes for new/create or edit/update actions:
|
|
347
|
+
|
|
348
|
+
```ruby
|
|
349
|
+
FORM_ATTRIBUTES_NEW = [
|
|
350
|
+
:name,
|
|
351
|
+
:email
|
|
352
|
+
]
|
|
353
|
+
FORM_ATTRIBUTES_EDIT = [
|
|
354
|
+
:name,
|
|
355
|
+
:email,
|
|
356
|
+
:orders
|
|
357
|
+
]
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Or for custom action with constant name `"FORM_ATTRIBUTES_#{action.upcase}"`
|
|
@@ -5,13 +5,13 @@ title: Extending Administrate
|
|
|
5
5
|
Apart from the configuration described in these pages, it is possible to
|
|
6
6
|
extend Administrate's capabilities with the use of plugins. There are a
|
|
7
7
|
number of plugins available, many of which can be found at [RubyGems.org].
|
|
8
|
-
|
|
8
|
+
These are some popular examples:
|
|
9
9
|
|
|
10
10
|
1. [ActiveStorage support](https://github.com/Dreamersoul/administrate-field-active_storage)
|
|
11
|
-
2. [
|
|
12
|
-
3. [
|
|
13
|
-
4. [
|
|
14
|
-
5. [
|
|
11
|
+
2. [Enum field](https://github.com/Valiot/administrate-field-enum)
|
|
12
|
+
3. [Nested has-many forms](https://github.com/nickcharlton/administrate-field-nested_has_many)
|
|
13
|
+
4. [Belongs-to with Ajax search](https://github.com/fishbrain/administrate-field-belongs_to_search)
|
|
14
|
+
5. [JSONb field plugin for Administrate](https://github.com/codica2/administrate-field-jsonb/)
|
|
15
15
|
|
|
16
16
|
See many more at https://rubygems.org/gems/administrate/reverse_dependencies.
|
|
17
17
|
|
data/docs/getting_started.md
CHANGED
|
@@ -3,7 +3,7 @@ title: Getting Started
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
Administrate is released as a Ruby gem, and can be installed on Rails
|
|
6
|
-
applications version 5.0 or greater. We support Ruby 2.
|
|
6
|
+
applications version 5.0 or greater. We support Ruby 2.6 and up.
|
|
7
7
|
|
|
8
8
|
First, add the following to your Gemfile:
|
|
9
9
|
|
|
@@ -50,8 +50,16 @@ module Administrate
|
|
|
50
50
|
attribute_types.keys
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def form_attributes
|
|
54
|
-
self.class::FORM_ATTRIBUTES
|
|
53
|
+
def form_attributes(action = nil)
|
|
54
|
+
specific_form_attributes_for(action) || self.class::FORM_ATTRIBUTES
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def specific_form_attributes_for(action)
|
|
58
|
+
return unless action
|
|
59
|
+
|
|
60
|
+
cname = "FORM_ATTRIBUTES_#{action.upcase}"
|
|
61
|
+
|
|
62
|
+
self.class.const_get(cname) if self.class.const_defined?(cname)
|
|
55
63
|
end
|
|
56
64
|
|
|
57
65
|
def permitted_attributes
|
|
@@ -71,6 +79,12 @@ module Administrate
|
|
|
71
79
|
self.class::COLLECTION_ATTRIBUTES
|
|
72
80
|
end
|
|
73
81
|
|
|
82
|
+
def search_attributes
|
|
83
|
+
attribute_types.keys.select do |attribute|
|
|
84
|
+
attribute_types[attribute].searchable?
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
74
88
|
def display_resource(resource)
|
|
75
89
|
"#{resource.class} ##{resource.id}"
|
|
76
90
|
end
|
|
@@ -3,6 +3,17 @@ require_relative "base"
|
|
|
3
3
|
module Administrate
|
|
4
4
|
module Field
|
|
5
5
|
class Time < Base
|
|
6
|
+
def time
|
|
7
|
+
return I18n.localize(data, format: format) if options[:format]
|
|
8
|
+
|
|
9
|
+
data.strftime("%I:%M%p")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def format
|
|
15
|
+
options[:format]
|
|
16
|
+
end
|
|
6
17
|
end
|
|
7
18
|
end
|
|
8
19
|
end
|
|
@@ -10,8 +10,15 @@ module Administrate
|
|
|
10
10
|
|
|
11
11
|
attr_reader :resource
|
|
12
12
|
|
|
13
|
-
def attributes
|
|
14
|
-
|
|
13
|
+
def attributes(action = nil)
|
|
14
|
+
action =
|
|
15
|
+
case action
|
|
16
|
+
when "update" then "edit"
|
|
17
|
+
when "create" then "new"
|
|
18
|
+
else action
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
dashboard.form_attributes(action).map do |attribute|
|
|
15
22
|
attribute_field(dashboard, resource, attribute, :form)
|
|
16
23
|
end
|
|
17
24
|
end
|
data/lib/administrate/search.rb
CHANGED
|
@@ -4,14 +4,15 @@ require "active_support/core_ext/object/blank"
|
|
|
4
4
|
module Administrate
|
|
5
5
|
class Search
|
|
6
6
|
class Query
|
|
7
|
-
attr_reader :filters
|
|
7
|
+
attr_reader :filters, :valid_filters
|
|
8
8
|
|
|
9
9
|
def blank?
|
|
10
10
|
terms.blank? && filters.empty?
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def initialize(original_query)
|
|
13
|
+
def initialize(original_query, valid_filters = nil)
|
|
14
14
|
@original_query = original_query
|
|
15
|
+
@valid_filters = valid_filters
|
|
15
16
|
@filters, @terms = parse_query(original_query)
|
|
16
17
|
end
|
|
17
18
|
|
|
@@ -30,7 +31,7 @@ module Administrate
|
|
|
30
31
|
private
|
|
31
32
|
|
|
32
33
|
def filter?(word)
|
|
33
|
-
word.match?(
|
|
34
|
+
valid_filters&.any? { |filter| word.match?(/^#{filter}:\w*$/) }
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def parse_query(query)
|
|
@@ -38,7 +39,7 @@ module Administrate
|
|
|
38
39
|
terms = []
|
|
39
40
|
query.to_s.split.each do |word|
|
|
40
41
|
if filter?(word)
|
|
41
|
-
filters << word
|
|
42
|
+
filters << word
|
|
42
43
|
else
|
|
43
44
|
terms << word
|
|
44
45
|
end
|
|
@@ -47,10 +48,10 @@ module Administrate
|
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
def initialize(scoped_resource,
|
|
51
|
-
@
|
|
51
|
+
def initialize(scoped_resource, dashboard, term)
|
|
52
|
+
@dashboard = dashboard
|
|
52
53
|
@scoped_resource = scoped_resource
|
|
53
|
-
@query = Query.new(term)
|
|
54
|
+
@query = Query.new(term, valid_filters.keys)
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def run
|
|
@@ -65,15 +66,20 @@ module Administrate
|
|
|
65
66
|
|
|
66
67
|
private
|
|
67
68
|
|
|
68
|
-
def apply_filter(filter, resources)
|
|
69
|
+
def apply_filter(filter, filter_param, resources)
|
|
69
70
|
return resources unless filter
|
|
70
|
-
filter.
|
|
71
|
+
if filter.parameters.size == 1
|
|
72
|
+
filter.call(resources)
|
|
73
|
+
else
|
|
74
|
+
filter.call(resources, filter_param)
|
|
75
|
+
end
|
|
71
76
|
end
|
|
72
77
|
|
|
73
78
|
def filter_results(resources)
|
|
74
|
-
query.filters.each do |
|
|
79
|
+
query.filters.each do |filter_query|
|
|
80
|
+
filter_name, filter_param = filter_query.split(":")
|
|
75
81
|
filter = valid_filters[filter_name]
|
|
76
|
-
resources = apply_filter(filter, resources)
|
|
82
|
+
resources = apply_filter(filter, filter_param, resources)
|
|
77
83
|
end
|
|
78
84
|
resources
|
|
79
85
|
end
|
|
@@ -102,9 +108,7 @@ module Administrate
|
|
|
102
108
|
end
|
|
103
109
|
|
|
104
110
|
def search_attributes
|
|
105
|
-
|
|
106
|
-
attribute_types[attribute].searchable?
|
|
107
|
-
end
|
|
111
|
+
@dashboard.search_attributes
|
|
108
112
|
end
|
|
109
113
|
|
|
110
114
|
def search_results(resources)
|
|
@@ -114,15 +118,15 @@ module Administrate
|
|
|
114
118
|
end
|
|
115
119
|
|
|
116
120
|
def valid_filters
|
|
117
|
-
if @
|
|
118
|
-
@
|
|
121
|
+
if @dashboard.class.const_defined?(:COLLECTION_FILTERS)
|
|
122
|
+
@dashboard.class.const_get(:COLLECTION_FILTERS).stringify_keys
|
|
119
123
|
else
|
|
120
124
|
{}
|
|
121
125
|
end
|
|
122
126
|
end
|
|
123
127
|
|
|
124
128
|
def attribute_types
|
|
125
|
-
@
|
|
129
|
+
@dashboard.class.const_get(:ATTRIBUTE_TYPES)
|
|
126
130
|
end
|
|
127
131
|
|
|
128
132
|
def query_table_name(attr)
|
data/lib/administrate/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module <%= namespace.to_s.
|
|
2
|
-
class <%= class_name.pluralize %>Controller < <%= namespace.to_s.
|
|
1
|
+
module <%= namespace.to_s.camelize %>
|
|
2
|
+
class <%= class_name.pluralize %>Controller < <%= namespace.to_s.camelize %>::ApplicationController
|
|
3
3
|
# Overwrite any of the RESTful controller actions to implement custom behavior
|
|
4
4
|
# For example, you may want to send an email after a foo is updated.
|
|
5
5
|
#
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#
|
|
5
5
|
# If you want to add pagination or other controller-level concerns,
|
|
6
6
|
# you're free to overwrite the RESTful controller actions.
|
|
7
|
-
module <%= namespace.
|
|
7
|
+
module <%= namespace.camelize %>
|
|
8
8
|
class ApplicationController < Administrate::ApplicationController
|
|
9
9
|
before_action :authenticate_admin
|
|
10
10
|
|
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.17.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: 2022-02-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: actionpack
|
|
@@ -137,20 +137,6 @@ dependencies:
|
|
|
137
137
|
- - "~>"
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
139
|
version: '0.6'
|
|
140
|
-
- !ruby/object:Gem::Dependency
|
|
141
|
-
name: rspec-rails
|
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
|
143
|
-
requirements:
|
|
144
|
-
- - ">="
|
|
145
|
-
- !ruby/object:Gem::Version
|
|
146
|
-
version: '0'
|
|
147
|
-
type: :development
|
|
148
|
-
prerelease: false
|
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
150
|
-
requirements:
|
|
151
|
-
- - ">="
|
|
152
|
-
- !ruby/object:Gem::Version
|
|
153
|
-
version: '0'
|
|
154
140
|
description: |
|
|
155
141
|
Administrate is heavily inspired by projects like Rails Admin and ActiveAdmin,
|
|
156
142
|
but aims to provide a better user experience for site admins,
|
|
@@ -203,9 +189,12 @@ files:
|
|
|
203
189
|
- app/controllers/concerns/administrate/punditize.rb
|
|
204
190
|
- app/helpers/administrate/application_helper.rb
|
|
205
191
|
- app/views/administrate/application/_collection.html.erb
|
|
192
|
+
- app/views/administrate/application/_collection_header_actions.html.erb
|
|
193
|
+
- app/views/administrate/application/_collection_item_actions.html.erb
|
|
206
194
|
- app/views/administrate/application/_flashes.html.erb
|
|
207
195
|
- app/views/administrate/application/_form.html.erb
|
|
208
196
|
- app/views/administrate/application/_icons.html.erb
|
|
197
|
+
- app/views/administrate/application/_index_header.html.erb
|
|
209
198
|
- app/views/administrate/application/_javascript.html.erb
|
|
210
199
|
- app/views/administrate/application/_navigation.html.erb
|
|
211
200
|
- app/views/administrate/application/_search.html.erb
|
|
@@ -381,7 +370,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
381
370
|
- !ruby/object:Gem::Version
|
|
382
371
|
version: '0'
|
|
383
372
|
requirements: []
|
|
384
|
-
rubygems_version: 3.1.
|
|
373
|
+
rubygems_version: 3.1.6
|
|
385
374
|
signing_key:
|
|
386
375
|
specification_version: 4
|
|
387
376
|
summary: A Rails engine for creating super-flexible admin dashboards
|