viniBaxterDesk 0.13.1

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.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +32 -0
  3. data/app/assets/javascripts/administrate/application.js +6 -0
  4. data/app/assets/javascripts/administrate/components/associative.js +4 -0
  5. data/app/assets/javascripts/administrate/components/date_time_picker.js +14 -0
  6. data/app/assets/javascripts/administrate/components/table.js +23 -0
  7. data/app/assets/stylesheets/administrate/application.scss +30 -0
  8. data/app/assets/stylesheets/administrate/base/_forms.scss +107 -0
  9. data/app/assets/stylesheets/administrate/base/_layout.scss +20 -0
  10. data/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
  11. data/app/assets/stylesheets/administrate/base/_tables.scss +58 -0
  12. data/app/assets/stylesheets/administrate/base/_typography.scss +45 -0
  13. data/app/assets/stylesheets/administrate/components/_app-container.scss +9 -0
  14. data/app/assets/stylesheets/administrate/components/_attributes.scss +26 -0
  15. data/app/assets/stylesheets/administrate/components/_buttons.scss +51 -0
  16. data/app/assets/stylesheets/administrate/components/_cells.scss +47 -0
  17. data/app/assets/stylesheets/administrate/components/_field-unit.scss +45 -0
  18. data/app/assets/stylesheets/administrate/components/_flashes.scss +28 -0
  19. data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  20. data/app/assets/stylesheets/administrate/components/_main-content.scss +29 -0
  21. data/app/assets/stylesheets/administrate/components/_navigation.scss +32 -0
  22. data/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
  23. data/app/assets/stylesheets/administrate/components/_search.scss +46 -0
  24. data/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
  25. data/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
  26. data/app/assets/stylesheets/administrate/library/_variables.scss +63 -0
  27. data/app/assets/stylesheets/administrate/reset/_normalize.scss +447 -0
  28. data/app/assets/stylesheets/administrate/utilities/_text-color.scss +3 -0
  29. data/app/assets/stylesheets/docs.scss +93 -0
  30. data/app/controllers/administrate/application_controller.rb +189 -0
  31. data/app/controllers/concerns/administrate/punditize.rb +36 -0
  32. data/app/helpers/administrate/application_helper.rb +83 -0
  33. data/app/views/administrate/application/_collection.html.erb +97 -0
  34. data/app/views/administrate/application/_flashes.html.erb +20 -0
  35. data/app/views/administrate/application/_form.html.erb +45 -0
  36. data/app/views/administrate/application/_icons.html.erb +13 -0
  37. data/app/views/administrate/application/_javascript.html.erb +21 -0
  38. data/app/views/administrate/application/_navigation.html.erb +20 -0
  39. data/app/views/administrate/application/_search.html.erb +25 -0
  40. data/app/views/administrate/application/_stylesheet.html.erb +14 -0
  41. data/app/views/administrate/application/edit.html.erb +36 -0
  42. data/app/views/administrate/application/index.html.erb +66 -0
  43. data/app/views/administrate/application/new.html.erb +37 -0
  44. data/app/views/administrate/application/show.html.erb +49 -0
  45. data/app/views/fields/belongs_to/_form.html.erb +26 -0
  46. data/app/views/fields/belongs_to/_index.html.erb +27 -0
  47. data/app/views/fields/belongs_to/_show.html.erb +27 -0
  48. data/app/views/fields/boolean/_form.html.erb +23 -0
  49. data/app/views/fields/boolean/_index.html.erb +19 -0
  50. data/app/views/fields/boolean/_show.html.erb +19 -0
  51. data/app/views/fields/date/_form.html.erb +24 -0
  52. data/app/views/fields/date/_index.html.erb +21 -0
  53. data/app/views/fields/date/_show.html.erb +21 -0
  54. data/app/views/fields/date_time/_form.html.erb +24 -0
  55. data/app/views/fields/date_time/_index.html.erb +21 -0
  56. data/app/views/fields/date_time/_show.html.erb +21 -0
  57. data/app/views/fields/email/_form.html.erb +23 -0
  58. data/app/views/fields/email/_index.html.erb +18 -0
  59. data/app/views/fields/email/_show.html.erb +18 -0
  60. data/app/views/fields/has_many/_form.html.erb +29 -0
  61. data/app/views/fields/has_many/_index.html.erb +19 -0
  62. data/app/views/fields/has_many/_show.html.erb +38 -0
  63. data/app/views/fields/has_one/_form.html.erb +28 -0
  64. data/app/views/fields/has_one/_index.html.erb +23 -0
  65. data/app/views/fields/has_one/_show.html.erb +40 -0
  66. data/app/views/fields/number/_form.html.erb +23 -0
  67. data/app/views/fields/number/_index.html.erb +19 -0
  68. data/app/views/fields/number/_show.html.erb +19 -0
  69. data/app/views/fields/password/_form.html.erb +23 -0
  70. data/app/views/fields/password/_index.html.erb +18 -0
  71. data/app/views/fields/password/_show.html.erb +18 -0
  72. data/app/views/fields/polymorphic/_form.html.erb +29 -0
  73. data/app/views/fields/polymorphic/_index.html.erb +24 -0
  74. data/app/views/fields/polymorphic/_show.html.erb +28 -0
  75. data/app/views/fields/select/_form.html.erb +31 -0
  76. data/app/views/fields/select/_index.html.erb +16 -0
  77. data/app/views/fields/select/_show.html.erb +16 -0
  78. data/app/views/fields/string/_form.html.erb +23 -0
  79. data/app/views/fields/string/_index.html.erb +18 -0
  80. data/app/views/fields/string/_show.html.erb +18 -0
  81. data/app/views/fields/text/_form.html.erb +22 -0
  82. data/app/views/fields/text/_index.html.erb +18 -0
  83. data/app/views/fields/text/_show.html.erb +18 -0
  84. data/app/views/fields/time/_form.html.erb +22 -0
  85. data/app/views/fields/time/_index.html.erb +17 -0
  86. data/app/views/fields/time/_show.html.erb +17 -0
  87. data/app/views/fields/url/_form.html.erb +23 -0
  88. data/app/views/fields/url/_index.html.erb +20 -0
  89. data/app/views/fields/url/_show.html.erb +20 -0
  90. data/app/views/layouts/administrate/application.html.erb +41 -0
  91. data/config/i18n-tasks.yml +18 -0
  92. data/config/locales/administrate.ar.yml +28 -0
  93. data/config/locales/administrate.bs.yml +27 -0
  94. data/config/locales/administrate.ca.yml +28 -0
  95. data/config/locales/administrate.da.yml +28 -0
  96. data/config/locales/administrate.de.yml +28 -0
  97. data/config/locales/administrate.en.yml +28 -0
  98. data/config/locales/administrate.es.yml +28 -0
  99. data/config/locales/administrate.fr.yml +28 -0
  100. data/config/locales/administrate.id.yml +28 -0
  101. data/config/locales/administrate.it.yml +28 -0
  102. data/config/locales/administrate.ja.yml +28 -0
  103. data/config/locales/administrate.ko.yml +28 -0
  104. data/config/locales/administrate.nl.yml +28 -0
  105. data/config/locales/administrate.pl.yml +28 -0
  106. data/config/locales/administrate.pt-BR.yml +29 -0
  107. data/config/locales/administrate.pt.yml +29 -0
  108. data/config/locales/administrate.ru.yml +28 -0
  109. data/config/locales/administrate.sq.yml +28 -0
  110. data/config/locales/administrate.sv.yml +28 -0
  111. data/config/locales/administrate.uk.yml +28 -0
  112. data/config/locales/administrate.vi.yml +28 -0
  113. data/config/locales/administrate.zh-CN.yml +28 -0
  114. data/config/locales/administrate.zh-TW.yml +28 -0
  115. data/config/routes.rb +2 -0
  116. data/config/unicorn.rb +30 -0
  117. data/docs/adding_controllers_without_related_model.md +36 -0
  118. data/docs/adding_custom_field_types.md +81 -0
  119. data/docs/authentication.md +63 -0
  120. data/docs/authorization.md +71 -0
  121. data/docs/contributing.md +1 -0
  122. data/docs/customizing_attribute_partials.md +56 -0
  123. data/docs/customizing_controller_actions.md +58 -0
  124. data/docs/customizing_dashboards.md +303 -0
  125. data/docs/customizing_page_views.md +84 -0
  126. data/docs/getting_started.md +128 -0
  127. data/docs/rails_api.md +45 -0
  128. data/lib/administrate/base_dashboard.rb +97 -0
  129. data/lib/administrate/custom_dashboard.rb +15 -0
  130. data/lib/administrate/engine.rb +44 -0
  131. data/lib/administrate/field/associative.rb +33 -0
  132. data/lib/administrate/field/base.rb +54 -0
  133. data/lib/administrate/field/belongs_to.rb +38 -0
  134. data/lib/administrate/field/boolean.rb +15 -0
  135. data/lib/administrate/field/date.rb +20 -0
  136. data/lib/administrate/field/date_time.rb +32 -0
  137. data/lib/administrate/field/deferred.rb +44 -0
  138. data/lib/administrate/field/email.rb +11 -0
  139. data/lib/administrate/field/has_many.rb +94 -0
  140. data/lib/administrate/field/has_one.rb +35 -0
  141. data/lib/administrate/field/number.rb +35 -0
  142. data/lib/administrate/field/password.rb +25 -0
  143. data/lib/administrate/field/polymorphic.rb +51 -0
  144. data/lib/administrate/field/select.rb +24 -0
  145. data/lib/administrate/field/string.rb +21 -0
  146. data/lib/administrate/field/text.rb +21 -0
  147. data/lib/administrate/field/time.rb +8 -0
  148. data/lib/administrate/field/url.rb +21 -0
  149. data/lib/administrate/generator_helpers.rb +13 -0
  150. data/lib/administrate/namespace/resource.rb +28 -0
  151. data/lib/administrate/namespace.rb +35 -0
  152. data/lib/administrate/order.rb +88 -0
  153. data/lib/administrate/page/base.rb +41 -0
  154. data/lib/administrate/page/collection.rb +37 -0
  155. data/lib/administrate/page/form.rb +28 -0
  156. data/lib/administrate/page/show.rb +24 -0
  157. data/lib/administrate/page.rb +4 -0
  158. data/lib/administrate/resource_resolver.rb +43 -0
  159. data/lib/administrate/search.rb +157 -0
  160. data/lib/administrate/version.rb +3 -0
  161. data/lib/administrate/view_generator.rb +36 -0
  162. data/lib/administrate.rb +4 -0
  163. data/lib/generators/administrate/assets/assets_generator.rb +12 -0
  164. data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
  165. data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
  166. data/lib/generators/administrate/dashboard/USAGE +9 -0
  167. data/lib/generators/administrate/dashboard/dashboard_generator.rb +143 -0
  168. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +46 -0
  169. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +68 -0
  170. data/lib/generators/administrate/field/field_generator.rb +31 -0
  171. data/lib/generators/administrate/field/templates/_form.html.erb +6 -0
  172. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  173. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  174. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  175. data/lib/generators/administrate/install/install_generator.rb +49 -0
  176. data/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
  177. data/lib/generators/administrate/routes/routes_generator.rb +96 -0
  178. data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  179. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  180. data/lib/generators/administrate/views/field_generator.rb +50 -0
  181. data/lib/generators/administrate/views/form_generator.rb +15 -0
  182. data/lib/generators/administrate/views/index_generator.rb +16 -0
  183. data/lib/generators/administrate/views/layout_generator.rb +24 -0
  184. data/lib/generators/administrate/views/navigation_generator.rb +15 -0
  185. data/lib/generators/administrate/views/new_generator.rb +16 -0
  186. data/lib/generators/administrate/views/show_generator.rb +15 -0
  187. data/lib/generators/administrate/views/views_generator.rb +14 -0
  188. data/lib/tasks/administrate_tasks.rake +4 -0
  189. metadata +398 -0
@@ -0,0 +1,189 @@
1
+ module Administrate
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+
5
+ def index
6
+ search_term = params[:search].to_s.strip
7
+ resources = Administrate::Search.new(scoped_resource,
8
+ dashboard_class,
9
+ search_term).run
10
+ resources = apply_collection_includes(resources)
11
+ resources = order.apply(resources)
12
+ resources = resources.page(params[:page]).per(records_per_page)
13
+ page = Administrate::Page::Collection.new(dashboard, order: order)
14
+
15
+ render locals: {
16
+ resources: resources,
17
+ search_term: search_term,
18
+ page: page,
19
+ show_search_bar: show_search_bar?,
20
+ }
21
+ end
22
+
23
+ def show
24
+ render locals: {
25
+ page: Administrate::Page::Show.new(dashboard, requested_resource),
26
+ }
27
+ end
28
+
29
+ def new
30
+ resource = new_resource
31
+ authorize_resource(resource)
32
+ render locals: {
33
+ page: Administrate::Page::Form.new(dashboard, resource),
34
+ }
35
+ end
36
+
37
+ def edit
38
+ render locals: {
39
+ page: Administrate::Page::Form.new(dashboard, requested_resource),
40
+ }
41
+ end
42
+
43
+ def create
44
+ resource = resource_class.new(resource_params)
45
+ authorize_resource(resource)
46
+
47
+ if resource.save
48
+ redirect_to(
49
+ [namespace, resource],
50
+ notice: translate_with_resource("create.success"),
51
+ )
52
+ else
53
+ render :new, locals: {
54
+ page: Administrate::Page::Form.new(dashboard, resource),
55
+ }
56
+ end
57
+ end
58
+
59
+ def update
60
+ if requested_resource.update(resource_params)
61
+ redirect_to(
62
+ [namespace, requested_resource],
63
+ notice: translate_with_resource("update.success"),
64
+ )
65
+ else
66
+ render :edit, locals: {
67
+ page: Administrate::Page::Form.new(dashboard, requested_resource),
68
+ }
69
+ end
70
+ end
71
+
72
+ def destroy
73
+ if requested_resource.destroy
74
+ flash[:notice] = translate_with_resource("destroy.success")
75
+ else
76
+ flash[:error] = requested_resource.errors.full_messages.join("<br/>")
77
+ end
78
+ redirect_to action: :index
79
+ end
80
+
81
+ private
82
+
83
+ helper_method :nav_link_state
84
+ def nav_link_state(resource)
85
+ resource_name.to_s.pluralize == resource.to_s ? :active : :inactive
86
+ end
87
+
88
+ helper_method :valid_action?
89
+ def valid_action?(name, resource = resource_class)
90
+ !!routes.detect do |controller, action|
91
+ controller == resource.to_s.underscore.pluralize && action == name.to_s
92
+ end
93
+ end
94
+
95
+ def routes
96
+ @routes ||= Namespace.new(namespace).routes
97
+ end
98
+
99
+ def records_per_page
100
+ params[:per_page] || 20
101
+ end
102
+
103
+ def order
104
+ @order ||= Administrate::Order.new(
105
+ params.fetch(resource_name, {}).fetch(:order, nil),
106
+ params.fetch(resource_name, {}).fetch(:direction, nil),
107
+ )
108
+ end
109
+
110
+ def dashboard
111
+ @dashboard ||= dashboard_class.new
112
+ end
113
+
114
+ def requested_resource
115
+ @requested_resource ||= find_resource(params[:id]).tap do |resource|
116
+ authorize_resource(resource)
117
+ end
118
+ end
119
+
120
+ def find_resource(param)
121
+ scoped_resource.find(param)
122
+ end
123
+
124
+ def scoped_resource
125
+ resource_class.default_scoped
126
+ end
127
+
128
+ def apply_collection_includes(relation)
129
+ resource_includes = dashboard.collection_includes
130
+ return relation if resource_includes.empty?
131
+ relation.includes(*resource_includes)
132
+ end
133
+
134
+ def resource_params
135
+ params.require(resource_class.model_name.param_key).
136
+ permit(dashboard.permitted_attributes).
137
+ transform_values { |v| read_param_value(v) }
138
+ end
139
+
140
+ def read_param_value(data)
141
+ if data.is_a?(ActionController::Parameters) && data[:type]
142
+ if data[:type] == Administrate::Field::Polymorphic.to_s
143
+ GlobalID::Locator.locate(data[:value])
144
+ else
145
+ raise "Unrecognised param data: #{data.inspect}"
146
+ end
147
+ else
148
+ data
149
+ end
150
+ end
151
+
152
+ delegate :dashboard_class, :resource_class, :resource_name, :namespace,
153
+ to: :resource_resolver
154
+ helper_method :namespace
155
+ helper_method :resource_name
156
+
157
+ def resource_resolver
158
+ @resource_resolver ||=
159
+ Administrate::ResourceResolver.new(controller_path)
160
+ end
161
+
162
+ def translate_with_resource(key)
163
+ t(
164
+ "administrate.controller.#{key}",
165
+ resource: resource_resolver.resource_title,
166
+ )
167
+ end
168
+
169
+ def show_search_bar?
170
+ dashboard.attribute_types_for(
171
+ dashboard.all_attributes,
172
+ ).any? { |_name, attribute| attribute.searchable? }
173
+ end
174
+
175
+ def show_action?(_action, _resource)
176
+ true
177
+ end
178
+ helper_method :show_action?
179
+
180
+ def new_resource
181
+ resource_class.new
182
+ end
183
+ helper_method :new_resource
184
+
185
+ def authorize_resource(resource)
186
+ resource
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,36 @@
1
+ module Administrate
2
+ module Punditize
3
+ if Object.const_defined?("Pundit")
4
+ extend ActiveSupport::Concern
5
+ include Pundit
6
+
7
+ included do
8
+ def scoped_resource
9
+ policy_scope_admin super
10
+ end
11
+
12
+ def authorize_resource(resource)
13
+ authorize resource
14
+ end
15
+
16
+ def show_action?(action, resource)
17
+ Pundit.policy!(pundit_user, resource).send("#{action}?".to_sym)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ # Like the policy_scope method in stock Pundit, but allows the 'resolve'
24
+ # to be overridden by 'resolve_admin' for a different index scope in Admin
25
+ # controllers.
26
+ def policy_scope_admin(scope)
27
+ ps = Pundit::PolicyFinder.new(scope).scope!.new(pundit_user, scope)
28
+ if ps.respond_to? :resolve_admin
29
+ ps.resolve_admin
30
+ else
31
+ ps.resolve
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ module Administrate
2
+ module ApplicationHelper
3
+ PLURAL_MANY_COUNT = 2.1
4
+
5
+ def application_title
6
+ if Rails::VERSION::MAJOR <= 5
7
+ Rails.application.class.parent_name.titlecase
8
+ else
9
+ Rails.application.class.module_parent_name.titlecase
10
+ end
11
+ end
12
+
13
+ def render_field(field, locals = {})
14
+ locals[:field] = field
15
+ render locals: locals, partial: field.to_partial_path
16
+ end
17
+
18
+ def requireness(field)
19
+ required_field?(field) ? "required" : "optional"
20
+ end
21
+
22
+ def required_field?(field)
23
+ has_presence_validator?(field.resource.class, field.attribute)
24
+ end
25
+
26
+ def has_presence_validator?(resource_class, field_name)
27
+ validators_on(resource_class, field_name).
28
+ any? { |v| v.class == ActiveRecord::Validations::PresenceValidator }
29
+ end
30
+
31
+ def validators_on(resource_class, field_name)
32
+ return [] unless resource_class.respond_to?(:validators_on)
33
+
34
+ resource_class.validators_on(field_name)
35
+ end
36
+
37
+ def dashboard_from_resource(resource_name)
38
+ "#{resource_name.to_s.singularize}_dashboard".classify.constantize
39
+ end
40
+
41
+ def display_resource_name(resource_name)
42
+ dashboard_from_resource(resource_name).resource_name(
43
+ count: PLURAL_MANY_COUNT,
44
+ default: default_resource_name(resource_name),
45
+ )
46
+ end
47
+
48
+ def sort_order(order)
49
+ case order
50
+ when "asc" then "ascending"
51
+ when "desc" then "descending"
52
+ else "none"
53
+ end
54
+ end
55
+
56
+ def resource_index_route(resource_name)
57
+ url_for(
58
+ action: "index",
59
+ controller: "/#{namespace}/#{resource_name}",
60
+ )
61
+ end
62
+
63
+ def sanitized_order_params(page, current_field_name)
64
+ collection_names = page.item_includes + [current_field_name]
65
+ association_params = collection_names.map do |assoc_name|
66
+ { assoc_name => %i[order direction page per_page] }
67
+ end
68
+ params.permit(:search, :id, :page, :per_page, association_params)
69
+ end
70
+
71
+ def clear_search_params
72
+ params.except(:search, :page).permit(
73
+ :per_page, resource_name => %i[order direction]
74
+ )
75
+ end
76
+
77
+ private
78
+
79
+ def default_resource_name(resource_name)
80
+ resource_name.to_s.pluralize.gsub("/", "_").titleize
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,97 @@
1
+ <%#
2
+ # Collection
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
+ - `collection_presenter`:
10
+ An instance of [Administrate::Page::Collection][1].
11
+ The table presenter uses `ResourceDashboard::COLLECTION_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/Collection
19
+ %>
20
+
21
+ <table aria-labelledby="<%= table_title %>">
22
+ <thead>
23
+ <tr>
24
+ <% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
25
+ <th class="cell-label
26
+ cell-label--<%= attr_type.html_class %>
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)) %>">
31
+ <%= link_to(sanitized_order_params(page, collection_field_name).merge(
32
+ collection_presenter.order_params_for(attr_name, key: collection_field_name)
33
+ )) do %>
34
+ <%= t(
35
+ "helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
36
+ default: attr_name.to_s,
37
+ ).titleize %>
38
+ <% if collection_presenter.ordered_by?(attr_name) %>
39
+ <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
40
+ <svg aria-hidden="true">
41
+ <use xlink:href="#icon-up-caret" />
42
+ </svg>
43
+ </span>
44
+ <% end %>
45
+ <% end %>
46
+ </th>
47
+ <% 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 %>
52
+ </tr>
53
+ </thead>
54
+
55
+ <tbody>
56
+ <% resources.each do |resource| %>
57
+ <tr class="js-table-row"
58
+ <% if show_action? :show, resource %>
59
+ <%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
60
+ <% end %>
61
+ >
62
+ <% collection_presenter.attributes_for(resource).each do |attribute| %>
63
+ <td class="cell-data cell-data--<%= attribute.html_class %>">
64
+ <% if show_action? :show, resource -%>
65
+ <a href="<%= polymorphic_path([namespace, resource]) -%>"
66
+ tabindex="-1"
67
+ class="action-show"
68
+ >
69
+ <%= render_field attribute %>
70
+ </a>
71
+ <% else %>
72
+ <%= render_field attribute %>
73
+ <% end -%>
74
+ </td>
75
+ <% end %>
76
+
77
+ <% if valid_action? :edit, collection_presenter.resource_name %>
78
+ <td><%= link_to(
79
+ t("administrate.actions.edit"),
80
+ [:edit, namespace, resource],
81
+ class: "action-edit",
82
+ ) if show_action? :edit, resource%></td>
83
+ <% end %>
84
+
85
+ <% if valid_action? :destroy, collection_presenter.resource_name %>
86
+ <td><%= link_to(
87
+ t("administrate.actions.destroy"),
88
+ [namespace, resource],
89
+ class: "text-color-red",
90
+ method: :delete,
91
+ data: { confirm: t("administrate.actions.confirm") }
92
+ ) if show_action? :destroy, resource %></td>
93
+ <% end %>
94
+ </tr>
95
+ <% end %>
96
+ </tbody>
97
+ </table>
@@ -0,0 +1,20 @@
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
+
14
+ <% if flash.any? %>
15
+ <div class="flashes">
16
+ <% flash.each do |key, value| -%>
17
+ <div class="flash flash-<%= key %>"><%= value.html_safe %></div>
18
+ <% end -%>
19
+ </div>
20
+ <% end %>
@@ -0,0 +1,45 @@
1
+ <%#
2
+ # Form Partial
3
+
4
+ This partial is rendered on a resource's `new` and `edit` pages,
5
+ and renders all form fields for a resource's editable attributes.
6
+
7
+ ## Local variables:
8
+
9
+ - `page`:
10
+ An instance of [Administrate::Page::Form][1].
11
+ Contains helper methods to display a form,
12
+ and knows which attributes should be displayed in the resource's form.
13
+
14
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
15
+ %>
16
+
17
+ <%= form_for([namespace, page.resource], html: { class: "form" }) do |f| %>
18
+ <% if page.resource.errors.any? %>
19
+ <div id="error_explanation">
20
+ <h2>
21
+ <%= t(
22
+ "administrate.form.errors",
23
+ pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
24
+ resource_name: display_resource_name(page.resource_name)
25
+ ) %>
26
+ </h2>
27
+
28
+ <ul>
29
+ <% page.resource.errors.full_messages.each do |message| %>
30
+ <li class="flash-error"><%= message %></li>
31
+ <% end %>
32
+ </ul>
33
+ </div>
34
+ <% end %>
35
+
36
+ <% page.attributes.each do |attribute| -%>
37
+ <div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
38
+ <%= render_field attribute, f: f %>
39
+ </div>
40
+ <% end -%>
41
+
42
+ <div class="form-actions">
43
+ <%= f.submit %>
44
+ </div>
45
+ <% end %>
@@ -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>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ # Javascript Partial
3
+
4
+ This partial imports the necessary javascript on each page.
5
+ By default, it includes the application JS,
6
+ but each page can define additional JS sources
7
+ by providing a `content_for(:javascript)` block.
8
+ %>
9
+
10
+ <% Administrate::Engine.javascripts.each do |js_path| %>
11
+ <%= javascript_include_tag js_path %>
12
+ <% end %>
13
+
14
+ <%= yield :javascript %>
15
+
16
+ <% if Rails.env.test? %>
17
+ <%= javascript_tag do %>
18
+ $.fx.off = true;
19
+ $.ajaxSetup({ async: false });
20
+ <% end %>
21
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <%#
2
+ # Navigation
3
+
4
+ This partial is used to display the navigation in Administrate.
5
+ By default, the navigation contains navigation links
6
+ for all resources in the admin dashboard,
7
+ as defined by the routes in the `admin/` namespace
8
+ %>
9
+
10
+ <nav class="navigation" role="navigation">
11
+ <%= link_to("Back to app", root_url, class: "button button--alt") if defined?(root_url) %>
12
+
13
+ <% Administrate::Namespace.new(namespace).resources_with_index_route.each do |resource| %>
14
+ <%= link_to(
15
+ display_resource_name(resource),
16
+ resource_index_route(resource),
17
+ class: "navigation__link navigation__link--#{nav_link_state(resource)}"
18
+ ) if valid_action? :index, resource %>
19
+ <% end %>
20
+ </nav>
@@ -0,0 +1,25 @@
1
+ <form class="search" role="search">
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 %>
25
+ </form>
@@ -0,0 +1,14 @@
1
+ <%#
2
+ # Stylesheet Partial
3
+
4
+ This partial imports the necessary stylesheets on each page.
5
+ By default, it includes the application CSS,
6
+ but each page can define additional CSS sources
7
+ by providing a `content_for(:stylesheet)` block.
8
+ %>
9
+
10
+ <% Administrate::Engine.stylesheets.each do |css_path| %>
11
+ <%= stylesheet_link_tag css_path %>
12
+ <% end %>
13
+
14
+ <%= yield :stylesheet %>
@@ -0,0 +1,36 @@
1
+ <%#
2
+ # Edit
3
+
4
+ This view is the template for the edit page.
5
+
6
+ It displays a header, and renders the `_form` partial to do the heavy lifting.
7
+
8
+ ## Local variables:
9
+
10
+ - `page`:
11
+ An instance of [Administrate::Page::Form][1].
12
+ Contains helper methods to help display a form,
13
+ and knows which attributes should be displayed in the resource's form.
14
+
15
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
16
+ %>
17
+
18
+ <% content_for(:title) { t("administrate.actions.edit_resource", name: page.page_title) } %>
19
+
20
+ <header class="main-content__header" role="banner">
21
+ <h1 class="main-content__page-title">
22
+ <%= content_for(:title) %>
23
+ </h1>
24
+
25
+ <div>
26
+ <%= link_to(
27
+ t("administrate.actions.show_resource", name: page.page_title),
28
+ [namespace, page.resource],
29
+ class: "button",
30
+ ) if valid_action?(:show) && show_action?(:show, page.resource) %>
31
+ </div>
32
+ </header>
33
+
34
+ <section class="main-content__body">
35
+ <%= render "form", page: page %>
36
+ </section>
@@ -0,0 +1,66 @@
1
+ <%#
2
+ # Index
3
+
4
+ This view is the template for the index page.
5
+ It is responsible for rendering the search bar, header and pagination.
6
+ It renders the `_table` partial to display details about the resources.
7
+
8
+ ## Local variables:
9
+
10
+ - `page`:
11
+ An instance of [Administrate::Page::Collection][1].
12
+ Contains helper methods to help display a table,
13
+ and knows which attributes should be displayed in the resource's table.
14
+ - `resources`:
15
+ An instance of `ActiveRecord::Relation` containing the resources
16
+ that match the user's search criteria.
17
+ By default, these resources are passed to the table partial to be displayed.
18
+ - `search_term`:
19
+ A string containing the term the user has searched for, if any.
20
+ - `show_search_bar`:
21
+ A boolean that determines if the search bar should be shown.
22
+
23
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
24
+ %>
25
+
26
+ <% content_for(:title) do %>
27
+ <%= display_resource_name(page.resource_name) %>
28
+ <% end %>
29
+
30
+ <header class="main-content__header" role="banner">
31
+ <h1 class="main-content__page-title" id="page-title">
32
+ <%= content_for(:title) %>
33
+ </h1>
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
+
43
+ <div>
44
+ <%= link_to(
45
+ t(
46
+ "administrate.actions.new_resource",
47
+ name: page.resource_name.titleize.downcase
48
+ ),
49
+ [:new, namespace, page.resource_path],
50
+ class: "button",
51
+ ) if valid_action?(:new) && show_action?(:new, new_resource) %>
52
+ </div>
53
+ </header>
54
+
55
+ <section class="main-content__body main-content__body--flush">
56
+ <%= render(
57
+ "collection",
58
+ collection_presenter: page,
59
+ collection_field_name: resource_name,
60
+ page: page,
61
+ resources: resources,
62
+ table_title: "page-title"
63
+ ) %>
64
+
65
+ <%= paginate resources %>
66
+ </section>