Skip to content

Commit 7dc0188

Browse files
authored
Merge pull request #24 from goosys/wip/issue-12
Wip/issue 12
2 parents 93be798 + f2d238c commit 7dc0188

23 files changed

+609
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
cell-label--<%= "#{collection_presenter.resource_name}_#{attr_name}" %>"
29+
scope="col"
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: resource_class.human_attribute_name(attr_name).titleize,
37+
) %>
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+
<%= render(
49+
"collection_header_actions",
50+
collection_presenter: collection_presenter,
51+
page: page,
52+
resources: resources,
53+
table_title: "page-title"
54+
) %>
55+
</tr>
56+
</thead>
57+
58+
<tbody>
59+
<% resources.each do |resource| %>
60+
<tr class="js-table-row"
61+
<% if accessible_action?(resource, :show) %>
62+
<%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
63+
<% end %>
64+
>
65+
<% collection_presenter.attributes_for(resource).each do |attribute| %>
66+
<td class="cell-data cell-data--<%= attribute.html_class %>">
67+
<% if accessible_action?(resource, :show) -%>
68+
<a href="<%= polymorphic_path([namespace, resource]) -%>"
69+
tabindex="-1"
70+
class="action-show"
71+
>
72+
<%= render_field attribute %>
73+
</a>
74+
<% else %>
75+
<%= render_field attribute %>
76+
<% end -%>
77+
</td>
78+
<% end %>
79+
80+
<%= render(
81+
"collection_item_actions",
82+
collection_presenter: collection_presenter,
83+
collection_field_name: collection_field_name,
84+
page: page,
85+
namespace: namespace,
86+
resource: resource,
87+
table_title: "page-title"
88+
) %>
89+
</tr>
90+
<% end %>
91+
</tbody>
92+
</table>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<% [existing_action?(collection_presenter.resource_name, :edit),
2+
existing_action?(collection_presenter.resource_name, :destroy)].count(true).times do %>
3+
<th scope="col"></th>
4+
<% end %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<% if existing_action?(collection_presenter.resource_name, :edit) %>
2+
<td><%= link_to(
3+
t("administrate.actions.edit"),
4+
[:edit, namespace, resource],
5+
class: "action-edit",
6+
) if accessible_action?(resource, :edit) %></td>
7+
<% end %>
8+
9+
<% if existing_action?(collection_presenter.resource_name, :destroy) %>
10+
<td><%= link_to(
11+
t("administrate.actions.destroy"),
12+
[namespace, resource],
13+
class: "text-color-red",
14+
method: :delete,
15+
data: { confirm: t("administrate.actions.confirm") }
16+
) if accessible_action?(resource, :destroy) %></td>
17+
<% end %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<% next unless value.respond_to?(:html_safe) %>
18+
<div class="flash flash-<%= key %>"><%= value.html_safe %></div>
19+
<% end -%>
20+
</div>
21+
<% end %>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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, singular: true)
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(controller.action_name).each do |title, attributes| -%>
37+
<fieldset class="<%= "field-unit--nested" if title.present? %>">
38+
<% if title.present? %>
39+
<legend><%= t "helpers.label.#{f.object_name}.#{title}", default: title %></legend>
40+
<% end %>
41+
42+
<% attributes.each do |attribute| %>
43+
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
44+
<%= render_field attribute, f: f %>
45+
46+
<% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %>
47+
<% if I18n.exists?(hint_key) -%>
48+
<div class="field-unit__hint">
49+
<%= I18n.t(hint_key) %>
50+
</div>
51+
<% end -%>
52+
</div>
53+
<% end %>
54+
</fieldset>
55+
<% end -%>
56+
57+
<div class="form-actions">
58+
<%= f.submit %>
59+
</div>
60+
<% end %>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<svg hidden xmlns="http://www.w3.org/2000/svg">
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>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<% content_for(:title) do %>
2+
<%= display_resource_name(page.resource_name) %>
3+
<% end %>
4+
5+
<header class="main-content__header">
6+
<h1 class="main-content__page-title" id="page-title">
7+
<%= content_for(:title) %>
8+
</h1>
9+
10+
<% if show_search_bar %>
11+
<%= render(
12+
"search",
13+
search_term: search_term,
14+
resource_name: display_resource_name(page.resource_name)
15+
) %>
16+
<% end %>
17+
18+
<div>
19+
<%= link_to(
20+
t(
21+
"administrate.actions.new_resource",
22+
name: display_resource_name(page.resource_name, singular: true).downcase
23+
),
24+
[:new, namespace, page.resource_path.to_sym],
25+
class: "button",
26+
) if accessible_action?(new_resource, :new) %>
27+
</div>
28+
</header>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 %>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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">
11+
<%= link_to(t("administrate.navigation.back_to_app"), root_url, class: "button button--alt button--nav") 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 accessible_action?(model_from_resource(resource), :index) %>
19+
<% end %>
20+
</nav>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= paginate resources, param_name: local_assigns.fetch(:param_name, "_page") %>

0 commit comments

Comments
 (0)