98 lines
4.0 KiB
ERB
98 lines
4.0 KiB
ERB
<%#
|
|
# Collection
|
|
|
|
This partial is used on the `index` and `show` pages
|
|
to display a collection of resources in an HTML table.
|
|
|
|
## Local variables:
|
|
|
|
- `collection_presenter`:
|
|
An instance of [Administrate::Page::Collection][1].
|
|
The table presenter uses `ResourceDashboard::COLLECTION_ATTRIBUTES` to determine
|
|
the columns displayed in the table
|
|
- `resources`:
|
|
An ActiveModel::Relation collection of resources to be displayed in the table.
|
|
By default, the number of resources is limited by pagination
|
|
or by a hard limit to prevent excessive page load times
|
|
|
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
|
|
%>
|
|
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full" aria-labelledby="<%= table_title %>">
|
|
<thead class="border-b border-n-weak">
|
|
<tr>
|
|
<% collection_presenter.attribute_types.each_with_index do |(attr_name, attr_type), index| %>
|
|
<th class="text-left py-3 px-4 text-sm text-n-slate-11 first:!pl-3 last:!pr-3"
|
|
scope="col"
|
|
role="columnheader"
|
|
aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
|
|
<%= link_to(sanitized_order_params(page, collection_field_name).merge(
|
|
collection_presenter.order_params_for(attr_name, key: collection_field_name)
|
|
), class: "inline-flex items-center gap-1 hover:text-n-slate-12") do %>
|
|
<%= t(
|
|
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
|
|
default: attr_name.to_s,
|
|
).titleize %>
|
|
<% if collection_presenter.ordered_by?(attr_name) %>
|
|
<span class="<%= collection_presenter.ordered_html_class(attr_name) == 'asc' ? '' : 'rotate-180' %>">
|
|
<svg class="w-3 h-3" aria-hidden="true">
|
|
<use xlink:href="#icon-up-caret" />
|
|
</svg>
|
|
</span>
|
|
<% end %>
|
|
<% end %>
|
|
</th>
|
|
<% end %>
|
|
<% if existing_action?(collection_presenter.resource_name, :edit) %>
|
|
<th scope="col"></th>
|
|
<% end %>
|
|
<% if existing_action?(collection_presenter.resource_name, :destroy) %>
|
|
<th scope="col" class="pr-3"></th>
|
|
<% end %>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody class="divide-y divide-n-weak">
|
|
<% resources.each do |resource| %>
|
|
<tr class="js-table-row hover:bg-n-alpha-1 transition-colors"
|
|
tabindex="0"
|
|
<% if existing_action? collection_presenter.resource_name, :show %>
|
|
<%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) %>
|
|
<% end %>
|
|
>
|
|
<% collection_presenter.attributes_for(resource).each_with_index do |attribute, index| %>
|
|
<td class="py-4 px-4 text-sm text-n-slate-12 first:!pl-3 last:!pr-3">
|
|
<% if authorized_action? resource, :show -%>
|
|
<a href="<%= polymorphic_path([namespace, resource]) -%>"
|
|
class="hover:underline"
|
|
>
|
|
<%= render_field attribute %>
|
|
</a>
|
|
<% end -%>
|
|
</td>
|
|
<% end %>
|
|
|
|
<% if existing_action?(collection_presenter.resource_name, :edit) %>
|
|
<td class="py-4 px-4 text-right"><%= link_to(
|
|
t("administrate.actions.edit"),
|
|
[:edit, namespace, resource],
|
|
class: "text-sm font-medium text-n-brand hover:underline",
|
|
) if authorized_action? resource, :edit%></td>
|
|
<% end %>
|
|
|
|
<% if existing_action?(collection_presenter.resource_name, :destroy) %>
|
|
<td class="py-4 px-4 !pr-3 text-right"><%= link_to(
|
|
t("administrate.actions.destroy"),
|
|
[namespace, resource],
|
|
class: "text-sm font-medium text-n-ruby-11 hover:underline",
|
|
method: :delete,
|
|
data: { confirm: t("administrate.actions.confirm") }
|
|
) if authorized_action? resource, :destroy %></td>
|
|
<% end %>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|