administrate 0.8.1 → 0.12.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 (100) hide show
  1. checksums.yaml +5 -5
  2. data/app/assets/javascripts/administrate/components/date_time_picker.js +5 -1
  3. data/app/assets/stylesheets/administrate/base/_typography.scss +1 -1
  4. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -6
  5. data/app/assets/stylesheets/docs.scss +1 -0
  6. data/app/controllers/administrate/application_controller.rb +53 -13
  7. data/app/controllers/concerns/administrate/punditize.rb +36 -0
  8. data/app/helpers/administrate/application_helper.rb +26 -7
  9. data/app/views/administrate/application/_collection.html.erb +11 -10
  10. data/app/views/administrate/application/_flashes.html.erb +1 -1
  11. data/app/views/administrate/application/_form.html.erb +5 -2
  12. data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +0 -0
  13. data/app/views/administrate/application/_navigation.html.erb +1 -1
  14. data/app/views/administrate/application/edit.html.erb +3 -3
  15. data/app/views/administrate/application/index.html.erb +7 -2
  16. data/app/views/administrate/application/new.html.erb +6 -1
  17. data/app/views/administrate/application/show.html.erb +4 -4
  18. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  19. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  20. data/app/views/fields/date_time/_form.html.erb +1 -1
  21. data/app/views/fields/date_time/_index.html.erb +1 -1
  22. data/app/views/fields/has_many/_form.html.erb +2 -2
  23. data/app/views/fields/has_many/_index.html.erb +1 -1
  24. data/app/views/fields/has_many/_show.html.erb +8 -5
  25. data/app/views/fields/has_one/_form.html.erb +1 -1
  26. data/app/views/fields/password/_form.html.erb +23 -0
  27. data/app/views/fields/password/_index.html.erb +18 -0
  28. data/app/views/fields/password/_show.html.erb +18 -0
  29. data/app/views/fields/polymorphic/_form.html.erb +11 -9
  30. data/app/views/fields/polymorphic/_show.html.erb +8 -4
  31. data/app/views/fields/select/_form.html.erb +1 -1
  32. data/app/views/fields/time/_form.html.erb +22 -0
  33. data/app/views/fields/time/_index.html.erb +17 -0
  34. data/app/views/fields/time/_show.html.erb +17 -0
  35. data/app/views/fields/url/_form.html.erb +23 -0
  36. data/app/views/fields/url/_index.html.erb +20 -0
  37. data/app/views/fields/url/_show.html.erb +20 -0
  38. data/app/views/layouts/administrate/application.html.erb +1 -1
  39. data/config/locales/administrate.al.yml +28 -0
  40. data/config/locales/administrate.ar.yml +6 -6
  41. data/config/locales/administrate.bs.yml +27 -0
  42. data/config/locales/administrate.ca.yml +28 -0
  43. data/config/locales/administrate.da.yml +6 -6
  44. data/config/locales/administrate.de.yml +8 -8
  45. data/config/locales/administrate.en.yml +6 -6
  46. data/config/locales/administrate.es.yml +6 -6
  47. data/config/locales/administrate.fr.yml +6 -6
  48. data/config/locales/administrate.id.yml +28 -0
  49. data/config/locales/administrate.it.yml +6 -6
  50. data/config/locales/administrate.ja.yml +6 -6
  51. data/config/locales/administrate.ko.yml +11 -11
  52. data/config/locales/administrate.nl.yml +6 -6
  53. data/config/locales/administrate.pl.yml +6 -6
  54. data/config/locales/administrate.pt-BR.yml +6 -6
  55. data/config/locales/administrate.pt.yml +6 -6
  56. data/config/locales/administrate.ru.yml +6 -6
  57. data/config/locales/administrate.sv.yml +6 -6
  58. data/config/locales/administrate.uk.yml +6 -6
  59. data/config/locales/administrate.vi.yml +6 -6
  60. data/config/locales/administrate.zh-CN.yml +6 -6
  61. data/config/locales/administrate.zh-TW.yml +8 -8
  62. data/docs/authorization.md +69 -0
  63. data/docs/customizing_attribute_partials.md +20 -1
  64. data/docs/customizing_controller_actions.md +2 -1
  65. data/docs/customizing_dashboards.md +152 -4
  66. data/docs/customizing_page_views.md +5 -1
  67. data/docs/getting_started.md +60 -10
  68. data/docs/rails_api.md +43 -0
  69. data/lib/administrate/base_dashboard.rb +27 -8
  70. data/lib/administrate/engine.rb +1 -1
  71. data/lib/administrate/field/associative.rb +8 -4
  72. data/lib/administrate/field/base.rb +1 -1
  73. data/lib/administrate/field/belongs_to.rb +6 -3
  74. data/lib/administrate/field/date_time.rb +13 -2
  75. data/lib/administrate/field/deferred.rb +10 -5
  76. data/lib/administrate/field/has_many.rb +18 -11
  77. data/lib/administrate/field/has_one.rb +16 -8
  78. data/lib/administrate/field/password.rb +25 -0
  79. data/lib/administrate/field/polymorphic.rb +41 -3
  80. data/lib/administrate/field/time.rb +8 -0
  81. data/lib/administrate/field/url.rb +21 -0
  82. data/lib/administrate/namespace.rb +1 -1
  83. data/lib/administrate/order.rb +40 -5
  84. data/lib/administrate/page/base.rb +8 -0
  85. data/lib/administrate/page/collection.rb +5 -1
  86. data/lib/administrate/resource_resolver.rb +2 -2
  87. data/lib/administrate/search.rb +121 -10
  88. data/lib/administrate/version.rb +1 -1
  89. data/lib/generators/administrate/dashboard/USAGE +1 -1
  90. data/lib/generators/administrate/dashboard/dashboard_generator.rb +11 -3
  91. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +24 -11
  92. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
  93. data/lib/generators/administrate/install/install_generator.rb +13 -6
  94. data/lib/generators/administrate/install/templates/{application_controller.rb → application_controller.rb.erb} +1 -1
  95. data/lib/generators/administrate/routes/routes_generator.rb +11 -1
  96. data/lib/generators/administrate/routes/templates/routes.rb.erb +1 -1
  97. data/lib/generators/administrate/views/field_generator.rb +19 -5
  98. data/lib/generators/administrate/views/layout_generator.rb +1 -0
  99. metadata +41 -28
  100. data/config/secrets.yml +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bbf40650e2f1b5fef6121aed98256dfc8225bb12
4
- data.tar.gz: ec4394132d9e3b0f5117b95e26dcbc8d3fca3bea
2
+ SHA256:
3
+ metadata.gz: 901108f5715bed268b4395d6edadf3738b127425910dc365390847710f19c98f
4
+ data.tar.gz: 6b61113c5c116250f2e46eaa5dbf77972473b16a6aae8042a6bcaef74f45308e
5
5
  SHA512:
6
- metadata.gz: 9e9014f2e04d659e1ca3d8e7fdb3b54f55097bfb8911279baf03f5114db200d4de3cc4a1b0fe745d70e033aa790e43e50a1f5b7f708897623cfeff75b156204b
7
- data.tar.gz: 23896d95877e97096300d8412b9a5ff9332aceb3f9aabee06cd297f6641a01bfe6a0e86b2b6c48cd55f047decb0d77935e21874bba5459a118cde5051a28adee
6
+ metadata.gz: ac4790d3bca102b4a27cc73f154e7167620f4589088b1207008f0915521735cfed483fbf085d24e7844e7b092f9f1a7d198ec6113cbc4be877758886c192f097
7
+ data.tar.gz: da2c64204adee3b43a566c67cf2aa42f37a0a38ea5f35b9988f704491f2b15dcd76210fb2f56f57de1576e77da71f429fe6572493e65933877b29f9eb9e5920f
@@ -1,5 +1,9 @@
1
1
  $(function () {
2
- $(".datetimepicker").datetimepicker({
2
+ $('[data-type="time"]').datetimepicker({
3
+ debug: false,
4
+ format: "HH:mm:ss",
5
+ });
6
+ $('[data-type="datetime"]').datetimepicker({
3
7
  debug: false,
4
8
  format: "YYYY-MM-DD HH:mm:ss",
5
9
  });
@@ -23,7 +23,7 @@ p {
23
23
 
24
24
  a {
25
25
  color: $action-color;
26
- text-decoration-skip: ink;
26
+ text-decoration-skip-ink: auto;
27
27
  transition: color $base-duration $base-timing;
28
28
 
29
29
  &:hover {
@@ -1,6 +1,4 @@
1
1
  .cell-label {
2
- position: relative;
3
-
4
2
  &:hover {
5
3
  a {
6
4
  color: $action-color;
@@ -26,10 +24,8 @@
26
24
  }
27
25
 
28
26
  .cell-label__sort-indicator {
29
- display: inline-block;
30
- overflow: hidden;
31
- position: absolute;
32
- right: 0;
27
+ float: right;
28
+ margin-left: 5px;
33
29
 
34
30
  svg {
35
31
  fill: $hint-grey;
@@ -80,6 +80,7 @@ code {
80
80
  padding-left: 1rem;
81
81
 
82
82
  .hljs-string { color: $code-green; }
83
+ .hljs-subst { color: $code-white; }
83
84
  .hljs-constant { color: $code-blue; }
84
85
  .hljs-symbol { color: $code-red; }
85
86
  .hljs-keyword { color: $code-yellow; }
@@ -7,7 +7,7 @@ module Administrate
7
7
  resources = Administrate::Search.new(scoped_resource,
8
8
  dashboard_class,
9
9
  search_term).run
10
- resources = resources.includes(*resource_includes) if resource_includes.any?
10
+ resources = apply_collection_includes(resources)
11
11
  resources = order.apply(resources)
12
12
  resources = resources.page(params[:page]).per(records_per_page)
13
13
  page = Administrate::Page::Collection.new(dashboard, order: order)
@@ -16,7 +16,7 @@ module Administrate
16
16
  resources: resources,
17
17
  search_term: search_term,
18
18
  page: page,
19
- show_search_bar: show_search_bar?
19
+ show_search_bar: show_search_bar?,
20
20
  }
21
21
  end
22
22
 
@@ -27,8 +27,10 @@ module Administrate
27
27
  end
28
28
 
29
29
  def new
30
+ resource = resource_class.new
31
+ authorize_resource(resource)
30
32
  render locals: {
31
- page: Administrate::Page::Form.new(dashboard, resource_class.new),
33
+ page: Administrate::Page::Form.new(dashboard, resource),
32
34
  }
33
35
  end
34
36
 
@@ -40,6 +42,7 @@ module Administrate
40
42
 
41
43
  def create
42
44
  resource = resource_class.new(resource_params)
45
+ authorize_resource(resource)
43
46
 
44
47
  if resource.save
45
48
  redirect_to(
@@ -67,8 +70,11 @@ module Administrate
67
70
  end
68
71
 
69
72
  def destroy
70
- requested_resource.destroy
71
- flash[:notice] = translate_with_resource("destroy.success")
73
+ if requested_resource.destroy
74
+ flash[:notice] = translate_with_resource("destroy.success")
75
+ else
76
+ flash[:error] = requested_resource.errors.full_messages.join("<br/>")
77
+ end
72
78
  redirect_to action: :index
73
79
  end
74
80
 
@@ -95,15 +101,20 @@ module Administrate
95
101
  end
96
102
 
97
103
  def order
98
- @_order ||= Administrate::Order.new(params[:order], params[:direction])
104
+ @order ||= Administrate::Order.new(
105
+ params.fetch(resource_name, {}).fetch(:order, nil),
106
+ params.fetch(resource_name, {}).fetch(:direction, nil),
107
+ )
99
108
  end
100
109
 
101
110
  def dashboard
102
- @_dashboard ||= dashboard_class.new
111
+ @dashboard ||= dashboard_class.new
103
112
  end
104
113
 
105
114
  def requested_resource
106
- @_requested_resource ||= find_resource(params[:id])
115
+ @requested_resource ||= find_resource(params[:id]).tap do |resource|
116
+ authorize_resource(resource)
117
+ end
107
118
  end
108
119
 
109
120
  def find_resource(param)
@@ -114,13 +125,28 @@ module Administrate
114
125
  resource_class.default_scoped
115
126
  end
116
127
 
117
- def resource_includes
118
- dashboard.association_includes
128
+ def apply_collection_includes(relation)
129
+ resource_includes = dashboard.collection_includes
130
+ return relation if resource_includes.empty?
131
+ relation.includes(*resource_includes)
119
132
  end
120
133
 
121
134
  def resource_params
122
135
  params.require(resource_class.model_name.param_key).
123
- permit(dashboard.permitted_attributes)
136
+ permit(dashboard.permitted_attributes).
137
+ transform_values { |v| read_param_value(v) }
138
+ end
139
+
140
+ def read_param_value(data)
141
+ if data.is_a?(ActionController::Parameters) && data[:type]
142
+ if data[:type] == Administrate::Field::Polymorphic.to_s
143
+ GlobalID::Locator.locate(data[:value])
144
+ else
145
+ raise "Unrecognised param data: #{data.inspect}"
146
+ end
147
+ else
148
+ data
149
+ end
124
150
  end
125
151
 
126
152
  delegate :dashboard_class, :resource_class, :resource_name, :namespace,
@@ -129,7 +155,7 @@ module Administrate
129
155
  helper_method :resource_name
130
156
 
131
157
  def resource_resolver
132
- @_resource_resolver ||=
158
+ @resource_resolver ||=
133
159
  Administrate::ResourceResolver.new(controller_path)
134
160
  end
135
161
 
@@ -142,8 +168,22 @@ module Administrate
142
168
 
143
169
  def show_search_bar?
144
170
  dashboard.attribute_types_for(
145
- dashboard.collection_attributes
171
+ dashboard.all_attributes,
146
172
  ).any? { |_name, attribute| attribute.searchable? }
147
173
  end
174
+
175
+ def show_action?(_action, _resource)
176
+ true
177
+ end
178
+ helper_method :show_action?
179
+
180
+ def new_resource
181
+ resource_class.new
182
+ end
183
+ helper_method :new_resource
184
+
185
+ def authorize_resource(resource)
186
+ resource
187
+ end
148
188
  end
149
189
  end
@@ -0,0 +1,36 @@
1
+ module Administrate
2
+ module Punditize
3
+ if Object.const_defined?("Pundit")
4
+ extend ActiveSupport::Concern
5
+ include Pundit
6
+
7
+ included do
8
+ def scoped_resource
9
+ policy_scope_admin super
10
+ end
11
+
12
+ def authorize_resource(resource)
13
+ authorize resource
14
+ end
15
+
16
+ def show_action?(action, resource)
17
+ Pundit.policy!(pundit_user, resource).send("#{action}?".to_sym)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ # Like the policy_scope method in stock Pundit, but allows the 'resolve'
24
+ # to be overridden by 'resolve_admin' for a different index scope in Admin
25
+ # controllers.
26
+ def policy_scope_admin(scope)
27
+ ps = Pundit::PolicyFinder.new(scope).scope!.new(pundit_user, scope)
28
+ if ps.respond_to? :resolve_admin
29
+ ps.resolve_admin
30
+ else
31
+ ps.resolve
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,16 +2,25 @@ module Administrate
2
2
  module ApplicationHelper
3
3
  PLURAL_MANY_COUNT = 2.1
4
4
 
5
+ def application_title
6
+ if Rails::VERSION::MAJOR <= 5
7
+ Rails.application.class.parent_name.titlecase
8
+ else
9
+ Rails.application.class.module_parent_name.titlecase
10
+ end
11
+ end
12
+
5
13
  def render_field(field, locals = {})
6
14
  locals.merge!(field: field)
7
15
  render locals: locals, partial: field.to_partial_path
8
16
  end
9
17
 
18
+ def class_from_resource(resource_name)
19
+ resource_name.to_s.classify.constantize
20
+ end
21
+
10
22
  def display_resource_name(resource_name)
11
- resource_name.
12
- to_s.
13
- classify.
14
- constantize.
23
+ class_from_resource(resource_name).
15
24
  model_name.
16
25
  human(
17
26
  count: PLURAL_MANY_COUNT,
@@ -27,12 +36,22 @@ module Administrate
27
36
  end
28
37
  end
29
38
 
30
- def sanitized_order_params
31
- params.permit(:search, :id, :order, :page, :per_page, :direction, :orders)
39
+ def resource_index_route_key(resource_name)
40
+ ActiveModel::Naming.route_key(class_from_resource(resource_name))
41
+ end
42
+
43
+ def sanitized_order_params(page, current_field_name)
44
+ collection_names = page.item_includes + [current_field_name]
45
+ association_params = collection_names.map do |assoc_name|
46
+ { assoc_name => %i[order direction page per_page] }
47
+ end
48
+ params.permit(:search, :id, :page, :per_page, association_params)
32
49
  end
33
50
 
34
51
  def clear_search_params
35
- params.except(:search, :page).permit(:order, :direction, :per_page)
52
+ params.except(:search, :page).permit(
53
+ :per_page, resource_name => %i[order direction]
54
+ )
36
55
  end
37
56
  end
38
57
  end
@@ -28,14 +28,13 @@ to display a collection of resources in an HTML table.
28
28
  scope="col"
29
29
  role="columnheader"
30
30
  aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
31
- <%= link_to(sanitized_order_params.merge(
32
- collection_presenter.order_params_for(attr_name)
31
+ <%= link_to(sanitized_order_params(page, collection_field_name).merge(
32
+ collection_presenter.order_params_for(attr_name, key: collection_field_name)
33
33
  )) do %>
34
34
  <%= t(
35
35
  "helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
36
36
  default: attr_name.to_s,
37
37
  ).titleize %>
38
-
39
38
  <% if collection_presenter.ordered_by?(attr_name) %>
40
39
  <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
41
40
  <svg aria-hidden="true">
@@ -63,11 +62,13 @@ to display a collection of resources in an HTML table.
63
62
  >
64
63
  <% collection_presenter.attributes_for(resource).each do |attribute| %>
65
64
  <td class="cell-data cell-data--<%= attribute.html_class %>">
66
- <a href="<%= polymorphic_path([namespace, resource]) -%>"
67
- class="action-show"
68
- >
69
- <%= render_field attribute %>
70
- </a>
65
+ <% if show_action? :show, resource -%>
66
+ <a href="<%= polymorphic_path([namespace, resource]) -%>"
67
+ class="action-show"
68
+ >
69
+ <%= render_field attribute %>
70
+ </a>
71
+ <% end -%>
71
72
  </td>
72
73
  <% end %>
73
74
 
@@ -76,7 +77,7 @@ to display a collection of resources in an HTML table.
76
77
  t("administrate.actions.edit"),
77
78
  [:edit, namespace, resource],
78
79
  class: "action-edit",
79
- ) %></td>
80
+ ) if show_action? :edit, resource%></td>
80
81
  <% end %>
81
82
 
82
83
  <% if valid_action? :destroy, collection_presenter.resource_name %>
@@ -86,7 +87,7 @@ to display a collection of resources in an HTML table.
86
87
  class: "text-color-red",
87
88
  method: :delete,
88
89
  data: { confirm: t("administrate.actions.confirm") }
89
- ) %></td>
90
+ ) if show_action? :destroy, resource %></td>
90
91
  <% end %>
91
92
  </tr>
92
93
  <% end %>
@@ -14,7 +14,7 @@ This partial renders flash messages on every page.
14
14
  <% if flash.any? %>
15
15
  <div class="flashes">
16
16
  <% flash.each do |key, value| -%>
17
- <div class="flash flash-<%= key %>"><%= value %></div>
17
+ <div class="flash flash-<%= key %>"><%= value.html_safe %></div>
18
18
  <% end -%>
19
19
  </div>
20
20
  <% end %>
@@ -18,8 +18,11 @@ and renders all form fields for a resource's editable attributes.
18
18
  <% if page.resource.errors.any? %>
19
19
  <div id="error_explanation">
20
20
  <h2>
21
- <%= pluralize(page.resource.errors.count, "error") %>
22
- prohibited this <%= page.resource_name %> from being saved:
21
+ <%= t(
22
+ "administrate.form.errors",
23
+ pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
24
+ resource_name: display_resource_name(page.resource_name)
25
+ ) %>
23
26
  </h2>
24
27
 
25
28
  <ul>
@@ -11,7 +11,7 @@ as defined by the routes in the `admin/` namespace
11
11
  <% Administrate::Namespace.new(namespace).resources.each do |resource| %>
12
12
  <%= link_to(
13
13
  display_resource_name(resource),
14
- [namespace, resource.path],
14
+ [namespace, resource_index_route_key(resource)],
15
15
  class: "navigation__link navigation__link--#{nav_link_state(resource)}"
16
16
  ) %>
17
17
  <% end %>
@@ -15,7 +15,7 @@ It displays a header, and renders the `_form` partial to do the heavy lifting.
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
16
16
  %>
17
17
 
18
- <% content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" } %>
18
+ <% content_for(:title) { t("administrate.actions.edit_resource", name: page.page_title) } %>
19
19
 
20
20
  <header class="main-content__header" role="banner">
21
21
  <h1 class="main-content__page-title">
@@ -24,10 +24,10 @@ It displays a header, and renders the `_form` partial to do the heavy lifting.
24
24
 
25
25
  <div>
26
26
  <%= link_to(
27
- "#{t("administrate.actions.show")} #{page.page_title}",
27
+ t("administrate.actions.show_resource", name: page.page_title),
28
28
  [namespace, page.resource],
29
29
  class: "button",
30
- ) if valid_action? :show %>
30
+ ) if valid_action?(:show) && show_action?(:show, page.resource) %>
31
31
  </div>
32
32
  </header>
33
33
 
@@ -42,10 +42,13 @@ It renders the `_table` partial to display details about the resources.
42
42
 
43
43
  <div>
44
44
  <%= link_to(
45
- "#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
45
+ t(
46
+ "administrate.actions.new_resource",
47
+ name: page.resource_name.titleize.downcase
48
+ ),
46
49
  [:new, namespace, page.resource_path],
47
50
  class: "button",
48
- ) if valid_action? :new %>
51
+ ) if valid_action?(:new) && show_action?(:new, new_resource) %>
49
52
  </div>
50
53
  </header>
51
54
 
@@ -53,6 +56,8 @@ It renders the `_table` partial to display details about the resources.
53
56
  <%= render(
54
57
  "collection",
55
58
  collection_presenter: page,
59
+ collection_field_name: resource_name,
60
+ page: page,
56
61
  resources: resources,
57
62
  table_title: "page-title"
58
63
  ) %>
@@ -15,7 +15,12 @@ to do the heavy lifting.
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
16
16
  %>
17
17
 
18
- <% content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" } %>
18
+ <% content_for(:title) do %>
19
+ <%= t(
20
+ "administrate.actions.new_resource",
21
+ name: display_resource_name(page.resource_name).titleize
22
+ ) %>
23
+ <% end %>
19
24
 
20
25
  <header class="main-content__header" role="banner">
21
26
  <h1 class="main-content__page-title">
@@ -16,7 +16,7 @@ as well as a link to its edit page.
16
16
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
17
17
  %>
18
18
 
19
- <% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %>
19
+ <% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
20
20
 
21
21
  <header class="main-content__header" role="banner">
22
22
  <h1 class="main-content__page-title">
@@ -25,10 +25,10 @@ as well as a link to its edit page.
25
25
 
26
26
  <div>
27
27
  <%= link_to(
28
- "#{t("administrate.actions.edit")} #{page.page_title}",
28
+ t("administrate.actions.edit_resource", name: page.page_title),
29
29
  [:edit, namespace, page.resource],
30
30
  class: "button",
31
- ) if valid_action? :edit %>
31
+ ) if valid_action?(:edit) && show_action?(:edit, page.resource) %>
32
32
  </div>
33
33
  </header>
34
34
 
@@ -43,7 +43,7 @@ as well as a link to its edit page.
43
43
  </dt>
44
44
 
45
45
  <dd class="attribute-data attribute-data--<%=attribute.html_class%>"
46
- ><%= render_field attribute %></dd>
46
+ ><%= render_field attribute, page: page %></dd>
47
47
  <% end %>
48
48
  </dl>
49
49
  </section>
@@ -16,7 +16,7 @@ By default, the relationship is rendered as a link to the associated object.
16
16
  %>
17
17
 
18
18
  <% if field.data %>
19
- <% if valid_action?(:show, field.attribute) %>
19
+ <% if valid_action?(:show, field.associated_class) %>
20
20
  <%= link_to(
21
21
  field.display_associated_resource,
22
22
  [namespace, field.data],
@@ -16,7 +16,7 @@ By default, the relationship is rendered as a link to the associated object.
16
16
  %>
17
17
 
18
18
  <% if field.data %>
19
- <% if valid_action?(:show, field.attribute) %>
19
+ <% if valid_action?(:show, field.associated_class) %>
20
20
  <%= link_to(
21
21
  field.display_associated_resource,
22
22
  [namespace, field.data],
@@ -20,5 +20,5 @@ By default, the input is a text field that is augmented with [DateTimePicker].
20
20
  <%= f.label field.attribute %>
21
21
  </div>
22
22
  <div class="field-unit__field">
23
- <%= f.text_field field.attribute, class: "datetimepicker" %>
23
+ <%= f.text_field field.attribute, data: { type: 'datetime' } %>
24
24
  </div>
@@ -17,5 +17,5 @@ as a localized date & time string.
17
17
  %>
18
18
 
19
19
  <% if field.data %>
20
- <%= field.date %>
20
+ <%= field.datetime %>
21
21
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <%#
2
2
  # HasMany Form Partial
3
3
 
4
- This partial renders an input element for belongs_to relationships.
4
+ This partial renders an input element for has_many relationships.
5
5
  By default, the input is a collection select box
6
6
  that displays all possible records to associate with.
7
7
  The collection select box supports multiple inputs,
@@ -20,7 +20,7 @@ and is augmented with [Selectize].
20
20
  %>
21
21
 
22
22
  <div class="field-unit__label">
23
- <%= f.label field.attribute_key, field.attribute %>
23
+ <%= f.label field.attribute, for: "#{f.object_name}_#{field.attribute_key}" %>
24
24
  </div>
25
25
  <div class="field-unit__field">
26
26
  <%= f.select(field.attribute_key, nil, {}, multiple: true) do %>
@@ -16,4 +16,4 @@ as a count of how many objects are associated through the relationship.
16
16
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
17
17
  %>
18
18
 
19
- <%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase) %>
19
+ <%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase.singularize) %>
@@ -19,15 +19,18 @@ from the associated resource class's dashboard.
19
19
  %>
20
20
 
21
21
  <% if field.resources.any? %>
22
+ <% order = field.order_from_params(params.fetch(field.name, {})) %>
23
+ <% page_number = params.fetch(field.name, {}).fetch(:page, nil) %>
22
24
  <%= render(
23
25
  "collection",
24
- collection_presenter: field.associated_collection,
25
- resources: field.resources(params[field.name]),
26
- table_title: field.name
26
+ collection_presenter: field.associated_collection(order),
27
+ collection_field_name: field.name,
28
+ page: page,
29
+ resources: field.resources(page_number, order),
30
+ table_title: field.name,
27
31
  ) %>
28
-
29
32
  <% if field.more_than_limit? %>
30
- <%= paginate field.resources(params[field.name]), param_name: "#{field.name}" %>
33
+ <%= paginate field.resources(page_number), param_name: "#{field.name}[page]" %>
31
34
  <% end %>
32
35
 
33
36
  <% else %>
@@ -18,7 +18,7 @@ The form will be rendered as nested_from to parent relationship.
18
18
 
19
19
  <%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
20
20
  <fieldset class="field-unit--nested">
21
- <legend><%= field.nested_form.resource_name.titleize %></legend>
21
+ <legend><%= t "helpers.label.#{f.object_name}.#{field.nested_form.resource_name}", default: field.nested_form.resource_name.titleize %></legend>
22
22
  <% field.nested_form.attributes.each do |attribute| -%>
23
23
  <div class="field-unit field-unit--<%= attribute.html_class %>">
24
24
  <%= render_field attribute, f: has_one_f %>
@@ -0,0 +1,23 @@
1
+ <%#
2
+ # Password Form Partial
3
+
4
+ This partial renders an input element for a password attribute.
5
+ By default, the input is a password field.
6
+
7
+ ## Local variables:
8
+
9
+ - `f`:
10
+ A Rails form generator, used to help create the appropriate input fields.
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <div class="field-unit__label">
19
+ <%= f.label field.attribute %>
20
+ </div>
21
+ <div class="field-unit__field">
22
+ <%= f.password_field field.attribute, value: field.data %>
23
+ </div>
@@ -0,0 +1,18 @@
1
+ <%#
2
+ # Password Index Partial
3
+
4
+ This partial renders a password attribute
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the attribute is rendered as a truncated string.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <%= field.truncate %>
@@ -0,0 +1,18 @@
1
+ <%#
2
+ # Password Show Partial
3
+
4
+ This partial renders a password attribute,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the attribute is rendered as an truncate string.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of [Administrate::Field::Password][1].
13
+ A wrapper around the Password.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password
16
+ %>
17
+
18
+ <%= field.truncate %>