administrate 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of administrate might be problematic. Click here for more details.

Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/table.js +8 -3
  3. data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
  4. data/app/assets/stylesheets/administrate/components/_flashes.scss +19 -7
  5. data/app/controllers/administrate/application_controller.rb +12 -5
  6. data/app/helpers/administrate/application_helper.rb +10 -6
  7. data/app/views/administrate/application/_collection.html.erb +20 -15
  8. data/app/views/administrate/application/_flashes.html.erb +1 -1
  9. data/app/views/administrate/application/_form.html.erb +1 -1
  10. data/app/views/administrate/application/edit.html.erb +3 -3
  11. data/app/views/administrate/application/index.html.erb +2 -2
  12. data/app/views/administrate/application/new.html.erb +2 -2
  13. data/app/views/administrate/application/show.html.erb +3 -3
  14. data/app/views/fields/belongs_to/_index.html.erb +8 -4
  15. data/app/views/fields/belongs_to/_show.html.erb +8 -4
  16. data/app/views/fields/has_many/_show.html.erb +2 -8
  17. data/config/locales/administrate.ar.yml +2 -0
  18. data/config/locales/administrate.da.yml +2 -0
  19. data/config/locales/administrate.de.yml +2 -0
  20. data/config/locales/administrate.en.yml +2 -0
  21. data/config/locales/administrate.es.yml +2 -0
  22. data/config/locales/administrate.fr.yml +2 -0
  23. data/config/locales/administrate.it.yml +2 -0
  24. data/config/locales/administrate.ja.yml +2 -0
  25. data/config/locales/administrate.ko.yml +25 -0
  26. data/config/locales/administrate.nl.yml +2 -0
  27. data/config/locales/administrate.pl.yml +2 -0
  28. data/config/locales/administrate.pt-BR.yml +2 -0
  29. data/config/locales/administrate.pt.yml +26 -0
  30. data/config/locales/administrate.ru.yml +2 -0
  31. data/config/locales/administrate.sv.yml +2 -0
  32. data/config/locales/administrate.uk.yml +2 -0
  33. data/config/locales/administrate.vi.yml +2 -0
  34. data/config/locales/administrate.zh-CN.yml +2 -0
  35. data/config/locales/administrate.zh-TW.yml +2 -0
  36. data/docs/adding_custom_field_types.md +79 -0
  37. data/docs/authentication.md +60 -0
  38. data/docs/customizing_attribute_partials.md +34 -0
  39. data/docs/customizing_controller_actions.md +32 -0
  40. data/docs/customizing_dashboards.md +143 -0
  41. data/docs/customizing_page_views.md +78 -0
  42. data/docs/getting_started.md +60 -0
  43. data/lib/administrate/field/has_many.rb +8 -3
  44. data/lib/administrate/field/number.rb +10 -2
  45. data/lib/administrate/namespace.rb +10 -10
  46. data/lib/administrate/resource_resolver.rb +1 -1
  47. data/lib/administrate/version.rb +1 -1
  48. data/lib/generators/administrate/routes/templates/routes.rb.erb +2 -2
  49. metadata +25 -14
@@ -6,6 +6,8 @@ nl:
6
6
  destroy: Verwijder
7
7
  edit: Bewerk
8
8
  show: Toon
9
+ new: Nieuw
10
+ back: Terug
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} was succesvol aangemaakt."
@@ -6,6 +6,8 @@ pl:
6
6
  destroy: Usuń
7
7
  edit: Edytuj
8
8
  show: Wyświetl
9
+ new: Nowy
10
+ back: Plecy
9
11
  controller:
10
12
  create:
11
13
  success: "Zasób %{resource} został pomyślnie utworzony."
@@ -7,6 +7,8 @@ pt-BR:
7
7
  destroy: Deletar
8
8
  edit: Editar
9
9
  show: Visualizar
10
+ new: Criar
11
+ back: Voltar
10
12
  controller:
11
13
  create:
12
14
  success: "%{resource} foi criado com sucesso."
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ ---
3
+ pt:
4
+ administrate:
5
+ actions:
6
+ confirm: Tem certeza?
7
+ destroy: Remover
8
+ edit: Editar
9
+ show: Visualizar
10
+ new: Novo
11
+ back: Voltar atrás
12
+ controller:
13
+ create:
14
+ success: "%{resource} foi criado com sucesso."
15
+ destroy:
16
+ success: "%{resource} foi removido com sucesso."
17
+ update:
18
+ success: "%{resource} foi actualizado com sucesso."
19
+ fields:
20
+ has_many:
21
+ more: "Mostrando %{count} de %{total_count}"
22
+ none: Nenhum
23
+ polymorphic:
24
+ not_supported: Relações polimórficas nos formulários não são suportadas.
25
+ has_one:
26
+ not_supported: Relações um para muitos nos formulários não são suportadas.
@@ -6,6 +6,8 @@ ru:
6
6
  destroy: Удалить
7
7
  edit: Редактировать
8
8
  show: Показать
9
+ new: Новый
10
+ back: Вернуться назад
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} был успешно создан."
@@ -6,6 +6,8 @@ sv:
6
6
  destroy: Ta bort
7
7
  edit: Ändra
8
8
  show: Visa
9
+ new: Ny
10
+ back: Tillbaka
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} har skapats."
@@ -6,6 +6,8 @@ uk:
6
6
  destroy: Видалити
7
7
  edit: Редагувати
8
8
  show: Показати
9
+ new: новий
10
+ back: назад
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} було успішно створено."
@@ -6,6 +6,8 @@ vi:
6
6
  destroy: Xóa
7
7
  edit: Sửa
8
8
  show: Xem
9
+ new: Mới
10
+ back: Trở lại
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} đã được tạo thành công."
@@ -6,6 +6,8 @@ zh-CN:
6
6
  destroy: 删除
7
7
  edit: 编辑
8
8
  show: 查看
9
+ new: 新建
10
+ back: 返回
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} 创建成功."
@@ -6,6 +6,8 @@ zh-TW:
6
6
  destroy: 刪除
7
7
  edit: 編輯
8
8
  show: 檢視
9
+ new: 删除
10
+ back: 背部
9
11
  controller:
10
12
  create:
11
13
  success: "已成功新增 %{resource}。"
@@ -0,0 +1,79 @@
1
+ # Adding Custom Field Types
2
+
3
+ If your application deals with a nonstandard data type,
4
+ you can create an `Administrate::Field` object to help display
5
+ the custom data type across the dashboard.
6
+
7
+ `Administrate::Field` objects consist of two parts:
8
+ a Ruby class and associated views.
9
+
10
+ For example, let's create a `Field` that displays [Gravatars] based on an email.
11
+
12
+ [Gravatars]: https://gravatar.com/
13
+
14
+ First, we'll run a generator to set us up with the files we need:
15
+
16
+ ```bash
17
+ rails generate administrate:field gravatar
18
+ ```
19
+
20
+ This creates a few files:
21
+
22
+ - `app/fields/gravatar_field.rb`
23
+ - `app/views/fields/gravatar_field/_show.html.erb`
24
+ - `app/views/fields/gravatar_field/_index.html.erb`
25
+ - `app/views/fields/gravatar_field/_form.html.erb`
26
+
27
+ We can edit the `app/fields/gravatar_field.rb` to add some custom logic:
28
+
29
+ ```ruby
30
+ # app/fields/gravatar_field.rb
31
+ require 'digest/md5'
32
+
33
+ class GravatarField < Administrate::Field::Base
34
+ def gravatar_url
35
+ email_address = data.downcase
36
+ hash = Digest::MD5.hexdigest(email_address)
37
+ "http://www.gravatar.com/avatar/#{hash}"
38
+ end
39
+ end
40
+ ```
41
+
42
+ Next, we can customize the partials to display data how we'd like.
43
+ Open up the `app/views/fields/gravatar_field/_show.html.erb` partial.
44
+ By default, it looks like:
45
+
46
+ ```eruby
47
+ <%= field.to_s %>
48
+ ```
49
+
50
+ Since we want to display an image, we can change it to:
51
+
52
+ ```eruby
53
+ <%= image_tag field.gravatar_url %>
54
+ ```
55
+
56
+ You can customize the other generated partials in the same way
57
+ for custom behavior on the index and form pages.
58
+
59
+ ## Using your custom field
60
+
61
+ We need to tell Administrate which attributes we'd like to be displayed as a
62
+ gravatar image.
63
+
64
+ Open up a dashboard file, and add the gravatar field into the `ATTRIBUTE_TYPES`
65
+ hash. It should look something like:
66
+
67
+ ```ruby
68
+ class UserDashboard < Administrate::BaseDashboard
69
+ ATTRIBUTE_TYPES = {
70
+ created_at: Field::DateTime,
71
+ updated_at: Field::DateTime,
72
+ name: Field::String,
73
+ email: GravatarField, # Update this email to use your new field class
74
+ # ...
75
+ }
76
+ end
77
+ ```
78
+
79
+ [Customizing Attribute Partials]: /customizing_attribute_partials
@@ -0,0 +1,60 @@
1
+ # Authenticating admin users
2
+
3
+ Authentication is left for you to implement after you install Administrate into
4
+ your app. You can easily plugin your existing authentication system.
5
+
6
+ The base `Admin::ApplicationController` has a `TODO` to be completed:
7
+
8
+ ```ruby
9
+ class Admin::ApplicationController < Administrate::ApplicationController
10
+ before_action :authenticate_admin
11
+
12
+ def authenticate_admin
13
+ # TODO Add authentication logic here.
14
+ end
15
+ end
16
+ ```
17
+
18
+ ## Using Clearance
19
+
20
+ [Clearance][clearance] provides Rails authentication with email & password.
21
+
22
+ ```ruby
23
+ class Admin::ApplicationController < Administrate::ApplicationController
24
+ include Clearance::Controller
25
+ before_action :require_login
26
+ end
27
+ ```
28
+
29
+ ## Using Devise
30
+
31
+ [Devise][devise] is an authentication solution for Rails with Warden. Include
32
+ the authentication method for your model as a `before_action`:
33
+
34
+ ```ruby
35
+ class Admin::ApplicationController < Administrate::ApplicationController
36
+ before_action :authenticate_user!
37
+ end
38
+ ```
39
+
40
+ ## Using HTTP Basic authentication
41
+
42
+ Rails includes the [`http_basic_authenticate_with`][rails-http-basic-auth]
43
+ method which can be added to your base admin controller:
44
+
45
+ ```ruby
46
+ class Admin::ApplicationController < Administrate::ApplicationController
47
+ http_basic_authenticate_with(
48
+ name: ENV.fetch("ADMIN_NAME"),
49
+ password: ENV.fetch("ADMIN_PASSWORD")
50
+ )
51
+ end
52
+ ```
53
+
54
+ With this approach consider using [dotenv][dotenv] to setup your environment and
55
+ avoid committing secrets in your repository.
56
+
57
+ [clearance]: https://github.com/thoughtbot/clearance
58
+ [devise]: https://github.com/plataformatec/devise
59
+ [rails-http-basic-auth]: http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html
60
+ [dotenv]: https://github.com/bkeepers/dotenv
@@ -0,0 +1,34 @@
1
+ # Customizing attribute partials
2
+
3
+ Occasionally you might want to change how specific types of attributes appear
4
+ across all dashboards.
5
+ For example, you might want all `Number` values to round to three decimal points.
6
+
7
+ To get started, run the appropriate rails generator:
8
+
9
+ ```bash
10
+ rails generate administrate:views:field number
11
+ ```
12
+
13
+ This will generate three files:
14
+
15
+ - `app/view/fields/number/_form.html.erb`
16
+ - `app/view/fields/number/_index.html.erb`
17
+ - `app/view/fields/number/_show.html.erb`
18
+
19
+ The generated templates will have documentation
20
+ describing which variables are in scope.
21
+ The rendering part of the partial will look like:
22
+
23
+ ```eruby
24
+ <%= field.data %>
25
+ ```
26
+
27
+ Changing numbers to display to three decimal places might look like this:
28
+
29
+ ```eruby
30
+ <%= field.data.round(3) %>
31
+ ```
32
+
33
+ If you only want to change how an attribute appears
34
+ on a single page (e.g. `index`), you may delete the unnecessary templates.
@@ -0,0 +1,32 @@
1
+ # Customizing controller actions
2
+
3
+ When you install Administrate into your app,
4
+ we generate empty controllers for each of your resources.
5
+ If you want to create more complex application behavior for a dashboard,
6
+ simply overwrite controller actions.
7
+
8
+ The generated controller will look something like:
9
+
10
+ ```ruby
11
+ # app/controllers/admin/foos_controller.rb
12
+
13
+ class Admin::FoosController < Admin::ApplicationController
14
+
15
+ # Overwrite any of the RESTful controller actions to implement custom behavior
16
+ # For example, you may want to send an email after a foo is updated.
17
+ #
18
+ # def update
19
+ # foo = Foo.find(params[:id])
20
+ # foo.update(params[:foo])
21
+ # send_foo_updated_email
22
+ # end
23
+
24
+ # Override this method to specify custom lookup behavior.
25
+ # This will be used to set the resource for the `show`, `edit`, and `update`
26
+ # actions.
27
+ #
28
+ # def find_resource(param)
29
+ # Foo.find_by!(slug: param)
30
+ # end
31
+ end
32
+ ```
@@ -0,0 +1,143 @@
1
+ # Customizing Dashboards
2
+
3
+ In order to customize which attributes get displayed for each resource,
4
+ edit the dashboard file generated by the installation generator.
5
+
6
+ By default, the file will look something like this:
7
+
8
+ ```ruby
9
+ require "administrate/dashboard/base"
10
+
11
+ class CustomerDashboard < Administrate::Dashboard::Base
12
+ ATTRIBUTE_TYPES = {
13
+ id: Field::Integer,
14
+ name: Field::String,
15
+ email: Field::String,
16
+ created_at: Field::DateTime,
17
+ updated_at: Field::DateTime,
18
+ orders: Field::HasMany,
19
+ }
20
+
21
+ COLLECTION_ATTRIBUTES = [
22
+ :id,
23
+ :name,
24
+ :email,
25
+ :created_at,
26
+ :updated_at,
27
+ :orders,
28
+ ]
29
+
30
+ SHOW_PAGE_ATTRIBUTES = [
31
+ :id,
32
+ :name,
33
+ :email,
34
+ :created_at,
35
+ :updated_at,
36
+ :orders,
37
+ ]
38
+
39
+ FORM_ATTRIBUTES = [
40
+ :name,
41
+ :email,
42
+ :orders,
43
+ ]
44
+ end
45
+ ```
46
+
47
+ To change which attributes appear on each of the `index`, `show`, and `edit`
48
+ pages, add or remove attributes to each constant array.
49
+
50
+ Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
51
+ throughout the dashboard. There are a number of `Field` classes that you can
52
+ specify, including:
53
+
54
+ - `Field::BelongsTo`
55
+ - `Field::Boolean`
56
+ - `Field::DateTime`
57
+ - `Field::Email`
58
+ - `Field::HasMany`
59
+ - `Field::HasOne`
60
+ - `Field::Number`
61
+ - `Field::Polymorphic`
62
+ - `Field::Select`
63
+ - `Field::String`
64
+
65
+ ## Customizing Fields
66
+
67
+ ### Setting Options
68
+
69
+ Each of the `Field` types take a different set of options,
70
+ which are specified through the `.with_options` class method:
71
+
72
+ **Field::HasMany**
73
+
74
+ `:limit` - Set the number of resources to display in the show view. Default is
75
+ `5`.
76
+
77
+ **Field::Number**
78
+
79
+ `:decimals` - Set the number of decimals to display. Defaults to `0`.
80
+
81
+ `:prefix` - Prefixes the number with a string. Defaults to `""`.
82
+
83
+ For example, you might use the following to display U.S. currency:
84
+
85
+ ```ruby
86
+ unit_price: Field::Number.with_options(
87
+ prefix: "$",
88
+ decimals: 2,
89
+ )
90
+ ```
91
+
92
+ **Field::Select**
93
+
94
+ `:collection` - Specify the array or range to select from. Defaults to `[]`.
95
+
96
+ `:searchable` - Specify if the attribute should be considered when searching.
97
+ Default is `true`.
98
+
99
+ **Field::String**
100
+
101
+ `:searchable` - Specify if the attribute should be considered when searching.
102
+ Default is `true`.
103
+
104
+ `:truncate` - Set the number of characters to display in the index view.
105
+ Defaults to `50`.
106
+
107
+ **Field::Text**
108
+
109
+ `:searchable` - Specify if the attribute should be considered when searching.
110
+ Default is `false`.
111
+
112
+ `:truncate` - Set the number of characters to display in the index view.
113
+ Defaults to `50`.
114
+
115
+ ### Defining Labels
116
+
117
+ To change the user-facing label for an attribute,
118
+ define a custom I18n translation:
119
+
120
+ ```yaml
121
+ en:
122
+ helpers:
123
+ label:
124
+ customer:
125
+ name: Full Name
126
+ ```
127
+
128
+
129
+ To change the labels used for resources in dashboard collections.
130
+ Assume you have a users dashboard and you want to change "User #1" to "Testy
131
+ McTesterson", the user's name.
132
+
133
+ Add this method to the dashboard for Users.
134
+ Use whatever attribute or method you like.
135
+ Example for *user*:
136
+
137
+ ````ruby
138
+ def display_resource(user)
139
+ user.name
140
+ end
141
+ ````
142
+
143
+ [define your own]: /adding_custom_field_types