viniBaxterDesk 0.13.1
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 +7 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/administrate/application.js +6 -0
- data/app/assets/javascripts/administrate/components/associative.js +4 -0
- data/app/assets/javascripts/administrate/components/date_time_picker.js +14 -0
- data/app/assets/javascripts/administrate/components/table.js +23 -0
- data/app/assets/stylesheets/administrate/application.scss +30 -0
- data/app/assets/stylesheets/administrate/base/_forms.scss +107 -0
- data/app/assets/stylesheets/administrate/base/_layout.scss +20 -0
- data/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
- data/app/assets/stylesheets/administrate/base/_tables.scss +58 -0
- data/app/assets/stylesheets/administrate/base/_typography.scss +45 -0
- data/app/assets/stylesheets/administrate/components/_app-container.scss +9 -0
- data/app/assets/stylesheets/administrate/components/_attributes.scss +26 -0
- data/app/assets/stylesheets/administrate/components/_buttons.scss +51 -0
- data/app/assets/stylesheets/administrate/components/_cells.scss +47 -0
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +45 -0
- data/app/assets/stylesheets/administrate/components/_flashes.scss +28 -0
- data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
- data/app/assets/stylesheets/administrate/components/_main-content.scss +29 -0
- data/app/assets/stylesheets/administrate/components/_navigation.scss +32 -0
- data/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
- data/app/assets/stylesheets/administrate/components/_search.scss +46 -0
- data/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
- data/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
- data/app/assets/stylesheets/administrate/library/_variables.scss +63 -0
- data/app/assets/stylesheets/administrate/reset/_normalize.scss +447 -0
- data/app/assets/stylesheets/administrate/utilities/_text-color.scss +3 -0
- data/app/assets/stylesheets/docs.scss +93 -0
- data/app/controllers/administrate/application_controller.rb +189 -0
- data/app/controllers/concerns/administrate/punditize.rb +36 -0
- data/app/helpers/administrate/application_helper.rb +83 -0
- data/app/views/administrate/application/_collection.html.erb +97 -0
- data/app/views/administrate/application/_flashes.html.erb +20 -0
- data/app/views/administrate/application/_form.html.erb +45 -0
- data/app/views/administrate/application/_icons.html.erb +13 -0
- data/app/views/administrate/application/_javascript.html.erb +21 -0
- data/app/views/administrate/application/_navigation.html.erb +20 -0
- data/app/views/administrate/application/_search.html.erb +25 -0
- data/app/views/administrate/application/_stylesheet.html.erb +14 -0
- data/app/views/administrate/application/edit.html.erb +36 -0
- data/app/views/administrate/application/index.html.erb +66 -0
- data/app/views/administrate/application/new.html.erb +37 -0
- data/app/views/administrate/application/show.html.erb +49 -0
- data/app/views/fields/belongs_to/_form.html.erb +26 -0
- data/app/views/fields/belongs_to/_index.html.erb +27 -0
- data/app/views/fields/belongs_to/_show.html.erb +27 -0
- data/app/views/fields/boolean/_form.html.erb +23 -0
- data/app/views/fields/boolean/_index.html.erb +19 -0
- data/app/views/fields/boolean/_show.html.erb +19 -0
- data/app/views/fields/date/_form.html.erb +24 -0
- data/app/views/fields/date/_index.html.erb +21 -0
- data/app/views/fields/date/_show.html.erb +21 -0
- data/app/views/fields/date_time/_form.html.erb +24 -0
- data/app/views/fields/date_time/_index.html.erb +21 -0
- data/app/views/fields/date_time/_show.html.erb +21 -0
- data/app/views/fields/email/_form.html.erb +23 -0
- data/app/views/fields/email/_index.html.erb +18 -0
- data/app/views/fields/email/_show.html.erb +18 -0
- data/app/views/fields/has_many/_form.html.erb +29 -0
- data/app/views/fields/has_many/_index.html.erb +19 -0
- data/app/views/fields/has_many/_show.html.erb +38 -0
- data/app/views/fields/has_one/_form.html.erb +28 -0
- data/app/views/fields/has_one/_index.html.erb +23 -0
- data/app/views/fields/has_one/_show.html.erb +40 -0
- data/app/views/fields/number/_form.html.erb +23 -0
- data/app/views/fields/number/_index.html.erb +19 -0
- data/app/views/fields/number/_show.html.erb +19 -0
- data/app/views/fields/password/_form.html.erb +23 -0
- data/app/views/fields/password/_index.html.erb +18 -0
- data/app/views/fields/password/_show.html.erb +18 -0
- data/app/views/fields/polymorphic/_form.html.erb +29 -0
- data/app/views/fields/polymorphic/_index.html.erb +24 -0
- data/app/views/fields/polymorphic/_show.html.erb +28 -0
- data/app/views/fields/select/_form.html.erb +31 -0
- data/app/views/fields/select/_index.html.erb +16 -0
- data/app/views/fields/select/_show.html.erb +16 -0
- data/app/views/fields/string/_form.html.erb +23 -0
- data/app/views/fields/string/_index.html.erb +18 -0
- data/app/views/fields/string/_show.html.erb +18 -0
- data/app/views/fields/text/_form.html.erb +22 -0
- data/app/views/fields/text/_index.html.erb +18 -0
- data/app/views/fields/text/_show.html.erb +18 -0
- data/app/views/fields/time/_form.html.erb +22 -0
- data/app/views/fields/time/_index.html.erb +17 -0
- data/app/views/fields/time/_show.html.erb +17 -0
- 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 +41 -0
- data/config/i18n-tasks.yml +18 -0
- data/config/locales/administrate.ar.yml +28 -0
- data/config/locales/administrate.bs.yml +27 -0
- data/config/locales/administrate.ca.yml +28 -0
- data/config/locales/administrate.da.yml +28 -0
- data/config/locales/administrate.de.yml +28 -0
- data/config/locales/administrate.en.yml +28 -0
- data/config/locales/administrate.es.yml +28 -0
- data/config/locales/administrate.fr.yml +28 -0
- data/config/locales/administrate.id.yml +28 -0
- data/config/locales/administrate.it.yml +28 -0
- data/config/locales/administrate.ja.yml +28 -0
- data/config/locales/administrate.ko.yml +28 -0
- data/config/locales/administrate.nl.yml +28 -0
- data/config/locales/administrate.pl.yml +28 -0
- data/config/locales/administrate.pt-BR.yml +29 -0
- data/config/locales/administrate.pt.yml +29 -0
- data/config/locales/administrate.ru.yml +28 -0
- data/config/locales/administrate.sq.yml +28 -0
- data/config/locales/administrate.sv.yml +28 -0
- data/config/locales/administrate.uk.yml +28 -0
- data/config/locales/administrate.vi.yml +28 -0
- data/config/locales/administrate.zh-CN.yml +28 -0
- data/config/locales/administrate.zh-TW.yml +28 -0
- data/config/routes.rb +2 -0
- data/config/unicorn.rb +30 -0
- data/docs/adding_controllers_without_related_model.md +36 -0
- data/docs/adding_custom_field_types.md +81 -0
- data/docs/authentication.md +63 -0
- data/docs/authorization.md +71 -0
- data/docs/contributing.md +1 -0
- data/docs/customizing_attribute_partials.md +56 -0
- data/docs/customizing_controller_actions.md +58 -0
- data/docs/customizing_dashboards.md +303 -0
- data/docs/customizing_page_views.md +84 -0
- data/docs/getting_started.md +128 -0
- data/docs/rails_api.md +45 -0
- data/lib/administrate/base_dashboard.rb +97 -0
- data/lib/administrate/custom_dashboard.rb +15 -0
- data/lib/administrate/engine.rb +44 -0
- data/lib/administrate/field/associative.rb +33 -0
- data/lib/administrate/field/base.rb +54 -0
- data/lib/administrate/field/belongs_to.rb +38 -0
- data/lib/administrate/field/boolean.rb +15 -0
- data/lib/administrate/field/date.rb +20 -0
- data/lib/administrate/field/date_time.rb +32 -0
- data/lib/administrate/field/deferred.rb +44 -0
- data/lib/administrate/field/email.rb +11 -0
- data/lib/administrate/field/has_many.rb +94 -0
- data/lib/administrate/field/has_one.rb +35 -0
- data/lib/administrate/field/number.rb +35 -0
- data/lib/administrate/field/password.rb +25 -0
- data/lib/administrate/field/polymorphic.rb +51 -0
- data/lib/administrate/field/select.rb +24 -0
- data/lib/administrate/field/string.rb +21 -0
- data/lib/administrate/field/text.rb +21 -0
- data/lib/administrate/field/time.rb +8 -0
- data/lib/administrate/field/url.rb +21 -0
- data/lib/administrate/generator_helpers.rb +13 -0
- data/lib/administrate/namespace/resource.rb +28 -0
- data/lib/administrate/namespace.rb +35 -0
- data/lib/administrate/order.rb +88 -0
- data/lib/administrate/page/base.rb +41 -0
- data/lib/administrate/page/collection.rb +37 -0
- data/lib/administrate/page/form.rb +28 -0
- data/lib/administrate/page/show.rb +24 -0
- data/lib/administrate/page.rb +4 -0
- data/lib/administrate/resource_resolver.rb +43 -0
- data/lib/administrate/search.rb +157 -0
- data/lib/administrate/version.rb +3 -0
- data/lib/administrate/view_generator.rb +36 -0
- data/lib/administrate.rb +4 -0
- data/lib/generators/administrate/assets/assets_generator.rb +12 -0
- data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
- data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
- data/lib/generators/administrate/dashboard/USAGE +9 -0
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +143 -0
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +46 -0
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +68 -0
- data/lib/generators/administrate/field/field_generator.rb +31 -0
- data/lib/generators/administrate/field/templates/_form.html.erb +6 -0
- data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
- data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
- data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
- data/lib/generators/administrate/install/install_generator.rb +49 -0
- data/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
- data/lib/generators/administrate/routes/routes_generator.rb +96 -0
- data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
- data/lib/generators/administrate/views/edit_generator.rb +16 -0
- data/lib/generators/administrate/views/field_generator.rb +50 -0
- data/lib/generators/administrate/views/form_generator.rb +15 -0
- data/lib/generators/administrate/views/index_generator.rb +16 -0
- data/lib/generators/administrate/views/layout_generator.rb +24 -0
- data/lib/generators/administrate/views/navigation_generator.rb +15 -0
- data/lib/generators/administrate/views/new_generator.rb +16 -0
- data/lib/generators/administrate/views/show_generator.rb +15 -0
- data/lib/generators/administrate/views/views_generator.rb +14 -0
- data/lib/tasks/administrate_tasks.rake +4 -0
- metadata +398 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Customizing page views
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
In order to change the appearance of any page,
|
|
6
|
+
you can write custom Rails views.
|
|
7
|
+
|
|
8
|
+
## Customizing for all resources
|
|
9
|
+
|
|
10
|
+
The easiest way to get started is by using the built-in generators.
|
|
11
|
+
In order to change the appearance of views for all resource types,
|
|
12
|
+
call the generators with no arguments.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
rails generate administrate:views:index
|
|
16
|
+
# -> app/views/admin/application/index.html.erb
|
|
17
|
+
# -> app/views/admin/application/_collection.html.erb
|
|
18
|
+
|
|
19
|
+
rails generate administrate:views:show
|
|
20
|
+
# -> app/views/admin/application/show.html.erb
|
|
21
|
+
|
|
22
|
+
rails generate administrate:views:edit
|
|
23
|
+
# -> app/views/admin/application/edit.html.erb
|
|
24
|
+
# -> app/views/admin/application/_form.html.erb
|
|
25
|
+
|
|
26
|
+
rails generate administrate:views:new
|
|
27
|
+
# -> app/views/admin/application/new.html.erb
|
|
28
|
+
# -> app/views/admin/application/_form.html.erb
|
|
29
|
+
|
|
30
|
+
rails generate administrate:views
|
|
31
|
+
# -> all of the above
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The generators copy over the default views that Administrate uses,
|
|
35
|
+
so you have a good starting point for customizations.
|
|
36
|
+
Feel free to change up the file type,
|
|
37
|
+
add extra sections to the page,
|
|
38
|
+
or blow it all away for your own custom look.
|
|
39
|
+
|
|
40
|
+
## Customizing for a specific resource
|
|
41
|
+
|
|
42
|
+
In order to change a dashboard page for a single type of resource,
|
|
43
|
+
pass in the resource name to the view generators.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
rails generate administrate:views:index User
|
|
47
|
+
# -> app/views/admin/users/index.html.erb
|
|
48
|
+
# -> app/views/admin/users/_collection.html.erb
|
|
49
|
+
|
|
50
|
+
rails generate administrate:views:show User
|
|
51
|
+
# -> app/views/admin/users/show.html.erb
|
|
52
|
+
|
|
53
|
+
rails generate administrate:views:edit User
|
|
54
|
+
# -> app/views/admin/users/edit.html.erb
|
|
55
|
+
# -> app/views/admin/users/_form.html.erb
|
|
56
|
+
|
|
57
|
+
rails generate administrate:views:new User
|
|
58
|
+
# -> app/views/admin/users/new.html.erb
|
|
59
|
+
# -> app/views/admin/users/_form.html.erb
|
|
60
|
+
|
|
61
|
+
rails generate administrate:views User
|
|
62
|
+
# -> all of the above
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Any changes to these template files
|
|
66
|
+
will *only* affect pages that display customers,
|
|
67
|
+
and will leave the show pages for other resources unchanged.
|
|
68
|
+
|
|
69
|
+
## Customizing layouts
|
|
70
|
+
|
|
71
|
+
Many developers need to customize the layouts of their admin dashboard.
|
|
72
|
+
It's as easy as passing in the "layout" keyword to the view generators.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
rails generate administrate:views:layout
|
|
76
|
+
# -> app/views/layouts/admin/application.html.erb
|
|
77
|
+
# -> app/views/admin/application/_navigation.html.erb
|
|
78
|
+
# -> app/views/admin/application/_javascript.html.erb
|
|
79
|
+
# -> app/views/admin/application/_flashes.html.erb
|
|
80
|
+
|
|
81
|
+
rails generate administrate:views:navigation
|
|
82
|
+
# It only generates the sidebar partial
|
|
83
|
+
# -> app/views/admin/application/_navigation.html.erb
|
|
84
|
+
```
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Getting Started
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Administrate is released as a Ruby gem, and can be installed on Rails
|
|
6
|
+
applications version 4.2 or greater.
|
|
7
|
+
|
|
8
|
+
Add the following to your Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
# Gemfile
|
|
12
|
+
gem "administrate"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Re-bundle, then run the installer:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ rails generate administrate:install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The installer adds some new routes to your `config/routes.rb`,
|
|
22
|
+
and creates a controller at `app/controllers/admin/application_controller.rb`
|
|
23
|
+
|
|
24
|
+
In addition, the generator creates a `Dashboard` and a `Controller` for each of
|
|
25
|
+
your ActiveRecord resources:
|
|
26
|
+
|
|
27
|
+
- `app/controllers/admin/foos_controller.rb`
|
|
28
|
+
- `app/dashboards/foo_dashboard.rb`
|
|
29
|
+
|
|
30
|
+
The `Admin::ApplicationController` can be customized to add
|
|
31
|
+
authentication logic, authorization, pagination,
|
|
32
|
+
or other controller-level concerns.
|
|
33
|
+
|
|
34
|
+
You will also want to add a `root` route to show a dashboard when you go to `/admin`.
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
Rails.application.routes.draw do
|
|
38
|
+
namespace :admin do
|
|
39
|
+
# Add dashboard for your models here
|
|
40
|
+
resources :customers,
|
|
41
|
+
resources :orders
|
|
42
|
+
|
|
43
|
+
root to: "customers#index" # <--- Root route
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The routes can be customized to show or hide
|
|
49
|
+
different models on the dashboard.
|
|
50
|
+
|
|
51
|
+
Each `FooDashboard` specifies which attributes should be displayed
|
|
52
|
+
on the admin dashboard for the `Foo` resource.
|
|
53
|
+
|
|
54
|
+
Each `Admin::FooController` can be overwritten to specify custom behavior.
|
|
55
|
+
|
|
56
|
+
Once you have Administrate installed,
|
|
57
|
+
visit <http://localhost:3000/admin> to see your new dashboard in action.
|
|
58
|
+
|
|
59
|
+
## Create Additional Dashboards
|
|
60
|
+
|
|
61
|
+
In order to create additional dashboards, pass in the resource name to
|
|
62
|
+
the dashboard generator. A dashboard and controller will be created.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
$ rails generate administrate:dashboard Foo
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Add a route for the new dashboard.
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
# config/routes.rb
|
|
72
|
+
|
|
73
|
+
namespace :admin do
|
|
74
|
+
resources :foos
|
|
75
|
+
end
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Using a Custom Namespace
|
|
79
|
+
|
|
80
|
+
Administrate supports using a namespace other than `Admin`, such as
|
|
81
|
+
`Supervisor`. This will also change the route it's using:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
rails generate administrate:install --namespace=supervisor
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Keep Dashboards Updated as Model Attributes Change
|
|
88
|
+
|
|
89
|
+
If you've installed Administrate and generated dashboards and _then_
|
|
90
|
+
subsequently added attributes to your models you'll need to manually add
|
|
91
|
+
these additions (or removals) to your dashboards.
|
|
92
|
+
|
|
93
|
+
Example:
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
# app/dashboards/your_model_dashboard.rb
|
|
97
|
+
|
|
98
|
+
ATTRIBUTE_TYPES = {
|
|
99
|
+
# ...
|
|
100
|
+
the_new_attribute: Field::String,
|
|
101
|
+
# ...
|
|
102
|
+
}.freeze
|
|
103
|
+
|
|
104
|
+
SHOW_PAGE_ATTRIBUTES = [
|
|
105
|
+
# ...
|
|
106
|
+
:the_new_attribute,
|
|
107
|
+
# ...
|
|
108
|
+
].freeze
|
|
109
|
+
|
|
110
|
+
FORM_ATTRIBUTES = [
|
|
111
|
+
# ...
|
|
112
|
+
:the_new_attribute,
|
|
113
|
+
# ...
|
|
114
|
+
].freeze
|
|
115
|
+
|
|
116
|
+
COLLECTION_ATTRIBUTES = [
|
|
117
|
+
# ...
|
|
118
|
+
:the_new_attribute, # if you want it on the index, also.
|
|
119
|
+
# ...
|
|
120
|
+
].freeze
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
It's recommended that you make this change at the same time as you add the
|
|
124
|
+
attribute to the model.
|
|
125
|
+
|
|
126
|
+
The alternative way to handle this is to re-run `rails g administrate:install`
|
|
127
|
+
and carefully pick through the diffs. This latter method is probably more
|
|
128
|
+
cumbersome.
|
data/docs/rails_api.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Rails API
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
|
|
6
|
+
we still want to have an admin.
|
|
7
|
+
|
|
8
|
+
To get this working, we recommend updating this config:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
# config/application.rb
|
|
12
|
+
config.api_only = false
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That means, when your app _boots_, we'll have access to flashes and such. We
|
|
16
|
+
also don't use your `ApplicationController`. Instead, Administrate provides its
|
|
17
|
+
own. Meaning you're free to specify `ActionController::API` as your parent
|
|
18
|
+
controller to make sure no flash, session, or cookie middleware is used by your
|
|
19
|
+
API.
|
|
20
|
+
|
|
21
|
+
Alternatively, if your application needs to have `config.api_only = true`, we
|
|
22
|
+
recommend you add the following lines to your `config/application.rb`
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
# Enable Flash, Cookies, MethodOverride for Administrate Gem
|
|
26
|
+
config.middleware.use ActionDispatch::Flash
|
|
27
|
+
config.session_store :cookie_store
|
|
28
|
+
config.middleware.use ActionDispatch::Cookies
|
|
29
|
+
config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
|
|
30
|
+
config.middleware.use ::Rack::MethodOverride
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You must also ensure that all the required controller actions are available
|
|
34
|
+
and accessible as routes since generators in API-only applications only
|
|
35
|
+
generate some of the required actions. Here is an example:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
# routes.rb
|
|
39
|
+
namespace :admin do
|
|
40
|
+
resources :name, only: %i(index show new create edit update destroy)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# names_controller.rb
|
|
44
|
+
# Ensure each of those methods are defined
|
|
45
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require "administrate/field/belongs_to"
|
|
2
|
+
require "administrate/field/boolean"
|
|
3
|
+
require "administrate/field/date_time"
|
|
4
|
+
require "administrate/field/date"
|
|
5
|
+
require "administrate/field/email"
|
|
6
|
+
require "administrate/field/has_many"
|
|
7
|
+
require "administrate/field/has_one"
|
|
8
|
+
require "administrate/field/number"
|
|
9
|
+
require "administrate/field/polymorphic"
|
|
10
|
+
require "administrate/field/select"
|
|
11
|
+
require "administrate/field/string"
|
|
12
|
+
require "administrate/field/text"
|
|
13
|
+
require "administrate/field/time"
|
|
14
|
+
require "administrate/field/url"
|
|
15
|
+
require "administrate/field/password"
|
|
16
|
+
|
|
17
|
+
module Administrate
|
|
18
|
+
class BaseDashboard
|
|
19
|
+
include Administrate
|
|
20
|
+
|
|
21
|
+
DASHBOARD_SUFFIX = "Dashboard".freeze
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
def model
|
|
25
|
+
to_s.chomp(DASHBOARD_SUFFIX).classify.constantize
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def resource_name(opts)
|
|
29
|
+
model.model_name.human(opts)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def attribute_types
|
|
34
|
+
self.class::ATTRIBUTE_TYPES
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def attribute_type_for(attribute_name)
|
|
38
|
+
attribute_types.fetch(attribute_name) do
|
|
39
|
+
fail attribute_not_found_message(attribute_name)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def attribute_types_for(attribute_names)
|
|
44
|
+
attribute_names.each_with_object({}) do |name, attributes|
|
|
45
|
+
attributes[name] = attribute_type_for(name)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def all_attributes
|
|
50
|
+
attribute_types.keys
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def form_attributes
|
|
54
|
+
self.class::FORM_ATTRIBUTES
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def permitted_attributes
|
|
58
|
+
form_attributes.map do |attr|
|
|
59
|
+
attribute_types[attr].permitted_attribute(attr)
|
|
60
|
+
end.uniq
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def show_page_attributes
|
|
64
|
+
self.class::SHOW_PAGE_ATTRIBUTES
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def collection_attributes
|
|
68
|
+
self.class::COLLECTION_ATTRIBUTES
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def display_resource(resource)
|
|
72
|
+
"#{resource.class} ##{resource.id}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def collection_includes
|
|
76
|
+
attribute_includes(collection_attributes)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def item_includes
|
|
80
|
+
attribute_includes(show_page_attributes)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def attribute_not_found_message(attr)
|
|
86
|
+
"Attribute #{attr} could not be found in #{self.class}::ATTRIBUTE_TYPES"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def attribute_includes(attributes)
|
|
90
|
+
attributes.map do |key|
|
|
91
|
+
field = self.class::ATTRIBUTE_TYPES[key]
|
|
92
|
+
|
|
93
|
+
key if field.associative?
|
|
94
|
+
end.compact
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Administrate
|
|
2
|
+
class CustomDashboard
|
|
3
|
+
include Administrate
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
def resource_name(_opts)
|
|
7
|
+
named_resource.pluralize.titleize
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def resource(resource_name)
|
|
11
|
+
define_singleton_method(:named_resource) { resource_name }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "datetime_picker_rails"
|
|
2
|
+
require "jquery-rails"
|
|
3
|
+
require "kaminari"
|
|
4
|
+
require "momentjs-rails"
|
|
5
|
+
require "sassc-rails"
|
|
6
|
+
require "selectize-rails"
|
|
7
|
+
require "sprockets/railtie"
|
|
8
|
+
|
|
9
|
+
require "administrate/page/form"
|
|
10
|
+
require "administrate/page/show"
|
|
11
|
+
require "administrate/page/collection"
|
|
12
|
+
require "administrate/order"
|
|
13
|
+
require "administrate/resource_resolver"
|
|
14
|
+
require "administrate/search"
|
|
15
|
+
require "administrate/namespace"
|
|
16
|
+
require "administrate/namespace/resource"
|
|
17
|
+
|
|
18
|
+
module Administrate
|
|
19
|
+
class Engine < ::Rails::Engine
|
|
20
|
+
isolate_namespace Administrate
|
|
21
|
+
|
|
22
|
+
@@javascripts = []
|
|
23
|
+
@@stylesheets = []
|
|
24
|
+
|
|
25
|
+
def self.add_javascript(script)
|
|
26
|
+
@@javascripts << script
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.add_stylesheet(stylesheet)
|
|
30
|
+
@@stylesheets << stylesheet
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.stylesheets
|
|
34
|
+
@@stylesheets
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.javascripts
|
|
38
|
+
@@javascripts
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
add_javascript "administrate/application"
|
|
42
|
+
add_stylesheet "administrate/application"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative "base"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class Associative < Base
|
|
6
|
+
def display_associated_resource
|
|
7
|
+
associated_dashboard.display_resource(data)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def associated_class
|
|
11
|
+
associated_class_name.constantize
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
|
|
16
|
+
def associated_dashboard
|
|
17
|
+
"#{associated_class_name}Dashboard".constantize.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def associated_class_name
|
|
21
|
+
options.fetch(:class_name, attribute.to_s.singularize.camelcase)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def primary_key
|
|
25
|
+
options.fetch(:primary_key, :id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def foreign_key
|
|
29
|
+
options.fetch(:foreign_key, :"#{attribute}_id")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_relative "deferred"
|
|
2
|
+
require "active_support/core_ext/string/inflections"
|
|
3
|
+
|
|
4
|
+
module Administrate
|
|
5
|
+
module Field
|
|
6
|
+
class Base
|
|
7
|
+
def self.with_options(options = {})
|
|
8
|
+
Deferred.new(self, options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.html_class
|
|
12
|
+
field_type.dasherize
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.associative?
|
|
16
|
+
self < Associative
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.searchable?
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.field_type
|
|
24
|
+
to_s.split("::").last.underscore
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.permitted_attribute(attr, _options = nil)
|
|
28
|
+
attr
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def initialize(attribute, data, page, options = {})
|
|
32
|
+
@attribute = attribute
|
|
33
|
+
@data = data
|
|
34
|
+
@page = page
|
|
35
|
+
@resource = options.delete(:resource)
|
|
36
|
+
@options = options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def html_class
|
|
40
|
+
self.class.html_class
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def name
|
|
44
|
+
attribute.to_s
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_partial_path
|
|
48
|
+
"/fields/#{self.class.field_type}/#{page}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
attr_reader :attribute, :data, :options, :page, :resource
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative "associative"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class BelongsTo < Associative
|
|
6
|
+
def self.permitted_attribute(attr, _options = nil)
|
|
7
|
+
:"#{attr}_id"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def permitted_attribute
|
|
11
|
+
foreign_key
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def associated_resource_options
|
|
15
|
+
[nil] + candidate_resources.map do |resource|
|
|
16
|
+
[display_candidate_resource(resource), resource.send(primary_key)]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def selected_option
|
|
21
|
+
data && data.send(primary_key)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def candidate_resources
|
|
27
|
+
scope = options[:scope] ? options[:scope].call : associated_class.all
|
|
28
|
+
|
|
29
|
+
order = options.delete(:order)
|
|
30
|
+
order ? scope.reorder(order) : scope
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def display_candidate_resource(resource)
|
|
34
|
+
associated_dashboard.display_resource(resource)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "base"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class Date < Base
|
|
6
|
+
def date
|
|
7
|
+
I18n.localize(
|
|
8
|
+
data.to_date,
|
|
9
|
+
format: format,
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def format
|
|
16
|
+
options.fetch(:format, :default)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative "base"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class DateTime < Base
|
|
6
|
+
def date
|
|
7
|
+
I18n.localize(
|
|
8
|
+
data.in_time_zone(timezone).to_date,
|
|
9
|
+
format: format,
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def datetime
|
|
14
|
+
I18n.localize(
|
|
15
|
+
data.in_time_zone(timezone),
|
|
16
|
+
format: format,
|
|
17
|
+
default: data,
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def format
|
|
24
|
+
options.fetch(:format, :default)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def timezone
|
|
28
|
+
options.fetch(:timezone, ::Time.zone.name || "UTC")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
|
2
|
+
|
|
3
|
+
module Administrate
|
|
4
|
+
module Field
|
|
5
|
+
class Deferred
|
|
6
|
+
def initialize(deferred_class, options = {})
|
|
7
|
+
@deferred_class = deferred_class
|
|
8
|
+
@options = options
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
attr_reader :deferred_class, :options
|
|
12
|
+
|
|
13
|
+
def new(*args)
|
|
14
|
+
new_options = args.last.respond_to?(:merge) ? args.pop : {}
|
|
15
|
+
deferred_class.new(*args, options.merge(new_options))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ==(other)
|
|
19
|
+
other.respond_to?(:deferred_class) &&
|
|
20
|
+
deferred_class == other.deferred_class &&
|
|
21
|
+
options == other.options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def associative?
|
|
25
|
+
deferred_class.associative?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def searchable?
|
|
29
|
+
options.fetch(:searchable, deferred_class.searchable?)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def searchable_field
|
|
33
|
+
options.fetch(:searchable_field)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def permitted_attribute(attr, _options = nil)
|
|
37
|
+
options.fetch(:foreign_key,
|
|
38
|
+
deferred_class.permitted_attribute(attr, options))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
delegate :html_class, to: :deferred_class
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|