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
@@ -0,0 +1,78 @@
1
+ # Customizing page views
2
+
3
+ In order to change the appearance of any page,
4
+ you can write custom Rails views.
5
+
6
+ ## Customizing for all resources
7
+
8
+ The easiest way to get started is by using the built-in generators.
9
+ In order to change the appearance of views for all resource types,
10
+ call the generators with no arguments.
11
+
12
+ ```bash
13
+ rails generate administrate:views:index
14
+ # -> app/views/admin/application/index.html.erb
15
+ # -> app/views/admin/application/_table.html.erb
16
+
17
+ rails generate administrate:views:show
18
+ # -> app/views/admin/application/show.html.erb
19
+
20
+ rails generate administrate:views:edit
21
+ # -> app/views/admin/application/edit.html.erb
22
+ # -> app/views/admin/application/_form.html.erb
23
+
24
+ rails generate administrate:views:new
25
+ # -> app/views/admin/application/new.html.erb
26
+ # -> app/views/admin/application/_form.html.erb
27
+
28
+ rails generate administrate:views
29
+ # -> all of the above
30
+ ```
31
+
32
+ The generators copy over the default views that Administrate uses,
33
+ so you have a good starting point for customizations.
34
+ Feel free to change up the file type,
35
+ add extra sections to the page,
36
+ or blow it all away for your own custom look.
37
+
38
+ ## Customizing for a specific resource
39
+
40
+ In order to change a dashboard page for a single type of resource,
41
+ pass in the resource name to the view generators.
42
+
43
+ ```bash
44
+ rails generate administrate:views:index User
45
+ # -> app/views/admin/users/index.html.erb
46
+ # -> app/views/admin/users/_table.html.erb
47
+
48
+ rails generate administrate:views:show User
49
+ # -> app/views/admin/users/show.html.erb
50
+
51
+ rails generate administrate:views:edit User
52
+ # -> app/views/admin/users/edit.html.erb
53
+ # -> app/views/admin/users/_form.html.erb
54
+
55
+ rails generate administrate:views:new User
56
+ # -> app/views/admin/users/new.html.erb
57
+ # -> app/views/admin/users/_form.html.erb
58
+
59
+ rails generate administrate:views User
60
+ # -> all of the above
61
+ ```
62
+
63
+ Any changes to these template files
64
+ will *only* affect pages that display customers,
65
+ and will leave the show pages for other resources unchanged.
66
+
67
+ ## Customizing layouts
68
+
69
+ Many developers need to customize the layouts of their admin dashboard.
70
+ It's so easy that pass in the "layout" key word to the view generators.
71
+
72
+ ```bash
73
+ rails generate administrate:views:layout
74
+ # -> app/views/layouts/admin/application.html.erb
75
+ # -> app/views/admin/application/_sidebar.html.erb
76
+ # -> app/views/admin/application/_javascript.html.erb
77
+ # -> app/views/admin/application/_flashes.html.erb
78
+ ```
@@ -0,0 +1,60 @@
1
+ # Getting Started
2
+
3
+ Administrate is released as a Ruby gem, and can be installed on Rails
4
+ applications version 4.2 or greater.
5
+
6
+ Add the following to your Gemfile:
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem "administrate"
11
+ ```
12
+
13
+ Re-bundle, then run the installer:
14
+
15
+ ```bash
16
+ $ rails generate administrate:install
17
+ ```
18
+
19
+ The installer adds some new routes to your `config/routes.rb`,
20
+ and creates a controller at `app/controllers/admin/application_controller.rb`
21
+
22
+ In addition, the generator creates a `Dashboard` and a `Controller` for each of
23
+ your ActiveRecord resources:
24
+
25
+ - `app/controllers/admin/foos_controller.rb`
26
+ - `app/dashboards/foo_dashboard.rb`
27
+
28
+ The `Admin::ApplicationController` can be customized to add
29
+ authentication logic, authorization, pagination,
30
+ or other controller-level concerns.
31
+
32
+ The routes can be customized to show or hide
33
+ different models on the dashboard.
34
+
35
+ Each `FooDashboard` specifies which attributes should be displayed
36
+ on the admin dashboard for the `Foo` resource.
37
+
38
+ Each `Admin::FooController` can be overwritten to specify custom behavior.
39
+
40
+ Once you have Administrate installed,
41
+ visit <http://localhost:3000/admin> to see your new dashboard in action.
42
+
43
+ ## Create Additional Dashboards
44
+
45
+ In order to create additional dashboards, pass in the resource name to
46
+ the dashboard generator. A dashboard and controller will be created.
47
+
48
+ ```bash
49
+ $ rails generate administrate:dashboard Foo
50
+ ```
51
+
52
+ Add a route for the new dashboard.
53
+
54
+ ```ruby
55
+ # config/routes.rb
56
+
57
+ namespace :admin do
58
+ resources :foos
59
+ end
60
+ ```
@@ -36,8 +36,8 @@ module Administrate
36
36
  self.class.permitted_attribute(attribute)
37
37
  end
38
38
 
39
- def resources
40
- data.limit(limit)
39
+ def resources(page = 1)
40
+ data.page(page).per(limit)
41
41
  end
42
42
 
43
43
  def more_than_limit?
@@ -47,7 +47,12 @@ module Administrate
47
47
  private
48
48
 
49
49
  def candidate_resources
50
- associated_class.all
50
+ if options.key?(:includes)
51
+ includes = options.fetch(:includes)
52
+ associated_class.includes(*includes).all
53
+ else
54
+ associated_class.all
55
+ end
51
56
  end
52
57
 
53
58
  def display_candidate_resource(resource)
@@ -7,23 +7,31 @@ module Administrate
7
7
  if data.nil?
8
8
  "-"
9
9
  else
10
- format_string % data
10
+ format_string % value
11
11
  end
12
12
  end
13
13
 
14
14
  private
15
15
 
16
16
  def format_string
17
- prefix + "%.#{decimals}f"
17
+ prefix + "%.#{decimals}f" + suffix
18
18
  end
19
19
 
20
20
  def prefix
21
21
  options[:prefix].to_s
22
22
  end
23
23
 
24
+ def suffix
25
+ options[:suffix].to_s
26
+ end
27
+
24
28
  def decimals
25
29
  options.fetch(:decimals, 0)
26
30
  end
31
+
32
+ def value
33
+ data * options.fetch(:multiplier, 1)
34
+ end
27
35
  end
28
36
  end
29
37
  end
@@ -5,8 +5,14 @@ module Administrate
5
5
  end
6
6
 
7
7
  def resources
8
- namespace_controller_paths.uniq.map do |controller|
9
- controller.gsub(/^#{namespace}\//, "").to_sym
8
+ @resources ||= routes.map(&:first).uniq.map(&:to_sym)
9
+ end
10
+
11
+ def routes
12
+ @routes ||= all_routes.select do |controller, _action|
13
+ controller.starts_with?(namespace.to_s)
14
+ end.map do |controller, action|
15
+ [controller.gsub(/^#{namespace}\//, ""), action]
10
16
  end
11
17
  end
12
18
 
@@ -14,15 +20,9 @@ module Administrate
14
20
 
15
21
  attr_reader :namespace
16
22
 
17
- def namespace_controller_paths
18
- all_controller_paths.select do |controller|
19
- controller.starts_with?(namespace.to_s)
20
- end
21
- end
22
-
23
- def all_controller_paths
23
+ def all_routes
24
24
  Rails.application.routes.routes.map do |route|
25
- route.defaults[:controller].to_s
25
+ route.defaults.values_at(:controller, :action).map(&:to_s)
26
26
  end
27
27
  end
28
28
  end
@@ -35,7 +35,7 @@ module Administrate
35
35
  end
36
36
 
37
37
  def controller_path_parts
38
- controller_path.singularize.split("/")[1..-1]
38
+ controller_path.split("/")[1..-1].map(&:singularize)
39
39
  end
40
40
 
41
41
  attr_reader :controller_path
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  namespace :admin do
2
- <% dashboard_resources.each do |resource| %>resources :<%= resource %>
3
- <% end %>
2
+ <% dashboard_resources.each do |resource| %> resources :<%= resource %>
3
+ <%end%>
4
4
  root to: "<%= dashboard_resources.first %>#index"
5
5
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Nick Charlton
7
8
  - Grayson Wright
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
12
+ date: 2017-03-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: autoprefixer-rails
@@ -28,16 +29,16 @@ dependencies:
28
29
  name: bourbon
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: '4.2'
34
+ version: 5.0.0.beta.6
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - "~>"
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
- version: '4.2'
41
+ version: 5.0.0.beta.6
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: datetime_picker_rails
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -56,30 +57,30 @@ dependencies:
56
57
  name: jquery-rails
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - "~>"
60
+ - - ">="
60
61
  - !ruby/object:Gem::Version
61
62
  version: '4.0'
62
63
  type: :runtime
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - "~>"
67
+ - - ">="
67
68
  - !ruby/object:Gem::Version
68
69
  version: '4.0'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: kaminari
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - "~>"
74
+ - - ">="
74
75
  - !ruby/object:Gem::Version
75
- version: '0.16'
76
+ version: '1.0'
76
77
  type: :runtime
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - "~>"
81
+ - - ">="
81
82
  - !ruby/object:Gem::Version
82
- version: '0.16'
83
+ version: '1.0'
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: momentjs-rails
85
86
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +113,14 @@ dependencies:
112
113
  name: normalize-rails
113
114
  requirement: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - "~>"
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
118
  version: '3.0'
118
119
  type: :runtime
119
120
  prerelease: false
120
121
  version_requirements: !ruby/object:Gem::Requirement
121
122
  requirements:
122
- - - "~>"
123
+ - - ">="
123
124
  - !ruby/object:Gem::Version
124
125
  version: '3.0'
125
126
  - !ruby/object:Gem::Dependency
@@ -184,6 +185,7 @@ description: |
184
185
  - Break up the library into core components and plugins,
185
186
  so each component stays small and easy to maintain.
186
187
  email:
188
+ - nick@nickcharlton.net
187
189
  - grayson@thoughtbot.com
188
190
  executables: []
189
191
  extensions: []
@@ -279,9 +281,11 @@ files:
279
281
  - config/locales/administrate.fr.yml
280
282
  - config/locales/administrate.it.yml
281
283
  - config/locales/administrate.ja.yml
284
+ - config/locales/administrate.ko.yml
282
285
  - config/locales/administrate.nl.yml
283
286
  - config/locales/administrate.pl.yml
284
287
  - config/locales/administrate.pt-BR.yml
288
+ - config/locales/administrate.pt.yml
285
289
  - config/locales/administrate.ru.yml
286
290
  - config/locales/administrate.sv.yml
287
291
  - config/locales/administrate.uk.yml
@@ -291,6 +295,13 @@ files:
291
295
  - config/routes.rb
292
296
  - config/secrets.yml
293
297
  - config/unicorn.rb
298
+ - docs/adding_custom_field_types.md
299
+ - docs/authentication.md
300
+ - docs/customizing_attribute_partials.md
301
+ - docs/customizing_controller_actions.md
302
+ - docs/customizing_dashboards.md
303
+ - docs/customizing_page_views.md
304
+ - docs/getting_started.md
294
305
  - lib/administrate.rb
295
306
  - lib/administrate/base_dashboard.rb
296
307
  - lib/administrate/engine.rb