administrate 0.0.12 → 0.1.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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/administrate/dropdown.svg +3 -0
  3. data/app/assets/javascripts/administrate/components/_search.js +2 -1
  4. data/app/assets/javascripts/administrate/components/has_many_form.js +1 -1
  5. data/app/assets/stylesheets/administrate/application.scss +0 -1
  6. data/app/assets/stylesheets/administrate/base/_forms.scss +3 -3
  7. data/app/assets/stylesheets/administrate/base/_lists.scss +7 -7
  8. data/app/assets/stylesheets/administrate/base/_variables.scss +3 -0
  9. data/app/assets/stylesheets/administrate/components/_attributes.scss +13 -0
  10. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -8
  11. data/app/assets/stylesheets/administrate/components/_form.scss +32 -25
  12. data/app/assets/stylesheets/administrate/components/_header.scss +1 -1
  13. data/app/assets/stylesheets/administrate/components/_search.scss +1 -1
  14. data/app/assets/stylesheets/administrate/components/_table.scss +4 -0
  15. data/app/assets/stylesheets/administrate/mixins/_data_label.scss +8 -0
  16. data/app/assets/stylesheets/administrate/mixins/_mixins.scss +1 -0
  17. data/app/controllers/administrate/application_controller.rb +35 -38
  18. data/app/views/administrate/application/{_table.html.erb → _collection.html.erb} +26 -6
  19. data/app/views/administrate/application/_flashes.html.erb +13 -0
  20. data/app/views/administrate/application/_form.html.erb +23 -7
  21. data/app/views/administrate/application/_javascript.html.erb +9 -0
  22. data/app/views/administrate/application/_sidebar.html.erb +9 -0
  23. data/app/views/administrate/application/edit.html.erb +22 -3
  24. data/app/views/administrate/application/index.html.erb +31 -6
  25. data/app/views/administrate/application/new.html.erb +22 -3
  26. data/app/views/administrate/application/show.html.erb +24 -4
  27. data/app/views/fields/belongs_to/_form.html.erb +18 -0
  28. data/app/views/fields/belongs_to/_index.html.erb +17 -0
  29. data/app/views/fields/belongs_to/_show.html.erb +17 -0
  30. data/app/views/fields/boolean/_form.html.erb +17 -0
  31. data/app/views/fields/boolean/_index.html.erb +19 -1
  32. data/app/views/fields/boolean/_show.html.erb +19 -1
  33. data/app/views/fields/date_time/_form.html.erb +18 -0
  34. data/app/views/fields/date_time/_index.html.erb +18 -0
  35. data/app/views/fields/date_time/_show.html.erb +18 -0
  36. data/app/views/fields/email/_form.html.erb +17 -0
  37. data/app/views/fields/email/_index.html.erb +17 -0
  38. data/app/views/fields/email/_show.html.erb +17 -0
  39. data/app/views/fields/has_many/_form.html.erb +21 -0
  40. data/app/views/fields/has_many/_index.html.erb +18 -0
  41. data/app/views/fields/has_many/_show.html.erb +33 -3
  42. data/app/views/fields/has_one/_form.html.erb +21 -1
  43. data/app/views/fields/has_one/_index.html.erb +17 -0
  44. data/app/views/fields/has_one/_show.html.erb +17 -0
  45. data/app/views/fields/image/_form.html.erb +17 -0
  46. data/app/views/fields/image/_index.html.erb +17 -0
  47. data/app/views/fields/image/_show.html.erb +17 -0
  48. data/app/views/fields/number/_form.html.erb +17 -0
  49. data/app/views/fields/number/_index.html.erb +19 -1
  50. data/app/views/fields/number/_show.html.erb +19 -1
  51. data/app/views/fields/polymorphic/_form.html.erb +20 -0
  52. data/app/views/fields/polymorphic/_index.html.erb +18 -0
  53. data/app/views/fields/polymorphic/_show.html.erb +18 -0
  54. data/app/views/fields/string/_form.html.erb +17 -0
  55. data/app/views/fields/string/_index.html.erb +17 -0
  56. data/app/views/fields/string/_show.html.erb +17 -0
  57. data/app/views/fields/text/_form.html.erb +2 -0
  58. data/app/views/fields/text/_index.html.erb +1 -0
  59. data/app/views/fields/text/_show.html.erb +1 -0
  60. data/app/views/layouts/administrate/application.html.erb +15 -1
  61. data/config/locales/administrate.en.yml +14 -10
  62. data/lib/administrate/base_dashboard.rb +3 -2
  63. data/lib/administrate/engine.rb +1 -1
  64. data/lib/administrate/fields/has_many.rb +7 -3
  65. data/lib/administrate/fields/text.rb +21 -0
  66. data/lib/administrate/page/{table.rb → collection.rb} +2 -6
  67. data/lib/administrate/version.rb +1 -1
  68. data/lib/administrate/view_generator.rb +27 -0
  69. data/lib/generators/administrate/dashboard/dashboard_generator.rb +7 -1
  70. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +16 -10
  71. data/lib/generators/administrate/field/field_generator.rb +31 -0
  72. data/lib/generators/administrate/field/templates/_form.html.erb +2 -0
  73. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  74. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  75. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  76. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  77. data/lib/generators/administrate/views/field_generator.rb +36 -0
  78. data/lib/generators/administrate/views/form_generator.rb +15 -0
  79. data/lib/generators/administrate/views/index_generator.rb +16 -0
  80. data/lib/generators/administrate/views/new_generator.rb +16 -0
  81. data/lib/generators/administrate/views/show_generator.rb +15 -0
  82. data/lib/generators/administrate/views/views_generator.rb +14 -0
  83. metadata +33 -15
  84. data/app/assets/stylesheets/administrate/_show.sass +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd6443bd06d24f63d4f5dcfbb96fd9678a661e54
4
- data.tar.gz: da323f68c0e013f7eeed53e9522081ef0e1accf6
3
+ metadata.gz: a63c6085034ba4b3ee39b90cd213593fbca55347
4
+ data.tar.gz: 3e4091678fda4953de68374a61c49f45573d843c
5
5
  SHA512:
6
- metadata.gz: ffe2364fe45f624b3fb422336cd00cb36fde0ef6217e492a77f5117a05dfe0e1dc69395b3bfdc08c4b94b36a81d7231bb3b7193e5ddafb0b62686b422d054d67
7
- data.tar.gz: 4e0e7c3d7cdd9dbc45ebe2195c0686f0c9fc852b1e1ffe8c6cd9b3716d61f7a03a801a15a22c25829af360f36eef8ed1af2140bf617a513d12a81182cf0e0461
6
+ metadata.gz: 232a793a6aad5135c044d957297f5850078fa4bfbf5e3e100a851a0efc4d3ec5ff0392eb9bcc85a99ea6e1b5480ef8c233ab1454913f95ccccf8271b4dc83902
7
+ data.tar.gz: e66a04e628f6a1afa97be1784a33deedb3baf782075279efbc2dcecf0a2d71eb3b5f7aed2d72845c4b6c54d6ce571e5838011925fb5bac3d4fd2546a4eb1fce9
@@ -0,0 +1,3 @@
1
+ <svg width="242" height="104" viewBox="0 0 242 104" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M0 0h242L121 104 0 0z" fill="#2d6586" fill-rule="evenodd"/>
3
+ </svg>
@@ -7,7 +7,8 @@ $(function() {
7
7
 
8
8
  $.fn.textWidth = function(text, font) {
9
9
  if (!$.fn.textWidth.fakeEl) {
10
- $.fn.textWidth.fakeEl = $("<span>").appendTo(document.body);
10
+ $.fn.textWidth.fakeEl = $('<span style="display: none;">')
11
+ .appendTo(document.body);
11
12
  }
12
13
 
13
14
  var htmlText = text || this.val() || this.text();
@@ -1,3 +1,3 @@
1
1
  $(function() {
2
- $(".form-field-has-many select").selectize({});
2
+ $(".form-field--has-many select").selectize({});
3
3
  });
@@ -13,6 +13,5 @@
13
13
 
14
14
  @import "layout";
15
15
  @import "sidebar";
16
- @import "show";
17
16
 
18
17
  @import "components/components";
@@ -36,8 +36,8 @@ select {
36
36
  box-sizing: border-box;
37
37
  font-family: $form-font-family;
38
38
  font-size: $form-font-size;
39
- margin-bottom: $base-spacing / 2;
40
- padding: ($base-spacing / 3) ($base-spacing / 3);
39
+ margin-bottom: $small-spacing;
40
+ padding: $form-input-padding;
41
41
  transition: border-color;
42
42
  width: 100%;
43
43
 
@@ -77,6 +77,6 @@ input[type="file"] {
77
77
 
78
78
  select {
79
79
  appearance: none;
80
- background: image-url("dropdown.svg") no-repeat 97% 50% / 10px;
80
+ background: image-url("administrate/dropdown.svg") no-repeat 97% 50% / 10px;
81
81
  margin-bottom: $base-spacing;
82
82
  }
@@ -19,13 +19,13 @@ ol {
19
19
 
20
20
  dl {
21
21
  margin-bottom: $base-spacing / 2;
22
+ }
22
23
 
23
- dt {
24
- font-weight: bold;
25
- margin-top: $base-spacing / 2;
26
- }
24
+ dt {
25
+ font-weight: bold;
26
+ margin-top: $base-spacing / 2;
27
+ }
27
28
 
28
- dd {
29
- margin: 0;
30
- }
29
+ dd {
30
+ margin: 0;
31
31
  }
@@ -28,6 +28,7 @@ $base-border-radius: 3px;
28
28
  $base-spacing: $base-line-height * 1em;
29
29
  $base-z-index: 0;
30
30
  $small-spacing: $base-spacing / 2;
31
+ $table-image-height: 2em;
31
32
 
32
33
  // Transitions
33
34
  $base-easing: cubic-bezier(0.215, 0.610, 0.355, 1);
@@ -101,3 +102,5 @@ $form-box-shadow: inset 0 1px 3px rgba(black,0.06);
101
102
  $form-box-shadow-focus: $form-box-shadow, 0 0 5px rgba(darken($form-border-color-focus, 5), 0.7);
102
103
  $form-font-size: $base-font-size;
103
104
  $form-font-family: $base-font-family;
105
+
106
+ $form-input-padding: $base-spacing / 3;
@@ -1,3 +1,16 @@
1
+ .attribute-label {
2
+ @include data-label;
3
+ @include span-columns(2 of 12);
4
+ margin-top: 0;
5
+ text-align: right;
6
+ }
7
+
1
8
  .attribute-data--string {
2
9
  white-space: pre;
3
10
  }
11
+
12
+ .attribute-data {
13
+ @include span-columns(10 of 12);
14
+ @include omega;
15
+ margin-bottom: $base-spacing;
16
+ }
@@ -1,11 +1,5 @@
1
- .cell-label,
2
- .attribute-label {
3
- color: $hint-grey;
4
- font-size: $small-font-size;
5
- font-weight: $normal-font-weight;
6
- letter-spacing: 0.0357em;
7
- position: relative;
8
- text-transform: uppercase;
1
+ .cell-label {
2
+ @include data-label;
9
3
 
10
4
  a {
11
5
  @include fill-parent;
@@ -1,33 +1,40 @@
1
- .form {
2
- &-actions {
3
- margin-left: 12em;
1
+ .form-actions {
2
+ @include shift(2);
3
+ }
4
+
5
+ .form-field {
6
+ @include clearfix;
7
+ @include fill-parent;
8
+ align-items: baseline;
9
+ width: 100%;
10
+
11
+ label {
12
+ @include data-label;
13
+ @include span-columns(2 of 12);
14
+ padding: $form-input-padding 0;
15
+ text-align: right;
4
16
  }
5
17
 
6
- &-heading {
7
- font-size: 1.75em;
8
- margin: 0;
9
- padding-bottom: 0.5em;
18
+ #{$all-text-inputs},
19
+ select,
20
+ textarea,
21
+ .selectize-control {
22
+ background-color: $form-field-background-color;
23
+ margin-bottom: $base-spacing;
10
24
  }
11
25
 
12
- &-field {
13
- align-items: baseline;
14
- display: flex;
15
- justify-content: flex-start;
16
- margin: 1.2em 0;
17
- width: 100%;
26
+ input,
27
+ select,
28
+ .selectize-control {
29
+ @include span-columns(4 of 12);
30
+ }
18
31
 
19
- label {
20
- margin-right: 2em;
21
- text-align: right;
22
- width: 10em;
23
- }
32
+ textarea {
33
+ @include span-columns(6 of 12);
34
+ }
24
35
 
25
- input,
26
- select,
27
- .selectize-control {
28
- background-color: $form-field-background-color;
29
- max-width: 30em;
30
- width: 30em;
31
- }
36
+ [type="checkbox"],
37
+ [type="radio"] {
38
+ margin: $small-spacing 0 ($base-spacing + $form-input-padding);
32
39
  }
33
40
  }
@@ -2,7 +2,7 @@
2
2
  align-items: flex-end;
3
3
  display: flex;
4
4
  justify-content: space-between;
5
- margin-bottom: $base-spacing;
5
+ margin-bottom: $base-spacing * 2;
6
6
 
7
7
  &-heading {
8
8
  margin-top: 0;
@@ -38,7 +38,7 @@
38
38
  }
39
39
 
40
40
  .search__hint {
41
- @include position(absolute, 1em null null null);
41
+ @include position(absolute, 1em 0 null null);
42
42
  @include transition($base-transition);
43
43
  color: $hint-grey;
44
44
  opacity: 0;
@@ -8,6 +8,10 @@
8
8
  border-left-color: $blue;
9
9
  cursor: pointer;
10
10
  }
11
+
12
+ img {
13
+ max-height: $table-image-height;
14
+ }
11
15
  }
12
16
 
13
17
  .table__action--destroy {
@@ -0,0 +1,8 @@
1
+ @mixin data-label {
2
+ color: $hint-grey;
3
+ font-size: $small-font-size;
4
+ font-weight: $normal-font-weight;
5
+ letter-spacing: 0.0357em;
6
+ position: relative;
7
+ text-transform: uppercase;
8
+ }
@@ -1 +1,2 @@
1
+ @import "data_label";
1
2
  @import "shadow";
@@ -1,31 +1,39 @@
1
1
  module Administrate
2
2
  class ApplicationController < ActionController::Base
3
3
  def index
4
- @search_term = params[:search].to_s.strip
5
- @resources = Administrate::Search.new(resource_resolver, @search_term).run
6
- @resources = order.apply(@resources)
7
- @resources = @resources.page(params[:page]).per(records_per_page)
8
- @page = Administrate::Page::Table.new(dashboard, order: order)
4
+ search_term = params[:search].to_s.strip
5
+ resources = Administrate::Search.new(resource_resolver, search_term).run
6
+ resources = order.apply(resources)
7
+ resources = resources.page(params[:page]).per(records_per_page)
8
+ page = Administrate::Page::Collection.new(dashboard, order: order)
9
+
10
+ render locals: {
11
+ resources: resources.page(params[:page]).per(records_per_page),
12
+ search_term: search_term,
13
+ page: page,
14
+ }
9
15
  end
10
16
 
11
17
  def show
12
- set_resource
13
-
14
- @page = Administrate::Page::Show.new(dashboard, resource)
18
+ render locals: {
19
+ page: Administrate::Page::Show.new(dashboard, requested_resource),
20
+ }
15
21
  end
16
22
 
17
23
  def new
18
- @page = Administrate::Page::Form.new(dashboard, resource_class.new)
24
+ render locals: {
25
+ page: Administrate::Page::Form.new(dashboard, resource_class.new),
26
+ }
19
27
  end
20
28
 
21
29
  def edit
22
- set_resource
23
-
24
- @page = Administrate::Page::Form.new(dashboard, resource)
30
+ render locals: {
31
+ page: Administrate::Page::Form.new(dashboard, requested_resource),
32
+ }
25
33
  end
26
34
 
27
35
  def create
28
- set_resource(resource_class.new(resource_params))
36
+ resource = resource_class.new(resource_params)
29
37
 
30
38
  if resource.save
31
39
  redirect_to(
@@ -33,29 +41,27 @@ module Administrate
33
41
  notice: translate("create.success"),
34
42
  )
35
43
  else
36
- @page = Administrate::Page::Form.new(dashboard, resource)
37
- render :new
44
+ render :new, locals: {
45
+ page: Administrate::Page::Form.new(dashboard, resource),
46
+ }
38
47
  end
39
48
  end
40
49
 
41
50
  def update
42
- set_resource
43
-
44
- if resource.update(resource_params)
51
+ if requested_resource.update(resource_params)
45
52
  redirect_to(
46
- [Administrate::NAMESPACE, resource],
53
+ [Administrate::NAMESPACE, requested_resource],
47
54
  notice: translate("update.success"),
48
55
  )
49
56
  else
50
- @page = Administrate::Page::Form.new(dashboard, resource)
51
- render :edit
57
+ render :edit, locals: {
58
+ page: Administrate::Page::Form.new(dashboard, requested_resource),
59
+ }
52
60
  end
53
61
  end
54
62
 
55
63
  def destroy
56
- set_resource
57
-
58
- resource.destroy
64
+ requested_resource.destroy
59
65
  flash[:notice] = translate("destroy.success")
60
66
  redirect_to action: :index
61
67
  end
@@ -76,26 +82,21 @@ module Administrate
76
82
  end
77
83
 
78
84
  def order
79
- @order ||= Administrate::Order.new(params[:order], params[:direction])
85
+ @_order ||= Administrate::Order.new(params[:order], params[:direction])
80
86
  end
81
87
 
82
88
  def dashboard
83
- @dashboard ||= resource_resolver.dashboard_class.new
89
+ @_dashboard ||= resource_resolver.dashboard_class.new
84
90
  end
85
91
 
86
- def set_resource(resource = nil)
87
- resource ||= find_resource(params[:id])
88
- instance_variable_set(instance_variable, resource)
92
+ def requested_resource
93
+ @_requested_resource ||= find_resource(params[:id])
89
94
  end
90
95
 
91
96
  def find_resource(param)
92
97
  resource_class.find(param)
93
98
  end
94
99
 
95
- def resource
96
- instance_variable_get(instance_variable)
97
- end
98
-
99
100
  def resource_params
100
101
  params.require(resource_name).permit(*permitted_attributes)
101
102
  end
@@ -104,14 +105,10 @@ module Administrate
104
105
  dashboard.permitted_attributes
105
106
  end
106
107
 
107
- def instance_variable
108
- "@#{resource_name}"
109
- end
110
-
111
108
  delegate :resource_class, :resource_name, to: :resource_resolver
112
109
 
113
110
  def resource_resolver
114
- @resource_resolver ||=
111
+ @_resource_resolver ||=
115
112
  Administrate::ResourceResolver.new(controller_path)
116
113
  end
117
114
 
@@ -1,17 +1,37 @@
1
+ <%#
2
+ # Table
3
+
4
+ This partial is used on the `index` and `show` pages
5
+ to display a collection of resources in an HTML table.
6
+
7
+ ## Local variables:
8
+
9
+ - `table_presenter`:
10
+ An instance of [Administrate::Page::Table][1].
11
+ The table presenter uses `ResourceDashboard::TABLE_ATTRIBUTES` to determine
12
+ the columns displayed in the table
13
+ - `resources`:
14
+ An ActiveModel::Relation collection of resources to be displayed in the table.
15
+ By default, the number of resources is limited by pagination
16
+ or by a hard limit to prevent excessive page load times
17
+
18
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Table
19
+ %>
20
+
1
21
  <table>
2
22
  <thead>
3
23
  <tr>
4
- <% table_presenter.attribute_types.each do |attr_name, attr_type| %>
24
+ <% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
5
25
  <th class="cell-label cell-label--<%= attr_type.html_class %>
6
- cell-label--<%= table_presenter.ordered_html_class(attr_name) %>
26
+ cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
7
27
  ">
8
28
  <%= link_to(params.merge(
9
- table_presenter.order_params_for(attr_name)
29
+ collection_presenter.order_params_for(attr_name)
10
30
  )) do %>
11
31
  <%= attr_name.to_s.titleize %>
12
32
 
13
- <% if table_presenter.ordered_by?(attr_name) %>
14
- <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= table_presenter.ordered_html_class(attr_name) %>">
33
+ <% if collection_presenter.ordered_by?(attr_name) %>
34
+ <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
15
35
  <%= inline_svg("administrate/sort_arrow.svg") %>
16
36
  </span>
17
37
  <% end %>
@@ -29,7 +49,7 @@
29
49
  tabindex="0"
30
50
  data-url="<%= polymorphic_path([Administrate::NAMESPACE, resource]) -%>"
31
51
  >
32
- <% table_presenter.attributes_for(resource).each do |attribute| %>
52
+ <% collection_presenter.attributes_for(resource).each do |attribute| %>
33
53
  <td class="cell-data cell-data--<%= attribute.html_class %>">
34
54
  <%= render_field attribute %>
35
55
  </td>
@@ -1,3 +1,16 @@
1
+ <%#
2
+ # Flash Partial
3
+
4
+ This partial renders flash messages on every page.
5
+
6
+ ## Relevant Helpers:
7
+
8
+ - `flash`:
9
+ Returns a hash,
10
+ where the keys are the type of flash (alert, error, notice, etc)
11
+ and the values are the message to be displayed.
12
+ %>
13
+
1
14
  <% if flash.any? %>
2
15
  <div id="flashes">
3
16
  <% flash.each do |key, value| -%>