From 23eb8ad6de4d889cc6564612769d970208ca219d Mon Sep 17 00:00:00 2001 From: Alicia Date: Sat, 11 Jan 2025 14:03:57 -0600 Subject: [PATCH 1/3] Fix service admin views --- app/controllers/admin/services_controller.rb | 6 +-- app/dashboards/service_dashboard.rb | 8 +-- app/views/admin/services/_collection.html.erb | 49 +++++++++---------- app/views/admin/services/_form.html.erb | 23 +++++++-- app/views/admin/services/index.html.erb | 38 ++++---------- app/views/admin/services/new.html.erb | 2 +- app/views/admin/services/show.html.erb | 40 ++++++++++----- 7 files changed, 82 insertions(+), 84 deletions(-) diff --git a/app/controllers/admin/services_controller.rb b/app/controllers/admin/services_controller.rb index 64fa2f0e9..64535cbbe 100644 --- a/app/controllers/admin/services_controller.rb +++ b/app/controllers/admin/services_controller.rb @@ -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 @@ -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 diff --git a/app/dashboards/service_dashboard.rb b/app/dashboards/service_dashboard.rb index 3dde3cd7b..ef70b6a45 100644 --- a/app/dashboards/service_dashboard.rb +++ b/app/dashboards/service_dashboard.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require "administrate/base_dashboard" class ServiceDashboard < Administrate::BaseDashboard @@ -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 @@ -62,8 +60,4 @@ class ServiceDashboard < Administrate::BaseDashboard # def display_resource(service) # "Service ##{service.id}" # end - - def display_resource(service) - service.name - end end diff --git a/app/views/admin/services/_collection.html.erb b/app/views/admin/services/_collection.html.erb index 1a3915eff..fafe8b01f 100644 --- a/app/views/admin/services/_collection.html.erb +++ b/app/views/admin/services/_collection.html.erb @@ -24,17 +24,17 @@ to display a collection of resources in an HTML table. <% collection_presenter.attribute_types.each do |attr_name, attr_type| %> + 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) %>
- <%= render_field attribute, f: f %> -
+ <% page.attributes(controller.action_name).each do |title, attributes| -%> +
"> + <% if title.present? %> + <%= t "helpers.label.#{f.object_name}.#{title}", default: title %> + <% end %> + + <% attributes.each do |attribute| %> +
+ <%= render_field attribute, f: f %> + + <% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %> + <% if I18n.exists?(hint_key) -%> +
+ <%= I18n.t(hint_key) %> +
+ <% end -%> +
+ <% end %> +
<% end -%>
diff --git a/app/views/admin/services/index.html.erb b/app/views/admin/services/index.html.erb index cd956b8a5..b4754b9d3 100644 --- a/app/views/admin/services/index.html.erb +++ b/app/views/admin/services/index.html.erb @@ -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 %> - - +<%= + render("index_header", + resources: resources, + search_term: search_term, + page: page, + show_search_bar: show_search_bar, + ) +%>
<%= render( @@ -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) %>
diff --git a/app/views/admin/services/new.html.erb b/app/views/admin/services/new.html.erb index d90cc6800..adacff316 100644 --- a/app/views/admin/services/new.html.erb +++ b/app/views/admin/services/new.html.erb @@ -22,7 +22,7 @@ to do the heavy lifting. ) %> <% end %> -
- <% page.attributes.each do |attribute| %> -
- <%= t( - "helpers.label.#{resource_name}.#{attribute.name}", - default: page.resource.class.human_attribute_name(attribute.name), - ) %> -
- -
<%= render_field attribute, page: page %>
+ <% page.attributes.each do |title, attributes| %> +
"> + <% if title.present? %> + <%= t "helpers.label.#{page.resource_name}.#{title}", default: title %> + <% end %> + + <% attributes.each do |attribute| %> +
+ <%= t( + "helpers.label.#{resource_name}.#{attribute.name}", + default: page.resource.class.human_attribute_name(attribute.name), + ) %> +
+ +
<%= render_field attribute, page: page %>
+ <% end %> +
<% end %>
From 43013bbfbe551b0fa76b4a5e4ff5b35371032099 Mon Sep 17 00:00:00 2001 From: Alicia Date: Mon, 13 Jan 2025 20:28:22 -0600 Subject: [PATCH 2/3] Update has_one partials --- app/views/fields/has_one/_form.html.erb | 20 ++++++++++---- app/views/fields/has_one/_index.html.erb | 3 ++- app/views/fields/has_one/_show.html.erb | 33 ++++++++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/views/fields/has_one/_form.html.erb b/app/views/fields/has_one/_form.html.erb index 8bdfa53ee..01bd843d0 100644 --- a/app/views/fields/has_one/_form.html.erb +++ b/app/views/fields/has_one/_form.html.erb @@ -18,11 +18,21 @@ The form will be rendered as nested_from to parent relationship. <%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
- <%= t "helpers.label.#{f.object_name}.#{field.nested_form.resource_name}", default: field.nested_form.resource_name.titleize %> - <% field.nested_form.attributes.each do |attribute| -%> -
- <%= render_field attribute, f: has_one_f %> -
+ <%= t "helpers.label.#{f.object_name}.#{field.name}", default: field.name.titleize %> + <% field.nested_form.attributes.each do |title, attributes| -%> + +
"> + <% if title.present? %> + <%= t "helpers.label.#{f.object_name}.#{title}", default: title %> + <% end %> + + <% attributes.each do |attribute| %> +
+ <%= render_field attribute, f: has_one_f %> +
+ <% end %> +
+ <% end -%>
<% end %> diff --git a/app/views/fields/has_one/_index.html.erb b/app/views/fields/has_one/_index.html.erb index e6fc01a44..4ff3ad174 100644 --- a/app/views/fields/has_one/_index.html.erb +++ b/app/views/fields/has_one/_index.html.erb @@ -16,7 +16,8 @@ By default, the relationship is rendered as a link to the associated object. %> <% if field.linkable? %> - <%= link_to( + <%= link_to_if( + accessible_action?(field.data, :show), field.display_associated_resource, [namespace, field.data], ) %> diff --git a/app/views/fields/has_one/_show.html.erb b/app/views/fields/has_one/_show.html.erb index a4b3dc5fe..b8636f6ef 100644 --- a/app/views/fields/has_one/_show.html.erb +++ b/app/views/fields/has_one/_show.html.erb @@ -18,23 +18,30 @@ All show page attributes of has_one relationship would be rendered <% if field.linkable? %>
- <%= link_to( + <%= link_to_if( + accessible_action?(field.data, :show), field.display_associated_resource, [namespace, field.data], ) %> - <% field.nested_show.attributes.each do |attribute| -%> -
-
- <%= t( - "helpers.label.#{resource_name}.#{attribute.name}", - default: attribute.name.titleize, - ) %> -
-
- <%= render_field attribute, { page: page } %> -
-
+ <% field.nested_show.attributes.each do |title, attributes| -%> +
"> + <% if title.present? %> + <%= t "helpers.label.#{namespace}.#{title}", default: title %> + <% end %> + + <% attributes.each do |attribute| %> +
+ <%= t( + "helpers.label.#{field.associated_class_name.underscore}.#{attribute.name}", + default: attribute.name.titleize, + ) %> +
+
+ <%= render_field attribute, { page: page } %> +
+ <% end %> +
<% end -%>
<% end %> From 2f49e8c69cf0b888edb9cbdf73a12f38b3be4e78 Mon Sep 17 00:00:00 2001 From: Alicia Date: Mon, 13 Jan 2025 20:41:04 -0600 Subject: [PATCH 3/3] Fix org form --- .../admin/organizations/_collection.html.erb | 49 +++++++++---------- app/views/admin/organizations/_form.html.erb | 23 +++++++-- app/views/admin/organizations/edit.html.erb | 4 +- app/views/admin/organizations/index.html.erb | 3 +- app/views/admin/organizations/new.html.erb | 2 +- app/views/admin/organizations/show.html.erb | 47 +++++++++++------- config/clock.rb | 6 +-- 7 files changed, 78 insertions(+), 56 deletions(-) diff --git a/app/views/admin/organizations/_collection.html.erb b/app/views/admin/organizations/_collection.html.erb index 1a3915eff..fafe8b01f 100644 --- a/app/views/admin/organizations/_collection.html.erb +++ b/app/views/admin/organizations/_collection.html.erb @@ -24,17 +24,17 @@ to display a collection of resources in an HTML table. <% collection_presenter.attribute_types.each do |attr_name, attr_type| %> + 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) %>
- <%= render_field attribute, f: f %> -
+ <% page.attributes(controller.action_name).each do |title, attributes| -%> +
"> + <% if title.present? %> + <%= t "helpers.label.#{f.object_name}.#{title}", default: title %> + <% end %> + + <% attributes.each do |attribute| %> +
+ <%= render_field attribute, f: f %> + + <% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %> + <% if I18n.exists?(hint_key) -%> +
+ <%= I18n.t(hint_key) %> +
+ <% end -%> +
+ <% end %> +
<% end -%>
diff --git a/app/views/admin/organizations/edit.html.erb b/app/views/admin/organizations/edit.html.erb index abacffce4..6c7484551 100644 --- a/app/views/admin/organizations/edit.html.erb +++ b/app/views/admin/organizations/edit.html.erb @@ -17,7 +17,7 @@ It displays a header, and renders the `_form` partial to do the heavy lifting. <% content_for(:title) { t("administrate.actions.edit_resource", name: page.page_title) } %> -
diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 89d8dcf31..21a8e013d 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -58,5 +58,6 @@ It renders the `_table` partial to display details about the resources. resources: resources, table_title: "page-title" ) %> - <%= paginate resources, param_name: '_page' %> + + <%= render("pagination", resources: resources) %> diff --git a/app/views/admin/organizations/new.html.erb b/app/views/admin/organizations/new.html.erb index d90cc6800..adacff316 100644 --- a/app/views/admin/organizations/new.html.erb +++ b/app/views/admin/organizations/new.html.erb @@ -22,7 +22,7 @@ to do the heavy lifting. ) %> <% end %> -