administrate 0.12.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/associative.js +5 -0
  3. data/app/assets/javascripts/administrate/components/date_time_picker.js +6 -2
  4. data/app/assets/javascripts/administrate/components/table.js +1 -1
  5. data/app/assets/stylesheets/administrate/base/_tables.scss +3 -0
  6. data/app/assets/stylesheets/administrate/components/_attributes.scss +4 -3
  7. data/app/assets/stylesheets/administrate/components/_buttons.scss +8 -0
  8. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -0
  9. data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -4
  10. data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
  11. data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -0
  12. data/app/assets/stylesheets/administrate/components/_navigation.scss +2 -3
  13. data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
  14. data/app/controllers/administrate/application_controller.rb +29 -8
  15. data/app/helpers/administrate/application_helper.rb +32 -14
  16. data/app/views/administrate/application/_collection.html.erb +6 -4
  17. data/app/views/administrate/application/_form.html.erb +2 -2
  18. data/app/views/administrate/application/_navigation.html.erb +5 -3
  19. data/app/views/administrate/application/index.html.erb +2 -2
  20. data/app/views/administrate/application/show.html.erb +1 -1
  21. data/app/views/fields/belongs_to/_form.html.erb +3 -3
  22. data/app/views/fields/date/_form.html.erb +24 -0
  23. data/app/views/fields/date/_index.html.erb +21 -0
  24. data/app/views/fields/date/_show.html.erb +21 -0
  25. data/app/views/fields/has_one/_index.html.erb +1 -1
  26. data/app/views/fields/has_one/_show.html.erb +4 -4
  27. data/app/views/fields/number/_form.html.erb +1 -1
  28. data/app/views/fields/polymorphic/_show.html.erb +1 -1
  29. data/app/views/fields/select/_form.html.erb +21 -9
  30. data/app/views/fields/string/_show.html.erb +2 -2
  31. data/app/views/fields/text/_show.html.erb +2 -3
  32. data/app/views/fields/time/_form.html.erb +3 -2
  33. data/app/views/fields/time/_index.html.erb +3 -1
  34. data/app/views/fields/time/_show.html.erb +3 -1
  35. data/app/views/layouts/administrate/application.html.erb +1 -0
  36. data/config/locales/administrate.ar.yml +2 -0
  37. data/config/locales/administrate.bs.yml +2 -0
  38. data/config/locales/administrate.ca.yml +2 -0
  39. data/config/locales/administrate.da.yml +2 -0
  40. data/config/locales/administrate.de.yml +2 -0
  41. data/config/locales/administrate.en.yml +2 -0
  42. data/config/locales/administrate.es.yml +2 -0
  43. data/config/locales/administrate.fi.yml +30 -0
  44. data/config/locales/administrate.fr.yml +4 -2
  45. data/config/locales/administrate.id.yml +2 -0
  46. data/config/locales/administrate.it.yml +2 -0
  47. data/config/locales/administrate.ja.yml +2 -0
  48. data/config/locales/administrate.ko.yml +2 -0
  49. data/config/locales/administrate.nl.yml +7 -5
  50. data/config/locales/administrate.pl.yml +2 -0
  51. data/config/locales/administrate.pt-BR.yml +4 -2
  52. data/config/locales/administrate.pt.yml +4 -2
  53. data/config/locales/administrate.ru.yml +2 -0
  54. data/config/locales/{administrate.al.yml → administrate.sq.yml} +3 -1
  55. data/config/locales/administrate.sv.yml +2 -0
  56. data/config/locales/administrate.tr.yml +30 -0
  57. data/config/locales/administrate.uk.yml +2 -0
  58. data/config/locales/administrate.vi.yml +2 -0
  59. data/config/locales/administrate.zh-CN.yml +2 -0
  60. data/config/locales/administrate.zh-TW.yml +2 -0
  61. data/config/unicorn.rb +8 -13
  62. data/docs/adding_controllers_without_related_model.md +54 -0
  63. data/docs/adding_custom_field_types.md +3 -1
  64. data/docs/authentication.md +3 -1
  65. data/docs/authorization.md +5 -3
  66. data/docs/customizing_attribute_partials.md +4 -1
  67. data/docs/customizing_controller_actions.md +30 -1
  68. data/docs/customizing_dashboards.md +47 -35
  69. data/docs/customizing_page_views.md +18 -4
  70. data/docs/extending_administrate.md +27 -0
  71. data/docs/getting_started.md +35 -11
  72. data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
  73. data/docs/guides.md +5 -0
  74. data/docs/rails_api.md +5 -3
  75. data/lib/administrate/base_dashboard.rb +19 -10
  76. data/lib/administrate/custom_dashboard.rb +15 -0
  77. data/lib/administrate/engine.rb +7 -0
  78. data/lib/administrate/field/associative.rb +49 -5
  79. data/lib/administrate/field/base.rb +35 -9
  80. data/lib/administrate/field/belongs_to.rb +13 -3
  81. data/lib/administrate/field/date.rb +20 -0
  82. data/lib/administrate/field/deferred.rb +22 -3
  83. data/lib/administrate/field/has_many.rb +15 -2
  84. data/lib/administrate/field/has_one.rb +32 -12
  85. data/lib/administrate/field/number.rb +19 -2
  86. data/lib/administrate/field/polymorphic.rb +5 -5
  87. data/lib/administrate/field/select.rb +6 -1
  88. data/lib/administrate/namespace.rb +4 -0
  89. data/lib/administrate/order.rb +17 -7
  90. data/lib/administrate/page/base.rb +1 -3
  91. data/lib/administrate/page/form.rb +1 -1
  92. data/lib/administrate/resource_resolver.rb +1 -1
  93. data/lib/administrate/search.rb +26 -19
  94. data/lib/administrate/version.rb +1 -1
  95. data/lib/administrate/view_generator.rb +9 -3
  96. data/lib/administrate.rb +19 -0
  97. data/lib/generators/administrate/dashboard/dashboard_generator.rb +18 -14
  98. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +20 -8
  99. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +4 -4
  100. data/lib/generators/administrate/install/install_generator.rb +37 -1
  101. data/lib/generators/administrate/install/templates/application_controller.rb.erb +3 -3
  102. data/lib/generators/administrate/routes/routes_generator.rb +15 -25
  103. data/lib/generators/administrate/views/views_generator.rb +5 -4
  104. metadata +26 -29
  105. data/app/assets/javascripts/administrate/components/has_many_form.js +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 901108f5715bed268b4395d6edadf3738b127425910dc365390847710f19c98f
4
- data.tar.gz: 6b61113c5c116250f2e46eaa5dbf77972473b16a6aae8042a6bcaef74f45308e
3
+ metadata.gz: bb407c439ba3795c3161109f57d64a8e20db553d80f583c6d2a66bfe0f713cd7
4
+ data.tar.gz: 1691010813773e6ecc19b067adb4a610c6624f2ec2d8a03bb6414a683d5d83b0
5
5
  SHA512:
6
- metadata.gz: ac4790d3bca102b4a27cc73f154e7167620f4589088b1207008f0915521735cfed483fbf085d24e7844e7b092f9f1a7d198ec6113cbc4be877758886c192f097
7
- data.tar.gz: da2c64204adee3b43a566c67cf2aa42f37a0a38ea5f35b9988f704491f2b15dcd76210fb2f56f57de1576e77da71f429fe6572493e65933877b29f9eb9e5920f
6
+ metadata.gz: 0fc7042ed3389b1cf87a4ba41681e310dc3678e790a5af0d3c3e3d64c213f50b5bf66409069159a18e784c9cdaf5e6d60e2d2614f4647b5ab0d8e0b4e2f6b70e
7
+ data.tar.gz: 1c8b66a38eca96f2002ccd8b253b4fc7abd082e7376111e2e1be399b870755ce29511982828760fd6a229f5571eb1ace83a9121fae2253db2653218ffbd237ce
@@ -0,0 +1,5 @@
1
+ $(function() {
2
+ $('.field-unit--belongs-to select').selectize({});
3
+ $(".field-unit--has-many select").selectize({});
4
+ $('.field-unit--polymorphic select').selectize({});
5
+ });
@@ -1,10 +1,14 @@
1
1
  $(function () {
2
2
  $('[data-type="time"]').datetimepicker({
3
3
  debug: false,
4
- format: "HH:mm:ss",
4
+ format: 'HH:mm:ss',
5
5
  });
6
6
  $('[data-type="datetime"]').datetimepicker({
7
7
  debug: false,
8
- format: "YYYY-MM-DD HH:mm:ss",
8
+ format: 'YYYY-MM-DD HH:mm:ss',
9
+ });
10
+ $('[data-type="date"]').datetimepicker({
11
+ debug: false,
12
+ format: 'YYYY-MM-DD',
9
13
  });
10
14
  });
@@ -13,7 +13,7 @@ $(function() {
13
13
  var dataUrl = $(event.target).closest("tr").data("url");
14
14
  var selection = window.getSelection().toString();
15
15
  if (selection.length === 0 && dataUrl) {
16
- window.location = dataUrl;
16
+ window.location = window.location.protocol + '//' + window.location.host + dataUrl;
17
17
  }
18
18
  }
19
19
  };
@@ -21,6 +21,9 @@ tr {
21
21
  tbody tr {
22
22
  &:hover {
23
23
  background-color: $base-background-color;
24
+ }
25
+
26
+ [role=link] {
24
27
  cursor: pointer;
25
28
  }
26
29
 
@@ -3,9 +3,9 @@
3
3
  clear: left;
4
4
  float: left;
5
5
  margin-bottom: $base-spacing;
6
- margin-top: 0;
6
+ margin-top: 0.25em;
7
7
  text-align: right;
8
- width: calc(15% - 1rem);
8
+ width: calc(20% - 1rem);
9
9
  }
10
10
 
11
11
  .preserve-whitespace {
@@ -17,7 +17,8 @@
17
17
  float: left;
18
18
  margin-bottom: $base-spacing;
19
19
  margin-left: 2rem;
20
- width: calc(85% - 1rem);
20
+ width: calc(80% - 1rem);
21
+ word-break: break-word;
21
22
  }
22
23
 
23
24
  .attribute--nested {
@@ -41,3 +41,11 @@ input[type="submit"],
41
41
  }
42
42
  }
43
43
  }
44
+
45
+ .button--alt {
46
+ background-color: transparent;
47
+ border: $base-border;
48
+ border-color: $blue;
49
+ color: $blue;
50
+ margin-bottom: $base-spacing;
51
+ }
@@ -1,4 +1,6 @@
1
1
  .cell-label {
2
+ padding-top: 0.15em;
3
+
2
4
  &:hover {
3
5
  a {
4
6
  color: $action-color;
@@ -17,20 +17,33 @@
17
17
  .field-unit__field {
18
18
  float: left;
19
19
  margin-left: 2rem;
20
- width: 45%;
20
+ max-width: 50rem;
21
+ width: 100%;
22
+
23
+ .optgroup-header {
24
+ font-weight: $bold-font-weight;
25
+ }
21
26
  }
22
27
 
23
28
  .field-unit--nested {
24
29
  border: $base-border;
25
30
  margin-left: 7.5%;
31
+ max-width: 60rem;
26
32
  padding: $small-spacing;
27
- width: 50%;
33
+ width: 100%;
28
34
 
29
35
  .field-unit__field {
30
- width: calc(75% - 1rem);
36
+ width: 100%;
31
37
  }
32
38
 
33
39
  .field-unit__label {
34
- width: calc(25% - 1rem);
40
+ width: 10rem;
41
+ }
42
+ }
43
+
44
+ .field-unit--required {
45
+ label::after {
46
+ color: $red;
47
+ content: " *";
35
48
  }
36
49
  }
@@ -1,11 +1,3 @@
1
- $base-spacing: 1.5em !default;
2
- $flashes: (
3
- "alert": #fff6bf,
4
- "error": #fbe3e4,
5
- "notice": #e5edf8,
6
- "success": #e6efc2,
7
- ) !default;
8
-
9
1
  @each $flash-type, $color in $flashes {
10
2
  .flash-#{$flash-type} {
11
3
  background-color: $color;
@@ -5,6 +5,7 @@
5
5
  0 2px 2px rgba($black, 0.2);
6
6
  flex: 1 1 100%;
7
7
  padding-bottom: 10vh;
8
+ min-width: 800px;
8
9
  }
9
10
 
10
11
  .main-content__header,
@@ -2,9 +2,8 @@ $_navigation-link-padding: 0.6em;
2
2
 
3
3
  .navigation {
4
4
  flex: 1 0 10rem;
5
- padding-bottom: $base-spacing;
6
- padding-right: calc(#{$base-spacing} - #{$_navigation-link-padding});
7
- padding-top: $base-spacing;
5
+ padding: $base-spacing;
6
+ padding-left: 0;
8
7
  }
9
8
 
10
9
  .navigation__link {
@@ -22,8 +22,10 @@ $black: #000 !default;
22
22
 
23
23
  $blue: #1976d2 !default;
24
24
  $red: #d32f2f !default;
25
- $light-yellow: #f0cd66 !default;
26
- $light-green: #4ab471 !default;
25
+ $light-yellow: #fff6bf !default;
26
+ $light-red: #fbe3e4 !default;
27
+ $light-green: #e6efc2 !default;
28
+ $light-blue: #e5edf8 !default;
27
29
 
28
30
  $grey-0: #f6f7f7 !default;
29
31
  $grey-1: #dfe0e1 !default;
@@ -47,12 +49,12 @@ $focus-outline: $focus-outline-width solid $focus-outline-color;
47
49
  $focus-outline-offset: 1px;
48
50
 
49
51
  // Flash Colors
50
- $flash-colors: (
51
- alert: $light-yellow,
52
- error: $red,
53
- notice: mix($white, $blue, 50%),
54
- success: $light-green
55
- );
52
+ $flashes: (
53
+ "alert": $light-yellow,
54
+ "error": $light-red,
55
+ "notice": $light-blue,
56
+ "success": $light-green
57
+ ) !default;
56
58
 
57
59
  // Border
58
60
  $base-border-color: $grey-1 !default;
@@ -3,13 +3,14 @@ module Administrate
3
3
  protect_from_forgery with: :exception
4
4
 
5
5
  def index
6
+ authorize_resource(resource_class)
6
7
  search_term = params[:search].to_s.strip
7
8
  resources = Administrate::Search.new(scoped_resource,
8
9
  dashboard_class,
9
10
  search_term).run
10
11
  resources = apply_collection_includes(resources)
11
12
  resources = order.apply(resources)
12
- resources = resources.page(params[:page]).per(records_per_page)
13
+ resources = resources.page(params[:_page]).per(records_per_page)
13
14
  page = Administrate::Page::Collection.new(dashboard, order: order)
14
15
 
15
16
  render locals: {
@@ -27,7 +28,7 @@ module Administrate
27
28
  end
28
29
 
29
30
  def new
30
- resource = resource_class.new
31
+ resource = new_resource
31
32
  authorize_resource(resource)
32
33
  render locals: {
33
34
  page: Administrate::Page::Form.new(dashboard, resource),
@@ -52,7 +53,7 @@ module Administrate
52
53
  else
53
54
  render :new, locals: {
54
55
  page: Administrate::Page::Form.new(dashboard, resource),
55
- }
56
+ }, status: :unprocessable_entity
56
57
  end
57
58
  end
58
59
 
@@ -65,7 +66,7 @@ module Administrate
65
66
  else
66
67
  render :edit, locals: {
67
68
  page: Administrate::Page::Form.new(dashboard, requested_resource),
68
- }
69
+ }, status: :unprocessable_entity
69
70
  end
70
71
  end
71
72
 
@@ -101,10 +102,27 @@ module Administrate
101
102
  end
102
103
 
103
104
  def order
104
- @order ||= Administrate::Order.new(
105
- params.fetch(resource_name, {}).fetch(:order, nil),
106
- params.fetch(resource_name, {}).fetch(:direction, nil),
107
- )
105
+ @order ||= Administrate::Order.new(sorting_attribute, sorting_direction)
106
+ end
107
+
108
+ def sorting_attribute
109
+ sorting_params.fetch(:order) { default_sorting_attribute }
110
+ end
111
+
112
+ def default_sorting_attribute
113
+ nil
114
+ end
115
+
116
+ def sorting_direction
117
+ sorting_params.fetch(:direction) { default_sorting_direction }
118
+ end
119
+
120
+ def default_sorting_direction
121
+ nil
122
+ end
123
+
124
+ def sorting_params
125
+ Hash.try_convert(request.query_parameters[resource_name]) || {}
108
126
  end
109
127
 
110
128
  def dashboard
@@ -144,6 +162,8 @@ module Administrate
144
162
  else
145
163
  raise "Unrecognised param data: #{data.inspect}"
146
164
  end
165
+ elsif data.is_a?(ActionController::Parameters)
166
+ data.transform_values { |v| read_param_value(v) }
147
167
  else
148
168
  data
149
169
  end
@@ -153,6 +173,7 @@ module Administrate
153
173
  to: :resource_resolver
154
174
  helper_method :namespace
155
175
  helper_method :resource_name
176
+ helper_method :resource_class
156
177
 
157
178
  def resource_resolver
158
179
  @resource_resolver ||=
@@ -1,6 +1,7 @@
1
1
  module Administrate
2
2
  module ApplicationHelper
3
3
  PLURAL_MANY_COUNT = 2.1
4
+ SINGULAR_COUNT = 1
4
5
 
5
6
  def application_title
6
7
  if Rails::VERSION::MAJOR <= 5
@@ -11,21 +12,28 @@ module Administrate
11
12
  end
12
13
 
13
14
  def render_field(field, locals = {})
14
- locals.merge!(field: field)
15
+ locals[:field] = field
15
16
  render locals: locals, partial: field.to_partial_path
16
17
  end
17
18
 
18
- def class_from_resource(resource_name)
19
- resource_name.to_s.classify.constantize
19
+ def requireness(field)
20
+ field.required? ? "required" : "optional"
20
21
  end
21
22
 
22
- def display_resource_name(resource_name)
23
- class_from_resource(resource_name).
24
- model_name.
25
- human(
26
- count: PLURAL_MANY_COUNT,
27
- default: resource_name.to_s.pluralize.titleize,
28
- )
23
+ def dashboard_from_resource(resource_name)
24
+ "#{resource_name.to_s.singularize}_dashboard".classify.constantize
25
+ end
26
+
27
+ def model_from_resource(resource_name)
28
+ dashboard = dashboard_from_resource(resource_name)
29
+ dashboard.try(:model) || resource_name.to_sym
30
+ end
31
+
32
+ def display_resource_name(resource_name, opts = {})
33
+ dashboard_from_resource(resource_name).resource_name(
34
+ count: opts[:singular] ? SINGULAR_COUNT : PLURAL_MANY_COUNT,
35
+ default: default_resource_name(resource_name, opts),
36
+ )
29
37
  end
30
38
 
31
39
  def sort_order(order)
@@ -36,8 +44,11 @@ module Administrate
36
44
  end
37
45
  end
38
46
 
39
- def resource_index_route_key(resource_name)
40
- ActiveModel::Naming.route_key(class_from_resource(resource_name))
47
+ def resource_index_route(resource_name)
48
+ url_for(
49
+ action: "index",
50
+ controller: "/#{namespace}/#{resource_name}",
51
+ )
41
52
  end
42
53
 
43
54
  def sanitized_order_params(page, current_field_name)
@@ -45,13 +56,20 @@ module Administrate
45
56
  association_params = collection_names.map do |assoc_name|
46
57
  { assoc_name => %i[order direction page per_page] }
47
58
  end
48
- params.permit(:search, :id, :page, :per_page, association_params)
59
+ params.permit(:search, :id, :_page, :per_page, association_params)
49
60
  end
50
61
 
51
62
  def clear_search_params
52
- params.except(:search, :page).permit(
63
+ params.except(:search, :_page).permit(
53
64
  :per_page, resource_name => %i[order direction]
54
65
  )
55
66
  end
67
+
68
+ private
69
+
70
+ def default_resource_name(name, opts = {})
71
+ resource_name = (opts[:singular] ? name.to_s : name.to_s.pluralize)
72
+ resource_name.gsub("/", "_").titleize
73
+ end
56
74
  end
57
75
  end
@@ -33,7 +33,7 @@ to display a collection of resources in an HTML table.
33
33
  )) do %>
34
34
  <%= t(
35
35
  "helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
36
- default: attr_name.to_s,
36
+ default: resource_class.human_attribute_name(attr_name),
37
37
  ).titleize %>
38
38
  <% if collection_presenter.ordered_by?(attr_name) %>
39
39
  <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
@@ -55,19 +55,21 @@ to display a collection of resources in an HTML table.
55
55
  <tbody>
56
56
  <% resources.each do |resource| %>
57
57
  <tr class="js-table-row"
58
- tabindex="0"
59
- <% if valid_action? :show, collection_presenter.resource_name %>
60
- <%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) %>
58
+ <% if show_action? :show, resource %>
59
+ <%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
61
60
  <% end %>
62
61
  >
63
62
  <% collection_presenter.attributes_for(resource).each do |attribute| %>
64
63
  <td class="cell-data cell-data--<%= attribute.html_class %>">
65
64
  <% if show_action? :show, resource -%>
66
65
  <a href="<%= polymorphic_path([namespace, resource]) -%>"
66
+ tabindex="-1"
67
67
  class="action-show"
68
68
  >
69
69
  <%= render_field attribute %>
70
70
  </a>
71
+ <% else %>
72
+ <%= render_field attribute %>
71
73
  <% end -%>
72
74
  </td>
73
75
  <% end %>
@@ -21,7 +21,7 @@ and renders all form fields for a resource's editable attributes.
21
21
  <%= t(
22
22
  "administrate.form.errors",
23
23
  pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
24
- resource_name: display_resource_name(page.resource_name)
24
+ resource_name: display_resource_name(page.resource_name, singular: true)
25
25
  ) %>
26
26
  </h2>
27
27
 
@@ -34,7 +34,7 @@ and renders all form fields for a resource's editable attributes.
34
34
  <% end %>
35
35
 
36
36
  <% page.attributes.each do |attribute| -%>
37
- <div class="field-unit field-unit--<%= attribute.html_class %>">
37
+ <div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
38
38
  <%= render_field attribute, f: f %>
39
39
  </div>
40
40
  <% end -%>
@@ -8,11 +8,13 @@ as defined by the routes in the `admin/` namespace
8
8
  %>
9
9
 
10
10
  <nav class="navigation" role="navigation">
11
- <% Administrate::Namespace.new(namespace).resources.each do |resource| %>
11
+ <%= link_to(t("administrate.navigation.back_to_app"), root_url, class: "button button--alt") if defined?(root_url) %>
12
+
13
+ <% Administrate::Namespace.new(namespace).resources_with_index_route.each do |resource| %>
12
14
  <%= link_to(
13
15
  display_resource_name(resource),
14
- [namespace, resource_index_route_key(resource)],
16
+ resource_index_route(resource),
15
17
  class: "navigation__link navigation__link--#{nav_link_state(resource)}"
16
- ) %>
18
+ ) if valid_action?(:index, resource) && show_action?(:index, model_from_resource(resource)) %>
17
19
  <% end %>
18
20
  </nav>
@@ -44,7 +44,7 @@ It renders the `_table` partial to display details about the resources.
44
44
  <%= link_to(
45
45
  t(
46
46
  "administrate.actions.new_resource",
47
- name: page.resource_name.titleize.downcase
47
+ name: display_resource_name(page.resource_name, singular: true).downcase
48
48
  ),
49
49
  [:new, namespace, page.resource_path],
50
50
  class: "button",
@@ -62,5 +62,5 @@ It renders the `_table` partial to display details about the resources.
62
62
  table_title: "page-title"
63
63
  ) %>
64
64
 
65
- <%= paginate resources %>
65
+ <%= paginate resources, param_name: '_page' %>
66
66
  </section>
@@ -38,7 +38,7 @@ as well as a link to its edit page.
38
38
  <dt class="attribute-label" id="<%= attribute.name %>">
39
39
  <%= t(
40
40
  "helpers.label.#{resource_name}.#{attribute.name}",
41
- default: attribute.name.titleize,
41
+ default: page.resource.class.human_attribute_name(attribute.name),
42
42
  ) %>
43
43
  </dt>
44
44
 
@@ -20,7 +20,7 @@ that displays all possible records to associate with.
20
20
  <%= f.label field.permitted_attribute %>
21
21
  </div>
22
22
  <div class="field-unit__field">
23
- <%= f.select(field.permitted_attribute) do %>
24
- <%= options_for_select(field.associated_resource_options, field.selected_option) %>
25
- <% end %>
23
+ <%= f.select(field.permitted_attribute,
24
+ options_for_select(field.associated_resource_options, field.selected_option),
25
+ include_blank: field.include_blank_option) %>
26
26
  </div>
@@ -0,0 +1,24 @@
1
+ <%#
2
+ # Date Form Partial
3
+
4
+ This partial renders an input element for a date attribute.
5
+ By default, the input is a text field that is augmented with [DateTimePicker].
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::Date][1].
13
+ A wrapper around the Date value pulled from the database.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
16
+ [DateTimePicker]: https://github.com/Eonasdan/bootstrap-datetimepicker
17
+ %>
18
+
19
+ <div class="field-unit__label">
20
+ <%= f.label field.attribute %>
21
+ </div>
22
+ <div class="field-unit__field">
23
+ <%= f.text_field field.attribute, data: { type: 'date' } %>
24
+ </div>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ # Date Index Partial
3
+
4
+ This partial renders a date attribute,
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the attribute is rendered
8
+ as a localized date string.
9
+
10
+ ## Local variables:
11
+
12
+ - `field`:
13
+ An instance of [Administrate::Field::Date][1].
14
+ A wrapper around the Date value pulled from the database.
15
+
16
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
17
+ %>
18
+
19
+ <% if field.data %>
20
+ <%= field.date %>
21
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ # Date Show Partial
3
+
4
+ This partial renders a date attribute,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the attribute is rendered
8
+ as a localized date string.
9
+
10
+ ## Local variables:
11
+
12
+ - `field`:
13
+ An instance of [Administrate::Field::Date][1].
14
+ A wrapper around the Date value pulled from the database.
15
+
16
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
17
+ %>
18
+
19
+ <% if field.data %>
20
+ <%= field.date %>
21
+ <% end %>
@@ -15,7 +15,7 @@ By default, the relationship is rendered as a link to the associated object.
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
16
16
  %>
17
17
 
18
- <% if field.data %>
18
+ <% if field.linkable? %>
19
19
  <%= link_to(
20
20
  field.display_associated_resource,
21
21
  [namespace, field.data],
@@ -4,7 +4,7 @@
4
4
  This partial renders a has_one relationship,
5
5
  to be displayed on a resource's show page.
6
6
 
7
- All fields of has_one relationship would be rendered
7
+ All show page attributes of has_one relationship would be rendered
8
8
 
9
9
  ## Local variables:
10
10
 
@@ -15,7 +15,7 @@ All fields of has_one relationship would be rendered
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
16
16
  %>
17
17
 
18
- <% if field.data %>
18
+ <% if field.linkable? %>
19
19
  <fieldset class="attribute--nested">
20
20
  <legend>
21
21
  <%= link_to(
@@ -23,7 +23,7 @@ All fields of has_one relationship would be rendered
23
23
  [namespace, field.data],
24
24
  ) %>
25
25
  </legend>
26
- <% field.nested_form.attributes.each do |attribute| -%>
26
+ <% field.nested_show.attributes.each do |attribute| -%>
27
27
  <div>
28
28
  <dt class="attribute-label">
29
29
  <%= t(
@@ -32,7 +32,7 @@ All fields of has_one relationship would be rendered
32
32
  ) %>
33
33
  </dt>
34
34
  <dd class="attribute-data attribute-data--<%= attribute.html_class %>">
35
- <%= attribute.data %>
35
+ <%= render_field attribute, { page: page } %>
36
36
  </dd>
37
37
  </div>
38
38
  <% end -%>
@@ -19,5 +19,5 @@ By default, the input is a text field.
19
19
  <%= f.label field.attribute %>
20
20
  </div>
21
21
  <div class="field-unit__field">
22
- <%= f.text_field field.attribute %>
22
+ <%= f.number_field field.attribute, step: "any" %>
23
23
  </div>
@@ -17,7 +17,7 @@ By default, the relationship is rendered as a link to the associated object.
17
17
  %>
18
18
 
19
19
  <% if field.data %>
20
- <% if valid_action?(:show, field.attribute) %>
20
+ <% if valid_action?(:show, field.data.class) %>
21
21
  <%= link_to(
22
22
  field.display_associated_resource,
23
23
  [namespace, field.data],
@@ -19,13 +19,25 @@ to be displayed on a resource's edit form page.
19
19
  <%= f.label field.attribute %>
20
20
  </div>
21
21
  <div class="field-unit__field">
22
- <%= f.select(
23
- field.attribute,
24
- options_from_collection_for_select(
25
- field.selectable_options,
26
- :to_s,
27
- :to_s,
28
- field.data.presence,
29
- )
30
- ) %>
22
+ <% if field.selectable_options.first&.is_a?(Array) %>
23
+ <%= f.select(
24
+ field.attribute,
25
+ options_from_collection_for_select(
26
+ field.selectable_options,
27
+ :last,
28
+ :first,
29
+ field.data,
30
+ )
31
+ ) %>
32
+ <% else %>
33
+ <%= f.select(
34
+ field.attribute,
35
+ options_from_collection_for_select(
36
+ field.selectable_options,
37
+ :to_s,
38
+ :to_s,
39
+ field.data,
40
+ )
41
+ ) %>
42
+ <% end %>
31
43
  </div>