[Fix #1098] Using custom views to remove edit and delete button from index

This can be reverted when Administrate gem will include this fix : https://github.com/thoughtbot/administrate/pull/597 (>=0.5.0)
This commit is contained in:
Mathieu Magnin 2018-01-08 17:40:09 +01:00
parent d0de9b9ae2
commit 65f0859357
3 changed files with 105 additions and 0 deletions

View file

@ -0,0 +1,38 @@
-# # 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
%table.collection-data{ "aria-labelledby": "page-title" }
%thead
%tr
- collection_presenter.attribute_types.each do |attr_name, attr_type|
%th.cell-label{ class: "cell-label--#{attr_type.html_class} cell-label--#{collection_presenter.ordered_html_class(attr_name)}", scope: "col" }
= link_to(sanitized_order_params.merge(collection_presenter.order_params_for(attr_name))) do
= t("helpers.label.#{resource_name}.#{attr_name}", default: attr_name.to_s).titleize
- if collection_presenter.ordered_by?(attr_name)
%span.cell-label__sort-indicator{ class: "cell-label__sort-indicator--#{collection_presenter.ordered_html_class(attr_name)}" }
= svg_tag("administrate/sort_arrow.svg", "sort_arrow", width: "13", height: "13")
%th{ colspan: "2", scope: "col" }
%tbody
- resources.each do |resource|
%tr.table__row{ role: "link", tabindex: "0", "data-url": polymorphic_path([namespace, resource]) }
- collection_presenter.attributes_for(resource).each do |attribute|
%td.cell-data{ class: "cell-data--#{attribute.html_class}" }
= link_to polymorphic_path([namespace, resource]), class: "action-show table__link-plain" do
= render_field attribute

View file

@ -0,0 +1,38 @@
-# # Index
-#
-# This view is the template for the index page.
-# It is responsible for rendering the search bar, header and pagination.
-# It renders the `_table` partial to display details about the resources.
-#
-# ## Local variables:
-#
-# - `page`:
-# An instance of [Administrate::Page::Collection][1].
-# Contains helper methods to help display a table,
-# and knows which attributes should be displayed in the resource's table.
-# - `resources`:
-# An instance of `ActiveRecord::Relation` containing the resources
-# that match the user's search criteria.
-# By default, these resources are passed to the table partial to be displayed.
-# - `search_term`:
-# A string containing the term the user has searched for, if any.
-# - `show_search_bar`:
-# A boolean that determines if the search bar should be shown.
-#
-# [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
- content_for(:title) do
= display_resource_name(page.resource_name)
- content_for(:search) do
- if show_search_bar
= render "search", search_term: search_term
%header.header
%h1.header__heading#page-title
= content_for(:title)
.header__actions
= render "collection", collection_presenter: page, resources: resources
= paginate resources

View file

@ -0,0 +1,29 @@
-# # Show
-#
-# This view is the template for the show page.
-# It renders the attributes of a resource,
-# as well as a link to its edit page.
-#
-# ## Local variables:
-#
-# - `page`:
-# An instance of [Administrate::Page::Show][1].
-# Contains methods for accessing the resource to be displayed on the page,
-# as well as helpers for describing how each attribute of the resource
-# should be displayed.
-#
-# [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
- content_for(:title) { page.page_title }
%header.header
%h1.header__heading= content_for(:title)
.header__actions
%dl
- page.attributes.each do |attribute|
%dt.attribute-label
= t("helpers.label.#{resource_name}.#{attribute.name}", default: attribute.name.titleize)
%dd.attribute-data{ class: "attribute-data--#{attribute.html_class}" }
= render_field attribute