administrate 0.7.0 → 0.8.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 (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
@@ -0,0 +1,13 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
2
+ <symbol id="icon-cancel" viewBox="0 0 48 48">
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
+ </symbol>
5
+
6
+ <symbol id="icon-eyeglass" viewBox="0 0 48 48">
7
+ <path d="M27.885 32.515c-2.864 1.966-6.333 3.116-10.07 3.116C7.976 35.63 0 27.656 0 17.817 0 7.976 7.976 0 17.816 0S35.63 7.976 35.63 17.816c0 3.736-1.15 7.205-3.115 10.07l14.53 14.53c1.278 1.277 1.275 3.352 0 4.628-1.28 1.278-3.353 1.278-4.63 0l-14.53-14.53zm-10.07-3.736c6.056 0 10.964-4.91 10.964-10.964 0-6.055-4.91-10.964-10.964-10.964-6.055 0-10.964 4.91-10.964 10.964 0 6.055 4.91 10.963 10.964 10.963z" />
8
+ </symbol>
9
+
10
+ <symbol id="icon-up-caret" viewBox="0 0 48 48">
11
+ <path d="M2.988 33.02c-1.66 0-1.943-.81-.618-1.824l20-15.28c.878-.672 2.31-.67 3.188 0l20.075 15.288c1.316 1.003 1.048 1.816-.62 1.816H2.987z" />
12
+ </symbol>
13
+ </svg>
@@ -1,21 +1,25 @@
1
1
  <form class="search" role="search">
2
- <span class="search__icon">
3
- <%= svg_tag "administrate/search.svg", "search", width: 16, height: 16 %>
4
- </span>
5
- <input
6
- type="text"
7
- name="search"
8
- class="search__input"
9
- placeholder="Search"
10
- value="<%= search_term %>"
11
- aria-label="Search"
12
- />
13
- <span class="search__hint">
14
- Press enter to search
15
- </span>
16
- <span class="search__clear">
17
- <%= link_to clear_search_params do %>
18
- <%= svg_tag "administrate/cancel.svg", "cancel-search", width: 16, height: 16 %>
19
- <% end %>
20
- </span>
2
+ <label class="search__label" for="search">
3
+ <svg class="search__eyeglass-icon" role="img">
4
+ <title>
5
+ <%= t("administrate.search.label", resource: resource_name) %>
6
+ </title>
7
+ <use xlink:href="#icon-eyeglass" />
8
+ </svg>
9
+ </label>
10
+
11
+ <input class="search__input"
12
+ id="search"
13
+ type="search"
14
+ name="search"
15
+ placeholder="<%= t("administrate.search.label",
16
+ resource: resource_name) %>"
17
+ value="<%= search_term %>">
18
+
19
+ <%= link_to clear_search_params, class: "search__clear-link" do %>
20
+ <svg class="search__clear-icon" role="img">
21
+ <title><%= t("administrate.search.clear") %></title>
22
+ <use xlink:href="#icon-cancel" />
23
+ </svg>
24
+ <% end %>
21
25
  </form>
@@ -27,17 +27,19 @@ It renders the `_table` partial to display details about the resources.
27
27
  <%= display_resource_name(page.resource_name) %>
28
28
  <% end %>
29
29
 
30
- <% content_for(:search) do %>
31
- <% if show_search_bar %>
32
- <%= render "search", search_term: search_term %>
33
- <% end %>
34
- <% end %>
35
-
36
30
  <header class="main-content__header" role="banner">
37
31
  <h1 class="main-content__page-title" id="page-title">
38
32
  <%= content_for(:title) %>
39
33
  </h1>
40
34
 
35
+ <% if show_search_bar %>
36
+ <%= render(
37
+ "search",
38
+ search_term: search_term,
39
+ resource_name: display_resource_name(page.resource_name)
40
+ ) %>
41
+ <% end %>
42
+
41
43
  <div>
42
44
  <%= link_to(
43
45
  "#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
@@ -48,6 +50,12 @@ It renders the `_table` partial to display details about the resources.
48
50
  </header>
49
51
 
50
52
  <section class="main-content__body main-content__body--flush">
51
- <%= render "collection", collection_presenter: page, resources: resources %>
53
+ <%= render(
54
+ "collection",
55
+ collection_presenter: page,
56
+ resources: resources,
57
+ table_title: "page-title"
58
+ ) %>
59
+
52
60
  <%= paginate resources %>
53
61
  </section>
@@ -35,7 +35,7 @@ as well as a link to its edit page.
35
35
  <section class="main-content__body">
36
36
  <dl>
37
37
  <% page.attributes.each do |attribute| %>
38
- <dt class="attribute-label">
38
+ <dt class="attribute-label" id="<%= attribute.name %>">
39
39
  <%= t(
40
40
  "helpers.label.#{resource_name}.#{attribute.name}",
41
41
  default: attribute.name.titleize,
@@ -22,7 +22,8 @@ from the associated resource class's dashboard.
22
22
  <%= render(
23
23
  "collection",
24
24
  collection_presenter: field.associated_collection,
25
- resources: field.resources(params[field.name])
25
+ resources: field.resources(params[field.name]),
26
+ table_title: field.name
26
27
  ) %>
27
28
 
28
29
  <% if field.more_than_limit? %>
@@ -3,8 +3,7 @@
3
3
 
4
4
  This partial renders an input element for has_one relationships.
5
5
 
6
- At the moment, has_one form fields are not supported,
7
- so this partial renders a message to that effect.
6
+ The form will be rendered as nested_from to parent relationship.
8
7
 
9
8
  ## Local variables:
10
9
 
@@ -17,10 +16,13 @@ so this partial renders a message to that effect.
17
16
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
18
17
  %>
19
18
 
20
- <div class="field-unit__label">
21
- <%= f.label field.attribute %>
22
- </div>
23
-
24
- <div class="field-unit__field">
25
- <%= t("administrate.fields.has_one.not_supported") %>
26
- </div>
19
+ <%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
20
+ <fieldset class="field-unit--nested">
21
+ <legend><%= field.nested_form.resource_name.titleize %></legend>
22
+ <% field.nested_form.attributes.each do |attribute| -%>
23
+ <div class="field-unit field-unit--<%= attribute.html_class %>">
24
+ <%= render_field attribute, f: has_one_f %>
25
+ </div>
26
+ <% end -%>
27
+ </fieldset>
28
+ <% end %>
@@ -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
- By default, the relationship is rendered as a link to the associated object.
7
+ All fields of has_one relationship would be rendered
8
8
 
9
9
  ## Local variables:
10
10
 
@@ -16,8 +16,25 @@ By default, the relationship is rendered as a link to the associated object.
16
16
  %>
17
17
 
18
18
  <% if field.data %>
19
- <%= link_to(
20
- field.display_associated_resource,
21
- [namespace, field.data],
22
- ) %>
19
+ <fieldset class="attribute--nested">
20
+ <legend>
21
+ <%= link_to(
22
+ field.display_associated_resource,
23
+ [namespace, field.data],
24
+ ) %>
25
+ </legend>
26
+ <% field.nested_form.attributes.each do |attribute| -%>
27
+ <div>
28
+ <dt class="attribute-label">
29
+ <%= t(
30
+ "helpers.label.#{resource_name}.#{attribute.name}",
31
+ default: attribute.name.titleize,
32
+ ) %>
33
+ </dt>
34
+ <dd class="attribute-data attribute-data--<%= attribute.html_class %>">
35
+ <%= attribute.data %>
36
+ </dd>
37
+ </div>
38
+ <% end -%>
39
+ </fieldset>
23
40
  <% end %>
@@ -25,11 +25,12 @@ By default, it renders:
25
25
  <%= csrf_meta_tags %>
26
26
  </head>
27
27
  <body>
28
+ <%= render "icons" %>
29
+
28
30
  <div class="app-container">
29
31
  <%= render "navigation" -%>
30
32
 
31
33
  <main class="main-content" role="main">
32
- <%= content_for(:search) %>
33
34
  <%= render "flashes" -%>
34
35
  <%= yield %>
35
36
  </main>
@@ -23,3 +23,6 @@ ar:
23
23
  not_supported: "غير مدعمه \"Polymorphic\" هذه العلاقه"
24
24
  has_one:
25
25
  not_supported: "غير مدعمه \"HasOne\" هذه العلاقه"
26
+ search:
27
+ clear: مسح البحث
28
+ label: بحث %{resource}
@@ -23,3 +23,6 @@ da:
23
23
  not_supported: "Formularer med polymorphic relationships er ikke understøttede."
24
24
  has_one:
25
25
  not_supported: "Formularer med has_one associationer er ikke understøttede."
26
+ search:
27
+ clear: Ryd søgning
28
+ label: Søg %{resource}
@@ -23,3 +23,6 @@ de:
23
23
  not_supported: Polymorphe Beziehungen werden nicht unterstützt.
24
24
  has_one:
25
25
  not_supported: HasOne Beziehungen werden nicht unterstützt.
26
+ search:
27
+ clear: Saubere Suche
28
+ label: Suche %{resource}
@@ -23,3 +23,6 @@ en:
23
23
  not_supported: Polymorphic relationship forms are not supported.
24
24
  has_one:
25
25
  not_supported: HasOne relationship forms are not supported.
26
+ search:
27
+ clear: Clear search
28
+ label: Search %{resource}
@@ -23,3 +23,6 @@ es:
23
23
  not_supported: Los formularios con relaciones polimórficas no están soportados.
24
24
  has_one:
25
25
  not_supported: Los formularios con relaciones HasOne no están soportados.
26
+ search:
27
+ clear: Borrar búsqueda
28
+ label: Buscar %{resource}
@@ -23,3 +23,6 @@ fr:
23
23
  not_supported: Les relations polymorphiques dans les formulaires ne sont pas supportées.
24
24
  has_one:
25
25
  not_supported: Les relations HasOne dans les formulaires ne sont pas supportées.
26
+ search:
27
+ clear: Effacer la recherche
28
+ label: Chercher %{resource}
@@ -23,3 +23,6 @@ it:
23
23
  not_supported: Associazioni polimorfiche non ancora supportate. Spiacenti!
24
24
  has_one:
25
25
  not_supported: Associazioni HasOne non ancora supportate. Spiacenti!
26
+ search:
27
+ clear: Cancella ricerca
28
+ label: Ricerca %{resource}
@@ -23,3 +23,6 @@ ja:
23
23
  not_supported: フォームでは「多:多」の関連をサポートしていません。
24
24
  has_one:
25
25
  not_supported: フォームでは「1:1」の関連をサポートしていません。
26
+ search:
27
+ clear: 検索をクリアする
28
+ label: サーチ %{resource}
@@ -23,3 +23,6 @@ ko:
23
23
  not_supported: 상속 관계에 대한 양식은 제공되지 않습니다.
24
24
  has_one:
25
25
  not_supported: 일대일 관계에 대한 양식은 제공되지 않습니다.
26
+ search:
27
+ clear: 검색 초기화
28
+ label: "%{resource} 검색"
@@ -23,3 +23,6 @@ nl:
23
23
  not_supported: Polymorphische relaties formulieren worden niet ondersteund.
24
24
  has_one:
25
25
  not_supported: HasOne relaties formulieren worden niet ondersteund.
26
+ search:
27
+ clear: CDuidelijke zoek
28
+ label: Zoeken %{resource}
@@ -23,3 +23,6 @@ pl:
23
23
  not_supported: Relacje polimorficzne nie są obsługiwane.
24
24
  has_one:
25
25
  not_supported: Relacje jeden-do-jednego nie są obsługiwane.
26
+ search:
27
+ clear: Wyczyść wyszukiwanie
28
+ label: Szukanie %{resource}
@@ -24,3 +24,6 @@ pt-BR:
24
24
  not_supported: Relações polimórficas nos formulários não são suportadas.
25
25
  has_one:
26
26
  not_supported: Relações um para muitos nos formulários não são suportadas.
27
+ search:
28
+ clear: Limpar pesquisa
29
+ label: Pesquisa %{resource}
@@ -24,3 +24,6 @@ pt:
24
24
  not_supported: Relações polimórficas nos formulários não são suportadas.
25
25
  has_one:
26
26
  not_supported: Relações um para muitos nos formulários não são suportadas.
27
+ search:
28
+ clear: Limpar pesquisa
29
+ label: Pesquisa %{resource}
@@ -23,3 +23,6 @@ ru:
23
23
  not_supported: Полиморфные отношения в формах не поддерживаются.
24
24
  has_one:
25
25
  not_supported: HasOne отношения в формах не поддерживаются.
26
+ search:
27
+ clear: Очистить поиск
28
+ label: Поиск %{resource}
@@ -23,3 +23,6 @@ sv:
23
23
  not_supported: Formulär med polymorfiska relationer stöds inte.
24
24
  has_one:
25
25
  not_supported: Formulär med HasOne relationer stöds inte.
26
+ search:
27
+ clear: Rensa sökningen
28
+ label: Sök %{resource}
@@ -23,3 +23,6 @@ uk:
23
23
  not_supported: Поліморфні відношення у формах не підтримуються.
24
24
  has_one:
25
25
  not_supported: HasOne відношення у формах не підтримуються.
26
+ search:
27
+ clear: Очистити пошук
28
+ label: пошук %{resource}
@@ -23,3 +23,6 @@ vi:
23
23
  not_supported: Quan hệ Polymorphic chưa được hỗ trợ.
24
24
  has_one:
25
25
  not_supported: Quan hệ HasOne chưa được hỗ trợ.
26
+ search:
27
+ clear: Tìm kiếm rõ ràng
28
+ label: Tìm kiếm %{resource}
@@ -23,3 +23,6 @@ zh-CN:
23
23
  not_supported: Polymorphic 关系暂不支持
24
24
  has_one:
25
25
  not_supported: HasOne 关系暂不支持.
26
+ search:
27
+ clear: 清除搜索
28
+ label: 搜索 %{resource}
@@ -23,3 +23,6 @@ zh-TW:
23
23
  not_supported: 表單尚未支援 Polymorphic 關聯。
24
24
  has_one:
25
25
  not_supported: 表單尚未支援 HasOne 關聯。
26
+ search:
27
+ clear: 清除搜索
28
+ label: 搜索 %{resource}
@@ -28,5 +28,15 @@ class Admin::FoosController < Admin::ApplicationController
28
28
  # def find_resource(param)
29
29
  # Foo.find_by!(slug: param)
30
30
  # end
31
+ #
32
+ # Override this if you have certain roles that require a subset
33
+ # this will be used to set the records shown on the `index` action.
34
+ # def scoped_resource
35
+ # if current_user.super_admin?
36
+ # resource_class
37
+ # else
38
+ # resource_class.with_less_stuff
39
+ # end
40
+ # end
31
41
  end
32
42
  ```
@@ -12,7 +12,7 @@ call the generators with no arguments.
12
12
  ```bash
13
13
  rails generate administrate:views:index
14
14
  # -> app/views/admin/application/index.html.erb
15
- # -> app/views/admin/application/_table.html.erb
15
+ # -> app/views/admin/application/_collection.html.erb
16
16
 
17
17
  rails generate administrate:views:show
18
18
  # -> app/views/admin/application/show.html.erb
@@ -43,7 +43,7 @@ pass in the resource name to the view generators.
43
43
  ```bash
44
44
  rails generate administrate:views:index User
45
45
  # -> app/views/admin/users/index.html.erb
46
- # -> app/views/admin/users/_table.html.erb
46
+ # -> app/views/admin/users/_collection.html.erb
47
47
 
48
48
  rails generate administrate:views:show User
49
49
  # -> app/views/admin/users/show.html.erb
@@ -2,7 +2,6 @@ require "datetime_picker_rails"
2
2
  require "jquery-rails"
3
3
  require "kaminari"
4
4
  require "momentjs-rails"
5
- require "normalize-rails"
6
5
  require "sass-rails"
7
6
  require "selectize-rails"
8
7
  require "sprockets/railtie"
@@ -23,13 +22,6 @@ module Administrate
23
22
  @@javascripts = []
24
23
  @@stylesheets = []
25
24
 
26
- Engine.config.assets.precompile << %w(
27
- administrate/cancel.svg
28
- administrate/dropdown.svg
29
- administrate/search.svg
30
- administrate/sort_arrow.svg
31
- )
32
-
33
25
  def self.add_javascript(script)
34
26
  @@javascripts << script
35
27
  end
@@ -20,6 +20,7 @@ module Administrate
20
20
  @attribute = attribute
21
21
  @data = data
22
22
  @page = page
23
+ @resource = options.delete(:resource)
23
24
  @options = options
24
25
  end
25
26
 
@@ -39,7 +40,7 @@ module Administrate
39
40
  "/fields/#{self.class.field_type}/#{page}"
40
41
  end
41
42
 
42
- attr_reader :attribute, :data, :page
43
+ attr_reader :attribute, :data, :page, :resource
43
44
 
44
45
  protected
45
46
 
@@ -11,7 +11,8 @@ module Administrate
11
11
  attr_reader :deferred_class, :options
12
12
 
13
13
  def new(*args)
14
- deferred_class.new(*args, options)
14
+ new_options = args.last.respond_to?(:merge) ? args.pop : {}
15
+ deferred_class.new(*args, options.merge(new_options))
15
16
  end
16
17
 
17
18
  def ==(other)
@@ -26,7 +26,9 @@ module Administrate
26
26
  end
27
27
 
28
28
  def selected_options
29
- data && data.map { |object| object.send(primary_key) }
29
+ return if data.empty?
30
+
31
+ data.map { |object| object.send(primary_key) }
30
32
  end
31
33
 
32
34
  def limit
@@ -46,6 +48,10 @@ module Administrate
46
48
  data.count(:all) > limit
47
49
  end
48
50
 
51
+ def data
52
+ @data ||= associated_class.none
53
+ end
54
+
49
55
  private
50
56
 
51
57
  def includes