administrate 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/administrate/application.scss +1 -1
  3. data/app/assets/stylesheets/administrate/base/_forms.scss +5 -1
  4. data/app/assets/stylesheets/administrate/components/_attributes.scss +5 -0
  5. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -2
  6. data/app/assets/stylesheets/administrate/components/_field-unit.scss +15 -0
  7. data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -2
  8. data/app/assets/stylesheets/administrate/components/_search.scss +30 -65
  9. data/app/assets/stylesheets/administrate/library/_variables.scss +28 -27
  10. data/app/controllers/administrate/application_controller.rb +15 -7
  11. data/app/helpers/administrate/application_helper.rb +5 -15
  12. data/app/views/administrate/application/_collection.html.erb +16 -14
  13. data/app/views/administrate/application/_icons.erb +13 -0
  14. data/app/views/administrate/application/_search.html.erb +23 -19
  15. data/app/views/administrate/application/index.html.erb +15 -7
  16. data/app/views/administrate/application/show.html.erb +1 -1
  17. data/app/views/fields/has_many/_show.html.erb +2 -1
  18. data/app/views/fields/has_one/_form.html.erb +11 -9
  19. data/app/views/fields/has_one/_show.html.erb +22 -5
  20. data/app/views/layouts/administrate/application.html.erb +2 -1
  21. data/config/locales/administrate.ar.yml +3 -0
  22. data/config/locales/administrate.da.yml +3 -0
  23. data/config/locales/administrate.de.yml +3 -0
  24. data/config/locales/administrate.en.yml +3 -0
  25. data/config/locales/administrate.es.yml +3 -0
  26. data/config/locales/administrate.fr.yml +3 -0
  27. data/config/locales/administrate.it.yml +3 -0
  28. data/config/locales/administrate.ja.yml +3 -0
  29. data/config/locales/administrate.ko.yml +3 -0
  30. data/config/locales/administrate.nl.yml +3 -0
  31. data/config/locales/administrate.pl.yml +3 -0
  32. data/config/locales/administrate.pt-BR.yml +3 -0
  33. data/config/locales/administrate.pt.yml +3 -0
  34. data/config/locales/administrate.ru.yml +3 -0
  35. data/config/locales/administrate.sv.yml +3 -0
  36. data/config/locales/administrate.uk.yml +3 -0
  37. data/config/locales/administrate.vi.yml +3 -0
  38. data/config/locales/administrate.zh-CN.yml +3 -0
  39. data/config/locales/administrate.zh-TW.yml +3 -0
  40. data/docs/customizing_controller_actions.md +10 -0
  41. data/docs/customizing_page_views.md +2 -2
  42. data/lib/administrate/engine.rb +0 -8
  43. data/lib/administrate/field/base.rb +2 -1
  44. data/lib/administrate/field/deferred.rb +2 -1
  45. data/lib/administrate/field/has_many.rb +7 -1
  46. data/lib/administrate/field/has_one.rb +17 -1
  47. data/lib/administrate/order.rb +1 -1
  48. data/lib/administrate/page/base.rb +1 -1
  49. data/lib/administrate/search.rb +8 -9
  50. data/lib/administrate/version.rb +1 -1
  51. data/lib/generators/administrate/assets/assets_generator.rb +0 -1
  52. data/lib/generators/administrate/routes/routes_generator.rb +1 -1
  53. data/lib/generators/administrate/views/layout_generator.rb +1 -0
  54. metadata +11 -30
  55. data/app/assets/images/administrate/cancel.svg +0 -6
  56. data/app/assets/images/administrate/dropdown.svg +0 -3
  57. data/app/assets/images/administrate/search.svg +0 -6
  58. data/app/assets/images/administrate/sort_arrow.svg +0 -4
  59. data/app/assets/javascripts/administrate/components/_search.js +0 -43
  60. data/lib/generators/administrate/assets/images_generator.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73036f129507204033611e21b5a8633f80ac5b07
4
- data.tar.gz: becbcb0e63d0b48e7d8c58cc722e51c57ab04640
3
+ metadata.gz: ecd4d11ba0fe55d836d185b1b88372b69fd661df
4
+ data.tar.gz: e0a491ee47a85a797d6a01df24091ab1ecb1473f
5
5
  SHA512:
6
- metadata.gz: ceed2a386fcf599d33808087ffa25acfd4416356901028206506aa2095bb5b6777dd712a961d952f99220bcc9f6b189ab215ba46779fa8b1172f6528ce1fb460
7
- data.tar.gz: c35a39f4b91ed15dc22b533013d6fa407c6197878e8cf4085037a25f5a9816ffc0d6de4cae4a4afe89da956bbff3bacbb11bca0c4bbfd0f4c00b53959d635461
6
+ metadata.gz: 0dba9aaf579c9814dabe44f50ee80cf4774a08a6aa502fdbddb34e0b518099fc0b5f598907626ff677ba34ac14c5edf77f519ecf0117a956d23dc69295d8401a
7
+ data.tar.gz: efecd0357a76bc8099c82e65b377b6cbff4fc30128e9f62728f54ed5359de8b38e3f342f57754e41196a1a2a643aad4603fb401de3f2669d2bb7e9a08019f213
@@ -1,6 +1,6 @@
1
1
  @charset "utf-8";
2
2
 
3
- @import "normalize-rails";
3
+ @import "normalize";
4
4
 
5
5
  @import "selectize";
6
6
  @import "datetime_picker";
@@ -51,7 +51,7 @@ textarea {
51
51
  background-color: $white;
52
52
  border: $base-border;
53
53
  border-radius: $base-border-radius;
54
- padding: $base-spacing / 3;
54
+ padding: 0.5em;
55
55
  transition: border-color $base-duration $base-timing;
56
56
  width: 100%;
57
57
 
@@ -72,6 +72,10 @@ textarea {
72
72
  border: $base-border;
73
73
  }
74
74
  }
75
+
76
+ &::placeholder {
77
+ font-style: italic;
78
+ }
75
79
  }
76
80
 
77
81
  textarea {
@@ -19,3 +19,8 @@
19
19
  margin-left: 2rem;
20
20
  width: calc(85% - 1rem);
21
21
  }
22
+
23
+ .attribute--nested {
24
+ border: $base-border;
25
+ padding: $small-spacing;
26
+ }
@@ -27,15 +27,15 @@
27
27
 
28
28
  .cell-label__sort-indicator {
29
29
  display: inline-block;
30
- height: 1em;
31
30
  overflow: hidden;
32
31
  position: absolute;
33
32
  right: 0;
34
33
 
35
34
  svg {
36
35
  fill: $hint-grey;
37
- height: 100%;
36
+ height: 13px;
38
37
  transition: transform $base-duration $base-timing;
38
+ width: 13px;
39
39
  }
40
40
  }
41
41
 
@@ -19,3 +19,18 @@
19
19
  margin-left: 2rem;
20
20
  width: 45%;
21
21
  }
22
+
23
+ .field-unit--nested {
24
+ border: $base-border;
25
+ margin-left: 7.5%;
26
+ padding: $small-spacing;
27
+ width: 50%;
28
+
29
+ .field-unit__field {
30
+ width: calc(75% - 1rem);
31
+ }
32
+
33
+ .field-unit__label {
34
+ width: calc(25% - 1rem);
35
+ }
36
+ }
@@ -21,10 +21,9 @@
21
21
  align-items: center;
22
22
  border-bottom: $base-border;
23
23
  display: flex;
24
- justify-content: space-between;
25
24
  }
26
25
 
27
26
  .main-content__page-title {
28
27
  font-size: 1.6em;
29
- margin-right: 1rem;
28
+ margin-right: auto;
30
29
  }
@@ -1,81 +1,46 @@
1
+ $_search-icon-size: 1rem;
2
+
1
3
  .search {
2
- align-items: center;
3
- border-bottom: $base-border;
4
- display: flex;
5
- flex-direction: row;
6
- justify-content: flex-start;
7
- padding-left: $base-spacing;
8
- padding-right: $base-spacing;
4
+ margin-left: auto;
5
+ margin-right: 2rem;
6
+ max-width: 20rem;
9
7
  position: relative;
10
8
  width: 100%;
11
9
  }
12
10
 
13
- .search__clear,
14
- .search__icon {
15
- svg {
16
- height: 1em;
17
- width: 1em;
18
- }
19
- }
20
-
21
- .search__icon {
22
- path {
23
- fill: $hint-grey;
24
- transition: fill $base-duration $base-timing;
25
- }
26
-
27
- &--active {
28
- svg {
29
- fill: $action-color;
30
- }
31
- }
11
+ .search__input {
12
+ border-radius: 100rem;
13
+ padding-left: $_search-icon-size * 2.5;
14
+ padding-right: $_search-icon-size * 2.5;
32
15
  }
33
16
 
34
- .search__clear {
35
- z-index: 2;
36
-
37
- path {
38
- fill: $hint-grey;
39
- }
40
-
41
- &:hover path {
42
- fill: $action-color;
43
- }
17
+ .search__eyeglass-icon {
18
+ fill: $grey-7;
19
+ height: $_search-icon-size;
20
+ left: $_search-icon-size;
21
+ position: absolute;
22
+ top: 50%;
23
+ transform: translateY(-50%);
24
+ width: $_search-icon-size;
44
25
  }
45
26
 
46
- .search__input {
47
- appearance: none;
48
- border: 0;
49
- box-shadow: none;
50
- flex-grow: 1;
51
- margin: 0;
52
- padding: ($small-spacing * 1.5) $small-spacing;
53
-
54
- &:focus {
55
- box-shadow: none;
56
- }
27
+ .search__clear-link {
28
+ height: $_search-icon-size;
29
+ position: absolute;
30
+ right: $_search-icon-size * 0.75;
31
+ top: 50%;
32
+ transform: translateY(-50%);
33
+ width: $_search-icon-size;
57
34
  }
58
35
 
59
- .search__hint {
60
- color: $hint-grey;
61
- left: 0;
62
- opacity: 0;
36
+ .search__clear-icon {
37
+ fill: $grey-5;
38
+ height: $_search-icon-size;
63
39
  position: absolute;
64
- top: 1em;
65
- transition: opacity $base-duration $base-timing;
66
- z-index: 1;
67
-
68
- svg {
69
- height: 100%;
70
- width: 100%;
71
- }
40
+ transition: fill $base-duration $base-timing;
41
+ width: $_search-icon-size;
72
42
 
73
- path,
74
- rect {
43
+ &:hover {
75
44
  fill: $action-color;
76
45
  }
77
-
78
- &--active {
79
- opacity: 1;
80
- }
81
46
  }
@@ -1,43 +1,44 @@
1
1
  // Typography
2
2
  $base-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
3
3
  "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
4
- sans-serif;
5
- $heading-font-family: $base-font-family;
4
+ sans-serif !default;
5
+ $heading-font-family: $base-font-family !default;
6
6
 
7
- $base-font-size: 1em;
7
+ $base-font-size: 1em !default;
8
8
 
9
- $bold-font-weight: 700;
9
+ $bold-font-weight: 700 !default;
10
10
 
11
- $base-line-height: 1.5;
12
- $heading-line-height: 1.2;
11
+ $base-line-height: 1.5 !default;
12
+ $heading-line-height: 1.2 !default;
13
13
 
14
14
  // Other Sizes
15
- $base-border-radius: 4px;
16
- $base-spacing: $base-line-height * 1em;
17
- $small-spacing: $base-spacing / 2;
15
+ $base-border-radius: 4px !default;
16
+ $base-spacing: $base-line-height * 1em !default;
17
+ $small-spacing: $base-spacing / 2 !default;
18
18
 
19
19
  // Colors
20
- $white: #fff;
21
- $black: #000;
20
+ $white: #fff !default;
21
+ $black: #000 !default;
22
22
 
23
- $blue: #1976d2;
24
- $red: #d32f2f;
25
- $light-yellow: #f0cd66;
26
- $light-green: #4ab471;
23
+ $blue: #1976d2 !default;
24
+ $red: #d32f2f !default;
25
+ $light-yellow: #f0cd66 !default;
26
+ $light-green: #4ab471 !default;
27
27
 
28
- $grey-0: #f6f7f7;
29
- $grey-1: #dfe0e1;
30
- $grey-2: #cfd8dc;
31
- $grey-7: #293f54;
28
+ $grey-0: #f6f7f7 !default;
29
+ $grey-1: #dfe0e1 !default;
30
+ $grey-2: #cfd8dc !default;
31
+ $grey-5: #adb5bd !default;
32
+ $grey-7: #293f54 !default;
32
33
 
33
- $hint-grey: #7b808c;
34
+ $hint-grey: #7b808c !default;
34
35
 
35
36
  // Font Colors
36
- $base-font-color: $grey-7;
37
- $action-color: $blue;
37
+ $base-font-color: $grey-7 !default;
38
+ $action-color: $blue !default;
38
39
 
39
40
  // Background Colors
40
- $base-background-color: $grey-0;
41
+ $base-background-color: $grey-0 !default;
41
42
 
42
43
  // Focus
43
44
  $focus-outline-color: transparentize($action-color, 0.4);
@@ -54,9 +55,9 @@ $flash-colors: (
54
55
  );
55
56
 
56
57
  // Border
57
- $base-border-color: $grey-1;
58
- $base-border: 1px solid $base-border-color;
58
+ $base-border-color: $grey-1 !default;
59
+ $base-border: 1px solid $base-border-color !default;
59
60
 
60
61
  // Transitions
61
- $base-duration: 250ms;
62
- $base-timing: ease-in-out;
62
+ $base-duration: 250ms !default;
63
+ $base-timing: ease-in-out !default;
@@ -4,7 +4,9 @@ module Administrate
4
4
 
5
5
  def index
6
6
  search_term = params[:search].to_s.strip
7
- resources = Administrate::Search.new(resource_resolver, search_term).run
7
+ resources = Administrate::Search.new(scoped_resource,
8
+ dashboard_class,
9
+ search_term).run
8
10
  resources = resources.includes(*resource_includes) if resource_includes.any?
9
11
  resources = order.apply(resources)
10
12
  resources = resources.page(params[:page]).per(records_per_page)
@@ -78,9 +80,9 @@ module Administrate
78
80
  end
79
81
 
80
82
  helper_method :valid_action?
81
- def valid_action?(name, resource = resource_name)
83
+ def valid_action?(name, resource = resource_class)
82
84
  !!routes.detect do |controller, action|
83
- controller == resource.to_s.pluralize && action == name.to_s
85
+ controller == resource.to_s.underscore.pluralize && action == name.to_s
84
86
  end
85
87
  end
86
88
 
@@ -97,7 +99,7 @@ module Administrate
97
99
  end
98
100
 
99
101
  def dashboard
100
- @_dashboard ||= resource_resolver.dashboard_class.new
102
+ @_dashboard ||= dashboard_class.new
101
103
  end
102
104
 
103
105
  def requested_resource
@@ -105,7 +107,11 @@ module Administrate
105
107
  end
106
108
 
107
109
  def find_resource(param)
108
- resource_class.find(param)
110
+ scoped_resource.find(param)
111
+ end
112
+
113
+ def scoped_resource
114
+ resource_class.default_scoped
109
115
  end
110
116
 
111
117
  def resource_includes
@@ -113,10 +119,12 @@ module Administrate
113
119
  end
114
120
 
115
121
  def resource_params
116
- params.require(resource_name).permit(dashboard.permitted_attributes)
122
+ params.require(resource_class.model_name.param_key).
123
+ permit(dashboard.permitted_attributes)
117
124
  end
118
125
 
119
- delegate :resource_class, :resource_name, :namespace, to: :resource_resolver
126
+ delegate :dashboard_class, :resource_class, :resource_name, :namespace,
127
+ to: :resource_resolver
120
128
  helper_method :namespace
121
129
  helper_method :resource_name
122
130
 
@@ -19,21 +19,11 @@ module Administrate
19
19
  )
20
20
  end
21
21
 
22
- def svg_tag(asset, svg_id, options = {})
23
- svg_attributes = {
24
- "xlink:href".freeze => "#{asset_url(asset)}##{svg_id}",
25
- height: "100%",
26
- width: "100%",
27
- }
28
- xml_attributes = {
29
- "xmlns".freeze => "http://www.w3.org/2000/svg".freeze,
30
- "xmlns:xlink".freeze => "http://www.w3.org/1999/xlink".freeze,
31
- height: options[:height],
32
- width: options[:width],
33
- }.delete_if { |_key, value| value.nil? }
34
-
35
- content_tag :svg, xml_attributes do
36
- content_tag :use, nil, svg_attributes
22
+ def sort_order(order)
23
+ case order
24
+ when "asc" then "ascending"
25
+ when "desc" then "descending"
26
+ else "none"
37
27
  end
38
28
  end
39
29
 
@@ -18,36 +18,36 @@ to display a collection of resources in an HTML table.
18
18
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
19
19
  %>
20
20
 
21
- <table aria-labelledby="page-title">
21
+ <table aria-labelledby="<%= table_title %>">
22
22
  <thead>
23
23
  <tr>
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) %>
28
- " scope="col">
27
+ cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>"
28
+ scope="col"
29
+ role="columnheader"
30
+ aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
29
31
  <%= link_to(sanitized_order_params.merge(
30
32
  collection_presenter.order_params_for(attr_name)
31
33
  )) do %>
32
34
  <%= t(
33
- "helpers.label.#{resource_name}.#{attr_name}",
35
+ "helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
34
36
  default: attr_name.to_s,
35
37
  ).titleize %>
36
38
 
37
39
  <% if collection_presenter.ordered_by?(attr_name) %>
38
40
  <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
39
- <%= svg_tag(
40
- "administrate/sort_arrow.svg",
41
- "sort_arrow",
42
- width: "13",
43
- height: "13"
44
- ) %>
41
+ <svg aria-hidden="true">
42
+ <use xlink:href="#icon-up-caret" />
43
+ </svg>
45
44
  </span>
46
45
  <% end %>
47
46
  <% end %>
48
47
  </th>
49
48
  <% end %>
50
- <% [valid_action?(:edit), valid_action?(:destroy)].count(true).times do %>
49
+ <% [valid_action?(:edit, collection_presenter.resource_name),
50
+ valid_action?(:destroy, collection_presenter.resource_name)].count(true).times do %>
51
51
  <th scope="col"></th>
52
52
  <% end %>
53
53
  </tr>
@@ -57,7 +57,9 @@ to display a collection of resources in an HTML table.
57
57
  <% resources.each do |resource| %>
58
58
  <tr class="js-table-row"
59
59
  tabindex="0"
60
- <%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) if valid_action? :show -%>
60
+ <% if valid_action? :show, collection_presenter.resource_name %>
61
+ <%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) %>
62
+ <% end %>
61
63
  >
62
64
  <% collection_presenter.attributes_for(resource).each do |attribute| %>
63
65
  <td class="cell-data cell-data--<%= attribute.html_class %>">
@@ -69,7 +71,7 @@ to display a collection of resources in an HTML table.
69
71
  </td>
70
72
  <% end %>
71
73
 
72
- <% if valid_action? :edit %>
74
+ <% if valid_action? :edit, collection_presenter.resource_name %>
73
75
  <td><%= link_to(
74
76
  t("administrate.actions.edit"),
75
77
  [:edit, namespace, resource],
@@ -77,7 +79,7 @@ to display a collection of resources in an HTML table.
77
79
  ) %></td>
78
80
  <% end %>
79
81
 
80
- <% if valid_action? :destroy %>
82
+ <% if valid_action? :destroy, collection_presenter.resource_name %>
81
83
  <td><%= link_to(
82
84
  t("administrate.actions.destroy"),
83
85
  [namespace, resource],