administrate 0.12.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) 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 +11 -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 +47 -13
  15. data/app/helpers/administrate/application_helper.rb +32 -14
  16. data/app/views/administrate/application/_collection.html.erb +24 -26
  17. data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
  18. data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
  19. data/app/views/administrate/application/_flashes.html.erb +1 -0
  20. data/app/views/administrate/application/_form.html.erb +3 -3
  21. data/app/views/administrate/application/_icons.html.erb +1 -1
  22. data/app/views/administrate/application/_index_header.html.erb +28 -0
  23. data/app/views/administrate/application/_navigation.html.erb +5 -3
  24. data/app/views/administrate/application/index.html.erb +9 -29
  25. data/app/views/administrate/application/show.html.erb +1 -1
  26. data/app/views/fields/belongs_to/_form.html.erb +3 -3
  27. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  28. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  29. data/app/views/fields/date/_form.html.erb +24 -0
  30. data/app/views/fields/date/_index.html.erb +21 -0
  31. data/app/views/fields/date/_show.html.erb +21 -0
  32. data/app/views/fields/has_one/_index.html.erb +1 -1
  33. data/app/views/fields/has_one/_show.html.erb +4 -4
  34. data/app/views/fields/number/_form.html.erb +1 -1
  35. data/app/views/fields/polymorphic/_show.html.erb +1 -1
  36. data/app/views/fields/select/_form.html.erb +23 -9
  37. data/app/views/fields/string/_show.html.erb +2 -2
  38. data/app/views/fields/text/_show.html.erb +2 -3
  39. data/app/views/fields/time/_form.html.erb +3 -2
  40. data/app/views/fields/time/_index.html.erb +3 -1
  41. data/app/views/fields/time/_show.html.erb +3 -1
  42. data/app/views/fields/url/_index.html.erb +1 -1
  43. data/app/views/fields/url/_show.html.erb +1 -1
  44. data/app/views/layouts/administrate/application.html.erb +1 -0
  45. data/config/locales/administrate.ar.yml +2 -0
  46. data/config/locales/administrate.bs.yml +2 -0
  47. data/config/locales/administrate.ca.yml +2 -0
  48. data/config/locales/administrate.da.yml +2 -0
  49. data/config/locales/administrate.de.yml +2 -0
  50. data/config/locales/administrate.en.yml +2 -0
  51. data/config/locales/administrate.es.yml +2 -0
  52. data/config/locales/administrate.fi.yml +30 -0
  53. data/config/locales/administrate.fr.yml +4 -2
  54. data/config/locales/administrate.id.yml +2 -0
  55. data/config/locales/administrate.it.yml +2 -0
  56. data/config/locales/administrate.ja.yml +2 -0
  57. data/config/locales/administrate.ko.yml +2 -0
  58. data/config/locales/administrate.nl.yml +7 -5
  59. data/config/locales/administrate.pl.yml +2 -0
  60. data/config/locales/administrate.pt-BR.yml +4 -2
  61. data/config/locales/administrate.pt.yml +4 -2
  62. data/config/locales/administrate.ru.yml +2 -0
  63. data/config/locales/{administrate.al.yml → administrate.sq.yml} +3 -1
  64. data/config/locales/administrate.sv.yml +2 -0
  65. data/config/locales/administrate.tr.yml +30 -0
  66. data/config/locales/administrate.uk.yml +2 -0
  67. data/config/locales/administrate.vi.yml +2 -0
  68. data/config/locales/administrate.zh-CN.yml +2 -0
  69. data/config/locales/administrate.zh-TW.yml +2 -0
  70. data/config/unicorn.rb +8 -13
  71. data/docs/adding_controllers_without_related_model.md +52 -0
  72. data/docs/adding_custom_field_types.md +3 -1
  73. data/docs/authentication.md +3 -1
  74. data/docs/authorization.md +5 -3
  75. data/docs/customizing_attribute_partials.md +4 -1
  76. data/docs/customizing_controller_actions.md +48 -1
  77. data/docs/customizing_dashboards.md +90 -37
  78. data/docs/customizing_page_views.md +18 -4
  79. data/docs/extending_administrate.md +27 -0
  80. data/docs/getting_started.md +35 -11
  81. data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
  82. data/docs/guides.md +5 -0
  83. data/docs/rails_api.md +5 -3
  84. data/lib/administrate/base_dashboard.rb +35 -12
  85. data/lib/administrate/custom_dashboard.rb +15 -0
  86. data/lib/administrate/engine.rb +7 -0
  87. data/lib/administrate/field/associative.rb +49 -5
  88. data/lib/administrate/field/base.rb +35 -9
  89. data/lib/administrate/field/belongs_to.rb +13 -3
  90. data/lib/administrate/field/date.rb +20 -0
  91. data/lib/administrate/field/deferred.rb +22 -3
  92. data/lib/administrate/field/has_many.rb +15 -2
  93. data/lib/administrate/field/has_one.rb +32 -12
  94. data/lib/administrate/field/number.rb +19 -2
  95. data/lib/administrate/field/polymorphic.rb +5 -5
  96. data/lib/administrate/field/select.rb +10 -1
  97. data/lib/administrate/field/time.rb +11 -0
  98. data/lib/administrate/namespace.rb +5 -1
  99. data/lib/administrate/order.rb +17 -7
  100. data/lib/administrate/page/base.rb +1 -3
  101. data/lib/administrate/page/form.rb +10 -3
  102. data/lib/administrate/resource_resolver.rb +2 -2
  103. data/lib/administrate/search.rb +47 -36
  104. data/lib/administrate/version.rb +1 -1
  105. data/lib/administrate/view_generator.rb +9 -3
  106. data/lib/administrate.rb +19 -0
  107. data/lib/generators/administrate/dashboard/dashboard_generator.rb +19 -15
  108. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +22 -10
  109. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +4 -4
  110. data/lib/generators/administrate/install/install_generator.rb +37 -1
  111. data/lib/generators/administrate/install/templates/application_controller.rb.erb +4 -4
  112. data/lib/generators/administrate/routes/routes_generator.rb +15 -25
  113. data/lib/generators/administrate/views/views_generator.rb +5 -4
  114. metadata +29 -43
  115. 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: 6a099c28c8a74491759229e6fe82de763f25b9ff59473d5c70b00d38675e3498
4
+ data.tar.gz: c24140b9e1bc63eb9ecd5f38cd0cfd3d3c0f125a81370df1dd6663af66121baa
5
5
  SHA512:
6
- metadata.gz: ac4790d3bca102b4a27cc73f154e7167620f4589088b1207008f0915521735cfed483fbf085d24e7844e7b092f9f1a7d198ec6113cbc4be877758886c192f097
7
- data.tar.gz: da2c64204adee3b43a566c67cf2aa42f37a0a38ea5f35b9988f704491f2b15dcd76210fb2f56f57de1576e77da71f429fe6572493e65933877b29f9eb9e5920f
6
+ metadata.gz: 8ada94532afa210a359eece24f042fdb7de549cdb6bb94507c044f85df7b26cfbd5855202de2016255d635d2448dcba303d91eac4dc41c896f30e52f95073345
7
+ data.tar.gz: 98e115c8c3acfe7dc5cab3a3055b5f06dfa5661f9d2eb135c528b474cbe36e6fb51b36a8c88489860a9fda200758ce37f4d60375705f0e0234af4dc2805e75ff
@@ -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,14 @@ 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
+ }
51
+
52
+ .button--nav {
53
+ margin-bottom: $base-spacing;
54
+ }
@@ -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
- dashboard_class,
9
+ dashboard,
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),
@@ -46,26 +47,26 @@ module Administrate
46
47
 
47
48
  if resource.save
48
49
  redirect_to(
49
- [namespace, resource],
50
+ after_resource_created_path(resource),
50
51
  notice: translate_with_resource("create.success"),
51
52
  )
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
 
59
60
  def update
60
61
  if requested_resource.update(resource_params)
61
62
  redirect_to(
62
- [namespace, requested_resource],
63
+ after_resource_updated_path(requested_resource),
63
64
  notice: translate_with_resource("update.success"),
64
65
  )
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
 
@@ -75,14 +76,27 @@ module Administrate
75
76
  else
76
77
  flash[:error] = requested_resource.errors.full_messages.join("<br/>")
77
78
  end
78
- redirect_to action: :index
79
+ redirect_to after_resource_destroyed_path(requested_resource)
79
80
  end
80
81
 
81
82
  private
82
83
 
84
+ def after_resource_destroyed_path(_requested_resource)
85
+ { action: :index }
86
+ end
87
+
88
+ def after_resource_created_path(requested_resource)
89
+ [namespace, requested_resource]
90
+ end
91
+
92
+ def after_resource_updated_path(requested_resource)
93
+ [namespace, requested_resource]
94
+ end
95
+
83
96
  helper_method :nav_link_state
84
97
  def nav_link_state(resource)
85
- resource_name.to_s.pluralize == resource.to_s ? :active : :inactive
98
+ underscore_resource = resource.to_s.split("/").join("__")
99
+ resource_name.to_s.pluralize == underscore_resource ? :active : :inactive
86
100
  end
87
101
 
88
102
  helper_method :valid_action?
@@ -101,10 +115,27 @@ module Administrate
101
115
  end
102
116
 
103
117
  def order
104
- @order ||= Administrate::Order.new(
105
- params.fetch(resource_name, {}).fetch(:order, nil),
106
- params.fetch(resource_name, {}).fetch(:direction, nil),
107
- )
118
+ @order ||= Administrate::Order.new(sorting_attribute, sorting_direction)
119
+ end
120
+
121
+ def sorting_attribute
122
+ sorting_params.fetch(:order) { default_sorting_attribute }
123
+ end
124
+
125
+ def default_sorting_attribute
126
+ nil
127
+ end
128
+
129
+ def sorting_direction
130
+ sorting_params.fetch(:direction) { default_sorting_direction }
131
+ end
132
+
133
+ def default_sorting_direction
134
+ nil
135
+ end
136
+
137
+ def sorting_params
138
+ Hash.try_convert(request.query_parameters[resource_name]) || {}
108
139
  end
109
140
 
110
141
  def dashboard
@@ -144,6 +175,8 @@ module Administrate
144
175
  else
145
176
  raise "Unrecognised param data: #{data.inspect}"
146
177
  end
178
+ elsif data.is_a?(ActionController::Parameters)
179
+ data.transform_values { |v| read_param_value(v) }
147
180
  else
148
181
  data
149
182
  end
@@ -153,6 +186,7 @@ module Administrate
153
186
  to: :resource_resolver
154
187
  helper_method :namespace
155
188
  helper_method :resource_name
189
+ helper_method :resource_class
156
190
 
157
191
  def resource_resolver
158
192
  @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
@@ -24,7 +24,8 @@ to display a collection of resources in an HTML table.
24
24
  <% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
25
25
  <th class="cell-label
26
26
  cell-label--<%= attr_type.html_class %>
27
- cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>"
27
+ cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
28
+ cell-label--<%= "#{resource_name}_#{attr_name}" %>"
28
29
  scope="col"
29
30
  role="columnheader"
30
31
  aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
@@ -33,7 +34,7 @@ to display a collection of resources in an HTML table.
33
34
  )) do %>
34
35
  <%= t(
35
36
  "helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
36
- default: attr_name.to_s,
37
+ default: resource_class.human_attribute_name(attr_name),
37
38
  ).titleize %>
38
39
  <% if collection_presenter.ordered_by?(attr_name) %>
39
40
  <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
@@ -45,50 +46,47 @@ to display a collection of resources in an HTML table.
45
46
  <% end %>
46
47
  </th>
47
48
  <% end %>
48
- <% [valid_action?(:edit, collection_presenter.resource_name),
49
- valid_action?(:destroy, collection_presenter.resource_name)].count(true).times do %>
50
- <th scope="col"></th>
51
- <% end %>
49
+ <%= render(
50
+ "collection_header_actions",
51
+ collection_presenter: collection_presenter,
52
+ page: page,
53
+ resources: resources,
54
+ table_title: "page-title"
55
+ ) %>
52
56
  </tr>
53
57
  </thead>
54
58
 
55
59
  <tbody>
56
60
  <% resources.each do |resource| %>
57
61
  <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])}) %>
62
+ <% if show_action? :show, resource %>
63
+ <%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
61
64
  <% end %>
62
65
  >
63
66
  <% collection_presenter.attributes_for(resource).each do |attribute| %>
64
67
  <td class="cell-data cell-data--<%= attribute.html_class %>">
65
68
  <% if show_action? :show, resource -%>
66
69
  <a href="<%= polymorphic_path([namespace, resource]) -%>"
70
+ tabindex="-1"
67
71
  class="action-show"
68
72
  >
69
73
  <%= render_field attribute %>
70
74
  </a>
75
+ <% else %>
76
+ <%= render_field attribute %>
71
77
  <% end -%>
72
78
  </td>
73
79
  <% end %>
74
80
 
75
- <% if valid_action? :edit, collection_presenter.resource_name %>
76
- <td><%= link_to(
77
- t("administrate.actions.edit"),
78
- [:edit, namespace, resource],
79
- class: "action-edit",
80
- ) if show_action? :edit, resource%></td>
81
- <% end %>
82
-
83
- <% if valid_action? :destroy, collection_presenter.resource_name %>
84
- <td><%= link_to(
85
- t("administrate.actions.destroy"),
86
- [namespace, resource],
87
- class: "text-color-red",
88
- method: :delete,
89
- data: { confirm: t("administrate.actions.confirm") }
90
- ) if show_action? :destroy, resource %></td>
91
- <% end %>
81
+ <%= render(
82
+ "collection_item_actions",
83
+ collection_presenter: collection_presenter,
84
+ collection_field_name: collection_field_name,
85
+ page: page,
86
+ namespace: namespace,
87
+ resource: resource,
88
+ table_title: "page-title"
89
+ ) %>
92
90
  </tr>
93
91
  <% end %>
94
92
  </tbody>
@@ -0,0 +1,4 @@
1
+ <% [valid_action?(:edit, collection_presenter.resource_name),
2
+ valid_action?(:destroy, collection_presenter.resource_name)].count(true).times do %>
3
+ <th scope="col"></th>
4
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% if valid_action?(:edit, collection_presenter.resource_name) %>
2
+ <td><%= link_to(
3
+ t("administrate.actions.edit"),
4
+ [:edit, namespace, resource],
5
+ class: "action-edit",
6
+ ) if show_action?(:edit, resource) %></td>
7
+ <% end %>
8
+
9
+ <% if valid_action?(:destroy, collection_presenter.resource_name) %>
10
+ <td><%= link_to(
11
+ t("administrate.actions.destroy"),
12
+ [namespace, resource],
13
+ class: "text-color-red",
14
+ method: :delete,
15
+ data: { confirm: t("administrate.actions.confirm") }
16
+ ) if show_action?(:destroy, resource) %></td>
17
+ <% end %>
@@ -14,6 +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
+ <% next unless value.respond_to?(:html_safe) %>
17
18
  <div class="flash flash-<%= key %>"><%= value.html_safe %></div>
18
19
  <% end -%>
19
20
  </div>
@@ -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
 
@@ -33,8 +33,8 @@ and renders all form fields for a resource's editable attributes.
33
33
  </div>
34
34
  <% end %>
35
35
 
36
- <% page.attributes.each do |attribute| -%>
37
- <div class="field-unit field-unit--<%= attribute.html_class %>">
36
+ <% page.attributes(controller.action_name).each do |attribute| -%>
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 -%>
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
1
+ <svg hidden xmlns="http://www.w3.org/2000/svg">
2
2
  <symbol id="icon-cancel" viewBox="0 0 48 48">
3
3
  <path fill-rule="evenodd" d="M24 19.757l-8.485-8.485c-.784-.783-2.047-.782-2.827 0l-1.417 1.416c-.777.777-.78 2.046.002 2.827L19.757 24l-8.485 8.485c-.783.784-.782 2.047 0 2.827l1.416 1.417c.777.777 2.046.78 2.827-.002L24 28.243l8.485 8.485c.784.783 2.047.782 2.827 0l1.417-1.416c.777-.777.78-2.046-.002-2.827L28.243 24l8.485-8.485c.783-.784.782-2.047 0-2.827l-1.416-1.417c-.777-.777-2.046-.78-2.827.002L24 19.757zM24 47c12.703 0 23-10.297 23-23S36.703 1 24 1 1 11.297 1 24s10.297 23 23 23z" />
4
4
  </symbol>
@@ -0,0 +1,28 @@
1
+ <% content_for(:title) do %>
2
+ <%= display_resource_name(page.resource_name) %>
3
+ <% end %>
4
+
5
+ <header class="main-content__header" role="banner">
6
+ <h1 class="main-content__page-title" id="page-title">
7
+ <%= content_for(:title) %>
8
+ </h1>
9
+
10
+ <% if show_search_bar %>
11
+ <%= render(
12
+ "search",
13
+ search_term: search_term,
14
+ resource_name: display_resource_name(page.resource_name)
15
+ ) %>
16
+ <% end %>
17
+
18
+ <div>
19
+ <%= link_to(
20
+ t(
21
+ "administrate.actions.new_resource",
22
+ name: display_resource_name(page.resource_name, singular: true).downcase
23
+ ),
24
+ [:new, namespace, page.resource_path.to_sym],
25
+ class: "button",
26
+ ) if valid_action?(:new) && show_action?(:new, new_resource) %>
27
+ </div>
28
+ </header>
@@ -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 button--nav") 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>