Skip to content

Commit 9fd6207

Browse files
committed
split index template
1 parent b8d4885 commit 9fd6207

9 files changed

+134
-84
lines changed

app/views/administrate/application/_collection.html.erb

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,22 @@ to display a collection of resources in an HTML table.
1717
1818
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
1919
%>
20+
<%# locals: (collection_presenter:, collection_field_name:, page:, resources:, table_title:, resource_class: nil) %>
2021

2122
<table aria-labelledby="<%= table_title %>" data-controller="table" data-action="click->table#visitDataUrl keydown->table#visitDataUrl">
2223
<thead>
2324
<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-
<% if attr_type.sortable? %>
31-
aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>"
32-
<% end %>
33-
>
34-
<% if attr_type.sortable? %>
35-
<%= link_to(params: sanitized_order_params(page, collection_field_name).merge(
36-
collection_presenter.order_params_for(attr_name, key: collection_field_name)
37-
)) do %>
38-
<%= t(
39-
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
40-
default: resource_class.human_attribute_name(attr_name).titleize,
41-
) %>
42-
<% if collection_presenter.ordered_by?(attr_name) %>
43-
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
44-
<svg aria-hidden="true">
45-
<use xlink:href="#icon-up-caret" />
46-
</svg>
47-
</span>
48-
<% end %>
49-
<% end %>
50-
<% else %>
51-
<%= t(
52-
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
53-
default: resource_class.human_attribute_name(attr_name).titleize,
54-
) %>
55-
<% end %>
56-
</th>
57-
<% end %>
25+
<%= render(
26+
partial: 'collection_header_item',
27+
layout: 'collection_header_item_layout',
28+
collection: collection_presenter.attribute_types.to_a,
29+
as: :attribute_type,
30+
locals: {
31+
collection_presenter: collection_presenter,
32+
collection_field_name: collection_field_name,
33+
page: page
34+
}
35+
) %>
5836
<%= render(
5937
"collection_header_actions",
6038
collection_presenter: collection_presenter,
@@ -66,37 +44,16 @@ to display a collection of resources in an HTML table.
6644
</thead>
6745

6846
<tbody>
69-
<% resources.each do |resource| %>
70-
<tr class="js-table-row"
71-
<% if accessible_action?(resource, :show) %>
72-
<%= %(tabindex=0 data-url=#{polymorphic_path([namespace, resource])}) %>
73-
<% end %>
74-
>
75-
<% collection_presenter.attributes_for(resource).each do |attribute| %>
76-
<td class="cell-data cell-data--<%= attribute.html_class %>">
77-
<% if accessible_action?(resource, :show) -%>
78-
<a href="<%= polymorphic_path([namespace, resource]) -%>"
79-
tabindex="-1"
80-
class="action-show"
81-
>
82-
<%= render_field attribute %>
83-
</a>
84-
<% else %>
85-
<%= render_field attribute %>
86-
<% end -%>
87-
</td>
88-
<% end %>
89-
90-
<%= render(
91-
"collection_item_actions",
92-
collection_presenter: collection_presenter,
93-
collection_field_name: collection_field_name,
94-
page: page,
95-
namespace: namespace,
96-
resource: resource,
97-
table_title: "page-title"
98-
) %>
99-
</tr>
100-
<% end %>
47+
<%= render(
48+
partial: "collection_item",
49+
layout: "collection_item_layout",
50+
collection: resources,
51+
as: :resource,
52+
locals: {
53+
collection_presenter: collection_presenter,
54+
collection_field_name: collection_field_name,
55+
page: page
56+
}
57+
) %>
10158
</tbody>
10259
</table>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, resource:, attribute:, attribute_counter: nil, attribute_iteration: nil) %>
2+
3+
<% if accessible_action?(resource, :show) -%>
4+
<a href="<%= polymorphic_path([namespace, resource]) -%>"
5+
tabindex="-1"
6+
class="action-show"
7+
>
8+
<%= render_field attribute %>
9+
</a>
10+
<% else %>
11+
<%= render_field attribute %>
12+
<% end -%>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, resource:, attribute:, attribute_counter: nil, attribute_iteration: nil) %>
2+
3+
<td class="cell-data cell-data--<%= attribute.html_class %>">
4+
<%= yield %>
5+
</td>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, attribute_type:, attribute_type_counter: nil, attribute_type_iteration: nil) %>
2+
<% attr_name = attribute_type.first %>
3+
<% attr_type = attribute_type.second %>
4+
5+
<% if attr_type.sortable? %>
6+
<%= link_to(params: sanitized_order_params(page, collection_field_name).merge(
7+
collection_presenter.order_params_for(attr_name, key: collection_field_name)
8+
)) do %>
9+
<%= t(
10+
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
11+
default: resource_class.human_attribute_name(attr_name).titleize,
12+
) %>
13+
<% if collection_presenter.ordered_by?(attr_name) %>
14+
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
15+
<svg aria-hidden="true">
16+
<use xlink:href="#icon-up-caret" />
17+
</svg>
18+
</span>
19+
<% end %>
20+
<% end %>
21+
<% else %>
22+
<%= t(
23+
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
24+
default: resource_class.human_attribute_name(attr_name).titleize,
25+
) %>
26+
<% end %>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, attribute_type:, attribute_type_counter: nil, attribute_type_iteration: nil) %>
2+
<% attr_name = attribute_type.first %>
3+
<% attr_type = attribute_type.second %>
4+
5+
<th class="cell-label
6+
cell-label--<%= attr_type.html_class %>
7+
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
8+
cell-label--<%= "#{collection_presenter.resource_name}_#{attr_name}" %>"
9+
scope="col"
10+
<% if attr_type.sortable? %>
11+
aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>"
12+
<% end %>
13+
>
14+
<%= yield %>
15+
</th>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, resource:, resource_counter:, resource_iteration:) %>
2+
3+
<%= render(
4+
partial: "collection_field_item",
5+
layout: "collection_field_item_layout",
6+
collection: collection_presenter.attributes_for(resource),
7+
as: :attribute,
8+
locals: {
9+
collection_presenter: collection_presenter,
10+
collection_field_name: collection_field_name,
11+
page: page,
12+
resource: resource
13+
}
14+
) %>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<%# locals: (collection_presenter:, collection_field_name:, page:, resource:, resource_counter:, resource_iteration:) %>
2+
3+
<tr class="js-table-row"
4+
<% if accessible_action?(resource, :show) %>
5+
<%= %(tabindex=0 data-url=#{polymorphic_path([namespace, resource])}) %>
6+
<% end %>
7+
>
8+
9+
<%= yield %>
10+
11+
<%= render(
12+
"collection_item_actions",
13+
collection_presenter: collection_presenter,
14+
collection_field_name: collection_field_name,
15+
page: page,
16+
namespace: namespace,
17+
resource: resource
18+
) %>
19+
</tr>

app/views/administrate/application/_index_header.html.erb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,7 @@
1616
resource_name: display_resource_name(page.resource_name)
1717
) %>
1818

19-
<% if filters.any? %>
20-
<div data-controller="tooltip">
21-
<button data-tooltip-target="tooltip" popovertarget="search-tooltip" class="button--tooltip search__tooltip">
22-
<svg role="img">
23-
<use xlink:href="#icon-question-mark" />
24-
</svg>
25-
</button>
26-
27-
<div data-tooltip-target="popover" popover id="search-tooltip" role="tooltip" class="search__tooltip-popover search__tooltip-popover-positioning">
28-
<p><strong>Use filters to refine your search</strong></p>
29-
<ul>
30-
<% filters.keys.each do |filter_key| %>
31-
<li><%= filter_key %>:<span class="search__tooltip-popover-value">&lt;value&gt;</span></li>
32-
<% end %>
33-
</ul>
34-
</div>
35-
</div>
36-
<% end %>
19+
<%= render "search_tooltip", page: page, filters: filters %>
3720
<% end %>
3821

3922
<div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<%# locals: (page:, filters:) %>
2+
<% return if filters.empty? %>
3+
4+
<div data-controller="tooltip">
5+
<button data-tooltip-target="tooltip" popovertarget="search-tooltip" class="button--tooltip search__tooltip">
6+
<svg role="img">
7+
<use xlink:href="#icon-question-mark" />
8+
</svg>
9+
</button>
10+
11+
<div data-tooltip-target="popover" popover id="search-tooltip" role="tooltip" class="search__tooltip-popover search__tooltip-popover-positioning">
12+
<p><strong>Use filters to refine your search</strong></p>
13+
<ul>
14+
<% filters.keys.each do |filter_key| %>
15+
<li><%= filter_key %>:<span class="search__tooltip-popover-value">&lt;value&gt;</span></li>
16+
<% end %>
17+
</ul>
18+
</div>
19+
</div>

0 commit comments

Comments
 (0)