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.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +32 -0
  3. data/app/assets/javascripts/administrate/application.js +6 -0
  4. data/app/assets/javascripts/administrate/components/associative.js +4 -0
  5. data/app/assets/javascripts/administrate/components/date_time_picker.js +14 -0
  6. data/app/assets/javascripts/administrate/components/table.js +23 -0
  7. data/app/assets/stylesheets/administrate/application.scss +30 -0
  8. data/app/assets/stylesheets/administrate/base/_forms.scss +107 -0
  9. data/app/assets/stylesheets/administrate/base/_layout.scss +20 -0
  10. data/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
  11. data/app/assets/stylesheets/administrate/base/_tables.scss +58 -0
  12. data/app/assets/stylesheets/administrate/base/_typography.scss +45 -0
  13. data/app/assets/stylesheets/administrate/components/_app-container.scss +9 -0
  14. data/app/assets/stylesheets/administrate/components/_attributes.scss +26 -0
  15. data/app/assets/stylesheets/administrate/components/_buttons.scss +51 -0
  16. data/app/assets/stylesheets/administrate/components/_cells.scss +47 -0
  17. data/app/assets/stylesheets/administrate/components/_field-unit.scss +45 -0
  18. data/app/assets/stylesheets/administrate/components/_flashes.scss +28 -0
  19. data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  20. data/app/assets/stylesheets/administrate/components/_main-content.scss +29 -0
  21. data/app/assets/stylesheets/administrate/components/_navigation.scss +32 -0
  22. data/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
  23. data/app/assets/stylesheets/administrate/components/_search.scss +46 -0
  24. data/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
  25. data/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
  26. data/app/assets/stylesheets/administrate/library/_variables.scss +63 -0
  27. data/app/assets/stylesheets/administrate/reset/_normalize.scss +447 -0
  28. data/app/assets/stylesheets/administrate/utilities/_text-color.scss +3 -0
  29. data/app/assets/stylesheets/docs.scss +93 -0
  30. data/app/controllers/administrate/application_controller.rb +189 -0
  31. data/app/controllers/concerns/administrate/punditize.rb +36 -0
  32. data/app/helpers/administrate/application_helper.rb +83 -0
  33. data/app/views/administrate/application/_collection.html.erb +97 -0
  34. data/app/views/administrate/application/_flashes.html.erb +20 -0
  35. data/app/views/administrate/application/_form.html.erb +45 -0
  36. data/app/views/administrate/application/_icons.html.erb +13 -0
  37. data/app/views/administrate/application/_javascript.html.erb +21 -0
  38. data/app/views/administrate/application/_navigation.html.erb +20 -0
  39. data/app/views/administrate/application/_search.html.erb +25 -0
  40. data/app/views/administrate/application/_stylesheet.html.erb +14 -0
  41. data/app/views/administrate/application/edit.html.erb +36 -0
  42. data/app/views/administrate/application/index.html.erb +66 -0
  43. data/app/views/administrate/application/new.html.erb +37 -0
  44. data/app/views/administrate/application/show.html.erb +49 -0
  45. data/app/views/fields/belongs_to/_form.html.erb +26 -0
  46. data/app/views/fields/belongs_to/_index.html.erb +27 -0
  47. data/app/views/fields/belongs_to/_show.html.erb +27 -0
  48. data/app/views/fields/boolean/_form.html.erb +23 -0
  49. data/app/views/fields/boolean/_index.html.erb +19 -0
  50. data/app/views/fields/boolean/_show.html.erb +19 -0
  51. data/app/views/fields/date/_form.html.erb +24 -0
  52. data/app/views/fields/date/_index.html.erb +21 -0
  53. data/app/views/fields/date/_show.html.erb +21 -0
  54. data/app/views/fields/date_time/_form.html.erb +24 -0
  55. data/app/views/fields/date_time/_index.html.erb +21 -0
  56. data/app/views/fields/date_time/_show.html.erb +21 -0
  57. data/app/views/fields/email/_form.html.erb +23 -0
  58. data/app/views/fields/email/_index.html.erb +18 -0
  59. data/app/views/fields/email/_show.html.erb +18 -0
  60. data/app/views/fields/has_many/_form.html.erb +29 -0
  61. data/app/views/fields/has_many/_index.html.erb +19 -0
  62. data/app/views/fields/has_many/_show.html.erb +38 -0
  63. data/app/views/fields/has_one/_form.html.erb +28 -0
  64. data/app/views/fields/has_one/_index.html.erb +23 -0
  65. data/app/views/fields/has_one/_show.html.erb +40 -0
  66. data/app/views/fields/number/_form.html.erb +23 -0
  67. data/app/views/fields/number/_index.html.erb +19 -0
  68. data/app/views/fields/number/_show.html.erb +19 -0
  69. data/app/views/fields/password/_form.html.erb +23 -0
  70. data/app/views/fields/password/_index.html.erb +18 -0
  71. data/app/views/fields/password/_show.html.erb +18 -0
  72. data/app/views/fields/polymorphic/_form.html.erb +29 -0
  73. data/app/views/fields/polymorphic/_index.html.erb +24 -0
  74. data/app/views/fields/polymorphic/_show.html.erb +28 -0
  75. data/app/views/fields/select/_form.html.erb +31 -0
  76. data/app/views/fields/select/_index.html.erb +16 -0
  77. data/app/views/fields/select/_show.html.erb +16 -0
  78. data/app/views/fields/string/_form.html.erb +23 -0
  79. data/app/views/fields/string/_index.html.erb +18 -0
  80. data/app/views/fields/string/_show.html.erb +18 -0
  81. data/app/views/fields/text/_form.html.erb +22 -0
  82. data/app/views/fields/text/_index.html.erb +18 -0
  83. data/app/views/fields/text/_show.html.erb +18 -0
  84. data/app/views/fields/time/_form.html.erb +22 -0
  85. data/app/views/fields/time/_index.html.erb +17 -0
  86. data/app/views/fields/time/_show.html.erb +17 -0
  87. data/app/views/fields/url/_form.html.erb +23 -0
  88. data/app/views/fields/url/_index.html.erb +20 -0
  89. data/app/views/fields/url/_show.html.erb +20 -0
  90. data/app/views/layouts/administrate/application.html.erb +41 -0
  91. data/config/i18n-tasks.yml +18 -0
  92. data/config/locales/administrate.ar.yml +28 -0
  93. data/config/locales/administrate.bs.yml +27 -0
  94. data/config/locales/administrate.ca.yml +28 -0
  95. data/config/locales/administrate.da.yml +28 -0
  96. data/config/locales/administrate.de.yml +28 -0
  97. data/config/locales/administrate.en.yml +28 -0
  98. data/config/locales/administrate.es.yml +28 -0
  99. data/config/locales/administrate.fr.yml +28 -0
  100. data/config/locales/administrate.id.yml +28 -0
  101. data/config/locales/administrate.it.yml +28 -0
  102. data/config/locales/administrate.ja.yml +28 -0
  103. data/config/locales/administrate.ko.yml +28 -0
  104. data/config/locales/administrate.nl.yml +28 -0
  105. data/config/locales/administrate.pl.yml +28 -0
  106. data/config/locales/administrate.pt-BR.yml +29 -0
  107. data/config/locales/administrate.pt.yml +29 -0
  108. data/config/locales/administrate.ru.yml +28 -0
  109. data/config/locales/administrate.sq.yml +28 -0
  110. data/config/locales/administrate.sv.yml +28 -0
  111. data/config/locales/administrate.uk.yml +28 -0
  112. data/config/locales/administrate.vi.yml +28 -0
  113. data/config/locales/administrate.zh-CN.yml +28 -0
  114. data/config/locales/administrate.zh-TW.yml +28 -0
  115. data/config/routes.rb +2 -0
  116. data/config/unicorn.rb +30 -0
  117. data/docs/adding_controllers_without_related_model.md +36 -0
  118. data/docs/adding_custom_field_types.md +81 -0
  119. data/docs/authentication.md +63 -0
  120. data/docs/authorization.md +71 -0
  121. data/docs/contributing.md +1 -0
  122. data/docs/customizing_attribute_partials.md +56 -0
  123. data/docs/customizing_controller_actions.md +58 -0
  124. data/docs/customizing_dashboards.md +303 -0
  125. data/docs/customizing_page_views.md +84 -0
  126. data/docs/getting_started.md +128 -0
  127. data/docs/rails_api.md +45 -0
  128. data/lib/administrate/base_dashboard.rb +97 -0
  129. data/lib/administrate/custom_dashboard.rb +15 -0
  130. data/lib/administrate/engine.rb +44 -0
  131. data/lib/administrate/field/associative.rb +33 -0
  132. data/lib/administrate/field/base.rb +54 -0
  133. data/lib/administrate/field/belongs_to.rb +38 -0
  134. data/lib/administrate/field/boolean.rb +15 -0
  135. data/lib/administrate/field/date.rb +20 -0
  136. data/lib/administrate/field/date_time.rb +32 -0
  137. data/lib/administrate/field/deferred.rb +44 -0
  138. data/lib/administrate/field/email.rb +11 -0
  139. data/lib/administrate/field/has_many.rb +94 -0
  140. data/lib/administrate/field/has_one.rb +35 -0
  141. data/lib/administrate/field/number.rb +35 -0
  142. data/lib/administrate/field/password.rb +25 -0
  143. data/lib/administrate/field/polymorphic.rb +51 -0
  144. data/lib/administrate/field/select.rb +24 -0
  145. data/lib/administrate/field/string.rb +21 -0
  146. data/lib/administrate/field/text.rb +21 -0
  147. data/lib/administrate/field/time.rb +8 -0
  148. data/lib/administrate/field/url.rb +21 -0
  149. data/lib/administrate/generator_helpers.rb +13 -0
  150. data/lib/administrate/namespace/resource.rb +28 -0
  151. data/lib/administrate/namespace.rb +35 -0
  152. data/lib/administrate/order.rb +88 -0
  153. data/lib/administrate/page/base.rb +41 -0
  154. data/lib/administrate/page/collection.rb +37 -0
  155. data/lib/administrate/page/form.rb +28 -0
  156. data/lib/administrate/page/show.rb +24 -0
  157. data/lib/administrate/page.rb +4 -0
  158. data/lib/administrate/resource_resolver.rb +43 -0
  159. data/lib/administrate/search.rb +157 -0
  160. data/lib/administrate/version.rb +3 -0
  161. data/lib/administrate/view_generator.rb +36 -0
  162. data/lib/administrate.rb +4 -0
  163. data/lib/generators/administrate/assets/assets_generator.rb +12 -0
  164. data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
  165. data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
  166. data/lib/generators/administrate/dashboard/USAGE +9 -0
  167. data/lib/generators/administrate/dashboard/dashboard_generator.rb +143 -0
  168. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +46 -0
  169. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +68 -0
  170. data/lib/generators/administrate/field/field_generator.rb +31 -0
  171. data/lib/generators/administrate/field/templates/_form.html.erb +6 -0
  172. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  173. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  174. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  175. data/lib/generators/administrate/install/install_generator.rb +49 -0
  176. data/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
  177. data/lib/generators/administrate/routes/routes_generator.rb +96 -0
  178. data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  179. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  180. data/lib/generators/administrate/views/field_generator.rb +50 -0
  181. data/lib/generators/administrate/views/form_generator.rb +15 -0
  182. data/lib/generators/administrate/views/index_generator.rb +16 -0
  183. data/lib/generators/administrate/views/layout_generator.rb +24 -0
  184. data/lib/generators/administrate/views/navigation_generator.rb +15 -0
  185. data/lib/generators/administrate/views/new_generator.rb +16 -0
  186. data/lib/generators/administrate/views/show_generator.rb +15 -0
  187. data/lib/generators/administrate/views/views_generator.rb +14 -0
  188. data/lib/tasks/administrate_tasks.rake +4 -0
  189. metadata +398 -0
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: Adding Custom Field Types
3
+ ---
4
+
5
+ If your application deals with a nonstandard data type,
6
+ you can create an `Administrate::Field` object to help display
7
+ the custom data type across the dashboard.
8
+
9
+ `Administrate::Field` objects consist of two parts:
10
+ a Ruby class and associated views.
11
+
12
+ For example, let's create a `Field` that displays [Gravatars] based on an email.
13
+
14
+ [Gravatars]: https://gravatar.com/
15
+
16
+ First, we'll run a generator to set us up with the files we need:
17
+
18
+ ```bash
19
+ rails generate administrate:field gravatar
20
+ ```
21
+
22
+ This creates a few files:
23
+
24
+ - `app/fields/gravatar_field.rb`
25
+ - `app/views/fields/gravatar_field/_show.html.erb`
26
+ - `app/views/fields/gravatar_field/_index.html.erb`
27
+ - `app/views/fields/gravatar_field/_form.html.erb`
28
+
29
+ We can edit the `app/fields/gravatar_field.rb` to add some custom logic:
30
+
31
+ ```ruby
32
+ # app/fields/gravatar_field.rb
33
+ require 'digest/md5'
34
+
35
+ class GravatarField < Administrate::Field::Base
36
+ def gravatar_url
37
+ email_address = data.downcase
38
+ hash = Digest::MD5.hexdigest(email_address)
39
+ "http://www.gravatar.com/avatar/#{hash}"
40
+ end
41
+ end
42
+ ```
43
+
44
+ Next, we can customize the partials to display data how we'd like.
45
+ Open up the `app/views/fields/gravatar_field/_show.html.erb` partial.
46
+ By default, it looks like:
47
+
48
+ ```eruby
49
+ <%= field.to_s %>
50
+ ```
51
+
52
+ Since we want to display an image, we can change it to:
53
+
54
+ ```eruby
55
+ <%= image_tag field.gravatar_url %>
56
+ ```
57
+
58
+ You can customize the other generated partials in the same way
59
+ for custom behavior on the index and form pages.
60
+
61
+ ## Using your custom field
62
+
63
+ We need to tell Administrate which attributes we'd like to be displayed as a
64
+ gravatar image.
65
+
66
+ Open up a dashboard file, and add the gravatar field into the `ATTRIBUTE_TYPES`
67
+ hash. It should look something like:
68
+
69
+ ```ruby
70
+ class UserDashboard < Administrate::BaseDashboard
71
+ ATTRIBUTE_TYPES = {
72
+ created_at: Field::DateTime,
73
+ updated_at: Field::DateTime,
74
+ name: Field::String,
75
+ email: GravatarField, # Update this email to use your new field class
76
+ # ...
77
+ }
78
+ end
79
+ ```
80
+
81
+ [Customizing Attribute Partials]: /customizing_attribute_partials
@@ -0,0 +1,63 @@
1
+ ---
2
+ title: Authenticating admin users
3
+ ---
4
+
5
+ Authentication is left for you to implement after you install Administrate into
6
+ your app. It's expected that you can plugin your existing authentication
7
+ system.
8
+
9
+ The base `Admin::ApplicationController` has a `TODO` to be completed:
10
+
11
+ ```ruby
12
+ class Admin::ApplicationController < Administrate::ApplicationController
13
+ before_action :authenticate_admin
14
+
15
+ def authenticate_admin
16
+ # TODO Add authentication logic here.
17
+ end
18
+ end
19
+ ```
20
+
21
+ ## Using Clearance
22
+
23
+ [Clearance][clearance] provides Rails authentication with email & password.
24
+
25
+ ```ruby
26
+ class Admin::ApplicationController < Administrate::ApplicationController
27
+ include Clearance::Controller
28
+ before_action :require_login
29
+ end
30
+ ```
31
+
32
+ ## Using Devise
33
+
34
+ [Devise][devise] is an authentication solution for Rails with Warden. Include
35
+ the authentication method for your model as a `before_action`:
36
+
37
+ ```ruby
38
+ class Admin::ApplicationController < Administrate::ApplicationController
39
+ before_action :authenticate_user!
40
+ end
41
+ ```
42
+
43
+ ## Using HTTP Basic authentication
44
+
45
+ Rails includes the [`http_basic_authenticate_with`][rails-http-basic-auth]
46
+ method which can be added to your base admin controller:
47
+
48
+ ```ruby
49
+ class Admin::ApplicationController < Administrate::ApplicationController
50
+ http_basic_authenticate_with(
51
+ name: ENV.fetch("ADMIN_NAME"),
52
+ password: ENV.fetch("ADMIN_PASSWORD")
53
+ )
54
+ end
55
+ ```
56
+
57
+ With this approach consider using [dotenv][dotenv] to setup your environment and
58
+ avoid committing secrets in your repository.
59
+
60
+ [clearance]: https://github.com/thoughtbot/clearance
61
+ [devise]: https://github.com/plataformatec/devise
62
+ [rails-http-basic-auth]: http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html
63
+ [dotenv]: https://github.com/bkeepers/dotenv
@@ -0,0 +1,71 @@
1
+ ---
2
+ title: Authorization
3
+ ---
4
+
5
+ The default configuration of Administrate is "authenticate-only" - once a
6
+ user is authenticated, that user has access to every action of every object.
7
+
8
+ You can add more fine-grained authorization by overriding methods in the
9
+ controller.
10
+
11
+ ## Using Pundit
12
+
13
+ If your app already uses [Pundit](https://github.com/elabs/pundit) for
14
+ authorization, you just need to add one line to your
15
+ `Admin::ApplicationController`:
16
+
17
+ ```ruby
18
+ include Administrate::Punditize
19
+ ```
20
+
21
+ This will use all the policies from your main app to determine if the
22
+ current user is able to view a given record or perform a given action.
23
+
24
+ ### Further limiting scope
25
+
26
+ You may want to limit the scope for a given user beyond what they
27
+ technically have access to see in the main app. For example, a user may
28
+ have all public records in their scope, but you want to only show *their*
29
+ records in the admin interface to reduce confusion.
30
+
31
+ In this case, you can add an additional `resolve_admin` to your policy's
32
+ scope and Administrate will use this instead of the `resolve` method.
33
+
34
+ For example:
35
+
36
+ ```ruby
37
+ class PostPolicy < ApplicationPolicy
38
+ class Scope < Scope
39
+ def resolve
40
+ scope.all
41
+ end
42
+
43
+ def resolve_admin
44
+ scope.where(owner: user)
45
+ end
46
+ end
47
+ end
48
+ ```
49
+
50
+ ## Authorization without Pundit
51
+
52
+ If you use a different authorization library, or you want to roll your own,
53
+ you just need to override a few methods in your controllers or
54
+ `Admin::ApplicationController`. For example:
55
+
56
+ ```ruby
57
+ # Limit the scope of the given resource
58
+ def scoped_resource
59
+ super.where(user: current_user)
60
+ end
61
+
62
+ # Raise an exception if the user is not permitted to access this resource
63
+ def authorize_resource(resource)
64
+ raise "Erg!" unless show_action?(params[:action], resource)
65
+ end
66
+
67
+ # Hide links to actions if the user is not allowed to do them
68
+ def show_action?(action, resource)
69
+ current_user.can? action, resource
70
+ end
71
+ ```
@@ -0,0 +1 @@
1
+ ../CONTRIBUTING.md
@@ -0,0 +1,56 @@
1
+ ---
2
+ title: Customizing attribute partials
3
+ ---
4
+
5
+ Occasionally you might want to change how specific types of attributes appear
6
+ across all dashboards. You can customize the following built in field types:
7
+
8
+ - `belongs_to`
9
+ - `boolean`
10
+ - `date_time`
11
+ - `date`
12
+ - `email`
13
+ - `has_many`
14
+ - `has_one`
15
+ - `number`
16
+ - `polymorphic`
17
+ - `select`
18
+ - `string`
19
+ - `text`
20
+
21
+ For example, you might want all `Number` values to round to three decimal points.
22
+
23
+ To get started, run the appropriate rails generator:
24
+
25
+ ```bash
26
+ rails generate administrate:views:field number
27
+ ```
28
+
29
+ This will generate three files:
30
+
31
+ - `app/view/fields/number/_form.html.erb`
32
+ - `app/view/fields/number/_index.html.erb`
33
+ - `app/view/fields/number/_show.html.erb`
34
+
35
+ You can generate the partials for all field types by passing `all` to the generator.
36
+
37
+ ```bash
38
+ rails generate administrate:views:field all
39
+ ```
40
+
41
+ The generated templates will have documentation
42
+ describing which variables are in scope.
43
+ The rendering part of the partial will look like:
44
+
45
+ ```eruby
46
+ <%= field.data %>
47
+ ```
48
+
49
+ Changing numbers to display to three decimal places might look like this:
50
+
51
+ ```eruby
52
+ <%= field.data.round(3) %>
53
+ ```
54
+
55
+ If you only want to change how an attribute appears
56
+ on a single page (e.g. `index`), you may delete the unnecessary templates.
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: Customizing controller actions
3
+ ---
4
+
5
+ When you install Administrate into your app,
6
+ we generate empty controllers for each of your resources.
7
+ If you want to create more complex application behavior for a dashboard,
8
+ you can overwrite controller actions.
9
+
10
+ The generated controller will look something like:
11
+
12
+ ```ruby
13
+ # app/controllers/admin/foos_controller.rb
14
+
15
+ class Admin::FoosController < Admin::ApplicationController
16
+
17
+ # Overwrite any of the RESTful controller actions to implement custom behavior
18
+ # For example, you may want to send an email after a foo is updated.
19
+ #
20
+ # def update
21
+ # foo = Foo.find(params[:id])
22
+ # foo.update(params[:foo])
23
+ # send_foo_updated_email
24
+ # end
25
+
26
+ # Override this method to specify custom lookup behavior.
27
+ # This will be used to set the resource for the `show`, `edit`, and `update`
28
+ # actions.
29
+ #
30
+ # def find_resource(param)
31
+ # Foo.find_by!(slug: param)
32
+ # end
33
+
34
+ # Override this if you have certain roles that require a subset
35
+ # this will be used to set the records shown on the `index` action.
36
+ #
37
+ # def scoped_resource
38
+ # if current_user.super_admin?
39
+ # resource_class
40
+ # else
41
+ # resource_class.with_less_stuff
42
+ # end
43
+ # end
44
+ end
45
+ ```
46
+
47
+ ## Customizing Actions
48
+
49
+ To enable or disable certain actions you could override `valid_action?` method in your dashboard controller like this:
50
+
51
+ ```ruby
52
+ # disable 'edit' and 'destroy' links
53
+ def valid_action?(name, resource = resource_class)
54
+ %w[edit destroy].exclude?(name.to_s) && super
55
+ end
56
+ ```
57
+
58
+ Action is one of `new`, `edit`, `show`, `destroy`.
@@ -0,0 +1,303 @@
1
+ ---
2
+ title: Customizing Dashboards
3
+ ---
4
+
5
+ In order to customize which attributes get displayed for each resource,
6
+ edit the dashboard file generated by the installation generator.
7
+
8
+ By default, the file will look something like this:
9
+
10
+ ```ruby
11
+ require "administrate/dashboard/base"
12
+
13
+ class CustomerDashboard < Administrate::Dashboard::Base
14
+ ATTRIBUTE_TYPES = {
15
+ id: Field::Number,
16
+ name: Field::String,
17
+ email: Field::String,
18
+ created_at: Field::DateTime,
19
+ updated_at: Field::DateTime,
20
+ orders: Field::HasMany,
21
+ }
22
+
23
+ COLLECTION_ATTRIBUTES = [
24
+ :id,
25
+ :name,
26
+ :email,
27
+ :created_at,
28
+ :updated_at,
29
+ :orders,
30
+ ]
31
+
32
+ SHOW_PAGE_ATTRIBUTES = [
33
+ :id,
34
+ :name,
35
+ :email,
36
+ :created_at,
37
+ :updated_at,
38
+ :orders,
39
+ ]
40
+
41
+ FORM_ATTRIBUTES = [
42
+ :name,
43
+ :email,
44
+ :orders,
45
+ ]
46
+ end
47
+ ```
48
+
49
+ To change which attributes appear on each of the `index`, `show`, and `edit`
50
+ pages, add or remove attributes to each constant array.
51
+
52
+ Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
53
+ throughout the dashboard. There are a number of `Field` classes that you can
54
+ specify, including:
55
+
56
+ - `Field::BelongsTo`
57
+ - `Field::Boolean`
58
+ - `Field::DateTime`
59
+ - `Field::Date`
60
+ - `Field::Email`
61
+ - `Field::HasMany`
62
+ - `Field::HasOne`
63
+ - `Field::Number`
64
+ - `Field::Polymorphic`
65
+ - `Field::Select`
66
+ - `Field::String`
67
+ - `Field::Text`
68
+ - `Field::Password`
69
+
70
+ ## Customizing Fields
71
+
72
+ ### Setting Options
73
+
74
+ Each of the `Field` types take a different set of options,
75
+ which are specified through the `.with_options` class method:
76
+
77
+ **Field::BelongsTo**
78
+
79
+ `:order` - Specifies the order of the dropdown menu, can be ordered by more
80
+ than one column. e.g.: `"name, email DESC"`.
81
+
82
+ `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
83
+
84
+ `:foreign_key` - Specifies the name of the foreign key directly.
85
+ Defaults to `:#{attribute}_id`.
86
+
87
+ `:scope` - Specifies a custom scope inside a callable. Useful for preloading.
88
+ Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
89
+
90
+ `:class_name` - Specifies the name of the associated class.
91
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
92
+
93
+ `:searchable` - Specify if the attribute should be considered when searching.
94
+ Default is `false`.
95
+
96
+ `searchable_field` - Specify which column to use on the search, only applies
97
+ if `searchable` is `true`
98
+
99
+ For example:
100
+
101
+ ```ruby
102
+ country: Field::BelongsTo.with_options(
103
+ searchable: true,
104
+ searchable_field: 'name',
105
+ )
106
+ ```
107
+
108
+ with this, you will be able to search through the column `name` from the
109
+ association `belongs_to :country`, from your model.
110
+
111
+ **Field::HasMany**
112
+
113
+ `:limit` - Set the number of resources to display in the show view. Default is
114
+ `5`.
115
+
116
+ `:sort_by` - What to sort the association by in the show view.
117
+
118
+ `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
119
+
120
+ `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
121
+
122
+ `:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
123
+
124
+ `:class_name` - Specifies the name of the associated class.
125
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
126
+
127
+ **Field::HasOne**
128
+
129
+ `:class_name` - Specifies the name of the associated class.
130
+ Defaults to `:#{attribute}.to_s.singularize.camelcase`.
131
+
132
+ `:searchable` - Specify if the attribute should be considered when searching.
133
+ Default is `false`.
134
+
135
+ `searchable_field` - Specify which column to use on the search, only applies if
136
+ `searchable` is `true`
137
+
138
+ For example:
139
+
140
+ ```ruby
141
+ cities: Field::HasMany.with_options(
142
+ searchable: true,
143
+ searchable_field: 'name',
144
+ )
145
+ ```
146
+
147
+ with this, you will be able to search through the column `name` from the
148
+ association `has_many :cities`, from your model.
149
+
150
+ **Field::Number**
151
+
152
+ `:searchable` - Specify if the attribute should be considered when searching.
153
+ Note that currently number fields are searched like text, which may yield
154
+ more results than expected. Default is `false`.
155
+
156
+ `:decimals` - Set the number of decimals to display. Defaults to `0`.
157
+
158
+ `:prefix` - Prefixes the number with a string. Defaults to `""`.
159
+
160
+ `:suffix` - Suffixes the number with a string. Defaults to `""`.
161
+
162
+ For example, you might use the following to display U.S. currency:
163
+
164
+ ```ruby
165
+ unit_price: Field::Number.with_options(
166
+ prefix: "$",
167
+ decimals: 2,
168
+ )
169
+ ```
170
+
171
+ Or, to display a distance in kilometers:
172
+
173
+ ```ruby
174
+ unit_price: Field::Number.with_options(
175
+ suffix: " km",
176
+ decimals: 2,
177
+ )
178
+ ```
179
+
180
+ **Field::Polymorphic**
181
+
182
+ `:classes` - Specify a list of classes whose objects will be used to populate select boxes for editing this polymorphic field.
183
+ Default is `[]`.
184
+
185
+ `:order` - What to sort the association by in the form select.
186
+ Default is `nil`.
187
+
188
+ **Field::DateTime**
189
+
190
+ `:format` - Specify what format, using `strftime` you would like `DateTime`
191
+ objects to display as.
192
+
193
+ `:timezone` - Specify which timezone `Date` and `DateTime` objects are based
194
+ in.
195
+
196
+ **Field::Date**
197
+
198
+ `:format` - Specify what format, using `strftime` you would like `Date`
199
+ objects to display as.
200
+
201
+ **Field::Select**
202
+
203
+ `:collection` - Specify the options shown on the select field. It accept either
204
+ an array or an object responding to `:call`. Defaults to `[]`.
205
+
206
+ `:searchable` - Specify if the attribute should be considered when searching.
207
+ Default is `true`.
208
+
209
+ **Field::String**
210
+
211
+ `:searchable` - Specify if the attribute should be considered when searching.
212
+ Default is `true`.
213
+
214
+ `:truncate` - Set the number of characters to display in the index view.
215
+ Defaults to `50`.
216
+
217
+ **Field::Text**
218
+
219
+ `:searchable` - Specify if the attribute should be considered when searching.
220
+ Default is `false`.
221
+
222
+ `:truncate` - Set the number of characters to display in the index view.
223
+ Defaults to `50`.
224
+
225
+ **Field::Password**
226
+
227
+ `:searchable` - Specify if the attribute should be considered when searching.
228
+ Default is `false`.
229
+
230
+ `:truncate` - Set the number of characters to display in the views.
231
+ Defaults to `50`.
232
+
233
+ `:character` - Set the replace character.
234
+ Defaults to `•`.
235
+
236
+ ### Defining Labels
237
+
238
+ To change the user-facing label for an attribute,
239
+ define a custom I18n translation:
240
+
241
+ ```yaml
242
+ en:
243
+ helpers:
244
+ label:
245
+ customer:
246
+ name: Full Name
247
+ ```
248
+
249
+
250
+ To change the labels used for resources in dashboard collections.
251
+ Assume you have a users dashboard and you want to change "User #1" to "Testy
252
+ McTesterson", the user's name.
253
+
254
+ Add this method to the dashboard for Users.
255
+ Use whatever attribute or method you like.
256
+ Example for *user*:
257
+
258
+ ```ruby
259
+ def display_resource(user)
260
+ user.name
261
+ end
262
+ ```
263
+
264
+ [define your own]: /adding_custom_field_types
265
+
266
+ To change the dashboard name in sidebar menu, sub-header and search string use default ActiveRecord i18n translations for models:
267
+
268
+ ```yaml
269
+ en:
270
+ activerecord:
271
+ models:
272
+ customer:
273
+ one: Happy Customer
274
+ other: Happy Customers
275
+ ```
276
+
277
+ ## Collection Filters
278
+
279
+ Resources can be filtered with pre-set filters. For example if we added:
280
+
281
+ ```ruby
282
+ COLLECTION_FILTERS = {
283
+ inactive: ->(resources) { resources.where("login_at < ?", 1.week.ago) }
284
+ }
285
+ ```
286
+
287
+ …to a dashboard, we can query the resources of that dashboard with:
288
+
289
+ ```ruby
290
+ bob inactive:
291
+ ```
292
+
293
+ …to find users named "bob" who hasn't logged in the last week.
294
+
295
+ If you already had the `inactive` scope you could define the filter like so to
296
+ take advantage of existing ActiveRecord scopes (and other class methods on the
297
+ resource class).
298
+
299
+ ```ruby
300
+ COLLECTION_FILTERS = {
301
+ inactive: ->(resources) { resources.inactive }
302
+ }
303
+ ```