Skip to content

Commit

Permalink
Fix service admin views
Browse files Browse the repository at this point in the history
  • Loading branch information
aliciapaz committed Jan 11, 2025
1 parent 2ceddcf commit 23eb8ad
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 84 deletions.
6 changes: 2 additions & 4 deletions app/controllers/admin/services_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

module Admin
class ServicesController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
Expand Down Expand Up @@ -38,11 +36,11 @@ class ServicesController < Admin::ApplicationController
#
# def resource_params
# params.require(resource_class.model_name.param_key).
# permit(dashboard.permitted_attributes).
# permit(dashboard.permitted_attributes(action_name)).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
# for more information
end
end
8 changes: 1 addition & 7 deletions app/dashboards/service_dashboard.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

require "administrate/base_dashboard"

class ServiceDashboard < Administrate::BaseDashboard
Expand All @@ -10,10 +8,10 @@ class ServiceDashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
cause: Field::BelongsTo,
location_services: Field::HasMany,
locations: Field::HasMany,
id: Field::Number,
name: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime
Expand Down Expand Up @@ -62,8 +60,4 @@ class ServiceDashboard < Administrate::BaseDashboard
# def display_resource(service)
# "Service ##{service.id}"
# end

def display_resource(service)
service.name
end
end
49 changes: 22 additions & 27 deletions app/views/admin/services/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ to display a collection of resources in an HTML table.
<% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
<th class="cell-label
cell-label--<%= attr_type.html_class %>
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>"
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
cell-label--<%= "#{collection_presenter.resource_name}_#{attr_name}" %>"
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)
)) do %>
<%= t(
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
default: resource_class.human_attribute_name(attr_name),
).titleize %>
default: resource_class.human_attribute_name(attr_name).titleize,
) %>
<% if collection_presenter.ordered_by?(attr_name) %>
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
<svg aria-hidden="true">
Expand All @@ -45,23 +45,26 @@ to display a collection of resources in an HTML table.
<% end %>
</th>
<% end %>
<% [valid_action?(:edit, collection_presenter.resource_name),
valid_action?(:destroy, collection_presenter.resource_name)].count(true).times do %>
<th scope="col"></th>
<% end %>
<%= render(
"collection_header_actions",
collection_presenter: collection_presenter,
page: page,
resources: resources,
table_title: "page-title"
) %>
</tr>
</thead>

<tbody>
<% resources.each do |resource| %>
<tr class="js-table-row"
<% if show_action? :show, resource %>
<% if accessible_action?(resource, :show) %>
<%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
<% end %>
>
<% collection_presenter.attributes_for(resource).each do |attribute| %>
<td class="cell-data cell-data--<%= attribute.html_class %>">
<% if show_action? :show, resource -%>
<% if accessible_action?(resource, :show) -%>
<a href="<%= polymorphic_path([namespace, resource]) -%>"
tabindex="-1"
class="action-show"
Expand All @@ -74,23 +77,15 @@ to display a collection of resources in an HTML table.
</td>
<% end %>

<% if valid_action? :edit, collection_presenter.resource_name %>
<td><%= link_to(
t("administrate.actions.edit"),
[:edit, namespace, resource],
class: "action-edit",
) if show_action? :edit, resource%></td>
<% end %>

<% if valid_action? :destroy, collection_presenter.resource_name %>
<td><%= link_to(
t("administrate.actions.destroy"),
[namespace, resource],
class: "text-color-red",
method: :delete,
data: { confirm: t("administrate.actions.confirm") }
) if show_action? :destroy, resource %></td>
<% end %>
<%= render(
"collection_item_actions",
collection_presenter: collection_presenter,
collection_field_name: collection_field_name,
page: page,
namespace: namespace,
resource: resource,
table_title: "page-title"
) %>
</tr>
<% end %>
</tbody>
Expand Down
23 changes: 19 additions & 4 deletions app/views/admin/services/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ and renders all form fields for a resource's editable attributes.
</div>
<% end %>

<% page.attributes.each do |attribute| -%>
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
<%= render_field attribute, f: f %>
</div>
<% page.attributes(controller.action_name).each do |title, attributes| -%>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{f.object_name}.#{title}", default: title %></legend>
<% end %>

<% attributes.each do |attribute| %>
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
<%= render_field attribute, f: f %>

<% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %>
<% if I18n.exists?(hint_key) -%>
<div class="field-unit__hint">
<%= I18n.t(hint_key) %>
</div>
<% end -%>
</div>
<% end %>
</fieldset>
<% end -%>

<div class="form-actions">
Expand Down
38 changes: 9 additions & 29 deletions app/views/admin/services/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,14 @@ It renders the `_table` partial to display details about the resources.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>

<% content_for(:title) do %>
<%= display_resource_name(page.resource_name) %>
<% end %>

<header class="main-content__header" role="banner">
<h1 class="main-content__page-title" id="page-title">
<%= content_for(:title) %>
</h1>

<% if show_search_bar %>
<%= render(
"search",
search_term: search_term,
resource_name: display_resource_name(page.resource_name)
) %>
<% end %>

<div>
<%= link_to(
t(
"administrate.actions.new_resource",
name: display_resource_name(page.resource_name, singular: true).downcase
),
[:new, namespace, page.resource_path.to_sym],
class: "button",
) if valid_action?(:new) && show_action?(:new, new_resource) %>
</div>
</header>
<%=
render("index_header",
resources: resources,
search_term: search_term,
page: page,
show_search_bar: show_search_bar,
)
%>

<section class="main-content__body main-content__body--flush">
<%= render(
Expand All @@ -62,5 +42,5 @@ It renders the `_table` partial to display details about the resources.
table_title: "page-title"
) %>

<%= paginate resources, param_name: '_page' %>
<%= render("pagination", resources: resources) %>
</section>
2 changes: 1 addition & 1 deletion app/views/admin/services/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ to do the heavy lifting.
) %>
<% end %>

<header class="main-content__header" role="banner">
<header class="main-content__header">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
Expand Down
40 changes: 28 additions & 12 deletions app/views/admin/services/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ as well as a link to its edit page.

<% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>

<header class="main-content__header" role="banner">
<header class="main-content__header">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
Expand All @@ -28,22 +28,38 @@ as well as a link to its edit page.
t("administrate.actions.edit_resource", name: page.page_title),
[:edit, namespace, page.resource],
class: "button",
) if valid_action?(:edit) && show_action?(:edit, page.resource) %>
) if accessible_action?(page.resource, :edit) %>

<%= link_to(
t("administrate.actions.destroy"),
[namespace, page.resource],
class: "button button--danger",
method: :delete,
data: { confirm: t("administrate.actions.confirm") }
) if accessible_action?(page.resource, :destroy) %>
</div>
</header>

<section class="main-content__body">
<dl>
<% page.attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% page.attributes.each do |title, attributes| %>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{page.resource_name}.#{title}", default: title %></legend>
<% end %>

<% attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% end %>
</fieldset>
<% end %>
</dl>
</section>

0 comments on commit 23eb8ad

Please sign in to comment.