administrate 0.4.0 → 0.5.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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/table.js +8 -3
  3. data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
  4. data/app/assets/stylesheets/administrate/components/_flashes.scss +19 -7
  5. data/app/controllers/administrate/application_controller.rb +12 -5
  6. data/app/helpers/administrate/application_helper.rb +10 -6
  7. data/app/views/administrate/application/_collection.html.erb +20 -15
  8. data/app/views/administrate/application/_flashes.html.erb +1 -1
  9. data/app/views/administrate/application/_form.html.erb +1 -1
  10. data/app/views/administrate/application/edit.html.erb +3 -3
  11. data/app/views/administrate/application/index.html.erb +2 -2
  12. data/app/views/administrate/application/new.html.erb +2 -2
  13. data/app/views/administrate/application/show.html.erb +3 -3
  14. data/app/views/fields/belongs_to/_index.html.erb +8 -4
  15. data/app/views/fields/belongs_to/_show.html.erb +8 -4
  16. data/app/views/fields/has_many/_show.html.erb +2 -8
  17. data/config/locales/administrate.ar.yml +2 -0
  18. data/config/locales/administrate.da.yml +2 -0
  19. data/config/locales/administrate.de.yml +2 -0
  20. data/config/locales/administrate.en.yml +2 -0
  21. data/config/locales/administrate.es.yml +2 -0
  22. data/config/locales/administrate.fr.yml +2 -0
  23. data/config/locales/administrate.it.yml +2 -0
  24. data/config/locales/administrate.ja.yml +2 -0
  25. data/config/locales/administrate.ko.yml +25 -0
  26. data/config/locales/administrate.nl.yml +2 -0
  27. data/config/locales/administrate.pl.yml +2 -0
  28. data/config/locales/administrate.pt-BR.yml +2 -0
  29. data/config/locales/administrate.pt.yml +26 -0
  30. data/config/locales/administrate.ru.yml +2 -0
  31. data/config/locales/administrate.sv.yml +2 -0
  32. data/config/locales/administrate.uk.yml +2 -0
  33. data/config/locales/administrate.vi.yml +2 -0
  34. data/config/locales/administrate.zh-CN.yml +2 -0
  35. data/config/locales/administrate.zh-TW.yml +2 -0
  36. data/docs/adding_custom_field_types.md +79 -0
  37. data/docs/authentication.md +60 -0
  38. data/docs/customizing_attribute_partials.md +34 -0
  39. data/docs/customizing_controller_actions.md +32 -0
  40. data/docs/customizing_dashboards.md +143 -0
  41. data/docs/customizing_page_views.md +78 -0
  42. data/docs/getting_started.md +60 -0
  43. data/lib/administrate/field/has_many.rb +8 -3
  44. data/lib/administrate/field/number.rb +10 -2
  45. data/lib/administrate/namespace.rb +10 -10
  46. data/lib/administrate/resource_resolver.rb +1 -1
  47. data/lib/administrate/version.rb +1 -1
  48. data/lib/generators/administrate/routes/templates/routes.rb.erb +2 -2
  49. metadata +25 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6a8554f3a353107a488efb3fec4ef4b30f8c936
4
- data.tar.gz: 7d0941da63a83224d077819a1d7976ded1d40288
3
+ metadata.gz: ab74a9176bf14060fc26e4346b4fca17b2672371
4
+ data.tar.gz: 990b4f062e37a68c7be97ee5104323d00e99a4ad
5
5
  SHA512:
6
- metadata.gz: f0b5072a78e97d7d320ae833c63e5f3d17294c2344a7597e392c1c8ca2eea89445bfbb23cb7943b09392457842b448589be7244c29df8a7306ba7bc7d89df9a7
7
- data.tar.gz: e67b6690e0ba8d3fbbe579d780f4780998e49bc27d67585cafae7f1741b7fd63e3028c477e95433f23083733dbd07b1e3b9bc3888d67ec4a9f16de52e89bd894
6
+ metadata.gz: 4f04b6bea3d168597600b14b390ec6ea6bc14836cf3236b34a0982b4067468c161b8014f253e8d4ca7ccac898aaac8ca9093dcf7143cc32aa51b8f6d54834c98
7
+ data.tar.gz: ec346e46a0ed10bbd38d14f5bffc2859fd8047467a1be90360a9b8fdc3dc8d7ebc67aa7472d9537c99527e7fd10960806a58502b88d7f6e4fddcb86e529adc72
@@ -2,12 +2,17 @@ $(function() {
2
2
  var keycodes = { space: 32, enter: 13 };
3
3
 
4
4
  var visitDataUrl = function(event) {
5
- if (event.type=="click" ||
5
+ if (event.type == "click" ||
6
6
  event.keyCode == keycodes.space ||
7
7
  event.keyCode == keycodes.enter) {
8
8
 
9
- if(!event.target.href) {
10
- window.location = $(event.target).closest("tr").data("url");
9
+ if (event.target.href) {
10
+ return;
11
+ }
12
+
13
+ var dataUrl = $(event.target).closest("tr").data("url");
14
+ if (dataUrl) {
15
+ window.location = dataUrl;
11
16
  }
12
17
  }
13
18
  };
@@ -7,7 +7,7 @@
7
7
  }
8
8
 
9
9
  .preserve-whitespace {
10
- white-space: pre;
10
+ white-space: pre-wrap;
11
11
  word-wrap: break-word;
12
12
  }
13
13
 
@@ -1,15 +1,27 @@
1
- @each $flash-type, $flash-color in $flash-colors {
2
- .flash--#{$flash-type} {
3
- background-color: $flash-color;
4
- color: darken($flash-color, 60%);
5
- padding: $small-spacing $base-spacing;
1
+ $base-spacing: 1.5em !default;
2
+ $flashes: (
3
+ "alert": #fff6bf,
4
+ "error": #fbe3e4,
5
+ "notice": #e5edf8,
6
+ "success": #e6efc2,
7
+ ) !default;
8
+
9
+ @each $flash-type, $color in $flashes {
10
+ .flash-#{$flash-type} {
11
+ background-color: $color;
12
+ color: shade($color, 60%);
13
+ display: block;
14
+ margin-bottom: $base-spacing / 2;
15
+ padding: $base-spacing / 2;
16
+ text-align: center;
6
17
 
7
18
  a {
8
- color: darken($flash-color, 70%);
19
+ color: shade($color, 70%);
20
+ text-decoration: underline;
9
21
 
10
22
  &:focus,
11
23
  &:hover {
12
- color: darken($flash-color, 90%);
24
+ color: shade($color, 90%);
13
25
  }
14
26
  }
15
27
  }
@@ -80,6 +80,17 @@ module Administrate
80
80
  end
81
81
  end
82
82
 
83
+ helper_method :valid_action?
84
+ def valid_action?(name, resource = resource_name)
85
+ !!routes.detect do |controller, action|
86
+ controller == resource.to_s.pluralize && action == name.to_s
87
+ end
88
+ end
89
+
90
+ def routes
91
+ @routes ||= Namespace.new(namespace).routes
92
+ end
93
+
83
94
  def records_per_page
84
95
  params[:per_page] || 20
85
96
  end
@@ -101,11 +112,7 @@ module Administrate
101
112
  end
102
113
 
103
114
  def resource_params
104
- params.require(resource_name).permit(*permitted_attributes)
105
- end
106
-
107
- def permitted_attributes
108
- dashboard.permitted_attributes
115
+ params.require(resource_name).permit(dashboard.permitted_attributes)
109
116
  end
110
117
 
111
118
  delegate :resource_class, :resource_name, :namespace, to: :resource_resolver
@@ -1,5 +1,7 @@
1
1
  module Administrate
2
2
  module ApplicationHelper
3
+ PLURAL_MANY_COUNT = 2.1
4
+
3
5
  def render_field(field, locals = {})
4
6
  locals.merge!(field: field)
5
7
  render locals: locals, partial: field.to_partial_path
@@ -12,7 +14,7 @@ module Administrate
12
14
  constantize.
13
15
  model_name.
14
16
  human(
15
- count: 0,
17
+ count: PLURAL_MANY_COUNT,
16
18
  default: resource_name.to_s.pluralize.titleize,
17
19
  )
18
20
  end
@@ -20,13 +22,15 @@ module Administrate
20
22
  def svg_tag(asset, svg_id, options = {})
21
23
  svg_attributes = {
22
24
  "xlink:href".freeze => "#{asset_url(asset)}##{svg_id}",
23
- height: options[:height],
24
- width: options[:width],
25
- }.delete_if { |_key, value| value.nil? }
25
+ height: "100%",
26
+ width: "100%",
27
+ }
26
28
  xml_attributes = {
27
29
  "xmlns".freeze => "http://www.w3.org/2000/svg".freeze,
28
30
  "xmlns:xlink".freeze => "http://www.w3.org/1999/xlink".freeze,
29
- }
31
+ height: options[:height],
32
+ width: options[:width],
33
+ }.delete_if { |_key, value| value.nil? }
30
34
 
31
35
  content_tag :svg, xml_attributes do
32
36
  content_tag :use, nil, svg_attributes
@@ -34,7 +38,7 @@ module Administrate
34
38
  end
35
39
 
36
40
  def sanitized_order_params
37
- params.permit(:search, :id, :order, :page, :per_page, :direction)
41
+ params.permit(:search, :id, :order, :page, :per_page, :direction, :orders)
38
42
  end
39
43
 
40
44
  def clear_search_params
@@ -47,16 +47,17 @@ to display a collection of resources in an HTML table.
47
47
  <% end %>
48
48
  </th>
49
49
  <% end %>
50
- <th colspan="2" scope="col"></th>
50
+ <% [valid_action?(:edit), valid_action?(:destroy)].count(true).times do %>
51
+ <th scope="col"></th>
52
+ <% end %>
51
53
  </tr>
52
54
  </thead>
53
55
 
54
56
  <tbody>
55
57
  <% resources.each do |resource| %>
56
58
  <tr class="table__row"
57
- role="link"
58
59
  tabindex="0"
59
- data-url="<%= polymorphic_path([namespace, resource]) -%>"
60
+ <%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) if valid_action? :show -%>
60
61
  >
61
62
  <% collection_presenter.attributes_for(resource).each do |attribute| %>
62
63
  <td class="cell-data cell-data--<%= attribute.html_class %>">
@@ -68,19 +69,23 @@ to display a collection of resources in an HTML table.
68
69
  </td>
69
70
  <% end %>
70
71
 
71
- <td><%= link_to(
72
- t("administrate.actions.edit"),
73
- [:edit, namespace, resource],
74
- class: "action-edit",
75
- ) %></td>
72
+ <% if valid_action? :edit %>
73
+ <td><%= link_to(
74
+ t("administrate.actions.edit"),
75
+ [:edit, namespace, resource],
76
+ class: "action-edit",
77
+ ) %></td>
78
+ <% end %>
76
79
 
77
- <td><%= link_to(
78
- t("administrate.actions.destroy"),
79
- [namespace, resource],
80
- class: "table__action--destroy",
81
- method: :delete,
82
- data: { confirm: t("administrate.actions.confirm") }
83
- ) %></td>
80
+ <% if valid_action? :destroy %>
81
+ <td><%= link_to(
82
+ t("administrate.actions.destroy"),
83
+ [namespace, resource],
84
+ class: "table__action--destroy",
85
+ method: :delete,
86
+ data: { confirm: t("administrate.actions.confirm") }
87
+ ) %></td>
88
+ <% end %>
84
89
  </tr>
85
90
  <% end %>
86
91
  </tbody>
@@ -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 %></div>
18
18
  <% end -%>
19
19
  </div>
20
20
  <% end %>
@@ -24,7 +24,7 @@ and renders all form fields for a resource's editable attributes.
24
24
 
25
25
  <ul>
26
26
  <% page.resource.errors.full_messages.each do |message| %>
27
- <li><%= message %></li>
27
+ <li class="flash-error"><%= message %></li>
28
28
  <% end %>
29
29
  </ul>
30
30
  </div>
@@ -15,16 +15,16 @@ 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) { "Edit #{page.page_title}" } %>
18
+ <% content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" } %>
19
19
 
20
20
  <header class="header">
21
21
  <h1 class="header__heading"><%= content_for(:title) %></h1>
22
22
  <div class="header__actions">
23
23
  <%= link_to(
24
- "Show #{page.page_title}",
24
+ "#{t("administrate.actions.show")} #{page.page_title}",
25
25
  [namespace, page.resource],
26
26
  class: "button",
27
- ) %>
27
+ ) if valid_action? :show %>
28
28
  </div>
29
29
  </header>
30
30
 
@@ -37,10 +37,10 @@ It renders the `_table` partial to display details about the resources.
37
37
  <h1 class="header__heading" id="page-title"><%= content_for(:title) %></h1>
38
38
  <div class="header__actions">
39
39
  <%= link_to(
40
- "New #{page.resource_name.titleize.downcase}",
40
+ "#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
41
41
  [:new, namespace, page.resource_name],
42
42
  class: "button",
43
- ) %>
43
+ ) if valid_action? :new %>
44
44
  </div>
45
45
  </header>
46
46
 
@@ -15,12 +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) { "New #{page.resource_name.titleize}" } %>
18
+ <% content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" } %>
19
19
 
20
20
  <header class="header">
21
21
  <h1 class="header__heading"><%= content_for(:title) %></h1>
22
22
  <div class="header__actions">
23
- <%= link_to 'Back', :back, class: "button" %>
23
+ <%= link_to t("administrate.actions.back"), :back, class: "button" %>
24
24
  </div>
25
25
  </header>
26
26
 
@@ -16,16 +16,16 @@ 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) { page.page_title } %>
19
+ <% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %>
20
20
 
21
21
  <header class="header">
22
22
  <h1 class="header__heading"><%= content_for(:title) %></h1>
23
23
  <div class="header__actions">
24
24
  <%= link_to(
25
- "Edit",
25
+ "#{t("administrate.actions.edit")} #{page.page_title}",
26
26
  [:edit, namespace, page.resource],
27
27
  class: "button",
28
- ) %>
28
+ ) if valid_action? :edit %>
29
29
  </div>
30
30
  </header>
31
31
 
@@ -16,8 +16,12 @@ 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
+ <% if valid_action?(:show, field.attribute) %>
20
+ <%= link_to(
21
+ field.display_associated_resource,
22
+ [namespace, field.data],
23
+ ) %>
24
+ <% else %>
25
+ <%= field.display_associated_resource %>
26
+ <% end %>
23
27
  <% end %>
@@ -16,8 +16,12 @@ 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
+ <% if valid_action?(:show, field.attribute) %>
20
+ <%= link_to(
21
+ field.display_associated_resource,
22
+ [namespace, field.data],
23
+ ) %>
24
+ <% else %>
25
+ <%= field.display_associated_resource %>
26
+ <% end %>
23
27
  <% end %>
@@ -22,17 +22,11 @@ from the associated resource class's dashboard.
22
22
  <%= render(
23
23
  "collection",
24
24
  collection_presenter: field.associated_collection,
25
- resources: field.resources
25
+ resources: field.resources(params[field.name])
26
26
  ) %>
27
27
 
28
28
  <% if field.more_than_limit? %>
29
- <span>
30
- <%= t(
31
- 'administrate.fields.has_many.more',
32
- count: field.limit,
33
- total_count: field.data.count(:all),
34
- ) %>
35
- </span>
29
+ <%= paginate field.resources(params[field.name]), param_name: "#{field.name}" %>
36
30
  <% end %>
37
31
 
38
32
  <% else %>
@@ -6,6 +6,8 @@ ar:
6
6
  destroy: "حذف"
7
7
  edit: "تعديل"
8
8
  show: "إظهار"
9
+ new: "جديد"
10
+ back: "الى الخلف"
9
11
  controller:
10
12
  create:
11
13
  success: ".بنجاح %{resource} لقد تم إنشاء"
@@ -6,6 +6,8 @@ da:
6
6
  destroy: Slet
7
7
  edit: Rediger
8
8
  show: Vis
9
+ new: Ny
10
+ back: Tilbage
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} blev oprettet."
@@ -6,6 +6,8 @@ de:
6
6
  destroy: Löschen
7
7
  edit: Editieren
8
8
  show: Anzeigen
9
+ new: Neu
10
+ back: Zurück
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} wurde erfolgreich erstellt."
@@ -6,6 +6,8 @@ en:
6
6
  destroy: Destroy
7
7
  edit: Edit
8
8
  show: Show
9
+ new: New
10
+ back: Back
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} was successfully created."
@@ -6,6 +6,8 @@ es:
6
6
  destroy: Destruir
7
7
  edit: Editar
8
8
  show: Mostrar
9
+ new: Nuevo
10
+ back: Volver
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} fue creado exitosamente."
@@ -6,6 +6,8 @@ fr:
6
6
  destroy: Supprimer
7
7
  edit: Modifier
8
8
  show: Détails
9
+ new: Création
10
+ back: Précédent
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} a été correctement créé(e)."
@@ -6,6 +6,8 @@ it:
6
6
  destroy: Elimina
7
7
  edit: Modifica
8
8
  show: Visualizza
9
+ new: Nuovo
10
+ back: Indietro
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource} è stato creato con successo."
@@ -6,6 +6,8 @@ ja:
6
6
  destroy: 削除
7
7
  edit: 編集
8
8
  show: 参照
9
+ new: 目新しい
10
+ back: バック
9
11
  controller:
10
12
  create:
11
13
  success: "%{resource}を作成しました。"
@@ -0,0 +1,25 @@
1
+ ---
2
+ ko:
3
+ administrate:
4
+ actions:
5
+ confirm: 괜찮습니까?
6
+ destroy: 삭제
7
+ edit: 편집
8
+ show: 보여주기
9
+ new: 새로운
10
+ back: 뒤로
11
+ controller:
12
+ create:
13
+ success: "%{resource} 가 성공적으로 생성되었습니다."
14
+ destroy:
15
+ success: "%{resource} 가 성공적으로 삭제되었습니다."
16
+ update:
17
+ success: "%{resource} 가 성공적으로 갱신되었습니다."
18
+ fields:
19
+ has_many:
20
+ more: "%{total_count} 개 중에서 %{count} 개"
21
+ none: 없음
22
+ polymorphic:
23
+ not_supported: 상속 관계에 대한 양식은 제공되지 않습니다.
24
+ has_one:
25
+ not_supported: 일대일 관계에 대한 양식은 제공되지 않습니다.